s3-store: initial commit

This commit is contained in:
Logan Allen 2020-04-23 16:53:00 -04:00
parent 3196179fbd
commit daf32fd0f9
7 changed files with 166 additions and 13 deletions

View File

@ -0,0 +1,71 @@
/- *s3
/+ default-agent, verb, dbug
~% %s3-top ..is ~
|%
+$ card card:agent:gall
+$ versioned-state
$% state-zero
==
::
+$ state-zero [%0 =credentials]
--
::
=| state-zero
=* state -
::
%- agent:dbug
%+ verb |
^- agent:gall
~% %s3-agent-core ..card ~
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
::
++ on-init on-init:def
++ on-save !>(state)
++ on-load
|= old-vase=vase
[~ this(state !<(state-zero old-vase))]
::
++ on-poke
~/ %s3-poke
|= [=mark =vase]
^- (quip card _this)
|^
?> (team:title our.bowl src.bowl)
=^ cards state
?+ mark (on-poke:def mark vase)
%s3-action (poke-action !<(action vase))
==
[cards this]
::
++ poke-action
|= act=action
^- (quip card _state)
[~ state]
--
::
++ on-watch
~/ %s3-watch
|= =path
^- (quip card _this)
|^
?> (team:title our.bowl src.bowl)
=/ cards=(list card)
?+ path (on-watch:def path)
[%all ~] (give %s3-update !>([%credentials credentials]))
==
[cards this]
::
++ give
|= =cage
^- (list card)
[%give %fact ~ cage]~
--
::
++ on-leave on-leave:def
++ on-peek on-peek:def
++ on-agent on-agent:def
++ on-arvo on-arvo:def
++ on-fail on-fail:def
--

View File

@ -118,6 +118,7 @@
%link-view
%metadata-store
%metadata-hook
%s3-store
==
::
++ deft-fish :: default connects
@ -223,7 +224,7 @@
==
::
++ on-load
|= ver=?(%1 %2)
|= ver=?(%1 %2 %3)
?- ver
%1
=< se-abet =< se-view
@ -237,7 +238,8 @@
=< (se-born %home %link-store)
=< (se-born %home %link-proxy-hook)
=< (se-born %home %link-listen-hook)
(se-born %home %link-view)
=< (se-born %home %link-view)
(se-born %home %s3-store)
::
%2
=< se-abet =< se-view
@ -250,7 +252,22 @@
=< (se-born %home %link-store)
=< (se-born %home %link-proxy-hook)
=< (se-born %home %link-listen-hook)
(se-born %home %link-view)
=< (se-born %home %link-view)
(se-born %home %s3-store)
%3
=< se-abet =< se-view
=< (se-emit %pass /kiln %arvo %g %sear ~wisrut-nocsub)
=< (se-born %home %metadata-store)
=< (se-born %home %metadata-hook)
=< (se-born %home %contact-store)
=< (se-born %home %contact-hook)
=< (se-born %home %contact-view)
=< (se-born %home %link-store)
=< (se-born %home %link-proxy-hook)
=< (se-born %home %link-listen-hook)
=< (se-born %home %link-view)
(se-born %home %s3-store)
==
::
++ reap-phat :: ack connect

22
pkg/arvo/lib/s3-json.hoon Normal file
View File

@ -0,0 +1,22 @@
/- *s3
|%
++ json-to-action
|= =json
^- action
|^ (parse-json json)
++ parse-json (of:dejs:format [%set-api-key so:dejs:format]~)
--
::
++ update-to-json
|= upd=update
^- json
%+ frond:enjs:format %s3-update
%- pairs:enjs:format
:~ ?- -.upd
%credentials
[%credentials (pairs:enjs:format [%api-key s+api-key.credentials.upd]~)]
%set-api-key
[%set-api-key (pairs:enjs:format [%api-key s+api-key.upd]~)]
==
==
--

View File

@ -0,0 +1,8 @@
/+ *s3-json
|_ act=action
++ grab
|%
++ noun action
++ json |=(jon=^json (json-to-action jon))
--
--

View File

@ -0,0 +1,12 @@
/+ *s3-json
|_ upd=update
++ grow
|%
++ json (update-to-json upd)
--
::
++ grab
|%
++ noun update
--
--

14
pkg/arvo/sur/s3.hoon Normal file
View File

@ -0,0 +1,14 @@
|%
+$ credentials
$: api-key=@t
==
::
+$ action
$% [%set-api-key api-key=@t]
==
::
+$ update
$% [%credentials =credentials]
action
==
--

View File

@ -7,12 +7,13 @@ import urbitOb from 'urbit-ob';
export class Subscription {
constructor() {
this.firstRoundSubscriptionComplete = false;
this.firstRoundComplete = false;
this.secondRoundComplete = false;
}
start() {
if (api.authTokens) {
this.firstRoundSubscription();
this.firstRound();
window.urb.setOnChannelError(this.onChannelError.bind(this));
} else {
console.error("~~~ ERROR: Must set api.authTokens before operation ~~~");
@ -22,7 +23,8 @@ export class Subscription {
onChannelError(err) {
console.error('event source error: ', err);
console.log('initiating new channel');
this.firstRoundSubscriptionComplete = false;
this.firstRoundComplete = false;
this.secondRoundComplete = false;
setTimeout(2000, () => {
store.handleEvent({
data: { clear : true}
@ -43,21 +45,28 @@ export class Subscription {
});
}
firstRoundSubscription() {
firstRound() {
this.subscribe('/primary', 'contact-view');
}
secondRoundSubscriptions() {
this.subscribe('/synced', 'contact-hook');
this.subscribe('/primary', 'invite-view');
secondRound() {
this.subscribe('/all', 'group-store');
this.subscribe('/all', 'metadata-store');
}
thirdRound() {
this.subscribe('/synced', 'contact-hook');
this.subscribe('/primary', 'invite-view');
this.subscribe('/all', 's3-store');
}
handleEvent(diff) {
if (!this.firstRoundSubscriptionComplete) {
this.firstRoundSubscriptionComplete = true;
this.secondRoundSubscriptions();
if (!this.firstRoundComplete) {
this.firstRoundComplete = true;
this.secondRound();
} else if (!this.secondRoundComplete) {
this.secondRoundComplete = true;
this.thirdRound();
}
store.handleEvent(diff);
}