diff --git a/bin/solid.pill b/bin/solid.pill index 1f07b5c38..bbd7d2c95 100644 --- a/bin/solid.pill +++ b/bin/solid.pill @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9701b98374a28ae99961871d4204856720e9ee6c3f769c389e6faf38392b95e7 -size 12715787 +oid sha256:8ebc16b420b2ce8e8bf7e6b0c611a102355f9ec013475da3cf66cc078f35e4b3 +size 12458781 diff --git a/pkg/arvo/app/chat-hook.hoon b/pkg/arvo/app/chat-hook.hoon index 47de70ffe..911d402d7 100644 --- a/pkg/arvo/app/chat-hook.hoon +++ b/pkg/arvo/app/chat-hook.hoon @@ -399,56 +399,31 @@ ^- (list card) ?> ?=(^ pax) =/ last (dec (lent pax)) - =/ backlog-start=(unit @ud) - %+ rush - (snag last `(list @ta)`pax) - dem:ag + =/ backlog-latest=(unit @ud) (rush (snag last `(list @ta)`pax) dem:ag) =/ pas `path`(oust [last 1] `(list @ta)`pax) ?> ?=([* ^] pas) ?> (~(has by synced) pas) - :: check if read is permitted ?> (is-permitted src.bol pas) + =/ envs envelopes:(need (chat-scry pas)) + =/ length (lent envs) + =/ latest + ?~ backlog-latest length + ?: (gth u.backlog-latest length) length + (sub length u.backlog-latest) + =. envs (scag latest envs) + =/ =vase !>([%messages pas 0 latest envs]) %- zing :~ [%give %fact ~ %chat-update !>([%create pas])]~ - ?. ?&(?=(^ backlog-start) (~(has by allow-history) pas)) ~ - (paginate-messages pas (need (chat-scry pas)) u.backlog-start) + ?. ?&(?=(^ backlog-latest) (~(has by allow-history) pas)) ~ + [%give %fact ~ %chat-update vase]~ [%give %kick [%backlog pax]~ `src.bol]~ == :: -++ paginate-messages - |= [=path =mailbox start=@ud] - ^- (list card) - =/ cards=(list card) ~ - =/ end (lent envelopes.mailbox) - ?: |((gte start end) =(end 0)) - cards - =. envelopes.mailbox (slag start `(list envelope)`envelopes.mailbox) - |- ^- (list card) - ?~ envelopes.mailbox - cards - ?: (lte end 5.000) - =. cards - %+ snoc cards - %- messages-fact - [path start (lent envelopes.mailbox) envelopes.mailbox] - $(envelopes.mailbox ~) - =. cards - %+ snoc cards - %- messages-fact - :^ path start - (add start 5.000) - (scag 5.000 `(list envelope)`envelopes.mailbox) - =: start (add start 5.000) - end (sub end 5.000) - == - $(envelopes.mailbox (slag 5.000 `(list envelope)`envelopes.mailbox)) -:: ++ fact-invite-update |= [wir=wire fact=invite-update] ^- (quip card _state) :_ state ?+ -.fact ~ - :: %accepted =/ ask-history ?~((chat-scry path.invite.fact) %.y %.n) =* shp ship.invite.fact @@ -644,11 +619,6 @@ ^- card [%pass / %agent [our.bol %invite-store] %poke %invite-action !>(act)] :: -++ messages-fact - |= [=path start=@ud end=@ud envelopes=(list envelope)] - ^- card - [%give %fact ~ %chat-update !>([%messages path start end envelopes])] -:: ++ sec-to-perm |= [pax=path =kind] ^- permission-action diff --git a/pkg/arvo/app/chat-store.hoon b/pkg/arvo/app/chat-store.hoon index b8629d169..16cb2990a 100644 --- a/pkg/arvo/app/chat-store.hoon +++ b/pkg/arvo/app/chat-store.hoon @@ -7,10 +7,12 @@ +$ versioned-state $% state-zero state-one + state-two == :: +$ state-zero [%0 =inbox] +$ state-one [%1 =inbox] ++$ state-two [%2 =inbox] :: +$ diff $% [%chat-initial inbox] @@ -19,7 +21,7 @@ == -- :: -=| state-one +=| state-two =* state - :: %- agent:dbug @@ -38,10 +40,14 @@ ++ on-load |= old-vase=vase =/ old !<(versioned-state old-vase) - ?: ?=(%1 -.old) + ?: ?=(%2 -.old) [~ this(state old)] - :_ this(state [%1 inbox.old]) - [%pass /lo-chst %agent [our.bowl %chat-hook] %poke %noun !>(%store-load)]~ + =/ reversed-inbox=^inbox + %- ~(run by inbox.old) + |= =mailbox + ^- ^mailbox + [config.mailbox (flop envelopes.mailbox)] + [~ this(state [%2 reversed-inbox])] :: ++ on-poke ~/ %chat-store-poke @@ -196,7 +202,7 @@ ?~ mailbox [~ state] =. letter.envelope.act (evaluate-letter [author letter]:envelope.act) - =^ envelope u.mailbox (append-envelope u.mailbox envelope.act) + =^ envelope u.mailbox (prepend-envelope u.mailbox envelope.act) :- (send-diff path.act act(envelope envelope)) state(inbox (~(put by inbox) path.act u.mailbox)) :: @@ -207,20 +213,16 @@ =/ mailbox=(unit mailbox) (~(get by inbox) path.act) ?~ mailbox [~ state] + =. envelopes.act (flop envelopes.act) =/ evaluated-envelopes=(list envelope) ~ |- ^- (quip card _state) ?~ envelopes.act :_ state(inbox (~(put by inbox) path.act u.mailbox)) %+ send-diff path.act - :* %messages - path.act - (sub length.config.u.mailbox (lent evaluated-envelopes)) - length.config.u.mailbox - evaluated-envelopes - == + [%messages path.act 0 (lent evaluated-envelopes) evaluated-envelopes] =. letter.i.envelopes.act (evaluate-letter [author letter]:i.envelopes.act) - =^ envelope u.mailbox (append-envelope u.mailbox i.envelopes.act) - =. evaluated-envelopes (snoc evaluated-envelopes envelope) + =^ envelope u.mailbox (prepend-envelope u.mailbox i.envelopes.act) + =. evaluated-envelopes [envelope evaluated-envelopes] $(envelopes.act t.envelopes.act) :: ++ handle-read @@ -246,12 +248,12 @@ letter(output (eval bol hoon)) letter :: -++ append-envelope +++ prepend-envelope |= [=mailbox =envelope] ^+ [envelope mailbox] =. number.envelope +(length.config.mailbox) =: length.config.mailbox +(length.config.mailbox) - envelopes.mailbox (snoc envelopes.mailbox envelope) + envelopes.mailbox [envelope envelopes.mailbox] == [envelope mailbox] :: diff --git a/pkg/arvo/app/chat-view.hoon b/pkg/arvo/app/chat-view.hoon index f9874ff5c..a967f791b 100644 --- a/pkg/arvo/app/chat-view.hoon +++ b/pkg/arvo/app/chat-view.hoon @@ -121,15 +121,7 @@ %- ~(run by inbox) |= =mailbox ^- ^mailbox - [config.mailbox (truncate-envelopes envelopes.mailbox)] - :: - ++ truncate-envelopes - |= envelopes=(list envelope) - ^- (list envelope) - =/ length (lent envelopes) - ?: (lth length message-limit) - envelopes - (slag (sub length message-limit) envelopes) + [config.mailbox (scag message-limit envelopes.mailbox)] -- :: ++ on-agent diff --git a/pkg/arvo/app/publish.hoon b/pkg/arvo/app/publish.hoon index 427da592e..857d578b3 100644 --- a/pkg/arvo/app/publish.hoon +++ b/pkg/arvo/app/publish.hoon @@ -52,14 +52,25 @@ :: +$ state-two $: our-paths=(list path) - books=(map @tas notebook) - subs=(map [@p @tas] notebook) + books=(map @tas notebook-2) + subs=(map [@p @tas] notebook-2) tile-num=@ud == :: ++$ state-three + $: our-paths=(list path) + books=(map [@p @tas] notebook) + tile-num=@ud + $= limbo + $: notes=(map [@p @tas @tas] note) + comments=(map [@p @tas @tas @da] comment) + == + == +:: +$ versioned-state $% [%1 state-two] [%2 state-two] + [%3 state-three] == :: +$ metadata-delta @@ -75,7 +86,7 @@ == -- :: -=| versioned-state +=| [%3 state-three] =* state - %- agent:dbug ^- agent:gall @@ -110,13 +121,51 @@ ^- (quip card _this) =/ old-state=(each versioned-state tang) (mule |.(!<(versioned-state old))) - ?: ?=(%& -.old-state) - ?- -.p.old-state - %1 - :_ this(state [%2 +.p.old-state]) + =| cards=(list card) + |^ + ?: ?=(%| -.old-state) + =/ zero !<(state-zero old) + =/ rav [%next %t [%da now.bol] /app/publish/notebooks] + =/ tile-json + (frond:enjs:format %notifications (numb:enjs:format 0)) + =/ init-cards=(list card) + :~ [%pass /read/paths %arvo %c %warp our.bol q.byk.bol `rav] + :* %pass /permissions %agent [our.bol %permission-store] %watch + /updates + == + (invite-poke:main [%create /publish]) + :* %pass /invites %agent [our.bol %invite-store] %watch + /invitatory/publish + == + [%give %fact [/publishtile]~ %json !>(tile-json)] + == + =+ ^- [kick-cards=(list card) old-subs=(jug @tas @p)] kick-subs + =/ inv-scry-pax + /(scot %p our.bol)/invite-store/(scot %da now.bol)/invitatory/publish/noun + =/ inv=(unit invitatory) .^((unit invitatory) %gx inv-scry-pax) + =| new-state=state-two + =? tile-num.new-state ?=(^ inv) + ~(wyt by u.inv) + %= $ + old-state [%& %2 new-state] + :: + cards + ;: weld + (kill-builds pubs.zero) + kick-cards + init-cards + (move-files old-subs) + == + == + ?- -.p.old-state + %1 + %= $ + -.p.old-state %2 + :: + cards %- zing %+ turn ~(tap by books.p.old-state) - |= [name=@tas book=notebook] + |= [name=@tas book=notebook-2] ^- (list card) =/ group-host=(unit @p) ?> ?=(^ writers.book) @@ -128,41 +177,56 @@ :: (perm-hook-poke:main [%add-owned writers.book writers.book]) == - :: - %2 - [~ this(state p.old-state)] == - =/ zero !<(state-zero old) - |^ - =/ rav [%next %t [%da now.bol] /app/publish/notebooks] - =/ tile-json - (frond:enjs:format %notifications (numb:enjs:format 0)) - =/ init-cards=(list card) - :~ [%pass /read/paths %arvo %c %warp our.bol q.byk.bol `rav] - :* %pass /permissions %agent [our.bol %permission-store] %watch - /updates - == - (invite-poke:main [%create /publish]) - :* %pass /invites %agent [our.bol %invite-store] %watch - /invitatory/publish - == - [%give %fact [/publishtile]~ %json !>(tile-json)] + :: + %2 + %= $ + p.old-state + =/ new-books=(map [@p @tas] notebook) + %- %~ uni by + %- ~(run by subs.p.old-state) + |= old-notebook=notebook-2 + ^- notebook-3 + (convert-notebook-2-3 old-notebook) + ^- (map [@p @tas] notebook) + %- ~(rep by books.p.old-state) + |= [[key=@tas val=notebook-2] out=(map [@p @tas] notebook)] + ^- (map [@p @tas] notebook) + %+ ~(put by out) + [our.bol key] + (convert-notebook-2-3 val) + [%3 our-paths.p.old-state new-books tile-num.p.old-state [~ ~]] == - =+ ^- [kick-cards=(list card) old-subs=(jug @tas @p)] kick-subs - =/ inv-scry-pax - /(scot %p our.bol)/invite-store/(scot %da now.bol)/invitatory/publish/noun - =/ inv=(unit invitatory) .^((unit invitatory) %gx inv-scry-pax) - =| new-state=state-two - =? tile-num.new-state ?=(^ inv) - ~(wyt by u.inv) - :_ this(state [%2 new-state]) - ;: weld - kill-builds - kick-cards - init-cards - (move-files old-subs) + :: + %3 + [cards this(state p.old-state)] == :: + ++ convert-comment-2-3 + |= prev=comment-2 + ^- comment-3 + %= prev + content [content.prev %.n] + == + :: + ++ convert-note-2-3 + |= prev=note-2 + ^- note-3 + %= prev + comments + [(~(run by comments.prev) convert-comment-2-3) %.n] + == + :: + ++ convert-notebook-2-3 + |= prev=notebook-2 + ^- notebook-3 + %= prev + notes + %- ~(run by notes.prev) + |= =note-2 + (convert-note-2-3 note-2) + == + :: ++ kick-subs ^- [(list card) (jug @tas @p)] =+ ^- [paths=(list path) subs=(jug @tas @p)] @@ -179,9 +243,10 @@ [[%give %kick paths ~]~ subs] :: ++ kill-builds + |= pubs=(map @tas collection-zero) ^- (list card) %- zing - %+ turn ~(tap by pubs.zero) + %+ turn ~(tap by pubs) |= [col-name=@tas col-data=collection-zero] ^- (list card) :- [%pass /collection/[col-name] %arvo %f %kill ~] @@ -247,8 +312,9 @@ =/ book i.t.t.pax =/ note i.t.t.t.pax =/ comm i.t.t.t.t.pax - =/ old=old-comment .^(old-comment %cx (welp our-beak:main pax)) - =/ new=comment [creator.old date-created.old content.old] + =/ old-com .^(old-comment %cx (welp our-beak:main pax)) + =/ new=comment-2 + [creator.old-com date-created.old-com content.old-com] :- car :+ [pax %del ~] @@ -263,13 +329,10 @@ |= [mar=mark vas=vase] ^- (quip card _this) ?+ mar (on-poke:def mar vas) + :: %noun - ?: =(%print-state q.vas) - ~& state - [~ this] - ?: =(%print-bowl q.vas) - ~& bol - [~ this] + ?: =(q.vas %flush-limbo) + [~ this(limbo [~ ~])] [~ this] :: %handle-http-request @@ -306,13 +369,56 @@ == :: ++ on-leave on-leave:def - ++ on-peek on-peek:def + ++ on-peek + |= pax=path + ^- (unit (unit cage)) + ?+ pax (on-peek:def pax) + :: + [%t %limbo ~] + :^ ~ ~ %noun + !> ^- (list path) + %+ weld + %+ turn ~(tap by notes.limbo) + |= [[who=@p book=@tas note=@tas] *] + ^- path + /(scot %p who)/[book]/[note] + %+ turn ~(tap by comments.limbo) + |= [[who=@p book=@tas note=@tas comment=@da] *] + ^- path + /(scot %p who)/[book]/[note]/(scot %ds comment) + :: + [%x %limbo @ @ @ ~] + =/ host=(unit @p) (slaw %p i.t.t.pax) + ?~ host [~ ~] + =/ book-name i.t.t.t.pax + =/ note-name i.t.t.t.t.pax + =/ note (~(get by notes.limbo) u.host book-name note-name) + ?~ note ~ + ``noun+!>(u.note) + :: + [%x %limbo @ @ @ @ ~] + =/ host=(unit @p) (slaw %p i.t.t.pax) + =/ comment-date=(unit @da) (slaw %da i.t.t.t.t.t.pax) + ?~ host [~ ~] + ?~ comment-date [~ ~] + =/ book-name i.t.t.t.pax + =/ note-name i.t.t.t.t.pax + =/ comment + (~(get by comments.limbo) u.host book-name note-name u.comment-date) + ?~ comment ~ + ``noun+!>(u.comment) + == :: ++ on-agent |= [wir=wire sin=sign:agent:gall] ^- (quip card _this) ?- -.sin - %poke-ack (on-agent:def wir sin) + %poke-ack + ?~ p.sin + [~ this] + =^ cards state + (handle-poke-fail:main wir) + [cards this] :: If our subscribe failed, delete notebook associated with subscription if :: it exists :: @@ -324,7 +430,7 @@ =/ who=@p (slav %p i.t.wir) =/ book=@tas i.t.t.wir =/ del [%del-book who book] - :_ this(subs (~(del by subs) who book)) + :_ this(books (~(del by books) who book)) [%give %fact [/primary]~ %publish-primary-delta !>(del)]~ :: Resubscribe to any subscription we get kicked from. The case of actually :: getting banned from a notebook is handled by %watch-ack @@ -470,7 +576,7 @@ ?> ?=([%app %publish %notebooks @ @ %udon ~] pax) =/ book-name i.t.t.t.pax =/ note-name i.t.t.t.t.pax - =/ book (~(get by books) book-name) + =/ book (~(get by books) our.bol book-name) ?~ book [~ state] =/ old-note (~(get by notes.u.book) note-name) @@ -548,7 +654,7 @@ [%app %publish %notebooks @ @ %udon ~] =/ book-name i.t.t.t.pax =/ note-name i.t.t.t.t.pax - =/ book (~(get by books.sty) book-name) + =/ book (~(get by books.sty) our.bol book-name) ?~ book [cad sty] =. notes.u.book (~(del by notes.u.book) note-name) @@ -695,14 +801,20 @@ =/ udon=@t .^(@t %cx (welp our-beak pax)) (form-note note-name udon) :: +++ form-snippet + |= file=@t + ^- @t + =/ front-idx (add 3 (need (find ";>" (trip file)))) + =/ front-matter (cat 3 (end 3 front-idx file) 'dummy text\0a') + =/ body (cut 3 [front-idx (met 3 file)] file) + (of-wain:format (scag 1 (to-wain:format body))) +:: ++ form-note - |= [note-name=@tas udon=@t] + |= [note-name=@tas file=@t] ^- note - =/ front-idx (add 3 (need (find ";>" (trip udon)))) - =/ front-matter - (cat 3 (end 3 front-idx udon) 'dummy text\0a') - =/ body (cut 3 [front-idx (met 3 udon)] udon) - =/ snippet=@t (of-wain:format (scag 1 (to-wain:format body))) + =/ snippet=@t (form-snippet file) + =/ front-idx (add 3 (need (find ";>" (trip file)))) + =/ front-matter (cat 3 (end 3 front-idx file) 'dummy text\0a') =/ meta=(each (map term knot) tang) %- mule |. %- ~(run by inf:(static:cram (ream front-matter))) @@ -739,9 +851,10 @@ date-created last-modified %.y - udon + file snippet ~ + %.n == :: ++ handle-permission-update @@ -751,10 +864,12 @@ [~ state] =/ book=(unit @tas) %+ roll ~(tap by books) - |= [[nom=@tas book=notebook] out=(unit @tas)] - ?: =(path.upd subscribers.book) - `nom - out + |= [[[who=@p nom=@tas] book=notebook] out=(unit @tas)] + ?. =(who our.bol) + out + ?. =(path.upd subscribers.book) + out + `nom ?~ book [~ state] :_ state @@ -822,7 +937,7 @@ =/ book-name i.t.pax ?. (allowed src.bol %read book-name) ~|("not permitted" !!) - =/ book (~(got by books) book-name) + =/ book (~(got by books) our.bol book-name) =/ delta=notebook-delta [%add-book our.bol book-name book] :_ state @@ -834,7 +949,7 @@ |= [who=@p mod=?(%read %write) book=@tas] ^- ? =/ scry-bek /(scot %p our.bol)/permission-store/(scot %da now.bol) - =/ book=notebook (~(got by books) book) + =/ book=notebook (~(got by books) our.bol book) =/ scry-pax ?: =(%read mod) subscribers.book @@ -893,6 +1008,11 @@ [' ==' ~] == :: +++ give-primary-delta + |= del=primary-delta + ^- card + [%give %fact [/primary]~ %publish-primary-delta !>(del)] +:: ++ group-poke |= act=group-action ^- card @@ -1006,14 +1126,161 @@ (generate-invites book (~(del in invitees.group) our.bol)) == :: +++ handle-poke-fail + |= wir=wire + ^- (quip card _state) + ?+ wir + [~ state] + :: new note failed, stash it in limbo + :: + [%forward %new-note @ @ @ ~] + =/ host=@p (slav %p i.t.t.wir) + =/ book-name i.t.t.t.wir + =/ note-name i.t.t.t.t.wir + =/ book (~(get by books) [host book-name]) + ?~ book + [~ state] + =/ note (~(get by notes.u.book) note-name) + ?~ note + [~ state] + =. notes.limbo (~(put by notes.limbo) [host book-name note-name] u.note) + =. notes.u.book (~(del by notes.u.book) note-name) + =/ del [%del-note host book-name note-name] + :- [(give-primary-delta del)]~ + state(books (~(put by books) [host book-name] u.book)) + :: new comment failed, stash it in limbo + :: + [%forward %new-comment @ @ @ @ ~] + =/ host=@p (slav %p i.t.t.wir) + =/ book-name i.t.t.t.wir + =/ note-name i.t.t.t.t.wir + =/ comment-date=@da (slav %da i.t.t.t.t.t.wir) + =/ book (~(get by books) [host book-name]) + ?~ book + [~ state] + =/ note (~(get by notes.u.book) note-name) + ?~ note + [~ state] + =/ comment (~(get by comments.u.note) comment-date) + ?~ comment + [~ state] + =. comments.limbo + %+ ~(put by comments.limbo) + [host book-name note-name comment-date] + u.comment + =. comments.u.note (~(del by comments.u.note) comment-date) + =. notes.u.book (~(put by notes.u.book) note-name u.note) + =/ del [%del-comment host book-name note-name comment-date] + :- [(give-primary-delta del)]~ + state(books (~(put by books) [host book-name] u.book)) + :: edit note failed, restore old version + :: + [%forward %edit-note @ @ @ ~] + =/ host=@p (slav %p i.t.t.wir) + =/ book-name i.t.t.t.wir + =/ note-name i.t.t.t.t.wir + =/ book (~(get by books) [host book-name]) + ?~ book + [~ state] + =/ note (~(get by notes.limbo) host book-name note-name) + ?~ note + [~ state] + =. notes.u.book (~(put by notes.u.book) note-name u.note) + =/ del [%edit-note host book-name note-name u.note] + :- [(give-primary-delta del)]~ + %= state + books (~(put by books) [host book-name] u.book) + notes.limbo (~(del by notes.limbo) host book-name note-name) + == + :: edit comment failed, restore old version + :: + [%forward %new-comment @ @ @ @ ~] + =/ host=@p (slav %p i.t.t.wir) + =/ book-name i.t.t.t.wir + =/ note-name i.t.t.t.t.wir + =/ comment-date=@da (slav %da i.t.t.t.t.t.wir) + =/ book (~(get by books) [host book-name]) + ?~ book + [~ state] + =/ note (~(get by notes.u.book) note-name) + ?~ note + [~ state] + =/ comment + (~(get by comments.limbo) host book-name note-name comment-date) + ?~ comment + [~ state] + =. comments.u.note (~(put by comments.u.note) comment-date u.comment) + =. notes.u.book (~(put by notes.u.book) note-name u.note) + =/ del [%edit-comment host book-name note-name comment-date u.comment] + :- [(give-primary-delta del)]~ + %= state + books (~(put by books) [host book-name] u.book) + :: + comments.limbo + %+ ~(del by comments.limbo) + [host book-name note-name comment-date] + u.comment + == + :: delete note failed, restore old version + :: + [%forward %del-note @ @ @ ~] + =/ host=@p (slav %p i.t.t.wir) + =/ book-name i.t.t.t.wir + =/ note-name i.t.t.t.t.wir + =/ book (~(get by books) [host book-name]) + ?~ book + [~ state] + =/ note (~(get by notes.limbo) host book-name note-name) + ?~ note + [~ state] + =. notes.u.book (~(put by notes.u.book) note-name u.note) + =/ del [%add-note host book-name note-name u.note] + :- [(give-primary-delta del)]~ + %= state + books (~(put by books) [host book-name] u.book) + notes.limbo (~(del by notes.limbo) host book-name note-name) + == + :: delete comment failed, restore old version + :: + [%forward %del-comment @ @ @ @ ~] + =/ host=@p (slav %p i.t.t.wir) + =/ book-name i.t.t.t.wir + =/ note-name i.t.t.t.t.wir + =/ comment-date=@da (slav %da i.t.t.t.t.t.wir) + =/ book (~(get by books) [host book-name]) + ?~ book + [~ state] + =/ note (~(get by notes.u.book) note-name) + ?~ note + [~ state] + =/ comment + (~(get by comments.limbo) host book-name note-name comment-date) + ?~ comment + [~ state] + =. comments.u.note (~(put by comments.u.note) comment-date u.comment) + =. notes.u.book (~(put by notes.u.book) note-name u.note) + =/ del [%add-comment host book-name note-name comment-date u.comment] + :- [(give-primary-delta del)]~ + %= state + books (~(put by books) [host book-name] u.book) + :: + comments.limbo + %+ ~(del by comments.limbo) + [host book-name note-name comment-date] + u.comment + == + == +:: ++ poke-publish-action |= act=action ^- (quip card _state) ?- -.act + :: %new-book: Make groups and save publish info file. + :: %new-book ?. (team:title our.bol src.bol) ~|("action not permitted" !!) - ?: (~(has by books) book.act) + ?: (~(has by books) our.bol book.act) ~|("notebook already exists: {}" !!) =+ ^- [cards=(list card) write-pax=path read-pax=path] (make-groups book.act group.act title.act about.act) @@ -1027,21 +1294,17 @@ =/ pax=path /app/publish/notebooks/[book.act]/publish-info :_ state [(write-file pax %publish-info !>(new-book)) cards] + :: %new-note: + :: If poke is from us, eagerly store new note in books. If poke is to us, + :: save file, otherwise forward the poke. If forwarded poke fails, note is + :: removed from books and stored in limbo. :: %new-note - ?: &(=(src.bol our.bol) !=(our.bol who.act)) - :_ state - [%pass /forward %agent [who.act %publish] %poke %publish-action !>(act)]~ - =/ book=(unit notebook) (~(get by books) book.act) + =/ book=(unit notebook) (~(get by books) who.act book.act) ?~ book ~|("nonexistent notebook {}" !!) ?: (~(has by notes.u.book) note.act) ~|("note already exists: {}" !!) - ?. ?| (team:title our.bol src.bol) - (allowed src.bol %write book.act) - == - ~|("action not permitted" !!) - =/ pax=path /app/publish/notebooks/[book.act]/[note.act]/udon =/ front=(map knot cord) %- my :~ title+title.act @@ -1049,19 +1312,86 @@ date-created+(scot %da now.bol) last-modified+(scot %da now.bol) == - =/ file=@t (add-front-matter front body.act) + =/ file=@t (add-front-matter front body.act) + :: + =^ cards books + ?. =(src.bol our.bol) + [~ books] + =/ new-note=note + :* src.bol + title.act + note.act + now.bol + now.bol + %.y + file + (form-snippet file) + ~ + %.y + == + =/ del=primary-delta [%add-note who.act book.act note.act new-note] + :- [(give-primary-delta del)]~ + %+ ~(put by books) + [who.act book.act] + u.book(notes (~(put by notes.u.book) note.act new-note)) + :: :_ state - [(write-file pax %udon !>(file))]~ + ?. =(who.act our.bol) + =/ poke-wir=wire + /forward/new-note/(scot %p who.act)/[book.act]/[note.act] + :_ cards + [%pass poke-wir %agent [who.act %publish] %poke %publish-action !>(act)] + ?. ?| (team:title our.bol src.bol) + (allowed src.bol %write book.act) + == + ~|("action not permitted" !!) + =/ pax=path /app/publish/notebooks/[book.act]/[note.act]/udon + :_ cards + [(write-file pax %udon !>(file))] + :: %new-comment + :: If poke is from us, eagerly store new comment in books. If poke is to + :: us, save file, otherwise forward the poke. If forwarded poke fails, + :: comment is removed from books and stored in limbo. :: %new-comment - ?: &(=(src.bol our.bol) !=(our.bol who.act)) - :_ state - [%pass /forward %agent [who.act %publish] %poke %publish-action !>(act)]~ - =/ book=(unit notebook) (~(get by books) book.act) + =/ book=(unit notebook) (~(get by books) who.act book.act) ?~ book ~|("nonexistent notebook {}" !!) - ?. (~(has by notes.u.book) note.act) + =/ note=(unit note) (~(get by notes.u.book) note.act) + ?~ note ~|("nonexistent note {}" !!) + =/ new-comment=comment + :* author=src.bol + date-created=now.bol + content=body.act + %.y + == + :: + =^ cards books + ?. =(src.bol our.bol) + [~ books] + =/ new-note + %= u.note + comments (~(put by comments.u.note) now.bol new-comment) + == + =/ del=primary-delta + [%add-comment who.act book.act note.act now.bol new-comment] + :- [(give-primary-delta del)]~ + %+ ~(put by books) + [who.act book.act] + u.book(notes (~(put by notes.u.book) note.act new-note)) + :_ state + ?. =(who.act our.bol) + =/ poke-wir=wire + :~ %forward + %new-comment + (scot %p who.act) + book.act + note.act + (scot %da now.bol) + == + :_ cards + [%pass poke-wir %agent [who.act %publish] %poke %publish-action !>(act)] ?. ?& ?| (team:title our.bol src.bol) (allowed src.bol %read book.act) == @@ -1071,18 +1401,13 @@ =/ pax=path %+ weld /app/publish/notebooks /[book.act]/[note.act]/(scot %da now.bol)/publish-comment - =/ new-comment=comment - :* author=src.bol - date-created=now.bol - content=body.act - == - :_ state - [(write-file pax %publish-comment !>(new-comment))]~ + [(write-file pax %publish-comment !>(new-comment(pending %.n)))]~ + :: %edit-book: Make groups and save publish-info file :: %edit-book ?. (team:title our.bol src.bol) ~|("action not permitted" !!) - =/ book (~(get by books) book.act) + =/ book (~(get by books) our.bol book.act) ?~ book ~|("nonexistent notebook" !!) =+ ^- [cards=(list card) write-pax=path read-pax=path] @@ -1099,24 +1424,18 @@ =/ pax=path /app/publish/notebooks/[book.act]/publish-info :_ state [(write-file pax %publish-info !>(new-info)) cards] + :: %edit-note: + :: If poke is from us, eagerly store new note in books, and place the old + :: note in limbo. If poke is to us, save file, otherwise forward the poke. + :: If forwarded poke fails, old note is restored from limbo. :: %edit-note - ?: &(=(src.bol our.bol) !=(our.bol who.act)) - :_ state - [%pass /forward %agent [who.act %publish] %poke %publish-action !>(act)]~ - =/ book=(unit notebook) (~(get by books) book.act) + =/ book=(unit notebook) (~(get by books) who.act book.act) ?~ book ~|("nonexistent notebook {}" !!) =/ note=(unit note) (~(get by notes.u.book) note.act) ?~ note ~|("nonexistent note: {}" !!) - ?. ?| (team:title our.bol src.bol) - ?& =(author.u.note src.bol) - (allowed src.bol %write book.act) - == - == - ~|("action not permitted" !!) - =/ pax=path /app/publish/notebooks/[book.act]/[note.act]/udon =/ front=(map knot cord) %- my :~ title+title.act @@ -1125,25 +1444,101 @@ last-modified+(scot %da now.bol) == =/ file=@t (add-front-matter front body.act) + :: + =^ cards state + ?. =(src.bol our.bol) + [~ state] + =/ new-note + %= u.note + author src.bol + title title.act + last-edit now.bol + file file + snippet (form-snippet file) + pending %.y + == + =/ del=primary-delta [%edit-note who.act book.act note.act new-note] + :- [(give-primary-delta del)]~ + %= state + notes.limbo + (~(put by notes.limbo) [who.act book.act note.act] u.note) + :: + books + %+ ~(put by books) + [who.act book.act] + u.book(notes (~(put by notes.u.book) note.act new-note)) + == + :: :_ state + ?. =(who.act our.bol) + =/ poke-wir=wire + /forward/edit-note/(scot %p who.act)/[book.act]/[note.act] + :_ cards + [%pass poke-wir %agent [who.act %publish] %poke %publish-action !>(act)] + ?. ?| (team:title our.bol src.bol) + ?& =(author.u.note src.bol) + (allowed src.bol %write book.act) + == + == + ~|("action not permitted" !!) + =/ pax=path /app/publish/notebooks/[book.act]/[note.act]/udon [(write-file pax %udon !>(file))]~ + :: %edit-comment: + :: If poke is from us, eagerly store new comment in books, and place the + :: old note in limbo. If poke is to us, save file, otherwise forward the + :: poke. If forwarded poke fails, old comment is restored from limbo. :: %edit-comment - ?: &(=(src.bol our.bol) !=(our.bol who.act)) - :_ state - [%pass /forward %agent [who.act %publish] %poke %publish-action !>(act)]~ - =/ book=(unit notebook) (~(get by books) book.act) + =/ book=(unit notebook) (~(get by books) who.act book.act) ?~ book ~|("nonexistent notebook {}" !!) - =/ not=(unit note) (~(get by notes.u.book) note.act) - ?~ not + =/ note=(unit note) (~(get by notes.u.book) note.act) + ?~ note ~|("nonexistent note {}" !!) - =/ com=(unit comment) - (~(get by comments.u.not) (slav %da comment.act)) - ?~ com + =/ comment-date (slav %da comment.act) + =/ comment=(unit comment) (~(get by comments.u.note) comment-date) + ?~ comment ~|("nonexistent comment {}" !!) + =/ new-comment + u.comment(content body.act, pending %.y) + :: + =^ cards state + ?. =(src.bol our.bol) + [~ state] + =/ new-note + %= u.note + comments + (~(put by comments.u.note) comment-date new-comment) + == + =/ del=primary-delta + [%edit-comment who.act book.act note.act comment-date new-comment] + :- [(give-primary-delta del)]~ + %= state + books + %+ ~(put by books) + [who.act book.act] + u.book(notes (~(put by notes.u.book) note.act new-note)) + :: + comments.limbo + %+ ~(put by comments.limbo) + [who.act book.act note.act comment-date] + u.comment + == + :: + :_ state + ?. =(who.act our.bol) + =/ poke-wir + :~ %forward + %edit-comment + (scot %p who.act) + book.act + note.act + comment.act + == + :_ cards + [%pass poke-wir %agent [who.act %publish] %poke %publish-action !>(act)] ?. ?| (team:title our.bol src.bol) - ?& =(author.u.com src.bol) + ?& =(author.u.comment src.bol) (allowed src.bol %read book.act) == == @@ -1151,15 +1546,13 @@ =/ pax=path %+ weld /app/publish/notebooks /[book.act]/[note.act]/[comment.act]/publish-comment - =/ new-comment .^(comment %cx (weld our-beak pax)) - =. content.new-comment body.act - :_ state - [(write-file pax %publish-comment !>(new-comment))]~ + [(write-file pax %publish-comment !>(new-comment(pending %.n)))]~ + :: %del-book: Delete whole notebook directory, delete groups and permissions :: %del-book ?. (team:title our.bol src.bol) ~|("action not permitted" !!) - =/ book=(unit notebook) (~(get by books) book.act) + =/ book=(unit notebook) (~(get by books) our.bol book.act) ?~ book ~|("nonexistent notebook {}" !!) =/ pax=path /app/publish/notebooks/[book.act] @@ -1175,17 +1568,36 @@ =? cards =('~' i.subscribers.u.book) [(group-poke [%unbundle subscribers.u.book]) cards] [cards state] + :: %del-note: + :: If poke is from us, eagerly remove note from books, and place the + :: old note in limbo. If poke is to us, save file, otherwise forward the + :: poke. If forwarded poke fails, old note is restored from limbo. :: %del-note - ?: &(=(src.bol our.bol) !=(our.bol who.act)) - :_ state - [%pass /forward %agent [who.act %publish] %poke %publish-action !>(act)]~ - =/ book=(unit notebook) (~(get by books) book.act) + =/ book=(unit notebook) (~(get by books) who.act book.act) ?~ book ~|("nonexistent notebook {}" !!) =/ note=(unit note) (~(get by notes.u.book) note.act) ?~ note ~|("nonexistent note: {}" !!) + :: + =^ cards state + ?. =(src.bol our.bol) + [~ state] + =/ del=primary-delta [%del-note who.act book.act note.act] + =. notes.u.book (~(del by notes.u.book) note.act) + :- [(give-primary-delta del)]~ + %= state + books (~(put by books) [who.act book.act] u.book) + notes.limbo (~(put by notes.limbo) [who.act book.act note.act] u.note) + == + :: + :_ state + ?. =(who.act our.bol) + =/ poke-wir=wire + /forward/del-note/(scot %p who.act)/[book.act]/[note.act] + :_ cards + [%pass poke-wir %agent [who.act %publish] %poke %publish-action !>(act)] ?. ?| (team:title our.bol src.bol) ?& =(author.u.note src.bol) (allowed src.bol %write book.act) @@ -1193,23 +1605,54 @@ == ~|("action not permitted" !!) =/ pax=path /app/publish/notebooks/[book.act]/[note.act]/udon - :_ state [(delete-file pax)]~ + :: %del-comment: + :: If poke is from us, eagerly remove comment from books, and place the + :: old note in limbo. If poke is to us, save file, otherwise forward the + :: poke. If forwarded poke fails, old comment is restored from limbo. :: %del-comment - ?: &(=(src.bol our.bol) !=(our.bol who.act)) - :_ state - [%pass /forward %agent [who.act %publish] %poke %publish-action !>(act)]~ - =/ book=(unit notebook) (~(get by books) book.act) + =/ book=(unit notebook) (~(get by books) who.act book.act) ?~ book ~|("nonexistent notebook {}" !!) =/ note=(unit note) (~(get by notes.u.book) note.act) ?~ note ~|("nonexistent note {}" !!) - =/ comment=(unit comment) - (~(get by comments.u.note) (slav %da comment.act)) + =/ comment-date (slav %da comment.act) + =/ comment=(unit comment) (~(get by comments.u.note) comment-date) ?~ comment ~|("nonexistent comment {}" !!) + :: + =^ cards state + ?. =(src.bol our.bol) + [~ state] + =/ del=primary-delta + [%del-comment who.act book.act note.act comment-date] + =. comments.u.note (~(del by comments.u.note) comment-date) + =. notes.u.book (~(put by notes.u.book) note.act u.note) + :- [(give-primary-delta del)]~ + %= state + books + (~(put by books) [who.act book.act] u.book) + :: + comments.limbo + %+ ~(put by comments.limbo) + [who.act book.act note.act comment-date] + u.comment + == + :: + :_ state + ?. =(who.act our.bol) + =/ poke-wir=wire + :~ %forward + %del-comment + (scot %p who.act) + book.act + note.act + comment.act + == + :_ cards + [%pass poke-wir %agent [who.act %publish] %poke %publish-action !>(act)] ?. ?| (team:title our.bol src.bol) ?& =(author.u.comment src.bol) (allowed src.bol %read book.act) @@ -1219,30 +1662,30 @@ =/ pax=path %+ weld /app/publish/notebooks /[book.act]/[note.act]/[comment.act]/publish-comment - :_ state [(delete-file pax)]~ + :: %subscribe :: %subscribe ?> (team:title our.bol src.bol) =/ wir=wire /subscribe/(scot %p who.act)/[book.act] :_ state [%pass wir %agent [who.act %publish] %watch /notebook/[book.act]]~ + :: %unsubscribe :: %unsubscribe ?> (team:title our.bol src.bol) =/ wir=wire /subscribe/(scot %p who.act)/[book.act] =/ del=primary-delta [%del-book who.act book.act] - :_ state(subs (~(del by subs) who.act book.act)) + :_ state(books (~(del by books) who.act book.act)) :~ `card`[%pass wir %agent [who.act %publish] %leave ~] `card`[%give %fact [/primary]~ %publish-primary-delta !>(del)] == + :: %read :: %read ?> (team:title our.bol src.bol) =/ book=(unit notebook) - ?: =(our.bol who.act) - (~(get by books) book.act) - (~(get by subs) who.act book.act) + (~(get by books) who.act book.act) ?~ book ~|("nonexistent notebook: {}" !!) =/ not=(unit note) (~(get by notes.u.book) note.act) @@ -1252,10 +1695,7 @@ (dec tile-num) =. read.u.not %.y =. notes.u.book (~(put by notes.u.book) note.act u.not) - =? books =(our.bol who.act) - (~(put by books) book.act u.book) - =? subs !=(our.bol who.act) - (~(put by subs) [who.act book.act] u.book) + =. books (~(put by books) [who.act book.act] u.book) =/ jon=json (frond:enjs:format %notifications (numb:enjs:format tile-num)) :_ state @@ -1267,9 +1707,7 @@ ++ get-notebook |= [host=@p book-name=@tas sty=_state] ^- (unit notebook) - ?: =(our.bol host) - (~(get by books.sty) book-name) - (~(get by subs.sty) host book-name) + (~(get by books.sty) host book-name) :: ++ get-unread |= book=notebook @@ -1283,14 +1721,13 @@ ++ emit-updates-and-state |= [host=@p book-name=@tas book=notebook del=notebook-delta sty=_state] ^- (quip card _state) + :_ sty(books (~(put by books.sty) [host book-name] book)) ?: =(our.bol host) - :_ sty(books (~(put by books.sty) book-name book)) :~ [%give %fact [/notebook/[book-name]]~ %publish-notebook-delta !>(del)] [%give %fact [/primary]~ %publish-primary-delta !>(del)] == =/ jon=json (frond:enjs:format %notifications (numb:enjs:format tile-num)) - :_ sty(subs (~(put by subs.sty) [host book-name] book)) :~ [%give %fact [/primary]~ %publish-primary-delta !>(del)] [%give %fact [/publishtile]~ %json !>(jon)] == @@ -1427,6 +1864,17 @@ =/ note (~(get by notes.u.book) note.del) ?~ note [~ sty] + =/ limbo-comment=(unit @da) + %- ~(rep by comments.u.note) + |= [[date=@da com=comment] out=(unit @da)] + ?: ?& =(author.com author.data.del) + =(content.com content.data.del) + =(%.y pending.com) + == + `date + out + =? comments.u.note ?=(^ limbo-comment) + (~(del by comments.u.note) u.limbo-comment) =. comments.u.note (~(put by comments.u.note) comment-date.del data.del) =. notes.u.book (~(put by notes.u.book) note.del u.note) (emit-updates-and-state host.del book.del u.book del sty) @@ -1457,6 +1905,7 @@ == :: %edit-note + =. notes.limbo.sty (~(del by notes.limbo.sty) host.del book.del note.del) =/ book=(unit notebook) (get-notebook host.del book.del sty) ?~ book @@ -1464,6 +1913,8 @@ =/ old-note (~(get by notes.u.book) note.del) ?~ old-note [~ sty] + ?: =(our.bol author.u.old-note) + [~ sty] =/ new-note=note %= data.del date-created date-created.u.old-note @@ -1474,6 +1925,9 @@ (emit-updates-and-state host.del book.del u.book del sty) :: %edit-comment + =. comments.limbo.sty + %- ~(del by comments.limbo.sty) + [host.del book.del note.del comment-date.del] =/ book=(unit notebook) (get-notebook host.del book.del sty) ?~ book @@ -1481,6 +1935,11 @@ =/ note (~(get by notes.u.book) note.del) ?~ note [~ sty] + =/ old-comment (~(get by comments.u.note) comment-date.del) + ?~ old-comment + [~ sty] + ?: =(our.bol author.u.old-comment) + [~ sty] =. comments.u.note (~(put by comments.u.note) comment-date.del data.del) =. notes.u.book (~(put by notes.u.book) note.del u.note) (emit-updates-and-state host.del book.del u.book del sty) @@ -1489,20 +1948,19 @@ =/ book=(unit notebook) (get-notebook host.del book.del sty) ?~ book [~ sty] + :_ sty(books (~(del by books.sty) host.del book.del)) ?. =(our.bol host.del) =. tile-num %+ sub tile-num - (get-unread (~(got by subs) host.del book.del)) + (get-unread (~(got by books) host.del book.del)) =/ jon=json (frond:enjs:format %notifications (numb:enjs:format tile-num.sty)) - :_ sty(subs (~(del by subs.sty) host.del book.del)) %+ welp :~ [%give %fact [/primary]~ %publish-primary-delta !>(del)] [%give %fact [/publishtile]~ %json !>(jon)] == ?: (is-managed writers.u.book) ~ [(metadata-hook-poke [%remove writers.u.book])]~ - :_ sty(books (~(del by books.sty) book.del)) %- zing :~ [%give %fact [/notebook/[book.del]]~ %publish-notebook-delta !>(del)]~ [%give %fact [/primary]~ %publish-primary-delta !>(del)]~ @@ -1513,17 +1971,23 @@ == :: %del-note + =. notes.limbo.sty (~(del by notes.limbo.sty) host.del book.del note.del) =/ book=(unit notebook) (get-notebook host.del book.del sty) ?~ book [~ sty] - =/ not=note (~(got by notes.u.book) note.del) - =? tile-num &(!read.not (gth tile-num 0)) + =/ not=(unit note) (~(get by notes.u.book) note.del) + ?~ not + [~ sty] + =? tile-num &(!read.u.not (gth tile-num 0)) (dec tile-num) =. notes.u.book (~(del by notes.u.book) note.del) (emit-updates-and-state host.del book.del u.book del sty) :: %del-comment + =. comments.limbo.sty + %- ~(del by comments.limbo.sty) + [host.del book.del note.del comment.del] =/ book=(unit notebook) (get-notebook host.del book.del sty) ?~ book @@ -1551,10 +2015,7 @@ |= [host=@p book-name=@tas] ^- (unit json) =, enjs:format - =/ book=(unit notebook) - ?: =(our.bol host) - (~(get by books) book-name) - (~(get by subs) host book-name) + =/ book=(unit notebook) (~(get by books) host book-name) ?~ book ~ =/ notebook-json (notebook-full-json host book-name u.book) @@ -1563,7 +2024,7 @@ (~(uni by p.notebook-json) (notes-page notes.u.book 0 50)) =. p.notebook-json (~(put by p.notebook-json) %subscribers (get-subscribers-json book-name)) - =/ notebooks-json (notebooks-map-json our.bol books subs) + =/ notebooks-json (notebooks-map-json our.bol books) ?> ?=(%o -.notebooks-json) =/ host-books-json (~(got by p.notebooks-json) (scot %p host)) ?> ?=(%o -.host-books-json) @@ -1576,10 +2037,7 @@ |= [host=@p book-name=@tas note-name=@tas] ^- (unit json) =, enjs:format - =/ book=(unit notebook) - ?: =(our.bol host) - (~(get by books) book-name) - (~(get by subs) host book-name) + =/ book=(unit notebook) (~(get by books) host book-name) ?~ book ~ =/ note=(unit note) (~(get by notes.u.book) note-name) @@ -1589,7 +2047,7 @@ ?> ?=(%o -.notebook-json) =/ note-json (note-presentation-json u.book note-name u.note) =. p.notebook-json (~(uni by p.notebook-json) note-json) - =/ notebooks-json (notebooks-map-json our.bol books subs) + =/ notebooks-json (notebooks-map-json our.bol books) ?> ?=(%o -.notebooks-json) =/ host-books-json (~(got by p.notebooks-json) (scot %p host)) ?> ?=(%o -.host-books-json) @@ -1633,7 +2091,7 @@ [[[~ %json] [%'~publish' %notebooks ~]] ~] %- json-response:gen %- json-to-octs - (notebooks-map-json our.bol books subs) + (notebooks-map-json our.bol books) :: :: notes pagination [[[~ %json] [%'~publish' %notes @ @ @ @ ~]] ~] @@ -1641,10 +2099,7 @@ ?~ host not-found:gen =/ book-name i.t.t.t.site.url - =/ book=(unit notebook) - ?: =(our.bol u.host) - (~(get by books) book-name) - (~(get by subs) u.host book-name) + =/ book=(unit notebook) (~(get by books) u.host book-name) ?~ book not-found:gen =/ start (rush i.t.t.t.t.site.url dem) @@ -1664,10 +2119,7 @@ ?~ host not-found:gen =/ book-name i.t.t.t.site.url - =/ book=(unit notebook) - ?: =(our.bol u.host) - (~(get by books) book-name) - (~(get by subs) u.host book-name) + =/ book=(unit notebook) (~(get by books) u.host book-name) ?~ book not-found:gen =/ note-name i.t.t.t.t.site.url @@ -1691,10 +2143,7 @@ ?~ host not-found:gen =/ book-name i.t.t.site.url - =/ book=(unit notebook) - ?: =(our.bol u.host) - (~(get by books) book-name) - (~(get by subs) u.host book-name) + =/ book=(unit notebook) (~(get by books) u.host book-name) ?~ book not-found:gen =/ notebook-json (notebook-full-json u.host book-name u.book) @@ -1713,10 +2162,7 @@ ?~ host not-found:gen =/ book-name i.t.t.site.url - =/ book=(unit notebook) - ?: =(our.bol u.host) - (~(get by books) book-name) - (~(get by subs) u.host book-name) + =/ book=(unit notebook) (~(get by books) u.host book-name) ?~ book not-found:gen =/ note-name i.t.t.t.site.url @@ -1731,7 +2177,7 @@ :: all notebooks, short form, wrapped in html [[~ [%'~publish' ?(~ [%join *] [%new ~])]] ~] =, enjs:format - =/ jon=json (pairs notebooks+(notebooks-map-json our.bol books subs) ~) + =/ jon=json (pairs notebooks+(notebooks-map-json our.bol books) ~) (manx-response:gen (index jon)) :: :: single notebook, with initial 50 notes in short form, wrapped in html diff --git a/pkg/arvo/lib/publish.hoon b/pkg/arvo/lib/publish.hoon index 0bb72ef46..906560825 100644 --- a/pkg/arvo/lib/publish.hoon +++ b/pkg/arvo/lib/publish.hoon @@ -60,11 +60,11 @@ (notebook-short-json book) :: ++ notebooks-map-json - |= [our=@p books=(map @tas notebook) subs=(map [@p @tas] notebook)] + |= [our=@p books=(map [@p @tas] notebook)] ^- json =, enjs:format - =/ subs-notebooks-map=json - %- ~(rep by subs) + =/ notebooks-map=json + %- ~(rep by books) |= [[[host=@p book-name=@tas] book=notebook] out=json] ^- json =/ host-ta (scot %p host) @@ -79,22 +79,9 @@ =. p.u.books (~(put by p.u.books) book-name (notebook-short-json book)) :- %o (~(put by p.out) host-ta u.books) - =? subs-notebooks-map ?=(~ subs-notebooks-map) + =? notebooks-map ?=(~ notebooks-map) [%o ~] - =/ our-notebooks-map=json - %- ~(rep by books) - |= [[book-name=@tas book=notebook] out=json] - ^- json - ?~ out - (frond book-name (notebook-short-json book)) - ?> ?=(%o -.out) - :- %o - (~(put by p.out) book-name (notebook-short-json book)) - ?~ our-notebooks-map - subs-notebooks-map - ?> ?=(%o -.subs-notebooks-map) - :- %o - (~(put by p.subs-notebooks-map) (scot %p our) our-notebooks-map) + notebooks-map :: ++ notebook-short-json |= book=notebook @@ -170,6 +157,7 @@ num-comments+(numb ~(wyt by comments.note)) comments+(comments-page comments.note 0 50) read+b+read.note + pending+b+pending.note == :: ++ notes-by-date @@ -197,6 +185,7 @@ num-comments+(numb ~(wyt by comments.note)) read+b+read.note snippet+s+snippet.note + pending+b+pending.note == :: ++ notes-page @@ -246,5 +235,6 @@ :~ author+s+(scot %p author.com) date-created+(time date-created.com) content+s+content.com + pending+b+pending.com == -- diff --git a/pkg/arvo/mar/publish/comment.hoon b/pkg/arvo/mar/publish/comment.hoon index c2a40cae5..9aabaf7d4 100644 --- a/pkg/arvo/mar/publish/comment.hoon +++ b/pkg/arvo/mar/publish/comment.hoon @@ -44,7 +44,7 @@ %+ cook |= [author=@ @ @ date-created=@da @ content=@t] ^- comment - [author date-created content] + [author date-created content %.n] old-parser == -- diff --git a/pkg/arvo/sur/publish.hoon b/pkg/arvo/sur/publish.hoon index 92baad254..24bc59d99 100644 --- a/pkg/arvo/sur/publish.hoon +++ b/pkg/arvo/sur/publish.hoon @@ -27,13 +27,24 @@ [%read who=@p book=@tas note=@tas] == :: -+$ comment ++$ comment comment-3 +:: ++$ comment-2 $: author=@p date-created=@da content=@t == :: -+$ note ++$ comment-3 + $: author=@p + date-created=@da + content=@t + pending=? + == +:: ++$ note note-3 +:: ++$ note-2 $: author=@p title=@t filename=@tas @@ -42,11 +53,37 @@ read=? file=@t snippet=@t -:: build=(each manx tang) - comments=(map @da comment) + comments=(map @da comment-2) == :: -+$ notebook ++$ note-3 + $: author=@p + title=@t + filename=@tas + date-created=@da + last-edit=@da + read=? + file=@t + snippet=@t + comments=(map @da comment) + pending=? + == +:: ++$ notebook notebook-3 +:: ++$ notebook-2 + $: title=@t + description=@t + comments=? + writers=path + subscribers=path + date-created=@da + notes=(map @tas note-2) + order=(list @tas) + unread=(set @tas) + == +:: ++$ notebook-3 $: title=@t description=@t comments=? diff --git a/pkg/arvo/sys/hoon.hoon b/pkg/arvo/sys/hoon.hoon index 70c2ab4a4..9b809933b 100644 --- a/pkg/arvo/sys/hoon.hoon +++ b/pkg/arvo/sys/hoon.hoon @@ -1493,10 +1493,12 @@ =| {l/(unit) r/(unit)} |- ^- ? ?~ a & - ?& ?~(l & (gor p.n.a u.l)) - ?~(r & (gor u.r p.n.a)) - ?~(l.a & ?&((mor p.n.a p.n.l.a) $(a l.a, l `p.n.a))) - ?~(r.a & ?&((mor p.n.a p.n.r.a) $(a r.a, r `p.n.a))) + ?& ?~(l & &((gor p.n.a u.l) !=(p.n.a u.l))) + ?~(r & &((gor u.r p.n.a) !=(u.r p.n.a))) + ?~ l.a & + &((mor p.n.a p.n.l.a) !=(p.n.a p.n.l.a) $(a l.a, l `p.n.a)) + ?~ r.a & + &((mor p.n.a p.n.r.a) !=(p.n.a p.n.r.a) $(a r.a, r `p.n.a)) == :: ++ gas :: concatenate diff --git a/pkg/arvo/sys/zuse.hoon b/pkg/arvo/sys/zuse.hoon index 29ed011ca..49aafbbb6 100644 --- a/pkg/arvo/sys/zuse.hoon +++ b/pkg/arvo/sys/zuse.hoon @@ -5836,6 +5836,7 @@ |* wil/(pole fist) |= jon/json ?. ?=({$a *} jon) ~ + ?. =((lent wil) (lent p.jon)) ~ =+ raw=((at-raw wil) p.jon) ?.((za raw) ~ (some (zp raw))) :: diff --git a/pkg/arvo/tests/sys/hoon/map.hoon b/pkg/arvo/tests/sys/hoon/map.hoon index 383291e4a..9f9e15c3d 100644 --- a/pkg/arvo/tests/sys/hoon/map.hoon +++ b/pkg/arvo/tests/sys/hoon/map.hoon @@ -137,6 +137,9 @@ :: doesn't follow horizontal & vertical ordering :: =/ unbalanced-e=(map @ @) [[1 1] [[3 3] ~ ~] [[2 2] ~ ~]] + :: has duplicate keys + :: + =/ duplicates=(map @ @) [[1 1] [[1 2] ~ ~] ~] ;: weld %+ expect-eq !> [%b-a %.y] @@ -156,6 +159,9 @@ %+ expect-eq !> [%u-e %.n] !> [%u-e ~(apt by unbalanced-e)] + %+ expect-eq + !> [%dup %.n] + !> [%dup ~(apt by duplicates)] == :: :: Test bifurcation (i.e. splits map a into two, discarding -.a) diff --git a/pkg/arvo/tests/sys/zuse/format.hoon b/pkg/arvo/tests/sys/zuse/format.hoon new file mode 100644 index 000000000..1ef96550f --- /dev/null +++ b/pkg/arvo/tests/sys/zuse/format.hoon @@ -0,0 +1,693 @@ +/+ *test +=, format +|% +:: split a cord on newlines +:: +++ test-to-wain + ;: weld + :: basic usage + :: + %+ expect-eq + !> ~['hello' 'world'] + !> (to-wain 'hello\0aworld') + :: string with no newlines + :: + %+ expect-eq + !> ~['hey'] + !> (to-wain 'hey') + :: empty string works fine + :: + %+ expect-eq + !> ~[''] + !> (to-wain '') + :: leading/trailing/consecutive newlines all work fine + :: + %+ expect-eq + !> ~['' 'hi' '' '' 'there' ''] + !> (to-wain '\0ahi\0a\0a\0athere\0a') + == +:: join a list of lines (cords) into a single cord +:: +++ test-of-wain + ;: weld + :: basic usage + :: + %+ expect-eq + !> 'hey\0athere\0aworld!' + !> (of-wain ~['hey' 'there' 'world!']) + :: empty list + :: + %+ expect-eq + !> '' + !> (of-wain ~) + :: single list + :: + %+ expect-eq + !> 'hey' + !> (of-wain ~['hey']) + :: list with empties + :: + %+ expect-eq + !> 'hey\0a\0athere' + !> (of-wain ~['hey' '' 'there']) + == +:: join a list of lines (tapes) into a single cord. +:: +:: Appends an extra newline - this matches unix conventions of a +:: trailing newline. Also see #1, #2 +:: +++ test-of-wall + ;: weld + :: basic usage + :: + %+ expect-eq + !> "hey\0athere\0aworld!\0a" + !> (of-wall ~["hey" "there" "world!"]) + :: empty list + :: + %+ expect-eq + !> "" + !> (of-wall ~) + :: single list + :: + %+ expect-eq + !> "hey\0a" + !> (of-wall ~["hey"]) + :: list with empties + :: + %+ expect-eq + !> "hey\0a\0athere\0a" + !> (of-wall ~["hey" "" "there"]) + == +:: encoding and decoding of beams <-> paths + +:: (a beam is a fully-qualified file reference. ship, desk, version, +:: path) +:: +++ test-beam + =/ b=beam [[p=~zod q=%home r=[%ud p=12]] s=/hoon/zuse/sys] + =/ p=path /~zod/home/12/sys/zuse/hoon + ;: weld + :: proper encode + :: + %+ expect-eq + !> p + !> (en-beam b) + :: proper decode + :: + %+ expect-eq + !> (some b) + !> (de-beam p) + :: proper round trip + :: + %+ expect-eq + !> (some b) + !> (de-beam (en-beam b)) + :: path too short + :: + %+ expect-eq + !> ~ + !> (de-beam /~zod/home) + :: invalid ship + :: + %+ expect-eq + !> ~ + !> (de-beam /'~zodisok'/home/12/sys/zuse/hoon) + :: invalid desk + :: + %+ expect-eq + !> ~ + !> (de-beam /~zod/12/12/sys/zuse/hoon) + :: invalid case + :: + %+ expect-eq + !> ~ + !> (de-beam /~zod/home/~zod/sys/zuse/hoon) + == +:: example values used in test +:: +++ ex + |% + ++ nul `json`~ + ++ tru `json`[%b &] + ++ num `json`[%n ~.12] + ++ str `json`[%s 'hey'] + ++ frond `json`(frond:enjs 'foo' num) + ++ obj `json`(pairs:enjs ~[['foo' num] ['bar' str]]) + -- +:: functions for creating `json` values +:: +++ test-enjs + =, enjs + ;: weld + :: numbers + :: + %+ expect-eq + !> num:ex + !> (numb 12) + %+ expect-eq + !> num:ex + !> (numb 0xc) + %+ expect-eq + !> [%n '0'] + !> (numb 0) + :: strings + :: + %+ expect-eq + !> str:ex + !> (tape "hey") + %+ expect-eq + :: uses of-wall, so adds the trailing newline + :: + !> [%s 'hi\0athere\0a'] + !> (wall ~["hi" "there"]) + :: objects + :: + %+ expect-eq + !> [%o (molt ~[['foo' num:ex]])] + !> (frond 'foo' num:ex) + =+ props=~[['foo' num:ex] ['bar' tru:ex]] + %+ expect-eq + !> [%o (molt props)] + !> (pairs props) + :: time - stored as integer number of milliseconds since the unix epoch + :: + %+ expect-eq + !> [%n '1000'] + !> (time ~1970.1.1..0.0.1) + :: ship - store ship identity as a string + :: + %+ expect-eq + !> [%s 'zod'] + !> (ship ~zod) + == +:: dejs - recursive processing of `json` values +:: +:: This version crashes when used on improper input. Prefer using +:: dejs-soft (also tested below) which returns units instead. +:: +:: decoding from null, booleans, numbers, strings +:: +++ test-dejs-primitives + =, dejs + ;: weld + :: null + :: + %+ expect-eq + !> ~ + !> (ul `json`~) + :: booleans + :: + :: bo extracts as-is, bu negates it + :: + %+ expect-eq + !> & + !> (bo tru:ex) + %+ expect-eq + !> | + !> (bu tru:ex) + %- expect-fail + |. (bo num:ex) + %- expect-fail + |. (bu num:ex) + :: integers + :: + :: as @ + :: + %+ expect-eq + !> 12 + !> (ni num:ex) + %- expect-fail + |. (ni tru:ex) + :: as cord + :: + %+ expect-eq + !> '12' + !> (no num:ex) + %- expect-fail + |. (no tru:ex) + :: timestamp - ms since the unix epoch + :: + %+ expect-eq + !> ~1970.1.1..00.00.01 + !> (di [%n ~.1000]) + %- expect-fail + |. (di tru:ex) + :: strings + :: + :: string as tape + :: + %+ expect-eq + !> "hey" + !> (sa str:ex) + %- expect-fail + |. (sa tru:ex) + :: string as cord + :: + %+ expect-eq + !> 'hey' + !> (so str:ex) + %- expect-fail + |. (so tru:ex) + :: string with custom parser + :: + %+ expect-eq + !> ' ' + !> ((su (just ' ')) [%s ' ']) + %- expect-fail + |. ((su (just ' ')) tru:ex) + == +:: decoding arrays +:: +++ test-dejs-arrays + =, dejs + ;: weld + :: ar - as list + :: + %+ expect-eq + !> ~[1 2 3] + !> ((ar ni) [%a ~[[%n '1'] [%n '2'] [%n '3']]]) + %- expect-fail + |. ((ar ni) str:ex) + %- expect-fail + |. ((ar ni) [%a ~[str:ex]]) + :: at - as tuple + :: + :: handlers must match exactly + :: + %+ expect-eq + !> [1 'hey'] + !> ((at ~[ni so]) [%a ~[[%n '1'] [%s 'hey']]]) + :: too few or many handlers crash + :: + %- expect-fail + |. ((at ~[ni so]) [%a ~]) + %- expect-fail + |. ((at ~[ni so]) [%a ~[[%n '1'] [%s 'hey'] [%b &]]]) + :: a nested error will crash + :: + %- expect-fail + |. ((at ~[ni]) [%a ~[[%s 'hey']]]) + == +:: decoding objects +:: +++ test-dejs-objects + =, dejs + ;: weld + :: of - single-property objects + :: + %+ expect-eq + !> ['foo' 12] + !> ((of ~[['foo' ni]]) frond:ex) + %+ expect-eq + !> ['foo' 12] + !> ((of ~[['bar' so] ['foo' ni]]) frond:ex) + %- expect-fail + :: the handler needs to apply properly to the value + :: + |. ((of ~[['foo' ni]]) num:ex) + %- expect-fail + :: the key of the frond needs to exist in the handler list + :: + |. ((of ~[['bar' so]]) frond:ex) + %- expect-fail + :: an object with multiple properties is an error + :: + |. ((of ~[['bar' so] ['foo' ni]]) obj:ex) + :: ot - exact-shape objects to tuple + :: + %+ expect-eq + !> [12 'hey'] + !> ((ot ~[['foo' ni] ['bar' so]]) obj:ex) + %- expect-fail + :: it checks it's called on an actual object + :: + |. ((ot ~[['foo' ni]]) num:ex) + %- expect-fail + :: missing property on the object + :: + |. ((ot ~[['foo' ni] ['baz' so]]) obj:ex) + :: ou - object to tuple, with optional properties. value handlers + :: + :: are passed (unit json) + :: + %+ expect-eq + !> [12 14] + !> ((ou ~[['foo' (uf 14 ni)] ['baz' (uf 14 ni)]]) obj:ex) + :: om - simple object as map + :: + %+ expect-eq + !> (molt ~[['foo' num:ex] ['bar' str:ex]]) + !> ((om same) obj:ex) + :: op - object to map, but run a parsing function on the keys + :: + %+ expect-eq + !> (molt ~[[12 num:ex] [14 str:ex]]) + !> ((op dem same) (pairs:enjs ~[['12' num:ex] ['14' str:ex]])) + == +:: decoder transformers +:: +++ test-dejs-transformers + =, dejs + ;: weld + :: cu - decode, then transform + :: + %+ expect-eq + !> 11 + !> ((cu dec ni) [%n ~.12]) + :: ci - decode, then assert a transformation succeeds + :: + %+ expect-eq + !> 12 + !> ((ci some ni) num:ex) + %- expect-fail + |. ((ci |=(* ~) ni) num:ex) + :: mu - decode if not null + :: + %+ expect-eq + !> ~ + !> ((mu ni) nul:ex) + %+ expect-eq + !> (some 12) + !> ((mu ni) num:ex) + :: pe - add prefix to decoded value + :: + %+ expect-eq + !> ['a' 12] + !> ((pe 'a' ni) num:ex) + :: uf - defaults for empty (unit json) + :: + %+ expect-eq + !> 'nah' + !> ((uf 'nah' ni) ~) + %+ expect-eq + !> 12 + !> ((uf 'nah' ni) (some num:ex)) + :: un - dangerous ensure a (unit json) + :: + %+ expect-eq + !> 12 + !> ((un ni) (some num:ex)) + %- expect-fail + |. ((un ni) ~) + == +:: various unit/collection helpers +:: +++ test-dejs-helpers + =, dejs + =+ all=`(list (unit @))`~[(some 1) (some 2) (some 3)] + =+ nall=`(list (unit @))`~[(some 1) ~ (some 3)] + ;: weld + :: za - are all units in this list full? + :: + %+ expect-eq + !> & + !> (za ~) + %+ expect-eq + !> & + !> (za all) + %+ expect-eq + !> | + !> (za nall) + :: zl - collapse (list (unit)) -> (unit (list)) + :: + %+ expect-eq + !> (some ~[1 2 3]) + !> (zl all) + %+ expect-eq + !> ~ + !> (zl nall) + %+ expect-eq + !> (some ~) + !> (zl ~) + :: zp - force unwrap a (list (unit)) as tuple + :: + %+ expect-eq + !> [1 2 3] + !> (zp all) + %- expect-fail + |. (zp nall) + %- expect-fail + |. (zp ~) + :: zm - collapse a (map @tas (unit *)) -> (unit (map @tas *)) + :: + %+ expect-eq + !> (some (molt ~[['a' 1] ['b' 2]])) + !> (zm (molt ~[['a' (some 1)] ['b' (some 2)]])) + %+ expect-eq + !> ~ + !> (zm (molt ~[['a' `(unit @)`(some 1)] ['b' ~]])) + %+ expect-eq + !> (some ~) + !> (zm ~) + == +:: +:: dejs-soft recursive processing of `json` values +:: +:: These functions return units, which will be nil if the input +:: doesn't match the defined structure. +:: +++ test-dejs-soft-primitives + =, dejs-soft + ;: weld + :: null + :: + %+ expect-eq + !> `~ + !> (ul `json`~) + :: booleans + :: + :: bo extracts as-is, bu negates it + :: + %+ expect-eq + !> `& + !> (bo tru:ex) + %+ expect-eq + !> `| + !> (bu tru:ex) + %+ expect-eq + !> ~ + !> (bo num:ex) + %+ expect-eq + !> ~ + !> (bu num:ex) + :: integers + :: as @ + :: + %+ expect-eq + !> `12 + !> (ni num:ex) + %+ expect-eq + !> ~ + !> (ni tru:ex) + :: as cord + :: + %+ expect-eq + !> `'12' + !> (no num:ex) + %+ expect-eq + !> ~ + !> (no tru:ex) + :: timestamp - ms since the unix epoch + :: + %+ expect-eq + !> `~1970.1.1..00.00.01 + !> (di [%n ~.1000]) + %+ expect-eq + !> ~ + !> (di tru:ex) + :: string as tape + :: + %+ expect-eq + !> `"hey" + !> (sa str:ex) + %+ expect-eq + !> ~ + !> (sa tru:ex) + :: string as cord + :: + %+ expect-eq + !> `'hey' + !> (so str:ex) + %+ expect-eq + !> ~ + !> (so tru:ex) + :: string with custom parser + :: + %+ expect-eq + !> `' ' + !> ((su (just ' ')) [%s ' ']) + %+ expect-eq + !> ~ + !> ((su (just ' ')) tru:ex) + == +:: decoding arrays +:: +++ test-dejs-soft-arrays + =, dejs-soft + ;: weld + :: ar - as list + :: + %+ expect-eq + !> `~[1 2 3] + !> ((ar ni) [%a ~[[%n '1'] [%n '2'] [%n '3']]]) + %+ expect-eq + !> ~ + !> ((ar ni) str:ex) + %+ expect-eq + !> ~ + !> ((ar ni) [%a ~[str:ex]]) + :: at - as tuple + :: + :: handlers must match exactly + :: + %+ expect-eq + !> `[1 'hey'] + !> ((at ~[ni so]) [%a ~[[%n '1'] [%s 'hey']]]) + :: too few or many handlers won't match + :: + %+ expect-eq + !> ~ + !> ((at ~[ni so]) [%a ~]) + %+ expect-eq + !> ~ + !> ((at ~[ni so]) [%a ~[[%n '1'] [%s 'hey'] [%b &]]]) + :: a nested failure to match will propagate upwards + :: + %+ expect-eq + !> ~ + !> ((at ~[ni]) [%a ~[[%s 'hey']]]) + == +:: decoding objects +:: +++ test-dejs-soft-objects + =, dejs-soft + ;: weld + :: of - single-property objects + :: + %+ expect-eq + !> `['foo' 12] + !> ((of ~[['foo' ni]]) frond:ex) + %+ expect-eq + !> `['foo' 12] + !> ((of ~[['bar' so] ['foo' ni]]) frond:ex) + %+ expect-eq + !> ~ + :: the handler needs to apply properly to the value + :: + !> ((of ~[['foo' ni]]) num:ex) + %+ expect-eq + !> ~ + :: the key of the frond needs to exist in the handler list + :: + !> ((of ~[['bar' so]]) frond:ex) + %+ expect-eq + !> ~ + :: an object with multiple properties is an error + :: + !> ((of ~[['bar' so] ['foo' ni]]) obj:ex) + :: ot - exact-shape objects to tuple + :: + %+ expect-eq + !> `[12 'hey'] + !> ((ot ~[['foo' ni] ['bar' so]]) obj:ex) + %+ expect-eq + !> ~ + :: missing property on the object + :: + !> ((ot ~[['foo' ni] ['baz' so]]) obj:ex) + :: om - simple object as map + :: + %+ expect-eq + !> `(molt ~[['foo' num:ex] ['bar' str:ex]]) + !> ((om some) obj:ex) + :: op - object to map, but run a parsing function on the keys + :: + %+ expect-eq + !> `(molt ~[[12 num:ex] [14 str:ex]]) + !> ((op dem some) (pairs:enjs ~[['12' num:ex] ['14' str:ex]])) + == +:: decoder transformers +:: +++ test-dejs-soft-transformers + =, dejs-soft + ;: weld + :: cu - decode, then transform + :: + %+ expect-eq + !> `11 + !> ((cu dec ni) [%n ~.12]) + :: ci - decode, then transform, adapting the transformer to return a + :: unit + :: + %+ expect-eq + !> `12 + !> ((ci some ni) num:ex) + %+ expect-eq + !> ~ + !> ((ci |=(* ~) ni) num:ex) + :: mu - decode if not null + :: + %+ expect-eq + !> `~ + !> ((mu ni) nul:ex) + %+ expect-eq + !> `(some 12) + !> ((mu ni) num:ex) + :: pe - add prefix to decoded value + :: + %+ expect-eq + !> `['a' 12] + !> ((pe 'a' ni) num:ex) + == +:: various unit/collection helpers +:: +++ test-dejs-soft-helpers + =, dejs-soft + =+ all=`(list (unit @))`~[(some 1) (some 2) (some 3)] + =+ nall=`(list (unit @))`~[(some 1) ~ (some 3)] + ;: weld + :: za - are all units in this list full? + :: + %+ expect-eq + !> & + !> (za ~) + %+ expect-eq + !> & + !> (za all) + %+ expect-eq + !> | + !> (za nall) + :: zl - collapse (list (unit)) -> (unit (list)) + :: + %+ expect-eq + !> (some ~[1 2 3]) + !> (zl all) + %+ expect-eq + !> ~ + !> (zl nall) + %+ expect-eq + !> (some ~) + !> (zl ~) + :: zp - force unwrap a (list (unit)) as tuple + :: + %+ expect-eq + !> [1 2 3] + !> (zp all) + %- expect-fail + |. (zp nall) + %- expect-fail + |. (zp ~) + :: zm - collapse a (map @tas (unit *)) -> (unit (map @tas *)) + :: + %+ expect-eq + !> (some (molt ~[['a' 1] ['b' 2]])) + !> (zm (molt ~[['a' (some 1)] ['b' (some 2)]])) + %+ expect-eq + !> ~ + !> (zm (molt ~[['a' `(unit @)`(some 1)] ['b' ~]])) + %+ expect-eq + !> (some ~) + !> (zm ~) + == +-- diff --git a/pkg/arvo/tests/sys/zuse/html.hoon b/pkg/arvo/tests/sys/zuse/html.hoon index be144b750..9d4b6facf 100644 --- a/pkg/arvo/tests/sys/zuse/html.hoon +++ b/pkg/arvo/tests/sys/zuse/html.hoon @@ -1,13 +1,15 @@ -:: tests for html +:: tests for html +:: /+ *test +=, html =, de-xml:html =, en-xml:html |% -:: de-xml takes a cord but en-xml returns a tape? +:: de-xml takes a cord but en-xml returns a tape? :: ++ test-de-xml ;: weld - :: Basic use + :: Basic use :: %+ expect-eq !> ^- manx +:(de-xml:html (crip "My first webpage

Welcome!

Hello, world! We are on the web.\0a
")) @@ -23,14 +25,15 @@ ;script(src "http://unsafely.tracking.you/cookiemonster.js"); == == - :: CDATA sections + :: CDATA sections :: %+ expect-eq !> ^- manx +:(de-xml:html (crip "")) !> ^- manx ;elem: text - :: comments + :: comments + :: %+ expect-eq !> ^- manx ;elem: text @@ -39,7 +42,7 @@ !> ^- manx ;elem; !> +:(de-xml:html (crip "")) - :: entities + :: entities :: %+ expect-eq !> ^- manx @@ -59,13 +62,13 @@ :: ++ test-en-xml ;: weld - :: Entities + :: Entities :: %+ expect-eq !> ">" !> %- en-xml:html ;elem: > - :: Basic use + :: Basic use :: %+ expect-eq !> %- en-xml:html @@ -82,11 +85,788 @@ == == !> "My first webpage

Welcome!

Hello, world!\0aWe are on the web.\0a
" - :: Attributes + :: Attributes :: %+ expect-eq !> "Submit" !> %- en-xml:html ;input(type "submit"): Submit == +:: JSON encoding/decoding +:: +++ from-code-points + |= points=(list @) + (tufa `(list @c)`points) +++ from-code-point + |= point=@ + (tuft point) ++$ json-parse-spec [name=tape input=cord expected=json] ++$ json-parse-rejection-spec [input=cord name=tape] +:: For checking a large list of examples against expected values. +:: It also nicely formats any failures. +:: +++ run-parse-specs + :: legend tells of a man who made the Kessel run in less than 12 + :: parse-specs... + |= specs=(list json-parse-spec) + %- zing + %- turn + :- specs + |= spec=json-parse-spec + ^- tang + =+ result=(expect-eq !>(`expected.spec) !>((de-json:html input.spec))) + ?~ result ~ + `tang`[[%leaf "in {name.spec}:"] result] +:: Checks that a list of examples all fail to parse +:: +++ run-parse-rejection-specs + |= specs=(list json-parse-rejection-spec) + %- zing + %- turn + :- specs + |= spec=json-parse-rejection-spec + ^- tang + =+ result=(expect-eq !>(~) !>((de-json:html input.spec))) + ?~ result ~ + `tang`[[%leaf "in {name.spec}:"] result] +:: example values used in tests +:: +++ ex + |% + ++ two `json`[%n '2'] + ++ tru `json`[%b &] + -- +:: encoding naked values +:: +++ test-en-json-basics + ;: weld + %+ expect-eq + !> "true" + !> (en-json [%b &]) + %+ expect-eq + !> "false" + !> (en-json [%b |]) + %+ expect-eq + !> "null" + !> (en-json ~) + %+ expect-eq + !> "123.45" + !> (en-json [%n '123.45']) + == +:: encoding strings, with proper escaping rules +:: +++ test-en-json-strings + :: A less-confusing representation of theses strings are included in comments + :: + :: Things get confusing with hoon string literal escapes. The + :: version included as a comment is if you opened the json output + :: in a simple text editor. + :: + ;: weld + :: "hello" + :: + %+ expect-eq + !> "\"hello\"" + !> (en-json [%s 'hello']) + :: it escapes quotes + :: "he said \"wow\"" + :: + %+ expect-eq + !> "\"he said \\\"wow\\\"\"" + !> (en-json [%s 'he said "wow"']) + :: it escapes backslashes + :: "Delete C:\\Windows\\System32" + :: + %+ expect-eq + !> "\"Delete C:\\\\Windows\\\\System32\"" + !> (en-json [%s 'Delete C:\\Windows\\System32']) + :: it uses \n for newlines + :: "hello\nworld" + :: + %+ expect-eq + !> "\"hello\\nworld\"" + !> (en-json [%s 'hello\0aworld']) + :: it uses \u encoding for control characters (0x1f and below) + :: "ding!\u0007" + :: + %+ expect-eq + !> "\"ding!\\u0007\"" + !> (en-json [%s 'ding!\07']) + :: it supports null bytes + :: + %+ expect-eq + !> "\"null\\u0000byte\\u0000separator\"" + !> (en-json [%s 'null\00byte\00separator']) + :: inline unicode characters + :: + %+ expect-eq + !> "\"lmao 🤣\"" + !> (en-json [%s 'lmao 🤣']) + == +:: encoding arrays +:: +++ test-en-json-arrays + ;: weld + :: empty array + :: + %+ expect-eq + !> "[]" + !> (en-json [%a ~]) + :: 1 element + :: + %+ expect-eq + !> "[2]" + !> (en-json [%a ~[two:ex]]) + :: multiple elements are comma-separated + :: + %+ expect-eq + !> "[2,2,2]" + !> (en-json [%a ~[two:ex two:ex two:ex]]) + == +:: encoding basic objects +:: +++ test-en-json-objects + :: opening curly braces are escaped to avoid urbit string literal + :: interpolation + :: + ;: weld + :: empty object + :: + %+ expect-eq + !> "\{}" + !> (en-json [%o ~]) + :: one property + :: + %+ expect-eq + !> "\{\"foo\":2}" + !> (en-json [%o (molt ~[['foo' two:ex]])]) + :: multiple properties are comma-separated + :: + %+ expect-eq + !> "\{\"foo\":2,\"bar\":true}" + !> (en-json [%o (molt ~[['foo' two:ex] ['bar' tru:ex]])]) + :: object keys use same encoding logic as strings + :: + %+ expect-eq + :: {"\u0007\"\n\\":true} + :: + !> "\{\"\\u0007\\\"\\n\\\\\":true}" + !> (en-json [%o (molt ~[['\07"\0a\\' tru:ex]])]) + == +:: object encoding stress-test +:: +++ test-en-json-complex-structure + %+ expect-eq + :: [{}, 4, [[], [{foo: {"4": 4, "true": true}}]]] + :: + !> "[\{},4,[[],[\{\"foo\":\{\"4\":4,\"true\":true}}]]]" + !> %- en-json:html + :- %a + :~ [%o ~] + [%n '4'] + :- %a + :~ [%a ~] + :- %a + :~ %+ frond:enjs:format + 'foo' + (pairs:enjs:format ~[['4' [%n '4']] ['true' [%b &]]]) + == + == + == +:: decoding naked values +:: +++ test-de-json-simple-values + =, html + ;: weld + %+ expect-eq + !> `~ + !> (de-json 'null') + %+ expect-eq + !> `[%b &] + !> (de-json 'true') + %+ expect-eq + !> `[%b |] + !> (de-json 'false') + == +:: The following parser test suite (test-de-json-bad-examples and +:: test-en-json-suite) is adapted from https://github.com/nst/JSONTestSuite/ +:: (Copyright (c) 2016 Nicolas Seriot) under the terms of the MIT license. +:: +:: These are all inputs that should be rejected by a valid json parser +:: +++ test-de-json-bad-examples + %- run-parse-rejection-specs + :~ + ['[1 true]' "n_array_1_true_without_comma"] + ['[aÂ]' "n_array_a_invalid_utf8"] + ['["": 1]' "n_array_colon_instead_of_comma"] + ['[""],' "n_array_comma_after_close"] + ['[,1]' "n_array_comma_and_number"] + ['[1,,2]' "n_array_double_comma"] + ['["x",,]' "n_array_double_extra_comma"] + ['["x"]]' "n_array_extra_close"] + ['["",]' "n_array_extra_comma"] + ['["x"' "n_array_incomplete"] + ['[x' "n_array_incomplete_invalid_value"] + ['[3[4]]' "n_array_inner_array_no_comma"] + ['[ˇ]' "n_array_invalid_utf8"] + ['[1:2]' "n_array_items_separated_by_semicolon"] + ['[,]' "n_array_just_comma"] + ['[-]' "n_array_just_minus"] + ['[ , ""]' "n_array_missing_value"] + ['["a",\0a4\0a,1,' "n_array_newlines_unclosed"] + ['[1,]' "n_array_number_and_comma"] + ['[1,,]' "n_array_number_and_several_commas"] + ['["\0b"\\f]' "n_array_spaces_vertical_tab_formfeed"] + ['[*]' "n_array_star_inside"] + ['[""' "n_array_unclosed"] + ['[1,' "n_array_unclosed_trailing_comma"] + ['[1,\0a1\0a,1' "n_array_unclosed_with_new_lines"] + ['[{}' "n_array_unclosed_with_object_inside"] + ['[fals]' "n_incomplete_false"] + ['[nul]' "n_incomplete_null"] + ['[tru]' "n_incomplete_true"] + ['[++1234]' "n_number_++"] + ['[+1]' "n_number_+1"] + ['[+Inf]' "n_number_+Inf"] + ['[-01]' "n_number_-01"] + ['[-1.0.]' "n_number_-1.0."] + ['[-NaN]' "n_number_-NaN"] + ['[.-1]' "n_number_.-1"] + ['[.2e-3]' "n_number_.2e-3"] + ['[0.1.2]' "n_number_0.1.2"] + ['[1 000.0]' "n_number_1_000"] + ['[1eE2]' "n_number_1eE2"] + ['[Inf]' "n_number_Inf"] + ['[NaN]' "n_number_NaN"] + ['[Ôºë]' "n_number_U+FF11_fullwidth_digit_one"] + ['[1+2]' "n_number_expression"] + ['[0x1]' "n_number_hex_1_digit"] + ['[0x42]' "n_number_hex_2_digits"] + ['[Infinity]' "n_number_infinity"] + ['[0e+-1]' "n_number_invalid+-"] + ['[-123.123foo]' "n_number_invalid-negative-real"] + ['[123Â]' "n_number_invalid-utf-8-in-bigger-int"] + ['[1e1Â]' "n_number_invalid-utf-8-in-exponent"] + ['[0Â]' "n_number_invalid-utf-8-in-int"] + ['[-Infinity]' "n_number_minus_infinity"] + ['[-foo]' "n_number_minus_sign_with_trailing_garbage"] + ['[- 1]' "n_number_minus_space_1"] + ['[-012]' "n_number_neg_int_starting_with_zero"] + ['[-.123]' "n_number_neg_real_without_int_part"] + ['[-1x]' "n_number_neg_with_garbage_at_end"] + ['[1ea]' "n_number_real_garbage_after_e"] + ['[1eÂ]' "n_number_real_with_invalid_utf8_after_e"] + ['[.123]' "n_number_starting_with_dot"] + ['[1.2a-3]' "n_number_with_alpha"] + ['[1.8011670033376514H-308]' "n_number_with_alpha_char"] + ['[012]' "n_number_with_leading_zero"] + ['["x", truth]' "n_object_bad_value"] + ['{[: "x"}' "n_object_bracket_key"] + ['{"x", null}' "n_object_comma_instead_of_colon"] + ['{"x"::"b"}' "n_object_double_colon"] + ['{üá®üá≠}' "n_object_emoji"] + ['{"a":"a" 123}' "n_object_garbage_at_end"] + ['{key: \'value\'}' "n_object_key_with_single_quotes"] + ['{"π":"0",}' "n_object_lone_continuation_byte_in_key_and_trailing_comma"] + ['{"a" b}' "n_object_missing_colon"] + ['{:"b"}' "n_object_missing_key"] + ['{"a" "b"}' "n_object_missing_semicolon"] + ['{"a":' "n_object_missing_value"] + ['{"a"' "n_object_no-colon"] + ['{1:1}' "n_object_non_string_key"] + ['{9999E9999:1}' "n_object_non_string_key_but_huge_number_instead"] + ['{null:null,null:null}' "n_object_repeated_null_null"] + ['{"id":0,,,,,}' "n_object_several_trailing_commas"] + ['{\'a\':0}' "n_object_single_quote"] + ['{"id":0,}' "n_object_trailing_comma"] + ['{"a":"b"}/**/' "n_object_trailing_comment"] + ['{"a":"b"}/**//' "n_object_trailing_comment_open"] + ['{"a":"b"}//' "n_object_trailing_comment_slash_open"] + ['{"a":"b"}/' "n_object_trailing_comment_slash_open_incomplete"] + ['{"a":"b",,"c":"d"}' "n_object_two_commas_in_a_row"] + ['{a: "b"}' "n_object_unquoted_key"] + ['{"a":"a' "n_object_unterminated-value"] + ['{ "foo" : "bar", "a" }' "n_object_with_single_string"] + ['{"a":"b"}#' "n_object_with_trailing_garbage"] + [' ' "n_single_space"] + ['["\\uD800\\"]' "n_string_1_surrogate_then_escape"] + ['["\\uD800\\u"]' "n_string_1_surrogate_then_escape_u"] + ['["\\uD800\\u1"]' "n_string_1_surrogate_then_escape_u1"] + ['["\\uD800\\u1x"]' "n_string_1_surrogate_then_escape_u1x"] + ['[√©]' "n_string_accentuated_char_no_quotes"] + ['["\\x00"]' "n_string_escape_x"] + ['["\\\\\\"]' "n_string_escaped_backslash_bad"] + ['["\\\09"]' "n_string_escaped_ctrl_char_tab"] + ['["\\üåÄ"]' "n_string_escaped_emoji"] + ['["\\"]' "n_string_incomplete_escape"] + ['["\\u00A"]' "n_string_incomplete_escaped_character"] + ['["\\uD834\\uDd"]' "n_string_incomplete_surrogate"] + ['["\\uD800\\uD800\\x"]' "n_string_incomplete_surrogate_escape_invalid"] + ['["\\uÂ"]' "n_string_invalid-utf-8-in-escape"] + ['["\\a"]' "n_string_invalid_backslash_esc"] + ['["\\uqqqq"]' "n_string_invalid_unicode_escape"] + ['["\\Â"]' "n_string_invalid_utf8_after_escape"] + ['[\\u0020"asd"]' "n_string_leading_uescaped_thinspace"] + ['[\\n]' "n_string_no_quotes_with_bad_escape"] + ['"' "n_string_single_doublequote"] + ['[\'single quote\']' "n_string_single_quote"] + ['abc' "n_string_single_string_no_double_quotes"] + ['["\\' "n_string_start_escape_unclosed"] + ['["new' "n_string_unescaped_newline"] + ['line"]' "n_string_unescaped_newline"] + ['["\09"]' "n_string_unescaped_tab"] + ['"\\UA66D"' "n_string_unicode_CapitalU"] + ['""x' "n_string_with_trailing_garbage"] + ['[‚ņ]' "n_structure_U+2060_word_joined"] + ['Ôªø' "n_structure_UTF8_BOM_no_data"] + ['<.>' "n_structure_angle_bracket_."] + ['[]' "n_structure_angle_bracket_null"] + ['[1]x' "n_structure_array_trailing_garbage"] + ['[1]]' "n_structure_array_with_extra_array_close"] + ['["asd]' "n_structure_array_with_unclosed_string"] + ['a√•' "n_structure_ascii-unicode-identifier"] + ['[True]' "n_structure_capitalized_True"] + ['1]' "n_structure_close_unopened_array"] + ['{"x": true,' "n_structure_comma_instead_of_closing_brace"] + ['[][]' "n_structure_double_array"] + [']' "n_structure_end_array"] + ['Ôª{}' "n_structure_incomplete_UTF8_BOM"] + ['Â' "n_structure_lone-invalid-utf-8"] + ['[' "n_structure_lone-open-bracket"] + ['["a\00a"]' "n_string_unescaped_crtl_char"] + ['["\\00"]' "n_string_backslash_00"] + == +:: TODO: de-json is accepting a slew of number formats it shouldn't. +:: +:: Tracking issue here: https://github.com/urbit/urbit/issues/1775 +:: Re-enable this test by removing the disable- prefix +:: +++ disable-test-reject-invalid-numbers + %- run-parse-rejection-specs + :~ + ['123\00' "n_multidigit_number_then_00"] + ['[1.]' "n_number_real_without_fractional_part"] + ['[2.e+3]' "n_number_2.e+3"] + ['[2.e-3]' "n_number_2.e-3"] + ['[2.e3]' "n_number_2.e3"] + ['[9.e+]' "n_number_9.e+"] + ['[0.3e+]' "n_number_0.3e+"] + ['[0.3e]' "n_number_0.3e"] + ['[0.e1]' "n_number_0.e1"] + ['[0E+]' "n_number_0_capital_E+"] + ['[0E]' "n_number_0_capital_E"] + ['[0e+]' "n_number_0e+"] + ['[0e]' "n_number_0e"] + ['[1.0e+]' "n_number_1.0e+"] + ['[1.0e-]' "n_number_1.0e-"] + ['[1.0e]' "n_number_1.0e"] + ['[-2.]' "n_number_-2."] + == +:: these are all inputs that should be accepted by a valid parser +:: +++ test-en-json-suite + =+ frond=frond:enjs:format + =+ pairs=pairs:enjs:format + %- run-parse-specs + :~ + :* "y_array_arraysWithSpaces" + '[[] ]' + [%a ~[[%a ~]]] + == + :* "y_array_empty-string" + '[""]' + [%a ~[[%s '']]] + == + :* "y_array_empty" + '[]' + [%a ~] + == + :* "y_array_ending_with_newline" + '["a"]\0a' + [%a ~[[%s 'a']]] + == + :* "y_array_false" + '[false]' + [%a ~[[%b |]]] + == + :* "y_array_heterogeneous" + '[null, 1, "1", {}]' + [%a ~[~ [%n '1'] [%s '1'] [%o ~]]] + == + :* "y_array_null" + '[null]' + [%a ~[~]] + == + :* "y_array_with_1_and_newline" + '[1\0a]' + [%a ~[[%n '1']]] + == + :* "y_array_with_leading_space" + ' [1]' + [%a ~[[%n '1']]] + == + :* "y_array_with_several_null" + '[1,null,null,null,2]' + [%a ~[[%n '1'] ~ ~ ~ [%n '2']]] + == + :* "y_array_with_trailing_space" + '[2] ' + [%a ~[[%n '2']]] + == + :* "y_number" + '[123e65]' + [%a ~[[%n '123e65']]] + == + :* "y_number_0e+1" + '[0e+1]' + [%a ~[[%n '0e+1']]] + == + :* "y_number_0e1" + '[0e1]' + [%a ~[[%n '0e1']]] + == + :* "y_number_after_space" + '[ 4]' + [%a ~[[%n '4']]] + == + :* "y_number_double_close_to_zero" + '[-0.0000000000000000000000000000000000000000000000000000000\ + /00000000000000000000001]' + [%a ~[[%n '-0.0000000000000000000000000000000000000000000000\ + /00000000000000000000000000000001']]] + == + :* "y_number_int_with_exp" + '[20e1]' + [%a ~[[%n '20e1']]] + == + :* "y_number_minus_zero" + '[-0]' + [%a ~[[%n '-0']]] + == + :* "y_number_negative_int" + '[-123]' + [%a ~[[%n '-123']]] + == + :* "y_number_negative_one" + '[-1]' + [%a ~[[%n '-1']]] + == + :* "y_number_negative_zero" + '[-0]' + [%a ~[[%n '-0']]] + == + :* "y_number_real_capital_e" + '[1E22]' + [%a ~[[%n '1E22']]] + == + :* "y_number_real_capital_e_neg_exp" + '[1E-2]' + [%a ~[[%n '1E-2']]] + == + :* "y_number_real_capital_e_pos_exp" + '[1E+2]' + [%a ~[[%n '1E+2']]] + == + :* "y_number_real_exponent" + '[123e45]' + [%a ~[[%n '123e45']]] + == + :* "y_number_real_fraction_exponent" + '[123.456e78]' + [%a ~[[%n '123.456e78']]] + == + :* "y_number_real_neg_exp" + '[1e-2]' + [%a ~[[%n '1e-2']]] + == + :* "y_number_real_pos_exponent" + '[1e+2]' + [%a ~[[%n '1e+2']]] + == + :* "y_number_simple_int" + '[123]' + [%a ~[[%n '123']]] + == + :* "y_number_simple_real" + '[123.456789]' + [%a ~[[%n '123.456789']]] + == + :* "y_object" + '{"asd":"sdf", "dfg":"fgh"}' + (pairs ~[['asd' [%s 'sdf']] ['dfg' [%s ['fgh']]]]) + == + :* "y_object_basic" + '{"asd":"sdf"}' + (frond ['asd' [%s 'sdf']]) + == + :: duplicated keys, it takes the latest one. + :: + :* "y_object_duplicated_key" + '{"a":"b","a":"c"}' + (frond ['a' [%s 'c']]) + == + :* "y_object_duplicated_key_and_value" + '{"a":"b","a":"b"}' + (frond ['a' [%s 'b']]) + == + :* "y_object_empty" + '{}' + [%o ~] + == + :* "y_object_empty_key" + '{"":0}' + (frond ['' [%n '0']]) + == + :* "y_object_extreme_numbers" + '{ "min": -1.0e+28, "max": 1.0e+28 }' + (pairs ~[['min' [%n '-1.0e+28']] ['max' [%n '1.0e+28']]]) + == + =/ long=@t 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' + :* "y_object_long_strings" + '{"x":[{"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}], \ + /"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}' + (pairs ~[['id' [%s long]] ['x' [%a ~[(frond ['id' [%s long]])]]]]) + == + :* "y_object_simple" + '{"a":[]}' + (frond 'a' [%a ~]) + == + :* "y_object_string_unicode" + '{"title":"\\u041f\\u043e\\u043b\\u0442\\u043e\\u0440\\u0430 \ + /\\u0417\\u0435\\u043c\\u043b\\u0435\\u043a\\u043e\\u043f\\u0430" }' + (frond 'title' [%s 'Полтора Землекопа']) + == + :* "y_object_with_newlines" + '{\0a"a": "b"\0a}' + (frond 'a' [%s 'b']) + == + :* "y_string_allowed_escapes" + '["\\"\\\\\\/\\b\\f\\n\\r\\t"]' + [%a ~[[%s '"\\/\08\0c\0a\0d\09']]] + == + :* "y_string_backslash_and_u_escaped_zero" + '["\\\\u0000"]' + [%a ~[[%s '\\u0000']]] + == + :* "y_string_backslash_doublequotes" + '["\\""]' + [%a ~[[%s '"']]] + == + :* "y_string_comments" + '["a/*b*/c/*d//e"]' + [%a ~[[%s 'a/*b*/c/*d//e']]] + == + :* "y_string_double_escape_a" + '["\\\\a"]' + [%a ~[[%s '\\a']]] + == + :* "y_string_double_escape_n" + '["\\\\n"]' + [%a ~[[%s '\\n']]] + == + :* "y_string_escaped_control_character" + '["\\u0012"]' + [%a ~[[%s '\12']]] + == + :* "y_string_in_array_with_leading_space" + '[ "asd"]' + [%a ~[[%s 'asd']]] + == + :* "y_string_nonCharacterInUTF-8_U+10FFFF" + '["􏿿"]' + [%a ~[[%s (from-code-point 0x10.ffff)]]] + == + :* "y_string_nonCharacterInUTF-8_U+FFFF" + '["￿"]' + [%a ~[[%s (from-code-point 0xffff)]]] + == + :* "y_string_null_escape" + '["\\u0000"]' + [%a ~[[%s '\00']]] + == + :* "y_string_one-byte-utf-8" + '["\\u002c"]' + [%a ~[[%s '\2c']]] + == + :* "y_string_pi" + '["π"]' + [%a ~[[%s 'π']]] + == + :* "y_string_reservedCharacterInUTF-8_U+1BFFF" + '["𛿿"]' + [%a ~[[%s (from-code-point 0x1.bfff)]]] + == + :* "y_string_simple_ascii" + '["asd "]' + [%a ~[[%s 'asd ']]] + == + :* "y_string_space" + '" "' + [%s ' '] + == + :* "y_string_three-byte-utf-8" + '["\\u0821"]' + [%a ~[[%s (from-code-point 0x821)]]] + == + :* "y_string_two-byte-utf-8" + '["\\u0123"]' + [%a ~[[%s (from-code-point 0x123)]]] + == + :* "y_string_u+2028_line_sep" + '["
"]' + [%a ~[[%s (from-code-point 0x2028)]]] + == + :* "y_string_u+2029_par_sep" + '["
"]' + [%a ~[[%s (from-code-point 0x2029)]]] + == + :* "y_string_unicode_2" + '["⍂㈴⍂"]' + [%a ~[[%s '⍂㈴⍂']]] + == + :* "y_string_unicode_U+2064_invisible_plus" + '["\\u2064"]' + [%a ~[[%s (from-code-point 0x2064)]]] + == + :* "y_string_unicode_escaped_double_quote" + '["\\u0022"]' + [%a ~[[%s (from-code-point 0x22)]]] + == + :* "y_string_utf8" + '["€𝄞"]' + [%a ~[[%s '€𝄞']]] + == + :* "y_structure_lonely_false" + 'false' + [%b |] + == + :* "y_structure_lonely_int" + '42' + [%n '42'] + == + :* "y_structure_lonely_negative_real" + '-0.1' + [%n '-0.1'] + == + :* "y_structure_lonely_null" + 'null' + ~ + == + :* "y_structure_lonely_string" + '"asd"' + [%s 'asd'] + == + :* "y_structure_lonely_true" + 'true' + [%b &] + == + :* "y_structure_string_empty" + '""' + [%s ''] + == + :* "y_structure_trailing_newline" + '["a"]\0a' + [%a ~[[%s 'a']]] + == + :* "y_structure_true_in_array" + '[true]' + [%a ~[[%b &]]] + == + :* "y_structure_whitespace_array" + ' [] ' + [%a ~] + == + == +:: TODO: de-json is rejecting or dropping unicode escape sequences +:: +:: Tracking issue here: https://github.com/urbit/urbit/issues/1776 +:: Re-enable this test by removing the disable- prefix +:: +++ disable-test-parse-unicode-escape-sequences + =+ frond=frond:enjs:format + =+ pairs=pairs:enjs:format + %- run-parse-specs + :~ + :* "y_string_with_del_character" + '["a\7fa"]' + [%a ~[[%s 'a\7fa']]] + == + :* "y_string_unicode_U+FDD0_nonchar" + '["\\uFDD0"]' + [%a ~[[%s (from-code-point 0xfdd0)]]] + == + :* "y_string_unicode_U+FFFE_nonchar" + '["\\uFFFE"]' + [%a ~[[%s (from-code-point 0xfffe)]]] + == + :* "y_string_unicode_U+10FFFE_nonchar" + '["\\uDBFF\\uDFFE"]' + [%a ~[[%s (crip (from-code-points ~[0xdbff 0xdffe]))]]] + == + :* "y_string_unicode_U+1FFFE_nonchar" + '["\\uD83F\\uDFFE"]' + [%a ~[[%s (crip (from-code-points ~[0xd83f 0xdffe]))]]] + == + :* "y_string_unicode_U+200B_ZERO_WIDTH_SPACE" + '["\\u200B"]' + [%a ~[[%s (from-code-point 0x200b)]]] + == + :* "y_string_uEscape" + '["\\u0061\\u30af\\u30EA\\u30b9"]' + [%a ~[[%s (crip (from-code-points ~[0x61 0x30af 0x30ea 0x30b9]))]]] + == + :* "y_string_uescaped_newline" + '["new\\u000Aline"]' + [%a ~[[%s 'new\0aline']]] + == + :* "y_string_unescaped_char_delete" + '["\7f"]' + [%a ~[[%s '\7f']]] + == + :* "y_string_unicode" + '["\\uA66D"]' + [%a ~[[%s (from-code-point 0xa66d)]]] + == + :* "y_string_unicodeEscapedBackslash" + '["\\u005C"]' + [%a ~[[%s (from-code-point 0x5c)]]] + == + :* "y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF" + '["\\uD834\\uDd1e"]' + [%a ~[[%s (crip (from-code-points ~[0xd834 0xdd1e]))]]] + == + :* "y_string_last_surrogates_1_and_2" + '["\\uDBFF\\uDFFF"]' + [%a ~[[%s (crip (from-code-points ~[0xdbff 0xdfff]))]]] + == + :* "y_string_nbsp_uescaped" + '["new\\u00A0line"]' + [%a ~[[%s (crip "new{(from-code-points ~[0xa0])}line")]]] + == + :* "y_string_escaped_noncharacter" + '["\\uFFFF"]' + [%a ~[[%s (from-code-point 0xffff)]]] + == + :* "y_string_escaped_null" + '"foo\\u0000bar"' + [%s 'foo\00bar'] + == + :* "y_object_escaped_null_in_key" + '{"foo\\u0000bar": 42}' + (frond ['foo\00bar' [%n '42']]) + == + :* "y_string_1_2_3_bytes_UTF-8_sequences" + '["\\u0060\\u012a\\u12AB"]' + [%a ~[[%s '`Īካ']]] + == + :* "y_string_accepted_surrogate_pair" + '["\\uD801\\udc37"]' + [%a ~[[%s '𐐷']]] + == + :* "y_string_accepted_surrogate_pairs" + '["\\ud83d\\ude39\\ud83d\\udc8d"]' + [%a ~[[%s '😹💍']]] + == + == -- diff --git a/pkg/interface/chat/src/js/components/chat.js b/pkg/interface/chat/src/js/components/chat.js index 2d74702cd..0ef1aac10 100644 --- a/pkg/interface/chat/src/js/components/chat.js +++ b/pkg/interface/chat/src/js/components/chat.js @@ -76,8 +76,7 @@ export class ChatScreen extends Component { props.history.push("/~chat"); } else if ( - props.envelopes.length - prevProps.envelopes.length >= - 40 + props.envelopes.length >= prevProps.envelopes.length + 10 ) { this.hasAskedForMessages = false; if (prevProps.envelopes.length <= 20) { @@ -106,24 +105,19 @@ export class ChatScreen extends Component { } if ( - state.numPages * 100 >= props.length || + props.envelopes.length >= props.length || this.hasAskedForMessages || props.length <= 0 ) { return; } - let end = props.envelopes[0].number; - if (end > 0) { - let start = end - 400 > 0 ? end - 400 : 0; - - if (start === 0 && end === 1) { - return; - } - + let start = + props.length - props.envelopes[props.envelopes.length - 1].number; + if (start > 0) { + let end = start + 300 < props.length ? start + 300 : props.length; this.hasAskedForMessages = true; - - props.subscription.fetchMessages(start, end - 1, props.station); + props.subscription.fetchMessages(start + 1, end, props.station); } } @@ -193,33 +187,29 @@ export class ChatScreen extends Component { const { props, state } = this; let messages = props.envelopes.slice(0); + let lastMsgNum = messages.length > 0 ? messages.length : 0; + if (messages.length > 100 * state.numPages) { - messages = messages.slice( - messages.length - 100 * state.numPages, - messages.length - ); + messages = messages.slice(0, 100 * state.numPages); } let pendingMessages = props.pendingMessages.has(props.station) - ? props.pendingMessages.get(props.station) + ? props.pendingMessages.get(props.station).reverse() : []; pendingMessages.map(function (value) { return (value.pending = true); }); - let reversedMessages = messages.concat(pendingMessages); - reversedMessages = reversedMessages.reverse(); - - reversedMessages = reversedMessages.map((msg, i) => { + let messageElements = pendingMessages.concat(messages).map((msg, i) => { // Render sigil if previous message is not by the same sender let aut = ["author"]; let renderSigil = - _.get(reversedMessages[i + 1], aut) !== + _.get(messages[i + 1], aut) !== _.get(msg, aut, msg.author); let paddingTop = renderSigil; let paddingBot = - _.get(reversedMessages[i - 1], aut) !== + _.get(messages[i - 1], aut) !== _.get(msg, aut, msg.author); return ( @@ -248,7 +238,7 @@ export class ChatScreen extends Component { }}> {( !(props.station in props.chatSynced) && - (reversedMessages.length > 0) + (messages.length > 0) ) ? ( ) : (
) } - {reversedMessages} + {messageElements}
)} @@ -272,7 +262,7 @@ export class ChatScreen extends Component { }}> {( !(props.station in props.chatSynced) && - (reversedMessages.length > 0) + (messages.length > 0) ) ? ( ) : (
) } - {reversedMessages} + {messageElements}
)} } diff --git a/pkg/interface/chat/src/js/components/lib/invite-search.js b/pkg/interface/chat/src/js/components/lib/invite-search.js index dc6cf8a20..71a43e63e 100644 --- a/pkg/interface/chat/src/js/components/lib/invite-search.js +++ b/pkg/interface/chat/src/js/components/lib/invite-search.js @@ -88,11 +88,11 @@ export class InviteSearch extends Component { this.setState({ searchValue: event.target.value }); - if (searchTerm.length < 2) { + if (searchTerm.length < 1) { this.setState({ searchResults: { groups: [], ships: [] } }); } - if (searchTerm.length > 2) { + if (searchTerm.length > 0) { if (this.state.inviteError === true) { this.setState({ inviteError: false }); } @@ -100,7 +100,7 @@ export class InviteSearch extends Component { let groupMatches = []; if (this.props.groupResults) { groupMatches = this.state.groups.filter(e => { - return (e[0].includes(searchTerm) || e[1].includes(searchTerm)); + return (e[0].includes(searchTerm) || e[1].toLowerCase().includes(searchTerm)); }); } @@ -127,8 +127,8 @@ export class InviteSearch extends Component { isValid = false; } - if (shipMatches.length === 0 && isValid) { - shipMatches.push(searchTerm); + if (isValid && shipMatches.findIndex(s => s === searchTerm) < 0) { + shipMatches.unshift(searchTerm); } } @@ -141,6 +141,15 @@ export class InviteSearch extends Component { this.setState({ selected: newSelection }) } + + if(searchTerm.length < 3) { + groupMatches = groupMatches.filter(([, name]) => + name.toLowerCase().split(' ').some(s => s.startsWith(searchTerm)) + ).sort((a,b) => a[1].length - b[1].length); + + shipMatches = shipMatches.slice(0,3); + } + this.setState({ searchResults: { groups: groupMatches, ships: shipMatches } }); diff --git a/pkg/interface/chat/src/js/reducers/chat-update.js b/pkg/interface/chat/src/js/reducers/chat-update.js index 7175ff628..7ded8c443 100644 --- a/pkg/interface/chat/src/js/reducers/chat-update.js +++ b/pkg/interface/chat/src/js/reducers/chat-update.js @@ -17,7 +17,7 @@ export class ChatUpdateReducer { message(json, state) { let data = _.get(json, 'message', false); if (data) { - state.inbox[data.path].envelopes.push(data.envelope); + state.inbox[data.path].envelopes.unshift(data.envelope); state.inbox[data.path].config.length = state.inbox[data.path].config.length + 1; } @@ -27,9 +27,7 @@ export class ChatUpdateReducer { let data = _.get(json, 'messages', false); if (data) { state.inbox[data.path].envelopes = - data.envelopes.concat(state.inbox[data.path].envelopes); - state.inbox[data.path].config.length = - state.inbox[data.path].config.length + data.envelopes.length; + state.inbox[data.path].envelopes.concat(data.envelopes); } } diff --git a/pkg/interface/groups/src/js/components/lib/invite-search.js b/pkg/interface/groups/src/js/components/lib/invite-search.js index 6dce2d595..adc9bcdd5 100644 --- a/pkg/interface/groups/src/js/components/lib/invite-search.js +++ b/pkg/interface/groups/src/js/components/lib/invite-search.js @@ -89,11 +89,11 @@ export class InviteSearch extends Component { this.setState({ searchValue: event.target.value }); - if (searchTerm.length < 2) { + if (searchTerm.length < 1) { this.setState({ searchResults: { groups: [], ships: [] } }); } - if (searchTerm.length > 2) { + if (searchTerm.length > 0) { if (this.state.inviteError === true) { this.setState({ inviteError: false }); } @@ -101,7 +101,7 @@ export class InviteSearch extends Component { let groupMatches = []; if (this.props.groupResults) { groupMatches = this.state.groups.filter(e => { - return e[0].includes(searchTerm) || e[1].includes(searchTerm); + return e[0].includes(searchTerm) || e[1].toLowerCase().includes(searchTerm); }); } @@ -128,8 +128,8 @@ export class InviteSearch extends Component { isValid = false; } - if (shipMatches.length === 0 && isValid) { - shipMatches.push(searchTerm); + if (isValid && shipMatches.findIndex(s => s === searchTerm) < 0) { + shipMatches.unshift(searchTerm); } } @@ -142,6 +142,15 @@ export class InviteSearch extends Component { this.setState({ selected: newSelection }) } + + if(searchTerm.length < 3) { + groupMatches = groupMatches.filter(([, name]) => + name.toLowerCase().split(' ').some(s => s.startsWith(searchTerm)) + ).sort((a,b) => a[1].length - b[1].length); + + shipMatches = shipMatches.slice(0,3); + } + this.setState({ searchResults: { groups: groupMatches, ships: shipMatches } }); diff --git a/pkg/interface/link/src/js/components/lib/invite-search.js b/pkg/interface/link/src/js/components/lib/invite-search.js index 734639e38..f1d0fc3fb 100644 --- a/pkg/interface/link/src/js/components/lib/invite-search.js +++ b/pkg/interface/link/src/js/components/lib/invite-search.js @@ -89,11 +89,11 @@ export class InviteSearch extends Component { this.setState({ searchValue: event.target.value }); - if (searchTerm.length < 2) { + if (searchTerm.length < 1) { this.setState({ searchResults: { groups: [], ships: [] } }); } - if (searchTerm.length > 2) { + if (searchTerm.length > 0) { if (this.state.inviteError === true) { this.setState({ inviteError: false }); } @@ -101,7 +101,7 @@ export class InviteSearch extends Component { let groupMatches = []; if (this.props.groupResults) { groupMatches = this.state.groups.filter(e => { - return e[0].includes(searchTerm) || e[1].includes(searchTerm); + return e[0].includes(searchTerm) || e[1].toLowerCase().includes(searchTerm); }); } @@ -128,8 +128,8 @@ export class InviteSearch extends Component { isValid = false; } - if (shipMatches.length === 0 && isValid) { - shipMatches.push(searchTerm); + if (isValid && shipMatches.findIndex(s => s === searchTerm) < 0) { + shipMatches.unshift(searchTerm); } } @@ -142,6 +142,14 @@ export class InviteSearch extends Component { this.setState({ selected: newSelection }) } + if(searchTerm.length < 3) { + groupMatches = groupMatches.filter(([, name]) => + name.toLowerCase().split(' ').some(s => s.startsWith(searchTerm)) + ).sort((a,b) => a[1].length - b[1].length); + + shipMatches = shipMatches.slice(0,3); + } + this.setState({ searchResults: { groups: groupMatches, ships: shipMatches } }); diff --git a/pkg/interface/publish/package-lock.json b/pkg/interface/publish/package-lock.json index 1078d32ec..c849cf82b 100644 --- a/pkg/interface/publish/package-lock.json +++ b/pkg/interface/publish/package-lock.json @@ -3764,6 +3764,11 @@ "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" }, + "mousetrap": { + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/mousetrap/-/mousetrap-1.6.5.tgz", + "integrity": "sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA==" + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", diff --git a/pkg/interface/publish/package.json b/pkg/interface/publish/package.json index 5dfdec94a..fe5d43f5f 100644 --- a/pkg/interface/publish/package.json +++ b/pkg/interface/publish/package.json @@ -32,6 +32,7 @@ "del": "^5.1.0", "lodash": "^4.17.11", "moment": "^2.20.1", + "mousetrap": "^1.6.5", "react": "^16.5.2", "react-codemirror2": "^6.0.0", "react-dom": "^16.8.6", diff --git a/pkg/interface/publish/src/js/components/lib/invite-search.js b/pkg/interface/publish/src/js/components/lib/invite-search.js index 6f8063b69..a15971102 100644 --- a/pkg/interface/publish/src/js/components/lib/invite-search.js +++ b/pkg/interface/publish/src/js/components/lib/invite-search.js @@ -89,11 +89,11 @@ export class InviteSearch extends Component { this.setState({ searchValue: event.target.value }); - if (searchTerm.length < 2) { + if (searchTerm.length < 1) { this.setState({ searchResults: { groups: [], ships: [] } }); } - if (searchTerm.length > 2) { + if (searchTerm.length > 0) { if (this.state.inviteError === true) { this.setState({ inviteError: false }); } @@ -101,7 +101,7 @@ export class InviteSearch extends Component { let groupMatches = []; if (this.props.groupResults) { groupMatches = this.state.groups.filter(e => { - return e[0].includes(searchTerm) || e[1].includes(searchTerm); + return e[0].includes(searchTerm) || e[1].toLowerCase().includes(searchTerm); }); } @@ -128,8 +128,8 @@ export class InviteSearch extends Component { isValid = false; } - if (shipMatches.length === 0 && isValid) { - shipMatches.push(searchTerm); + if (isValid && shipMatches.findIndex(s => s === searchTerm) < 0) { + shipMatches.unshift(searchTerm); } } @@ -142,6 +142,14 @@ export class InviteSearch extends Component { this.setState({ selected: newSelection }) } + if(searchTerm.length < 3) { + groupMatches = groupMatches.filter(([, name]) => + name.toLowerCase().split(' ').some(s => s.startsWith(searchTerm)) + ).sort((a,b) => a[1].length - b[1].length); + + shipMatches = shipMatches.slice(0,3); + } + this.setState({ searchResults: { groups: groupMatches, ships: shipMatches } }); diff --git a/pkg/interface/publish/src/js/reducers/primary.js b/pkg/interface/publish/src/js/reducers/primary.js index bed201e8a..b483746c6 100644 --- a/pkg/interface/publish/src/js/reducers/primary.js +++ b/pkg/interface/publish/src/js/reducers/primary.js @@ -60,18 +60,22 @@ export class PrimaryReducer { let book = Object.keys(json[host])[0]; let noteId = json[host][book]["note-id"]; if (state.notebooks[host] && state.notebooks[host][book]) { - if (state.notebooks[host][book]["notes-by-date"]) { - state.notebooks[host][book]["notes-by-date"].unshift(noteId); - } else { - state.notebooks[host][book]["notes-by-date"] = [noteId]; - } - if (state.notebooks[host][book].notes) { + if (state.notebooks[host][book].notes[noteId] && + state.notebooks[host][book].notes[noteId].pending) + { + state.notebooks[host][book].notes[noteId].pending = false; + return; + } + if (state.notebooks[host][book]["notes-by-date"]) { + state.notebooks[host][book]["notes-by-date"].unshift(noteId); + } else { + state.notebooks[host][book]["notes-by-date"] = [noteId]; + } state.notebooks[host][book].notes[noteId] = json[host][book]; } else { state.notebooks[host][book].notes = {[noteId]: json[host][book]}; } - state.notebooks[host][book]["num-notes"] += 1; if (!json[host][book].read) { state.notebooks[host][book]["num-unread"] += 1; @@ -79,7 +83,6 @@ export class PrimaryReducer { let prevNoteId = state.notebooks[host][book]["notes-by-date"][1] || null; state.notebooks[host][book].notes[noteId]["prev-note"] = prevNoteId state.notebooks[host][book].notes[noteId]["next-note"] = null; - if (state.notebooks[host][book].notes[prevNoteId]) { state.notebooks[host][book].notes[prevNoteId]["next-note"] = noteId; } @@ -96,10 +99,26 @@ export class PrimaryReducer { state.notebooks[host][book].notes && state.notebooks[host][book].notes[note]) { - state.notebooks[host][book].notes[note]["num-comments"] += 1; + if (state.notebooks[host][book].notes[note].comments) { - state.notebooks[host][book].notes[note].comments.unshift(comment); + let limboCommentIdx = + _.findIndex(state.notebooks[host][book].notes[note].comments, (o) => { + let oldVal = o[Object.keys(o)[0]]; + let newVal = comment[Object.keys(comment)[0]]; + return (oldVal.pending && + (oldVal.author === newVal.author) && + (oldVal.content === newVal.content) + ); + }); + if (limboCommentIdx === -1) { + state.notebooks[host][book].notes[note]["num-comments"] += 1; + state.notebooks[host][book].notes[note].comments.unshift(comment); + } else { + state.notebooks[host][book].notes[note].comments[limboCommentIdx] = + comment; + } } else if (state.notebooks[host][book].notes[note]["num-comments"] === 1) { + state.notebooks[host][book].notes[note]["num-comments"] += 1; state.notebooks[host][book].notes[note].comments = [comment]; } }