shrub/pkg/arvo/sur/neo.hoon

563 lines
11 KiB
Plaintext
Raw Normal View History

2024-01-28 06:20:35 +03:00
:: $neo: New Shrub
::
:: Urbit is a namespace, from a path -> data
:: /~hastuc-dibtux/chats/unit-731 :: this a chat
:: /~hastuc-dibtux/chats/unit-731/msg/~2024.1.27..10.30 :: this is a
:: message inside the chat
::
:: neo is a recipe for defining the kinds of data that live at these
:: paths. For instance, you would maybe like to define a chat
:: datatype, that could be bound into your namespace, so that your
:: friends could send you memes.
::
::
::
::
::
::
2024-01-19 02:07:28 +03:00
|%
2024-03-13 22:38:08 +03:00
++ pave
|= p=path
^- pith
%+ turn p
|= i=@ta
(fall (rush i spot:stip) [%ta i])
::
++ stip :: typed path parser
=< swot
|%
++ swot |=(n=nail `(like pith)`(;~(pfix fas (more fas spot)) n))
::
++ spot
%+ sear
|= a=*
^- (unit iota)
?+ a ~
@ ?:(((sane %tas) a) [~ `@tas`a] ~)
[@ @] ((soft iota) a)
==
%- stew
^. stet ^. limo
:~ :- 'a'^'z' sym
:- '$' (cold [%tas %$] buc)
:- '0'^'9' bisk:so
:- '-' tash:so
:- '.' zust:so
:- '~' ;~(pfix sig ;~(pose crub:so (easy [%n ~])))
:- '\'' (stag %t qut)
==
--
2024-03-09 01:37:44 +03:00
++ goon
|%
:: $date: date w/ TZ offset
+$ date [dat=@da off=@ud]
:: $size: size of a rect
+$ size [w=@ud h=@ud]
:: $hsrc: HTTP source (URL)
+$ hsrc @t
:: $dims: Spatial dimensions
+$ dims [ideal=size min=(unit size)]
:: $dimt: Temporal dimension
+$ dimt [len=@dr sta=@ud]
+$ scar
$? %patp
%patud
%cord
%patda
%date
%img
%video
%audio
==
+$ clot
$? [%patp p=@p]
[%patud p=@ud]
[%cord p=cord]
[%patda p=@da]
[%date =date]
[%img =hsrc =dims]
[%video =hsrc =dims =dimt]
[%audio =hsrc =dimt]
==
--
++ pike
=< pike
|%
++ card
$% [%peek =path]
[%grab items=(list item)]
==
++ sign
$% [%peek =cage]
[%grab items=(list clot:goon)]
==
+$ item
$: lede=cord
info=cord
err=(unit cord)
=scar:goon
==
+$ bowl
$: wer=name
eny=@uvJ
now=@da
==
+$ input [=bowl syn=(unit sign)]
++ raw
|%
++ output
|* a=mold
$~ [%done *a]
$% [%emit =card]
[%cont self=(form a)]
[%fail err=(pair term tang)]
[%done value=a]
==
++ form |*(a=mold $-(input (output a)))
--
++ fail
|= err=(pair term tang)
|= input
[~ %fail err]
++ pikv
(pike vase)
++ pike
|* a=mold
|%
++ output (output:raw a)
++ form (form:raw a)
++ pure
|= arg=a
^- form
|= input
[%done arg]
++ bind
|* b=mold
|= [m-b=(form:raw b) fun=$-(b form)]
^- form
=* loop $
|= in=input
=/ b-res=(output:raw b)
(m-b in)
^- output
?- -.b-res
%emit [%emit card.b-res]
%cont [%cont loop(m-b self.b-res)]
%fail [%fail err.b-res]
%done [%cont (fun value.b-res)]
==
+$ eval-form
$: =form
==
::
:: Convert initial form to eval-form
::
++ from-form
|= =form
^- eval-form
form
::
:: The cases of results of +take
::
+$ eval-result
$% [%emit car=card]
[%fail err=(pair term tang)]
[%done value=a]
==
++ take
|= [=eval-form =input]
^- [=eval-result _eval-form]
=* take-loop $
:: =? car.input ?=(^ car.input)
=/ =output (form.eval-form input)
?- -.output
%emit [[%emit card.output] eval-form]
%fail [[%fail err.output] eval-form]
%done [[%done value.output] eval-form]
%cont
%_ take-loop
form.eval-form self.output
input [bowl.input ~]
==
==
--
--
2024-02-23 19:23:42 +03:00
:: $stud: mark name
+$ stud
$@ @tas :: auth=urbit
$: mark=@tas ::
2024-03-13 22:38:08 +03:00
[=ship =desk]
2024-02-23 19:23:42 +03:00
== ::
::
2024-02-19 23:56:04 +03:00
++ pith
|^ $+(pith ^pith)
++ en-tape
|= pit=$
(spud (pout pit))
2024-03-11 20:44:33 +03:00
++ prefix
=| res=$
|= [long=$ curt=$]
^- (unit _res)
?~ curt `(flop res)
?~ long ~
?. =(i.long i.curt)
~
$(long t.long, curt t.curt, res [i.long res])
++ suffix
|= [long=$ curt=$]
^- _curt
?~ curt
long
?~ long
~
$(curt t.curt, long t.long)
2024-02-19 23:56:04 +03:00
--
++ name
|^ ,[=ship =pith]
++ en-pith
|= nam=$
^- pith
[p/ship.nam pith.nam]
++ en-tape
|= nam=$
(spud (pout (en-pith nam)))
++ en-path
|= nam=$
(pout (en-pith nam))
2024-03-13 22:38:08 +03:00
++ de-pith |=(pith ~|(de-pith/+< (need (de-pith-soft +<))))
2024-02-19 23:56:04 +03:00
++ de-pith-soft
|= =pith
^- (unit ^$)
?. ?=([[%p @] *] pith)
~
`[+.i.pith t.pith]
--
2024-03-12 22:17:20 +03:00
+$ axal
$~ [~ ~]
[fil=(unit hall) kid=(map iota axal)]
++ of
|_ fat=axal
++ del
|= pax=pith
^+ fat
?~ pax [~ kid.fat]
=/ kid (~(get by kid.fat) i.pax)
?~ kid fat
fat(kid (~(put by kid.fat) i.pax $(fat u.kid, pax t.pax)))
:: Descend to the axal at this path
::
++ dip
|= pax=pith
^+ fat
?~ pax fat
=/ kid (~(get by kid.fat) i.pax)
?~ kid [~ ~]
$(fat u.kid, pax t.pax)
::
++ gas
|= lit=(list (pair pith hall))
^+ fat
?~ lit fat
$(fat (put p.i.lit q.i.lit), lit t.lit)
++ got-room
|= pax=pith
^- room
(de-hall:room (got pax))
++ got
|= pax=pith
~| missing-room/pax
(need (get pax))
::
++ get
|= pax=pith
fil:(dip pax)
:: Fetch file at longest existing prefix of the path
::
++ fit
|= pax=pith
^+ [pax fil.fat]
?~ pax [~ fil.fat]
=/ kid (~(get by kid.fat) i.pax)
?~ kid [pax fil.fat]
=/ low $(fat u.kid, pax t.pax)
?~ +.low
[pax fil.fat]
low
::
++ has
2024-03-13 22:38:08 +03:00
|= pax=pith
2024-03-12 22:17:20 +03:00
!=(~ (get pax))
:: Delete subtree
::
++ lop
2024-03-13 22:38:08 +03:00
|= pax=pith
2024-03-12 22:17:20 +03:00
^+ fat
?~ pax fat
|-
?~ t.pax fat(kid (~(del by kid.fat) i.pax))
=/ kid (~(get by kid.fat) i.pax)
?~ kid fat
fat(kid (~(put by kid.fat) i.pax $(fat u.kid, pax t.pax)))
::
++ put
|= [pax=pith dat=hall]
|- ^+ fat
?~ pax fat(fil `dat)
=/ kid (~(gut by kid.fat) i.pax ^+(fat [~ ~]))
fat(kid (~(put by kid.fat) i.pax $(fat kid, pax t.pax)))
::
++ tap
=| pax=pith
=| out=(list (pair pith _?>(?=(^ fil.fat) u.fil.fat)))
|- ^+ out
=? out ?=(^ fil.fat) :_(out [pax u.fil.fat])
=/ kid ~(tap by kid.fat)
|- ^+ out
?~ kid out
%= $
kid t.kid
out ^$(pax (weld pax /[p.i.kid]), fat q.i.kid)
==
:: Serialize to map
::
++ tar
(~(gas by *(map pith hall)) tap)
--
+$ pate [[%p p=ship] q=pith]
++ petty-port
|* a=mold
^- port
[a a]
+$ dita (each iota aura)
+$ pish (list dita)
+$ conf (map term pith)
+$ card
$% [%arvo note-arvo]
[%neo note]
==
2024-02-19 23:56:04 +03:00
+$ request
[src=pith dest=pith val=*]
+$ response
[src=pith dest=pith status=response-status]
2024-02-23 19:23:42 +03:00
+$ diff
$% [%poke p=*]
[%init p=*]
==
2024-02-19 23:56:04 +03:00
+$ update
$: =pith
case=@ud
2024-02-23 19:23:42 +03:00
=diff
2024-02-19 23:56:04 +03:00
==
+$ watch (list update)
::
+$ err
$% [%here =pith]
[%goof err=*]
[%fail err=*]
==
+$ response-status
$% [%done ~]
err
==
::
2024-01-19 02:07:28 +03:00
+$ note
%+ pair pith
2024-02-23 19:23:42 +03:00
$% [%make =stud init=(unit vase) =conf] :: todo: configuration values, init cannot be ^ if installing over
2024-01-19 02:07:28 +03:00
[%poke val=*]
[%tomb =case]
2024-02-23 19:23:42 +03:00
[%link from=pith src=stud]
2024-01-19 02:07:28 +03:00
==
+$ poke
(pair pith *)
+$ yard
$+ yard
$~ ~
2024-01-19 20:56:14 +03:00
(map iota hall)
2024-03-12 22:17:20 +03:00
++ yird
|%
+$ yird
$+ yird
$~ ~
(map iota $+(yird-inner $~([%& *hall] (each hall yird))))
++ put
|= [y=yird p=pith h=hall]
^+ y
?> ?=(^ p)
=/ in (~(got by y) i.p)
?> ?=(%| -.in)
%+ ~(put by y) i.p
?: =(~ t.p)
&/h
[%| (~(put by y) i.p [%| $(y p.in, p t.p)])]
++ get-fit
|= [y=yird p=pith]
^- (unit [pith hall])
?> ?=(^ p)
=/ in (~(get by y) i.p)
?~ in
~
?~ t.p
?> ?=(%& -.u.in)
`[~ p.u.in]
?. ?=(%| -.u.in)
`[t.p p.u.in]
$(y p.u.in, p t.p)
++ get
|= [y=yird p=pith]
^- (unit hall)
?> ?=(^ p)
=/ in (~(get by y) i.p)
?~ in
~
?~ t.p
?> ?=(%& -.u.in)
`p.u.in
?. ?=(%| -.u.in)
~
$(y p.u.in, p t.p)
--
::
2024-03-11 21:41:22 +03:00
+$ sign-conf
2024-03-12 02:33:01 +03:00
$% [%val p=term]
[%pith p=term q=pith]
2024-03-11 21:41:22 +03:00
==
2024-02-19 23:56:04 +03:00
+$ sign-neo
2024-03-11 21:41:22 +03:00
$% [%poke dest=pith status=response-status]
[%conf p=sign-conf]
==
+$ sign
$+ sign
$% [%arvo p=sign-arvo]
2024-03-12 02:33:01 +03:00
[%neo p=sign-neo]
==
+$ move (pair pith card)
2024-02-23 19:23:42 +03:00
+$ span (pair stud firm)
2024-01-19 02:07:28 +03:00
+$ icon
2024-02-19 23:56:04 +03:00
[case=@ud state=vase history=(list *) migration=(list *)]
:: subscription metadata
+$ jail
2024-02-23 19:23:42 +03:00
$+ jail
$~ ~
(map iota cell)
+$ cell
$+ cell
[case=@ud state=vase =span =jail]
+$ brig
$+ brig
$~ ~
(map pith cell)
+$ fleet
$+ fleet
$~ ~
(map ship brig)
2024-03-12 22:17:20 +03:00
+$ hall hall:room
2024-02-19 23:56:04 +03:00
:: $room: state of a shrub
::
:: TODO: refactor for networking?
2024-03-12 22:17:20 +03:00
++ room
=< room
|%
+$ hall
$% [%exit pith]
[%room room]
==
+$ room
$+ room
$~ [*span ~ *icon]
$: =span
=conf
=icon
==
++ de-hall-soft
|= hal=hall
^- (unit room)
?. ?=(%room -.hal)
~
`+.hal
++ de-hall
|= hal=hall
2024-03-13 22:38:08 +03:00
(need (de-hall-soft hal))
2024-03-12 22:17:20 +03:00
--
+$ bowl
2024-01-27 22:55:44 +03:00
$: src=@p
our=@p
were=pith
now=@da
2024-03-12 02:33:01 +03:00
deps=(map term (pair pith vase))
kids=(map pith vase)
==
+$ fief
[required=? =port]
+$ port :: TODO: how to specify behaviour
2024-03-14 21:35:39 +03:00
[state=* diff=*] :: state, diff actually $stud
+$ deps (map term fief)
2024-01-19 23:52:55 +03:00
+$ kids (map pish port)
2024-01-28 06:20:35 +03:00
:: $firm: type of the value in the urbit namespace
::
+$ firm
$_ ^&
|%
2024-01-28 06:20:35 +03:00
:: $state: the state of this value in the urbit namespace
::
:: For instance, a message would be
:: ```hoon
:: [author=ship time-sent=time message=txt]
:: ```
::
:: ```
2024-03-14 21:35:39 +03:00
++ state ** :: stud
2024-01-28 06:20:35 +03:00
:: $poke: a poke is a request to change a value in teh urbit
:: namespace.
::
:: For instance a blocked list that is a set of users would be
:: [%add who=user]
:: [%del who=user]
::
::
2024-03-14 21:35:39 +03:00
++ poke ** :: stud
++ form *^form
2024-01-28 06:20:35 +03:00
::
:: +kids: Some nodes in the namespace define what children are
:: allowed to be under them. For instance, it should not be allowed
:: to create /~hastuc-dibtux/chats/unit-731/blog-post-1. This is
:: nonsensical because blog posts don't go in chats.
2024-01-19 23:52:55 +03:00
++ kids *(map pish port)
2024-01-28 06:20:35 +03:00
::
:: +deps: Some nodes in the namespace might like to hear about other
:: things that happen in the namespace. For instance, a substack-type
:: software would like to know where the wallet software is located
:: in the name
++ deps *(map term fief)
--
2024-01-19 02:07:28 +03:00
+$ form
$_ ^|
|_ [=bowl =icon]
++ call
2024-02-19 23:56:04 +03:00
|~ [prev=vase val=*]
2024-01-19 02:07:28 +03:00
*(list card)
2024-01-28 06:20:35 +03:00
:: +reduce: apply %poke, producing state
::
:: ('liam'' ~) [%add who='ruby'] -> ('liam' 'ruby')
:: ('liam' 'ruby' ~) [%del who='ruby'] -> ('liam')
2024-01-19 02:07:28 +03:00
++ reduce
|~ val=*
2024-02-19 23:56:04 +03:00
*vase
2024-01-19 02:07:28 +03:00
++ take
|~ =sign
*(list card)
2024-01-19 20:56:14 +03:00
++ born
*(list card)
2024-01-19 02:07:28 +03:00
++ init
2024-02-19 23:56:04 +03:00
|~ old=(unit vase)
*vase
2024-01-19 20:56:14 +03:00
++ echo
|~ [=pith val=*]
2024-01-19 02:07:28 +03:00
*(list card)
--
--