unstorage-driver
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data β all from the browser, and deployed in milliseconds.
An Unstorage driver that provides seamless integration with Val Town's Blob Storage.
- π Drop-in driver for Unstorage
- πΎ Full CRUD operations for Val Town blobs
- π Key normalization and prefix support
- π¦ Binary and text data support
- π Secure API key authentication
Import the driver directly from this val:
import driver from "https://esm.town/v/pomdtr/unstorage-driver/main.tsx";
Or use it with the Unstorage library:
import { createStorage } from "https://esm.sh/unstorage";
import driver from "https://esm.town/v/pomdtr/unstorage-driver/main.tsx";
import { createStorage } from "https://esm.sh/unstorage";
import driver from "https://esm.town/v/pomdtr/unstorage-driver/main.tsx";
const storage = createStorage({
driver: driver({
apiKey: Deno.env.get("VALTOWN_API_KEY")
})
});
// Store data
await storage.setItem("user:123", { name: "Alice", email: "alice@example.com" });
// Retrieve data
const user = await storage.getItem("user:123");
// Check if key exists
const exists = await storage.hasItem("user:123");
// List all keys
const keys = await storage.getKeys();
// Remove item
await storage.removeItem("user:123");
// Clear all items (or with prefix)
await storage.clear("user:");
// Store binary data
const imageData = new Uint8Array([/* ... */]);
await storage.setItemRaw("images:logo.png", imageData);
// Retrieve binary data
const data = await storage.getItemRaw("images:logo.png");
// List all keys with a specific prefix
const userKeys = await storage.getKeys("user:");
// Clear all items with a prefix
await storage.clear("user:");
type ValTownBlobOptions = {
apiKey?: string; // Your Val Town API key (optional if running on Val Town)
}
hasItem(key)- Check if a key existsgetItem(key)- Get item as textgetItemRaw(key)- Get item as ArrayBuffersetItem(key, value)- Store text/JSON datasetItemRaw(key, value)- Store binary dataremoveItem(key)- Delete an itemgetKeys(base?)- List all keys (optionally filtered by prefix)clear(base?)- Remove all items (optionally filtered by prefix)
- Key-Value Store: Simple persistent storage for your Val Town applications
- Session Management: Store user sessions and authentication data
- Cache Layer: Cache API responses or computed results
- Configuration Storage: Store and retrieve application configuration
- File Storage: Store and manage binary files like images or documents
- Keys are automatically normalized using Unstorage's
normalizeKeyfunction - The driver uses Val Town's official SDK (
@valtown/sdk) for blob operations - All operations are asynchronous and return Promises
MIT
