API Reference
Complete API documentation for Strata Storage.
Core API
Strata Class
The main class for interacting with storage. Provides methods for all storage operations.
import { Strata } from 'strata-storage';
const storage = new Strata(config);
await storage.initialize();
Type Definitions
TypeScript interfaces and type definitions used throughout the library.
Error Classes
Custom error classes for better error handling and debugging.
Storage Adapters
Adapter Overview
Learn about the different storage adapters available and their capabilities.
Web Adapters
- Memory Adapter - In-memory storage
- LocalStorage Adapter - Persistent browser storage
- SessionStorage Adapter - Session-based storage
- IndexedDB Adapter - Large-scale database storage
- Cookie Adapter - HTTP cookie storage
- Cache Adapter - Service Worker cache storage
Capacitor Adapters
- Preferences Adapter - Native preferences
- SQLite Adapter - SQL database storage
- Secure Adapter - Encrypted secure storage
- Filesystem Adapter - File-based storage
Features
Encryption
AES-GCM encryption for secure data storage.
const encrypted = await encryptionManager.encrypt(data, password);
const decrypted = await encryptionManager.decrypt(encrypted, password);
Compression
LZ-based compression for efficient storage.
const compressed = await compressionManager.compress(data);
const decompressed = await compressionManager.decompress(compressed);
Synchronization
Cross-tab and cross-window synchronization.
storage.subscribe((change) => {
console.log('Storage changed:', change);
});
TTL Management
Time-to-live support with automatic expiration.
await storage.set('temp', data, { ttl: 60000 }); // Expires in 1 minute
Query Engine
Advanced querying capabilities for stored data.
const results = await storage.query({
tags: { $in: ['important'] },
created: { $gt: new Date('2024-01-01') }
});
Migration Utilities
Tools for migrating data between schema versions.
Experimental:
MigrationManageris exported fromstrata-storage, but it is a standalone, adapter-level utility — it is not configured throughStrataConfig(there is nomigrationsoption onnew Strata(...)). It operates directly on an initialized storage adapter.
import { MigrationManager, LocalStorageAdapter } from 'strata-storage';
const adapter = new LocalStorageAdapter();
await adapter.initialize();
const migrator = new MigrationManager();
migrator.register({
version: 1,
up: async (a) => { /* transform stored data via a.get/a.set/... */ },
});
await migrator.migrate(adapter, 1);
Quick Reference
Basic Operations
// Initialize
const storage = new Strata();
await storage.initialize();
// Set data
await storage.set(key, value, options?);
// Get data
const value = await storage.get(key, options?);
// Remove data
await storage.remove(key, options?);
// Check existence
const exists = await storage.has(key, options?);
// Clear storage
await storage.clear(options?);
// Get all keys
const keys = await storage.keys(pattern?, options?);
// Get size info
const size = await storage.size(detailed?);
Advanced Operations
// Query data
const results = await storage.query(condition, options?);
// Subscribe to changes
const unsubscribe = storage.subscribe(callback, options?);
// Export data
const exported = await storage.export(options?);
// Import data
await storage.import(data, options?);
// Get TTL
const ttl = await storage.getTTL(key, options?);
// Extend TTL
await storage.extendTTL(key, extension, options?);
// Make persistent
await storage.persist(key, options?);
Utility Functions
// Generate secure password
const password = storage.generatePassword(length?);
// Hash data
const hash = await storage.hash(data);
// Get available storage types
const types = storage.getAvailableStorageTypes();
// Get adapter capabilities
const capabilities = storage.getCapabilities(storage?);
Framework Integration
Next Steps
- Read the Strata Class API documentation
- Explore Storage Adapters
- Learn about Advanced Features