-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Super simple client/server app setup in new desk
- Loading branch information
1 parent
324f0cc
commit 7302270
Showing
20 changed files
with
1,226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/- near-rpc | ||
/+ dbug, default-agent | ||
:: | ||
|% | ||
+$ versioned-state | ||
$% state-0 | ||
== | ||
+$ state-0 [%0 ~] | ||
+$ 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 | ||
|= =path | ||
^- (unit (unit cage)) | ||
[~ ~] | ||
:: | ||
++ on-watch | ||
|= =path | ||
^- (quip card _this) | ||
`this | ||
:: | ||
++ on-agent | ||
|= [=wire =sign:agent:gall] | ||
^- (quip card _this) | ||
`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-rpc-ask | ||
=+ !<(act=ask:near-rpc vase) | ||
?- -.act | ||
%request | ||
~& >> "Got request" | ||
%- emit | ||
:* %pass /response | ||
%agent [src.bowl %rpc-requester] | ||
%poke %near-rpc-response | ||
!>(`response:near-rpc`[%response ~]) | ||
== | ||
== | ||
== | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/- near-rpc | ||
/+ dbug, default-agent | ||
:: | ||
|% | ||
+$ versioned-state | ||
$% state-0 | ||
== | ||
+$ state-0 [%0 =provider:near-rpc queue=(set request:near-rpc)] | ||
+$ 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 | ||
|= =path | ||
^- (unit (unit cage)) | ||
[~ ~] | ||
:: | ||
++ on-watch | ||
|= =path | ||
^- (quip card _this) | ||
`this | ||
:: | ||
++ on-agent | ||
|= [=wire =sign:agent:gall] | ||
^- (quip card _this) | ||
`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 | ||
=. provider our.bowl ::we're our own provider to start (for testing) | ||
that | ||
:: | ||
++ load | ||
|= vaz=vase | ||
^+ that | ||
?> ?=([%0 *] q.vaz) | ||
that(state !<(state-0 vaz)) | ||
:: | ||
++ poke | ||
|= [=mark =vase] | ||
^+ that | ||
?+ mark that | ||
%near-rpc-response | ||
?> =(src.bowl provider) | ||
~& > 'Got response' | ||
that | ||
:: | ||
%near-rpc-action | ||
?> from-self | ||
=+ !<(act=action:near-rpc vase) | ||
?- -.act | ||
%change-provider | ||
=. provider provider.act | ||
that | ||
:: | ||
%send-request | ||
=/ req [now.bowl content.act] | ||
=. queue (~(put in queue) req) | ||
%- emit | ||
:* %pass /request | ||
%agent [provider %rpc-provider] | ||
%poke %near-rpc-ask | ||
!>(`ask:near-rpc`[%request req]) | ||
== | ||
== | ||
== | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:~ %rpc-provider | ||
%rpc-requester | ||
== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
-- | ||
-- |
Oops, something went wrong.