Vaultrice is more than just a key-value store. It's a comprehensive platform designed to solve the challenges of modern state management with a suite of powerful, integrated features.
import { NonLocalStorage } from '@vaultrice/sdk';
const nls = new NonLocalStorage(credentials, 'shared-object-id');
// Set a value from one client...
await nls.setItem('hello', 'world from client A');
// ...and listen for it on another.
nls.on('setItem', 'hello', (item) => {
console.log(item.value); // 'world from client A'
});
// messaging...
nls.send({ chat: 'hi there' });
nls.on('message', (msg) => {
console.log(msg.chat);
});
// presence...
nls.join({ name: 'Alice' });
nls.on('presence:join', (conn) => {
console.log(conn.data);
});
const connections = await nls.getJoinedConnections();
console.log(connections); // Array of connection info
// ...
At its heart, Vaultrice offers a simple and intuitive key-value storage API that will feel instantly familiar. But unlike traditional databases or localStorage
, it's built on a global edge network to deliver your data with minimal latency.
Get started in minutes with an API modeled after the browser's localStorage
. We support basic CRUD operations, batch actions for efficiency, and atomic counters for concurrent operations.
Basic CRUD operations that feel familiar
setItem(key, value)
, getItem(key)
, removeItem(key)
Efficient bulk operations for better performance
setItems({key1: value1})
, getItems(['key1', 'key2'])
Thread-safe increment/decrement operations
incrementItem(key, amount)
, decrementItem(key, amount)
Helpful methods for data management
getAllItems()
, getAllKeys()
, clear()
Every Vaultrice data object is powered by a Durable Object, ensuring that all operations on a specific object are strongly consistent. When you write a value, you can be confident that any subsequent read will return that same value, eliminating race conditions.
// This operation is atomic and strongly consistent.
await nls.incrementItem('page_visits', 1);
const visits = await nls.getItem('page_visits');
console.log(visits.value); // The most up-to-date value
Stop polling for changes. Vaultrice includes a powerful real-time engine that uses WebSockets to push data updates to all connected clients instantly.
You can subscribe to data changes on any object using the on()
method. This allows you to build dynamic, responsive user interfaces that react to changes as they happen.
on('setItem', callback)
: Fires when a key is created or updated.on('removeItem', callback)
: Fires when a key is removed.on('message', callback)
: Listen for custom broadcast messages.on('connect', callback)
: Fires when a real-time connection is established.on('disconnect', callback)
: Fires when the connection is lost.on('error', callback)
: Listen for errors.const statusDisplay = document.getElementById('status');
// Listen for updates to the 'projectStatus' key
nls.on('setItem', 'projectStatus', (item) => {
// Update the UI instantly when the status changes
statusDisplay.innerText = item.value;
});
// Listen for custom messages
nls.on('message', (msg) => {
if (msg.type === 'notification') {
showToast(msg.text);
}
});
// Listen for connection events
nls.on('connect', () => {
console.log('Connected to Vaultrice');
});
nls.on('disconnect', () => {
console.log('Disconnected from Vaultrice');
});
Send your own messages to all connected clients using send()
. This is perfect for chat, cursor sharing, notifications, and more.
// Send a custom message to all clients
nls.send({ type: 'notification', text: 'Welcome to the app!' });
// You can also send via HTTP if you don't want to use WebSockets:
await nls.send({ type: 'important', text: 'Critical update' }, { transport: 'http' });
Easily build collaborative features by knowing exactly who is connected to a shared object at any given moment. Our built-in Presence API handles the complexity of tracking user connections for you.
join(userData)
: Announce a user's presence to other clients.leave()
: Announce that a user has disconnected.getJoinedConnections()
: Get a list of all currently connected users.on('presence:join', callback)
: Fires when a new user joins.on('presence:leave', callback)
: Fires when a user leaves.import { NonLocalStorage } from '@vaultrice/sdk';
const nls = new NonLocalStorage(credentials, 'collaborative-document-123');
// Have the current user join the presence channel
await nls.join({ name: 'Alice' });
// Get everyone who is already online
const onlineUsers = await nls.getJoinedConnections();
console.log(onlineUsers); // [{ connectionId, joinedAt, data: { name: 'Bob' } }]
// Listen for new users
nls.on('presence:join', (connection) => {
console.log(`${connection.data.name} just joined the document.`);
});
// Listen for custom messages
nls.on('message', (msg) => {
if (msg.type === 'cursor-move') {
updateCursor(msg.userId, msg.position);
}
});
// Send a message to all clients
nls.send({ type: 'cursor-move', userId: 'alice', position: { x: 100, y: 200 } });
For the ultimate developer experience, the SyncObject
API provides a reactive JavaScript object that automatically handles state synchronization.
The createSyncObject
function returns a Proxy object that you can interact with directly. When you set a property, the change is automatically sent to all other clients. When another client updates a property, your local object is updated instantly. This is perfect for modern frontend frameworks.
import { createSyncObject } from '@vaultrice/sdk';
interface UserSettings {
theme?: 'light' | 'dark';
notifications?: boolean;
}
const userPrefs = await createSyncObject<UserSettings>(credentials, 'user-prefs-ada');
// This simple assignment automatically syncs to the cloud and all other clients.
userPrefs.theme = 'dark';
// If another client changes the language, your object will update.
// After a moment...
console.log(userPrefs.language); // 'fr'
SyncObject supports the full real-time event system, including custom messaging and connection events, just like NonLocalStorage.
joinedConnections
property. The join()
and leave()
methods make managing user presence effortless.on()
and off()
methods to listen for property changes, user joins/leaves, custom real-time messages, and connection events directly on the object.import { createSyncObject } from '@vaultrice/sdk';
// A single object to manage a collaborative document
const doc = await createSyncObject(credentials, 'doc-123');
// 1. Join presence
await doc.join({ name: 'Alice', avatar: 'url_to_avatar.png' });
// 2. Read the live presence list
console.log(`${doc.joinedConnections.length} users are online.`);
// 3. Set a property, and it syncs to everyone
doc.title = 'My Collaborative Document';
// 4. Listen for other users joining
doc.on('presence:join', (connection) => {
console.log(`${connection.data.name} just joined!`);
});
// 5. Listen for custom messages
doc.on('message', (msg) => {
if (msg.type === 'chat') {
showChatMessage(msg.from, msg.text);
}
});
// 6. Listen for connection events
doc.on('connect', () => {
console.log('Connected to real-time sync');
});
doc.on('disconnect', () => {
console.log('Disconnected from real-time sync');
});
// 7. Send a custom message to all clients
doc.send({ type: 'chat', from: 'Alice', text: 'Hello, everyone!' });
Vaultrice provides a flexible, multi-level security model that allows you to choose the right level of protection for your data.
This approach ensures that you have the tools to secure your application, from simple projects to those handling highly sensitive information.
Security Level | Key Features | Best For |
---|---|---|
Level 0 | Public data & prototypes | |
Level 1 | Controlled access & internal apps | |
Level 2 | Enhanced server-side data protection | |
Level 3 | Maximum confidentiality & sensitive data |
This approach ensures that you have the tools to secure your application, from simple projects to those handling highly sensitive information.
Create an account and start building your next real-time application in minutes. Your first project is on us.