Skip to content

Commit

Permalink
tweaks and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
djellemah committed Jun 10, 2024
1 parent 91500eb commit edf5318
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
18 changes: 7 additions & 11 deletions cmds.fish
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function redeploy -a version --description "redeploy to a version"
# Normal output is something like
# Updated component with ID 3825415a-f2f9-42dc-99d3-715ff89690a0. New version: 1. Component size is 168531 bytes.
set result_msg (golem-cli component update --component-name slkvs target/wasm32-wasi/release/slkvs.wasm)
echo vs: (count $result_msg)

# extract version
set captures (string match --regex -g 'Updated component with ID (.*?) New version: (\d+). Component size is (\d+) bytes.*' $result_msg)
Expand Down Expand Up @@ -77,7 +76,7 @@ function get
--parameters=(gli_parameters $argv[1])
end

function hgettree
function hgettree --description "For a given path, retrieve the entire subtree, with output in json"
set component_id (gli_component_id)
set worker_name fst
set function_name golem:component/api/gettree
Expand All @@ -87,21 +86,21 @@ function hgettree
echo -e (curl --silent --json $params $url) | jq .result[0] | string unescape | jq .
end

function gettree
function gettree --description "For a given path, retrieve the entire subtree, with output in WAVE"
golem-cli worker invoke-and-await --component-name=slkvs \
--worker-name=fst \
--function=golem:component/api/gettree \
--parameters=(gli_parameters $argv[1])
end

function delete
function delete --description "For a given path, delete the value. Fails on a subtree."
golem-cli worker invoke-and-await --component-name=slkvs \
--worker-name=fst \
--function=golem:component/api/delete \
--parameters=(gli_parameters $argv[1])
end

function add
function add --description "For a given path, add the value."
golem-cli worker invoke-and-await --component-name=slkvs \
--worker-name=fst \
--function=golem:component/api/add \
Expand All @@ -128,15 +127,12 @@ function gli_component_id
echo $component_id
end

function hlistpaths --description "invoke listpaths via http api"
function hlistpaths --description "List all paths, with output in json rather than WAVE"
set component_id (gli_component_id)
set worker_name fst
set function_name golem:component/api/listpaths
# curl -d '{"function": "listpaths"}' "http://localhost:9881/v2/components/$component_id/workers/$worker_name/invoke-and-await?function=$function_name&calling-convention=Component"
# Content-Type: multipart/form-data
# curl -F '{"params": null}' "http://localhost:9881/v2/components/$component_id/workers/$worker_name/invoke-and-await?function=$function_name&calling-convention=Component"
# curl -F "function=$function_name" -F "calling-convention=Component" "http://localhost:9881/v2/components/$component_id/workers/$worker_name/invoke-and-await"
set json_rsp (curl --silent --json '{"params": []}' "http://localhost:9881/v2/components/$component_id/workers/$worker_name/invoke-and-await?function=$function_name&calling-convention=Component")
# because golem api returns this in a top-level result: []
echo $json_rsp | jq .result[0]
end

Expand All @@ -160,7 +156,7 @@ function addtree
--parameters=(gli_noquote_parameters (gli_quote $argv[1]) $escaped_tree)
end

function drop
function drop --description "Remove all key->values"
golem-cli worker invoke-and-await \
--component-name=slkvs \
--worker-name=fst \
Expand Down
2 changes: 1 addition & 1 deletion sample.paths.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add web-app/servlet/0/servlet-name cofaxCDS
add web-app/servlet/0/servlet-class org.cofax.cds.CDSServlet
add web-app/servlet/0/init-param/configGlossary:installationAt Philadelphia, PA
add web-app/servlet/0/init-param/configGlossary:installationAt "Philadelphia, PA"
add web-app/servlet/0/init-param/configGlossary:adminEmail [email protected]
add web-app/servlet/0/init-param/configGlossary:poweredBy Cofax
add web-app/servlet/0/init-param/configGlossary:poweredByIcon /images/cofax.gif
Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
#![feature(btree_cursors)]
#![feature(iter_intersperse)]

use std::cell::RefCell;

mod tree;
// generated by cargo component build
mod bindings;
mod tree;

use crate::bindings::exports::golem::component::api::*;
use std::cell::RefCell;

use crate::tree::LeafPaths;

Expand All @@ -19,7 +18,7 @@ thread_local! {

struct Component;

impl Guest for Component {
impl crate::bindings::exports::golem::component::cli::Guest for Component {
fn add(path: String, leaf: String) {
STATE.with_borrow_mut(|state| state.add(path, leaf));
}
Expand Down
4 changes: 2 additions & 2 deletions wit/slkvs.wit
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package golem:component;

// naming is a little odd, because these map directly to cli commands,
// and there, it's a PITA to type unnecessary - and _
interface api {
interface cli {
add: func(path: string, value: string);
get: func(path: string) -> option<string>;
listpaths: func() -> list<string>;
Expand All @@ -17,5 +17,5 @@ interface api {
}

world slkvs {
export api;
export cli;
}

0 comments on commit edf5318

Please sign in to comment.