Skip to main content

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.

πŸ“¦ Crate

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.

caution

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