SDK
The following functions are provided to help you work with document and asset data inside your Satellite. They are part of the tools available when writing serverless functions in Rust and support common tasks such as interacting with the datastore, storage, and custom hook logic.
The SDK is provided by the junobuild-satellite crate.
To use them, add this to your Cargo.toml:
[dependencies]
junobuild-satellite = "*"
You have to follow the pace of the Juno release to ensure compatibility. Refer to the maintenance guide for instructions.
Datastoreβ
The following functions can be used to manage documents within the Datastore from your serverless functions.
set_doc_storeβ
Sets a document in a collectionβs of the datastore. Use this to insert or update document data.
pub fn set_doc_store(
caller: UserId,
collection: CollectionKey,
key: Key,
value: SetDoc,
) -> Result<DocContext<DocUpsert>, String>
π¦ See full definition on docs.rs
get_doc_storeβ
Retrieves a document from a collection.
pub fn get_doc_store(
caller: UserId,
collection: CollectionKey,
key: Key,
) -> Result<Option<Doc>, String>
π¦ See full definition on docs.rs
list_docs_storeβ
Lists documents in a collection based on filter criteria.
pub fn list_docs_store(
caller: Principal,
collection: CollectionKey,
filter: &ListParams,
) -> Result<ListResults<Doc>, String>
π¦ See full definition on docs.rs
count_docs_storeβ
Counts documents in a collection based on filter criteria.
pub fn count_docs_store(
caller: Principal,
collection: CollectionKey,
filter: &ListParams,
) -> Result<usize, String>
π¦ See full definition on docs.rs
count_collection_docs_storeβ
Counts all documents in a collection.
pub fn count_collection_docs_store(
collection: &CollectionKey
) -> Result<usize, String>
π¦ See full definition on docs.rs
delete_doc_storeβ
Deletes a document from a collection.
pub fn delete_doc_store(
caller: UserId,
collection: CollectionKey,
key: Key,
value: DelDoc,
) -> Result<DocContext<Option<Doc>>, String>
π¦ See full definition on docs.rs
delete_docs_storeβ
Deletes all documents in a collection.
pub fn delete_docs_store(
collection: &CollectionKey
) -> Result<(), String>
π¦ See full definition on docs.rs
delete_filtered_docs_storeβ
Deletes documents matching filter criteria.
pub fn delete_filtered_docs_store(
caller: Principal,
collection: CollectionKey,
filter: &ListParams,
) -> Result<Vec<DocContext<Option<Doc>>>, String>
π¦ See full definition on docs.rs
Storageβ
The following functions can be used to manage assets within the Storage from your serverless functions.
set_asset_handlerβ
Sets an asset in the store for the identity encoding (no compression applied).
pub fn set_asset_handler(
key: &AssetKey,
content: &Blob,
headers: &[HeaderField],
) -> Result<(), String>
π¦ See full definition on docs.rs
get_asset_storeβ
Retrieves an asset from a collection.
pub fn get_asset_store(
caller: Principal,
collection: &CollectionKey,
full_path: FullPath,
) -> Result<Option<Asset>, String>
π¦ See full definition on docs.rs
list_assets_storeβ
Lists assets in a collection, excluding their content.
pub fn list_assets_store(
caller: Principal,
collection: &CollectionKey,
filters: &ListParams,
) -> Result<ListResults<AssetNoContent>, String>
π¦ See full definition on docs.rs
count_assets_storeβ
Counts assets in a collection matching the filter criteria.
pub fn count_assets_store(
caller: Principal,
collection: &CollectionKey,
filters: &ListParams,
) -> Result<usize, String>
π¦ See full definition on docs.rs
count_collection_assets_storeβ
Counts all assets in a collection.
pub fn count_collection_assets_store(
collection: &CollectionKey,
) -> Result<usize, String>
π¦ See full definition on docs.rs
delete_asset_storeβ
Deletes an asset from a collection.
pub fn delete_asset_store(
caller: Principal,
collection: &CollectionKey,
full_path: FullPath,
) -> Result<Option<Asset>, String>
π¦ See full definition on docs.rs
delete_assets_storeβ
Deletes all assets in a collection.
pub fn delete_assets_store(
collection: &CollectionKey,
) -> Result<(), String>
π¦ See full definition on docs.rs
delete_filtered_assets_storeβ
Deletes assets matching filter criteria.
pub fn delete_filtered_assets_store(
caller: Principal,
collection: CollectionKey,
filters: &ListParams,
) -> Result<Vec<Option<Asset>>, String>
π¦ See full definition on docs.rs
get_content_chunks_storeβ
Retrieves content chunks of an asset. Particularly useful when stable memory is used.
pub fn get_content_chunks_store(
encoding: &AssetEncoding,
chunk_index: usize,
memory: &Memory,
) -> Option<Blob>
π¦ See full definition on docs.rs
Controllersβ
The following functions allow you to inspect and assert the controllers of your Satellite.
get_controllersβ
Retrieves all controllers of the Satellite.
pub fn get_controllers() -> Controllers
π¦ See full definition on docs.rs
get_admin_controllersβ
Retrieves only the admin controllers of the Satellite.
pub fn get_admin_controllers() -> Controllers
π¦ See full definition on docs.rs
Othersβ
The SDK also provides various Satellite-specific functions
randomβ
Generates a random i32
.
The generator is seeded once after upgrade of the Satellite. This makes it unsuitable for use cases requiring unpredictable randomness, like lotteries.
pub fn random() -> Result<i32, String>
π¦ See full definition on docs.rs