Hey everybody,
I’m absolutely thrilled to unveil today’s new addition to the set of features offered by Juno: the introduction of serverless Functions enabling developers to extend the native capabilities of Satellites.
Functions are a set of Rust-based features enabling developers the creation and management of serverless behaviors, called hooks, within canisters which are triggered by specific events like document and asset operations.
A picture is worth a thousand words, so here is basically a representation of a hook that is triggered when a document is set:
In terms of coding, functions are declared using macros.
#[on_set_doc(collections = ["demo"])]
async fn on_set_doc(context: OnSetDocContext) -> Result<(), String> {
ic_cdk::print(format!({}, context.caller.to_text()));
Ok(())
}
Each hook receives a context which includes caller, collection, document, or asset information.
In addition to those functions, I have also improved our custom local development environment, which now supports HTTP outcalls as well. More importantly, it has been simplified to only a few command lines:
juno dev eject
: scaffolds a Satellite in your project.juno dev start
: starts and sets up the configuration for the environment if needed.juno dev build
: compiles your custom Satellite.
And that’s it. The local environment takes care of the rest; it supports hot reload .
Got a tweet out that summarizes all the links. https://twitter.com/daviddalbusco/status/1755961160614965497
Give it a try and let me know what you think.
Happy weekend