API reference / @evolu/common / local-first / Storage

Interface: Storage

Defined in: packages/common/src/local-first/Storage.ts:91

Evolu Storage

Evolu protocol using Storage is agnostic to storage implementation details—any storage can be plugged in, as long as it implements this interface. Implementations must handle their own errors; return values only indicate overall success or failure.

The Storage API is synchronous because SQLite's synchronous API is the fastest way to use SQLite. Synchronous bindings (like better-sqlite3) call SQLite's C API directly with no context switching between the event loop and native code, and no promise microtasks or await overhead.

The only exception is Storage#writeMessages, which is async to allow for async validation logic before writing to storage. The write operation itself remains synchronous.

Extended by

Properties

PropertyModifierTypeDescriptionDefined in
deleteOwnerreadonly(ownerId) => booleanDelete all data for the given Owner. Returns true on success, false on failure.packages/common/src/local-first/Storage.ts:167
findLowerBoundreadonly(ownerId, begin, end, upperBound) => | number & Brand<"Int"> & Brand<"NonNegative"> | null-packages/common/src/local-first/Storage.ts:113
fingerprintreadonly(ownerId, begin, end) => | Fingerprint | null-packages/common/src/local-first/Storage.ts:94
fingerprintRangesreadonly(ownerId, buckets, upperBound?) => | readonly FingerprintRange[] | nullComputes fingerprints with their upper bounds in one call. This function can be replaced with many fingerprint/findLowerBound calls, but implementations can leverage it for batching and more efficient fingerprint computation.packages/common/src/local-first/Storage.ts:107
getSizereadonly(ownerId) => | number & Brand<"Int"> & Brand<"NonNegative"> | null-packages/common/src/local-first/Storage.ts:92
iteratereadonly(ownerId, begin, end, callback) => void-packages/common/src/local-first/Storage.ts:120
readDbChangereadonly(ownerId, timestamp) => | EncryptedDbChange | nullRead encrypted DbChanges from storage.packages/common/src/local-first/Storage.ts:157
setWriteKeyreadonly(ownerId, writeKey) => booleanSets the OwnerWriteKey for the given Owner.packages/common/src/local-first/Storage.ts:138
validateWriteKeyreadonly(ownerId, writeKey) => booleanValidates the OwnerWriteKey for the given Owner. Returns true if the write key is valid, false otherwise.packages/common/src/local-first/Storage.ts:132
writeMessagesreadonly(ownerIdBytes, messages) => MaybeAsync<Result<void, | StorageWriteError | StorageQuotaError>>Write encrypted CrdtMessages to storage. Must use a mutex per ownerId to ensure sequential processing and proper protocol logic handling during sync operations. TODO: Use MaybeAsyncpackages/common/src/local-first/Storage.ts:151

Was this page helpful?