Module storage

Module storage 

Source
Expand description

Persistent storage API for OutLayer WASM components

Storage is encrypted and persisted across executions. For projects, storage is shared across all versions (same encryption key derived from project UUID).

§Basic Usage

use outlayer::storage;

// Store a value
storage::set("my-key", b"my-value")?;

// Retrieve a value
if let Some(value) = storage::get("my-key")? {
    println!("Got: {:?}", value);
}

// Check if key exists
if storage::has("my-key") {
    println!("Key exists!");
}

// Delete a key
storage::delete("my-key");

// List keys with prefix
let keys = storage::list_keys("prefix:")?;

§Worker-Private Storage

Worker-private storage is only accessible from within WASM code, not by the user. Use this for internal state that shouldn’t be exposed.

use outlayer::storage;

// Store worker-private data
storage::set_worker("internal-state", b"secret")?;

// Retrieve worker-private data
let state = storage::get_worker("internal-state")?;

§Version Migration

When upgrading your WASM, you can read data from a previous version:

use outlayer::storage;

// Read from previous WASM version (by its SHA256 hash)
let old_data = storage::get_by_version("my-key", "abc123...")?;

Structs§

StorageError
Storage error

Functions§

clear_all
Clear all storage for the current project/account
clear_version
Clear storage written by a specific WASM version
decrement
Atomically decrement a numeric value
delete
Delete a key
get
Get a value by key
get_by_version
Get data from a specific WASM version (for migration)
get_json
Get a JSON-deserializable value
get_string
Get a string value
get_worker
Get worker-private data
get_worker_from_project
Get worker data from another project (public data only)
has
Check if a key exists
increment
Atomically increment a numeric value
list_keys
List all keys with optional prefix filter
set
Store a value by key
set_if_absent
Set a key only if it doesn’t already exist
set_if_equals
Set a key only if current value equals expected (compare-and-swap)
set_json
Store a JSON-serializable value
set_string
Store a string value
set_worker
Store worker-private data
set_worker_with_options
Store worker data with encryption control

Type Aliases§

Result
Result type for storage operations