shrub/pkg/arvo/lib/hark/store.hoon

563 lines
12 KiB
Plaintext
Raw Normal View History

2020-10-27 08:04:39 +03:00
/- sur=hark-store, post
/+ resource, graph-store, group-store
2020-10-27 08:04:39 +03:00
^?
=< [. sur]
=, sur
|%
2021-05-04 07:17:55 +03:00
++ upgrade
|%
2021-05-04 08:21:49 +03:00
++ to-three
=* two state-two
=* three state-three
|%
++ index
|= =index:two
^- (unit index:three)
`index
++ contents
|= =contents:two
^- (unit contents:three)
?. ?=(%group -.contents)
`contents
=- ?: =(~ -) ~
`[%group -]
%+ murn list.contents
|= =group-contents:two
^- (unit group-contents:three)
?: ?=(?(%add %remove) -.group-contents)
~
`group-contents
::
++ stats-index
|= =stats-index:two
^- (unit stats-index:three)
`stats-index
::
++ notifications
upg-notifications:upg
::
++ upg
%. [index stats-index contents]
%: upgrade
index:two
stats-index:two
contents:two
index:three
stats-index:three
contents:three
==
--
::
2021-05-04 07:17:55 +03:00
++ to-four
=* three state-three
=* four state-four
|%
++ index
|= =index:three
^- (unit index:four)
`index
++ contents
|= =contents:three
^- (unit contents:four)
?. ?=(%graph -.contents)
`contents
`[%graph (turn list.contents post-to-one:upgrade:graph-store)]
::
++ unreads-each
upg-unreads-each:upg
::
++ notifications
upg-notifications:upg
::
++ stats-index
|= =stats-index:three
^- (unit stats-index:four)
`stats-index
::
++ upg
%. [index stats-index contents]
%: upgrade
index:three
stats-index:three
contents:three
index:four
stats-index:four
contents:four
==
--
::
++ to-five
=* four state-four
=* five sur
|%
++ mark
|= module=@t
^- (unit @t)
?+ module ~
%chat `%graph-validator-chat
%publish `%graph-validator-publish
%link `%graph-validator-link
==
++ index
|= =index:four
^- (unit index:five)
?: ?=(%group -.index)
`index
=* i index
`[%graph graph.i (mark module.i) description.i index.i]
::
++ contents
|= =contents:four
^- (unit contents:five)
`contents
::
++ unreads-each
upg-unreads-each:upg
::
++ stats-index
|= =stats-index:four
^- (unit stats-index:five)
`stats-index
::
++ upg
%. [index stats-index contents]
%: upgrade
index:four
stats-index:four
contents:four
index:five
stats-index:five
contents:five
==
++ notifications
upg-notifications:upg
--
::
++ upgrade
|* $: :: input molds
in-index=mold
in-stats-index=mold
in-contents=mold
:: output molds
out-index=mold
out-stats-index=mold
out-contents=mold
==
=> . =>
|%
::
++ in
|%
::
+$ index in-index
+$ stats-index in-stats-index
+$ contents in-contents
+$ unreads-each (jug stats-index index)
+$ timebox (map index notification)
+$ notification
[date=@da read=? =contents]
++ orm
((ordered-map time timebox) gth)
+$ notifications
((mop time timebox) gth)
--
++ out
|%
::
::
+$ index out-index
+$ stats-index out-stats-index
+$ contents out-contents
+$ timebox (map out-index notification)
+$ unreads-each (jug stats-index index)
+$ notification
[date=@da read=? contents=out-contents]
+$ notifications
((mop time timebox) gth)
++ orm
((ordered-map time timebox) gth)
--
--
|= $: fun-index=$-(index:in (unit index:out))
fun-stats-index=$-(stats-index:in (unit stats-index:out))
fun-contents=$-(contents:in (unit contents:out))
==
|%
::
++ upg-unreads-each
|= =unreads-each:in
^- unreads-each:out
%- ~(gas by *unreads-each:out)
%+ murn ~(tap by unreads-each)
|= [=stats-index:in indices=(set index:in)]
^- (unit [stats-index:out (set index:out)])
=/ new-stats
(fun-stats-index stats-index)
?~ new-stats ~
=/ new-indices
(upg-indices indices)
?: =(0 ~(wyt ^in new-indices)) ~
`[u.new-stats new-indices]
::
++ upg-indices
|= indices=(set index:in)
^- (set index:out)
%- ~(gas ^in *(set index:out))
(murn ~(tap ^in indices) fun-index)
::
++ upg-notifications
|= =notifications:in
^- notifications:out
%+ gas:orm:out *notifications:out
^- (list [@da timebox:out])
%+ murn (tap:orm:in notifications)
|= [time=@da =timebox:in]
^- (unit [@da =timebox:out])
=/ new-timebox=timebox:out
(upg-timebox timebox)
?: =(0 ~(wyt by timebox))
~
`[time new-timebox]
::
++ upg-timebox
|= =timebox:in
^- timebox:out
%- ~(gas by *timebox:out)
%+ murn ~(tap by timebox)
|= [=index:in =notification:in]
^- (unit [index:out notification:out])
=/ new-index
(fun-index index)
?~ new-index ~
=/ new-notification
(upg-notification notification)
?~ new-notification ~
`[u.new-index u.new-notification]
::
++ upg-notification
|= n=notification:in
^- (unit notification:out)
=/ new-contents
(fun-contents contents.n)
?~ new-contents ~
`[date.n read.n u.new-contents]
--
--
2020-10-27 08:04:39 +03:00
++ dejs
=, dejs:format
|%
++ index
%- of
:~ graph+graph-index
group+group-index
==
::
++ group-index
%- ot
:~ group+dejs-path:resource
description+so
==
::
++ graph-index
%- ot
:~ graph+dejs-path:resource
2021-05-03 09:11:57 +03:00
mark+(mu so)
2020-10-27 08:04:39 +03:00
description+so
index+(su ;~(pfix fas (more fas dem)))
2020-10-27 08:04:39 +03:00
==
2020-12-16 07:22:23 +03:00
::
++ stats-index
%- of
:~ graph+graph-stats-index
2020-12-16 10:37:10 +03:00
group+dejs-path:resource
2020-12-16 07:22:23 +03:00
==
++ graph-stats-index
%- ot
2020-12-16 10:37:10 +03:00
:~ graph+dejs-path:resource
index+graph-store-index
2020-12-16 07:22:23 +03:00
==
2020-10-27 08:04:39 +03:00
:: parse date as @ud
:: TODO: move to zuse
++ sd
|= jon=json
^- @da
?> ?=(%s -.jon)
`@da`(rash p.jon dem:ag)
::
++ notif-ref
2021-05-17 06:35:00 +03:00
^- $-(json [(unit @da) ^index])
2020-10-27 08:04:39 +03:00
%- ot
2021-05-17 06:35:00 +03:00
:~ time+(mu sd)
2020-10-27 08:04:39 +03:00
index+index
==
2020-12-16 10:37:10 +03:00
++ graph-store-index
2020-12-16 07:22:23 +03:00
(su ;~(pfix fas (more fas dem)))
2020-10-27 08:04:39 +03:00
::
++ add
|= jon=json
[*^index *notification]
::
++ read-graph-index
%- ot
2020-12-16 07:22:23 +03:00
:~ index+stats-index
2020-12-16 10:37:10 +03:00
target+graph-store-index
==
::
2020-10-27 08:04:39 +03:00
++ action
^- $-(json ^action)
%- of
:~ seen+ul
archive+notif-ref
2021-05-17 06:35:00 +03:00
read-note+index
add-note+add
2020-10-27 08:04:39 +03:00
set-dnd+bo
2020-12-16 07:22:23 +03:00
read-count+stats-index
read-graph+dejs-path:resource
read-group+dejs-path:resource
read-each+read-graph-index
2021-02-05 02:54:17 +03:00
read-all+ul
2020-10-27 08:04:39 +03:00
==
--
::
++ enjs
=, enjs:format
|%
++ update
|= upd=^update
^- json
|^
%+ frond -.upd
?+ -.upd a+~
2020-10-28 08:52:59 +03:00
%added (added +.upd)
2020-10-27 08:04:39 +03:00
%timebox (timebox +.upd)
%set-dnd b+dnd.upd
%count (numb count.upd)
%more (more +.upd)
2020-12-01 08:46:28 +03:00
%read-each (read-each +.upd)
2020-12-16 07:22:23 +03:00
%read-count (stats-index +.upd)
%unread-each (unread-each +.upd)
2020-12-01 08:46:28 +03:00
%unread-count (unread-count +.upd)
2020-12-17 09:10:26 +03:00
%remove-graph s+(enjs-path:resource +.upd)
%seen-index (seen-index +.upd)
2021-05-17 06:35:00 +03:00
%unreads (unreads +.upd)
%read-note (index +.upd)
%note-read (note-read +.upd)
2020-11-10 06:32:48 +03:00
::
2021-05-17 06:35:00 +03:00
%archive
2020-10-27 08:04:39 +03:00
(notif-ref +.upd)
==
::
2021-05-17 06:35:00 +03:00
++ note-read
|= [tim=@da idx=^index]
%- pairs
:~ time+s+(scot %ud tim)
index+(index idx)
==
::
2020-12-16 07:22:23 +03:00
++ stats-index
|= s=^stats-index
%+ frond -.s
|^
?- -.s
%graph (graph-stats-index +.s)
2020-12-16 10:37:10 +03:00
%group s+(enjs-path:resource +.s)
2020-12-16 07:22:23 +03:00
==
::
++ graph-stats-index
|= [graph=resource =index:graph-store]
%- pairs
2020-12-16 10:37:10 +03:00
:~ graph+s+(enjs-path:resource graph)
2020-12-16 07:22:23 +03:00
index+(index:enjs:graph-store index)
==
--
::
2020-11-16 05:22:42 +03:00
++ unreads
2020-12-16 07:22:23 +03:00
|= l=(list [^stats-index ^stats])
2020-11-12 04:31:33 +03:00
^- json
2020-11-16 05:22:42 +03:00
:- %a
^- (list json)
%+ turn l
2020-12-16 07:22:23 +03:00
|= [idx=^stats-index s=^stats]
2020-11-12 04:31:33 +03:00
%- pairs
2020-12-16 07:22:23 +03:00
:~ stats+(stats s)
index+(stats-index idx)
2020-11-16 05:22:42 +03:00
==
2020-11-12 04:31:33 +03:00
::
++ unread
|= =^unreads
%+ frond
-.unreads
?- -.unreads
%each a+(turn ~(tap by indices.unreads) index:enjs:graph-store)
2020-12-01 08:46:28 +03:00
::
%count
(numb num.unreads)
==
::
2020-12-16 07:22:23 +03:00
++ stats
|= s=^stats
^- json
%- pairs
2020-12-16 07:22:23 +03:00
:~ unreads+(unread unreads.s)
last+(time last-seen.s)
==
2020-10-28 08:52:59 +03:00
++ added
2021-05-17 06:35:00 +03:00
|= [idx=^index not=^notification]
2020-10-28 08:52:59 +03:00
^- json
%- pairs
2021-05-17 06:35:00 +03:00
:~ index+(index idx)
2020-10-28 08:52:59 +03:00
notification+(notification not)
==
::
2020-10-27 08:04:39 +03:00
++ notif-ref
2021-05-17 06:35:00 +03:00
|= [tim=(unit @da) idx=^index]
2020-10-27 08:04:39 +03:00
^- json
%- pairs
2021-05-17 06:35:00 +03:00
:~ [%time ?~(tim ~ s+(scot %ud u.tim))]
2020-10-27 08:04:39 +03:00
index+(index idx)
==
++ seen-index
2020-12-16 07:22:23 +03:00
|= [tim=@da idx=^stats-index]
^- json
%- pairs
:~ time+(time tim)
2020-12-16 07:22:23 +03:00
index+(stats-index idx)
==
2020-10-27 08:04:39 +03:00
::
++ more
|= upds=(list ^update)
^- json
a+(turn upds update)
::
++ index
|= =^index
%+ frond -.index
|^
?- -.index
%graph (graph-index +.index)
%group (group-index +.index)
==
::
++ graph-index
|= $: graph=resource
mark=(unit mark)
description=@t
idx=index:graph-store
==
2020-10-27 08:04:39 +03:00
^- json
%- pairs
:~ graph+s+(enjs-path:resource graph)
mark+s+(fall mark '')
2020-10-27 08:04:39 +03:00
description+s+description
index+(index:enjs:graph-store idx)
2020-10-27 08:04:39 +03:00
==
::
++ group-index
|= [group=resource description=@t]
^- json
%- pairs
:~ group+s+(enjs-path:resource group)
description+s+description
==
--
::
++ notification
|= ^notification
^- json
%- pairs
:~ time+(time date)
contents+(^contents contents)
==
::
++ contents
|= =^contents
^- json
%+ frond -.contents
|^
?- -.contents
%graph (graph-contents +.contents)
%group (group-contents +.contents)
==
::
++ graph-contents
|= =(list post:post)
^- json
:- %a
(turn list post:enjs:graph-store)
::
++ group-contents
|= =(list ^group-contents)
^- json
:- %a
2021-01-12 07:26:19 +03:00
%+ turn list
2020-10-27 08:04:39 +03:00
|= =^group-contents
2021-01-12 07:26:19 +03:00
(update:enjs:group-store group-contents)
2020-10-27 08:04:39 +03:00
--
::
++ indexed-notification
|= [=^index =^notification]
%- pairs
:~ index+(^index index)
notification+(^notification notification)
==
::
++ timebox
2021-05-18 03:57:25 +03:00
|= [tim=(unit @da) l=(list [^index ^notification])]
2020-10-27 08:04:39 +03:00
^- json
%- pairs
2021-05-18 03:57:25 +03:00
:~ time+`json`?~(tim ~ s+(scot %ud u.tim))
2020-10-27 08:04:39 +03:00
:- %notifications
^- json
:- %a
%+ turn l
|= [=^index =^notification]
^- json
(indexed-notification index notification)
==
::
2020-12-01 08:46:28 +03:00
++ read-each
2020-12-16 07:22:23 +03:00
|= [s=^stats-index target=index:graph-store]
%- pairs
2020-12-16 07:22:23 +03:00
:~ index+(stats-index s)
target+(index:enjs:graph-store target)
==
::
++ unread-each
2020-12-16 07:22:23 +03:00
|= [s=^stats-index target=index:graph-store tim=@da]
%- pairs
2020-12-16 07:22:23 +03:00
:~ index+(stats-index s)
target+(index:enjs:graph-store target)
last+(time tim)
==
::
2020-12-01 08:46:28 +03:00
++ unread-count
2020-12-16 07:22:23 +03:00
|= [s=^stats-index tim=@da]
%- pairs
2020-12-16 07:22:23 +03:00
:~ index+(stats-index s)
last+(time tim)
==
2020-10-27 08:04:39 +03:00
--
--
2020-12-16 07:22:23 +03:00
::
++ to-stats-index
|= =index
^- stats-index
?- -.index
%graph [%graph graph.index index.index]
%group [%group group.index]
==
++ stats-index-is-index
|= [=stats-index =index]
?- -.index
%graph
?. ?=(%graph -.stats-index) %.n
=([graph index]:index [graph index]:stats-index)
::
%group
?. ?=(%group -.stats-index) %.n
=(group:index group:stats-index)
==
2020-10-27 08:04:39 +03:00
--