Storage Adapters
kSync provides multiple storage adapters to persist events to different backends. All storage adapters implement theStorageAdapter interface.
Storage Interface
InMemoryStorage
A simple in-memory storage adapter for development and testing.Constructor
maxEvents?(number): Maximum number of events to keep in memory (default: unlimited)ttl?(number): Time-to-live for events in milliseconds (default: unlimited)
Methods
save(event)
Saves an event to memory.
load()
Loads all events from memory.
clear()
Clears all events from memory.
getMetadata()
Gets storage metadata.
Example
FileStorage
Persists events to a local file system.Constructor
filePath(string): Path to the storage fileoptions(optional):compression?(boolean): Enable gzip compression (default: false)backup?(boolean): Create backup files (default: true)syncWrites?(boolean): Synchronous writes for durability (default: false)
Methods
Same asStorageAdapter interface.
Example
IndexedDBStorage
Browser-based storage using IndexedDB.Constructor
dbName(string): Name of the IndexedDB databaseoptions(optional):version?(number): Database version (default: 1)storeName?(string): Object store name (default: ‘events’)
Methods
Same asStorageAdapter interface.
Example
SQLiteStorage
Server-side SQLite storage for Node.js applications.Constructor
dbPath(string): Path to SQLite database fileoptions(optional):tableName?(string): Table name for events (default: ‘events’)wal?(boolean): Enable WAL mode (default: true)cache?(number): Cache size in pages (default: 2000)
Methods
Same asStorageAdapter interface, plus:
vacuum()
Optimizes the database by reclaiming space.
analyze()
Updates database statistics for query optimization.
Example
RedisStorage
Redis-based storage for distributed applications.Constructor
host(string): Redis hostport(number): Redis portpassword?(string): Redis passworddb?(number): Redis database numberkeyPrefix?(string): Prefix for Redis keys (default: ‘ksync:’)compression?(boolean): Enable compression (default: false)
Methods
Same asStorageAdapter interface, plus:
getStats()
Gets Redis storage statistics.
Example
CloudStorage
Cloud storage adapter for AWS S3, Google Cloud Storage, etc.Constructor
provider(‘s3’ | ‘gcs’ | ‘azure’): Cloud provideroptions: Provider-specific configuration
S3 Options
Example
Custom Storage Adapter
You can create custom storage adapters by implementing theStorageAdapter interface:

