Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Near handler #8

Merged
merged 19 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@ jobs:
with:
node-version: "16.x"

- name: Copy dist/index.js
- name: Create target directory and copy file
run: |
mkdir target
cp dist/index.js target/index.js
mkdir -p near/target
cp near/dist/index.js near/target/index.js

- name: Install dependencies
run: yarn
working-directory: ./near

- name: Build
run: yarn build
working-directory: ./near

- name: Check dist/index.js
run: cmp dist/index.js target/index.js
working-directory: ./near

- name: Failure message
if: failure()
uses: actions/github-script@v3
with:
script: |
core.setFailed('The dist/index.js seems to be stale. Please run *yarn build* and commit the dist/index.js file.')
working-directory: ./near
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/near/node_modules
/.pnp
.pnp.js

Expand Down
139 changes: 139 additions & 0 deletions desk/app/near-handler.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/- *near-handler
/+ dbug, default-agent, *near-handler
::
|%
::
+$ versioned-state
$% state-0
==
::
+$ state-0
$: %0
accs=(set acc)
==
::
+$ card $+(card card:agent:gall)
--
::
%- agent:dbug
=| state-0
=* state -
::
^- agent:gall
::
=<
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
hc ~(. +> [bowl ~])
++ on-init
^- (quip card _this)
=^ cards state abet:init:hc
[cards this]
::
++ on-save
^- vase
!>(state)
::
++ on-load
|= =vase
^- (quip card _this)
=^ cards state abet:(load:hc vase)
[cards this]
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
=^ cards state abet:(poke:hc mark vase)
[cards this]
::
++ on-peek peek:hc
::
++ on-watch
|= =path
^- (quip card _this)
=^ cards state abet:(watch:hc path)
[cards this]
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
=^ cards state abet:(agent:hc wire sign)
[cards this]
++ on-arvo on-arvo:def
++ on-fail on-fail:def
++ on-leave on-leave:def
--
|_ [=bowl:gall deck=(list card)]
+* that .
++ emit |=(=card that(deck [card deck]))
++ emil |=(lac=(list card) that(deck (welp lac deck)))
++ abet ^-((quip card _state) [(flop deck) state])
::
++ from-self =(our src):bowl
::
++ init
^+ that
that
::
++ load
|= vaz=vase
^+ that
?> ?=([%0 *] q.vaz)
that(state !<(state-0 vaz))
::
++ poke
|= [=mark =vase]
^+ that
?+ mark that
%near-handler-action
?> from-self
=+ !<(act=action vase)
?- -.act
%add
=. accs (~(put in accs) +.act)
give-accs
::
%del
=. accs (~(del in accs) +.act)
give-accs
::
%poke
%- emit
[%pass /poke-to/[dude.act] %agent [our.bowl dude.act] %poke-as mark.act [%json !>((need json.act))]]
==
==
::
++ peek
|= =path
^- (unit (unit cage))
?+ path [~ ~]
[%x %accs ~]
``near-handler-update+!>([%accs accs])
==
::
++ watch
|= =path
^+ that
?+ path ~|(bad-watch-path+path !!)
[%accs ~]
?> from-self
give-accs
==
::
++ agent
|= [=wire =sign:agent:gall]
^+ that
?+ wire ~|(bad-agent-wire+wire !!)
[%poke-to * ~]
?. ?=(%poke-ack -.sign) that
?~ p.sign that
%- (slog 'Failed to poke' `@t`(scot %tas -.+.wire) ~)
that
==
::
++ give-accs
%- emit
[%give %fact ~[/accs] %near-handler-update !>([%accs accs])]
::
--
2 changes: 2 additions & 0 deletions desk/desk.bill
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:~ %near-handler
==
15 changes: 15 additions & 0 deletions desk/gen/acc.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
!:
:- %say
:: :near-handler +near-handler!acc %add 0x0
|= $: [now=@da eny=@uvJ bec=beak]
$: act=?(%add %del %poke)
acc=@uxH
~
==
~
==
?- act
%del [%near-handler-action [%del acc]]
%add [%near-handler-action [%add acc]]
%poke [%near-handler-action [%poke-to [%test %test-action (need (de:json:html '{"poke":1}'))]]]
==
155 changes: 155 additions & 0 deletions desk/lib/dbug.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
:: dbug: agent wrapper for generic debugging tools
::
:: usage: %-(agent:dbug your-agent)
::
|%
+$ poke
$% [%bowl ~]
[%state grab=cord]
[%incoming =about]
[%outgoing =about]
==
::
+$ about
$@ ~
$% [%ship =ship]
[%path =path]
[%wire =wire]
[%term =term]
==
::
++ agent
|= =agent:gall
^- agent:gall
!.
|_ =bowl:gall
+* this .
ag ~(. agent bowl)
::
++ on-poke
|= [=mark =vase]
^- (quip card:agent:gall agent:gall)
?. ?=(%dbug mark)
=^ cards agent (on-poke:ag mark vase)
[cards this]
=/ dbug
!<(poke vase)
=; =tang
((%*(. slog pri 1) tang) [~ this])
?- -.dbug
%bowl [(sell !>(bowl))]~
::
%state
=? grab.dbug =('' grab.dbug) '-'
=; product=^vase
[(sell product)]~
=/ state=^vase
:: if the underlying app has implemented a /dbug/state scry endpoint,
:: use that vase in place of +on-save's.
::
=/ result=(each ^vase tang)
(mule |.(q:(need (need (on-peek:ag /x/dbug/state)))))
?:(?=(%& -.result) p.result on-save:ag)
%+ slap
(slop state !>([bowl=bowl ..zuse]))
(ream grab.dbug)
::
%incoming
=; =tang
?^ tang tang
[%leaf "no matching subscriptions"]~
%+ murn
%+ sort ~(tap by sup.bowl)
|= [[* a=[=ship =path]] [* b=[=ship =path]]]
(aor [path ship]:a [path ship]:b)
|= [=duct [=ship =path]]
^- (unit tank)
=; relevant=?
?. relevant ~
`>[path=path from=ship duct=duct]<
?: ?=(~ about.dbug) &
?- -.about.dbug
%ship =(ship ship.about.dbug)
%path ?=(^ (find path.about.dbug path))
%wire %+ lien duct
|=(=wire ?=(^ (find wire.about.dbug wire)))
%term !!
==
::
%outgoing
=; =tang
?^ tang tang
[%leaf "no matching subscriptions"]~
%+ murn
%+ sort ~(tap by wex.bowl)
|= [[[a=wire *] *] [[b=wire *] *]]
(aor a b)
|= [[=wire =ship =term] [acked=? =path]]
^- (unit tank)
=; relevant=?
?. relevant ~
`>[wire=wire agnt=[ship term] path=path ackd=acked]<
?: ?=(~ about.dbug) &
?- -.about.dbug
%ship =(ship ship.about.dbug)
%path ?=(^ (find path.about.dbug path))
%wire ?=(^ (find wire.about.dbug wire))
%term =(term term.about.dbug)
==
==
::
++ on-peek
|= =path
^- (unit (unit cage))
?. ?=([@ %dbug *] path)
(on-peek:ag path)
?+ path [~ ~]
[%u %dbug ~] ``noun+!>(&)
[%x %dbug %state ~] ``noun+!>(on-save:ag)
[%x %dbug %subscriptions ~] ``noun+!>([wex sup]:bowl)
==
::
++ on-init
^- (quip card:agent:gall agent:gall)
=^ cards agent on-init:ag
[cards this]
::
++ on-save on-save:ag
::
++ on-load
|= old-state=vase
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-load:ag old-state)
[cards this]
::
++ on-watch
|= =path
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-watch:ag path)
[cards this]
::
++ on-leave
|= =path
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-leave:ag path)
[cards this]
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-agent:ag wire sign)
[cards this]
::
++ on-arvo
|= [=wire =sign-arvo]
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-arvo:ag wire sign-arvo)
[cards this]
::
++ on-fail
|= [=term =tang]
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-fail:ag term tang)
[cards this]
--
--
Loading