metadata-store: added scry + watch paths, an %update-metadata update

This commit is contained in:
Logan Allen 2020-02-13 17:22:52 -08:00
parent 9205c7c7db
commit 498c6e8e97
2 changed files with 50 additions and 25 deletions

View File

@ -12,9 +12,9 @@
::
+$ state-zero
$: %0
associated=(map [group-path app-name app-path] metadata)
=associated
group-indices=(jug group-path [app-name app-path])
app-name-indices=(jug app-name [app-path group-path])
app-name-indices=(jug app-name [group-path app-path])
app-path-indices=(map [app-name app-path] group-path)
==
--
@ -29,8 +29,8 @@
mc ~(. metadata-core bowl)
def ~(. (default-agent this %|) bowl)
::
++ on-init on-init:def
++ on-save !>(state)
++ on-init on-init:def
++ on-save !>(state)
++ on-load
|= old=vase
`this(state !<(state-zero old))
@ -54,6 +54,10 @@
?+ path (on-watch:def path)
[%all ~] (give %metadata-initial !>(associated))
[%updates ~] ~
[%app-name @ ~]
=/ =app-name i.t.path
=/ app-indices (metadata-for-app:mc app-name)
(give %metadata-update !>([%app-indices app-indices]))
==
[cards this]
::
@ -69,14 +73,19 @@
|= =path
^- (unit (unit cage))
?+ path (on-peek:def path)
[%x %all ~] ``noun+!>(associated)
[%x %group-indices ~] ``noun+!>(group-indices)
[%x %app-name-indices ~] ``noun+!>(app-name-indices)
[%x %app-path-indices ~] ``noun+!>(app-path-indices)
[%x %metadata * * *]
:: TODO: figure out the best way to do this with two
:: variable-length arguments, talk to mark?
!!
[%x %all ~] ``noun+!>(associated)
[%x %group-indices ~] ``noun+!>(group-indices)
[%x %app-name-indices ~] ``noun+!>(app-name-indices)
[%x %app-path-indices ~] ``noun+!>(app-path-indices)
[%x %metadata @ @ @ ~]
=/ =group-path (stab i.t.t.path)
=/ =app-name `@tas`i.t.t.t.path
=/ =app-path (stab i.t.t.t.t.path)
``noun+!>((~(got by associated) [group-path app-name app-path]))
::
[%x %app-name @ ~]
=/ =app-name i.t.t.path
``noun+!>((metadata-for-app:mc app-name))
==
::
++ on-agent on-agent:def
@ -84,12 +93,12 @@
++ on-fail on-fail:def
--
::
|_ bol=bowl:gall
|_ =bowl:gall
::
++ poke-metadata-action
|= act=metadata-action
^- (quip card _state)
?> (team:title our.bol src.bol)
?> (team:title our.bowl src.bowl)
?- -.act
%add
(handle-add group-path.act app-name.act app-path.act metadata.act)
@ -101,8 +110,10 @@
++ handle-add
|= [=group-path =app-name =app-path =metadata]
^- (quip card _state)
?< (~(has by app-path-indices) [app-name app-path])
:- (send-diff [%add group-path app-name app-path metadata])
:- %+ send-diff app-name
?. (~(has by app-path-indices) [app-name app-path])
[%add group-path app-name app-path metadata]
[%update-metadata group-path app-name app-path metadata]
%= state
associated
(~(put by associated) [group-path app-name app-path] metadata)
@ -111,7 +122,7 @@
(~(put ju group-indices) group-path [app-name app-path])
::
app-name-indices
(~(put ju app-name-indices) app-name [app-path group-path])
(~(put ju app-name-indices) app-name [group-path app-path])
::
app-path-indices
(~(put by app-path-indices) [app-name app-path] group-path)
@ -120,7 +131,7 @@
++ handle-remove
|= [=group-path =app-name =app-path]
^- (quip card _state)
:- (send-diff [%remove group-path app-name app-path])
:- (send-diff app-name [%remove group-path app-name app-path])
%= state
associated
(~(del by associated) [group-path app-name app-path])
@ -129,24 +140,33 @@
(~(del ju group-indices) group-path [app-name app-path])
::
app-name-indices
(~(del ju app-name-indices) app-name [app-path group-path])
(~(del ju app-name-indices) app-name [group-path app-path])
::
app-path-indices
(~(del by app-path-indices) [app-name app-path])
==
::
++ metadata-for-app
|= =app-name
%- ~(gas by *(map [group-path ^app-name app-path] metadata))
%+ turn ~(tap in (~(got by app-name-indices) app-name))
|= [=group-path =app-path]
:- [group-path app-name app-path]
(~(got by associated) [group-path app-name app-path])
::
++ send-diff
|= act=metadata-action
|= [=app-name upd=metadata-update]
^- (list card)
|^
%- zing
:~ (update-subscribers /all act)
(update-subscribers /updates act)
:~ (update-subscribers /all upd)
(update-subscribers /updates upd)
(update-subscribers [%app-name app-name ~] upd)
==
::
++ update-subscribers
|= [pax=path act=metadata-action]
|= [pax=path upd=metadata-update]
^- (list card)
[%give %fact ~[pax] %metadata-update !>(act)]~
[%give %fact ~[pax] %metadata-update !>(upd)]~
--
--

View File

@ -2,6 +2,7 @@
+$ group-path path
+$ app-name @tas
+$ app-path path
+$ associated (map [group-path app-name app-path] metadata)
::
+$ metadata
$: title=@t
@ -14,5 +15,9 @@
[%remove =group-path =app-name =app-path]
==
::
+$ metadata-update metadata-action
+$ metadata-update
$% metadata-action
[%app-indices app-indices=associated]
[%update-metadata =group-path =app-name =app-path =metadata]
==
--