API Reference / @evolu/common / Evolu/Internal

Evolu/Internal

🛠️

Example

import { Evolu } from "@evolu/common/evolu";

Interfaces

InterfaceDescription
AppOwnerThe root owner of an Evolu app, created from a mnemonic safely generated on a device when the app is initialized or restored on another device using an existing mnemonic. It manages the app's core data, including the storage of other owners' mnemonics in an encrypted app table. Its writeKey is deterministic and rotatable. Never share the AppOwner mnemonic with anyone.
AppState-
ClientStorageCommon interface for both client and relay SQLite storages.
ClientStorageDep-
Config-
ConfigDep-
CreateAppStateDep-
CreateDbWorkerDep-
CreateSyncDep-
DbSchema-
DbSnapshot-
Evolu-
EvoluConfigWithInitialData-
EvoluForInitialData-
FlushSyncDep-
MutationOptions-
NetworkError-
OwnerOwner is an entity in Evolu that owns data, meaning it is locally stored on a device under the user’s control. Data can be personal private, peer-to-peer shared, or aggregated from multiple owners.
OwnerRowStoreDep-
OwnerWithWriteAccess-
PaymentRequiredError-
QueryPatches-
QueryRowsCache-
Relay-
RelayConfig-
ReplaceAllPatch-
ReplaceAtPatch-
Row-
ServerError-
ShardOwnerUsed to shard data within an app for partial or deferred sync. Created in the Evolu initialData function or dynamically as needed. Its mnemonic is stored in an app table (encrypted by AppOwner) and synced between devices. Its writeKey is deterministic and rotatable, enabling selective syncing of data subsets. Not intended for sharing outside the app.
SharedOwnerUsed to share data among one or more users, enabling collaboration or controlled access. Its writeKey is random (not derived from the mnemonic, stored alongside it in the app table) and rotatable, ensuring it cannot be regenerated by others if shared. Share the mnemonic alone for read-only access (as SharedReadonlyOwner) or share SharedOwner itself for write access.
SharedReadonlyOwnerUsed for sharing data that can only be read, such as with followers or peers in a read-only sync scenario. It lacks a writeKey, containing only the mnemonic from which id and encryptionKey are derived by Evolu. Typically derived from a SharedOwner by sharing its mnemonic without the writeKey.
SubscribedQueries-
Sync-
SyncConfig-
SyncDep-
SyncStateInitialThe initial synchronization state when the app starts. In this state, the app needs to determine whether the data is synced.
SyncStateIsNotSynced-
SyncStateIsSynced-
SyncStateIsSyncing-
Table-
TimestampConfig-
TimestampConfigDep-
TimestampCounterOverflowError-
TimestampDriftError-
TimestampDuplicateNodeError-
TimestampTimeOutOfRangeError-
ValidEvoluSchemaError-
ValidMutationSizeError-

Type Aliases

Type AliasDescription
BinaryTimestampBinaryTimestamp is a binary and sortable version of Timestamp for DB.
Counter-
CreateAppState-
CreateDbWorker-
CreateQuery-
CreateSync-
DbWorker-
DbWorkerInput-
DbWorkerOutput-
DbWorkerPlatformDeps-
DefaultColumns-
EvoluDeps-
EvoluErrorRepresent errors that can occur in Evolu.
EvoluSchemaDefines the schema of an Evolu database.
FlushSyncFlushSync is for libraries like React to flush updates synchronously inside the provided callback to ensure the DOM is updated immediately.
Index-
Indexex-
InferColumnErrors-
InferEvoluSchemaError-
InferMutationTypeErrors-
InferRow-
Insertable-
InsertableProps-
Millis-
Mutation-
MutationKind-
MutationMapping-
NodeId-
OwnerId-
OwnerRowAn OwnerRow represents a row in the evolu_owner table, based on an Owner with an added timestamp (TimestampString) for CRDT sync. It supports all Owner variants with an optional writeKey; use createOwnerRow to align it with a specific Owner.
Patch-
Queries-
QueriesToQueryRows-
QueriesToQueryRowsPromises-
QueryA type-safe SQL query.
QueryRowsRows returned by a query.
QueryRowsMap-
SyncStateThe possible states of a synchronization process. The SyncState can be one of the following:
Timestamp-
TimestampError-
TimestampStringTimestampString is a sortable string version of Timestamp.
Updateable-
UpdateableProps-
Upsertable-
UpsertableProps-
ValidEvoluSchema-
ValidMutationSize-
WriteKey-

Variables

VariableDescription
binaryTimestampLength-
Counter-
createIndex-
createWebSocketSync-
DefaultColumns-
defaultColumnsNames-
defaultConfig-
emptyRows-
formatValidMutationSizeError-
Index-
initialSyncState-
kysely-
kyselyJsonIdentifierA unique identifier prepended to JSON-encoded strings. This allows safe detection and parsing of only those columns that require JSON.parse.
maxCounter-
maxMillis-
maxMutationSizeEvolu has to limit the maximum mutation size. Otherwise, sync couldn't use the max frame size. The max size is 640KB in bytes, measured via MessagePack. Evolu Protocol DbChange will be smaller thanks to various optimizations.
maxNodeId-
MillisMillis is a timestamp in milliseconds, like Date.now(), but limited to the maximum value representable in 6 bytes (281474976710655) minus 1 (reserved for infinity). This enables more efficient binary serialization, saving 2 bytes compared to the typical 8-byte (64-bit) timestamp representation.
minCounter-
minMillis-
minNodeId-
NodeIdA NodeId uniquely identifies an owner's device. Generated once per device using cryptographic randomness.
orderBinaryTimestamp-
OwnerIdThe unique identifier of Owner derived from the Mnemonic.
TimestampHybrid Logical Clock timestamp.
ValidEvoluSchemaValid EvoluSchema.
WriteKeyA secure token proving the initiator can write changes. Derived from a mnemonic or randomly generated. It's rotatable.
writeKeyLength-

Functions

FunctionDescription
applyMessageToTimestampAndHistoryTables-
applyPatches-
assertValidEvoluSchemaAsserts that the given value is ValidEvoluSchema.
binaryTimestampToTimestamp-
createAppOwnerCreates an AppOwner, optionally from an existing mnemonic to restore it on another device; otherwise, generates a new mnemonic.
createAppTable-
createDbWorkerForPlatform-
createEvoluCreates an Evolu instance configured with the specified EvoluSchema and optional configuration.
createIndexes-
createInitialTimestamp-
createNamespaceName-
createOwnerCreates an Owner with optional mnemonic and writeKey.
createOwnerRowCreates an OwnerRow from any Owner variant for the evolu_owner table, adding a timestamp (TimestampString) for CRDT sync.
createQueryRowsCache-
createRelayStorage-
createShardOwnerCreates a ShardOwner for sharding app data with a freshly generated mnemonic. Unlike createAppOwner, it doesn’t accept an existing mnemonic because ShardOwner mnemonics are always generated and restored automatically via database sync.
createSharedOwnerCreates a fresh SharedOwner for sharing data with write access. Takes no arguments as both mnemonic and rotatable writeKey are newly generated; when shared, recipients use the provided mnemonic and writeKey directly as a SharedOwner without needing to recreate it.
createSharedReadonlyOwnerCreates a SharedReadonlyOwner from a SharedOwner for read-only data sharing. Extracts the mnemonic from the provided SharedOwner, omitting its writeKey to ensure read-only access.
createSubscribedQueries-
createTimestamp-
createWriteKey-
deserializeQuery-
getDbSchema-
getDbSnapshot-
insertableType Factory to create insertable Type. It makes nullable Types optional, omits Id, and ensures the maxMutationSize.
makePatchesWe detect only changes in the whole result and in-place edits. In the future, we will add more heuristics. We will probably not implement the Myers diff algorithm because it's faster to rerender all than to compute many detailed patches. We will only implement logic a developer would implement manually, if necessary.
maybeMigrateToVersion0-
parseSqliteJsonArray-
receiveTimestamp-
rotateWriteKeyRotates the WriteKey for an AppOwner, ShardOwner, or SharedOwner, returning a new instance with the updated key.
sendTimestamp-
serializeQueryEvolu serializes SqliteQuery into a string to be easily used as a key and for comparison.
timestampStringToTimestamp-
timestampToBinaryTimestamp-
timestampToTimestampString-
updateableType Factory to create updateable Type. It makes everything except for the id column partial (i.e. optional) and ensures the maxMutationSize.
upsertableType Factory to create upsertable Type. It makes nullable Types optional and ensures the maxMutationSize.
validEvoluSchemaToDbSchema-

applyProtocolMessageAsClient

Re-exports applyProtocolMessageAsClient


ApplyProtocolMessageAsClientOptions

Re-exports ApplyProtocolMessageAsClientOptions


applyProtocolMessageAsRelay

Re-exports applyProtocolMessageAsRelay


ApplyProtocolMessageAsRelayOptions

Re-exports ApplyProtocolMessageAsRelayOptions


Base64Url256

Re-exports Base64Url256


base64Url256ToBytes

Re-exports base64Url256ToBytes


Base64Url256Variant

Re-exports Base64Url256Variant


BinaryId

Re-exports BinaryId


binaryIdLength

Re-exports binaryIdLength


binaryIdToId

Re-exports binaryIdToId


BinaryOwnerId

Re-exports BinaryOwnerId


binaryOwnerIdToOwnerId

Re-exports binaryOwnerIdToOwnerId


binaryTimestampToFingerprint

Re-exports binaryTimestampToFingerprint


ColumnName

Re-exports ColumnName


CrdtMessage

Re-exports CrdtMessage


createProtocolMessageBuffer

Re-exports createProtocolMessageBuffer


createProtocolMessageForSync

Re-exports createProtocolMessageForSync


createProtocolMessageFromCrdtMessages

Re-exports createProtocolMessageFromCrdtMessages


createSqliteStorageBase

Re-exports createSqliteStorageBase


CreateSqliteStorageBaseOptions

Re-exports CreateSqliteStorageBaseOptions


createTimestampsBuffer

Re-exports createTimestampsBuffer


DbChange

Re-exports DbChange


DbIdentifier

Re-exports DbIdentifier


decodeBase64Url256

Re-exports decodeBase64Url256


decodeBase64Url256WithLength

Re-exports decodeBase64Url256WithLength


decodeColumnName

Re-exports decodeColumnName


decodeDbChange

Re-exports decodeDbChange


decodeDbIdentifier

Re-exports decodeDbIdentifier


decodeLength

Re-exports decodeLength


decodeNodeId

Re-exports decodeNodeId


decodeNonNegativeInt

Re-exports decodeNonNegativeInt


decodeNumber

Re-exports decodeNumber


decodeRanges

Re-exports decodeRanges


decodeSqliteValue

Re-exports decodeSqliteValue


decodeString

Re-exports decodeString


decodeTableName

Re-exports decodeTableName


decryptDbChange

Re-exports decryptDbChange


encodeBase64Url256

Re-exports encodeBase64Url256


encodeColumnName

Re-exports encodeColumnName


encodeDbChange

Re-exports encodeDbChange


encodeDbIdentifier

Re-exports encodeDbIdentifier


encodeLength

Re-exports encodeLength


encodeNodeId

Re-exports encodeNodeId


encodeNonNegativeInt

Re-exports encodeNonNegativeInt


encodeNumber

Re-exports encodeNumber


encodeSqliteValue

Re-exports encodeSqliteValue


encodeString

Re-exports encodeString


encodeTableName

Re-exports encodeTableName


encryptDbChange

Re-exports encryptDbChange


EncryptedCrdtMessage

Re-exports EncryptedCrdtMessage


EncryptedDbChange

Re-exports EncryptedDbChange


Fingerprint

Re-exports Fingerprint


FingerprintRange

Re-exports FingerprintRange


fingerprintSize

Re-exports fingerprintSize


getTimestampByIndex

Re-exports getTimestampByIndex


idToBinaryId

Re-exports idToBinaryId


InfiniteUpperBound

Re-exports InfiniteUpperBound


maxProtocolMessageRangesSize

Re-exports maxProtocolMessageRangesSize


maxProtocolMessageSize

Re-exports maxProtocolMessageSize


ownerIdToBinaryOwnerId

Re-exports ownerIdToBinaryOwnerId


ProtocolError

Re-exports ProtocolError


ProtocolErrorCode

Re-exports ProtocolErrorCode


ProtocolInvalidDataError

Re-exports ProtocolInvalidDataError


ProtocolMessage

Re-exports ProtocolMessage


ProtocolMessageBuffer

Re-exports ProtocolMessageBuffer


ProtocolSyncError

Re-exports ProtocolSyncError


ProtocolUnsupportedVersionError

Re-exports ProtocolUnsupportedVersionError


ProtocolValueType

Re-exports ProtocolValueType


protocolVersion

Re-exports protocolVersion


ProtocolWriteError

Re-exports ProtocolWriteError


ProtocolWriteKeyError

Re-exports ProtocolWriteKeyError


Range

Re-exports Range


RangeType

Re-exports RangeType


RangeUpperBound

Re-exports RangeUpperBound


SkipRange

Re-exports SkipRange


SqliteStorageBase

Re-exports SqliteStorageBase


SqliteStorageBaseDep

Re-exports SqliteStorageBaseDep


SqliteStorageDeps

Re-exports SqliteStorageDeps


Storage

Re-exports Storage


StorageDep

Re-exports StorageDep


TableName

Re-exports TableName


TimestampsBuffer

Re-exports TimestampsBuffer


TimestampsRange

Re-exports TimestampsRange


TimestampsRangeWithTimestampsBuffer

Re-exports TimestampsRangeWithTimestampsBuffer


zeroFingerprint

Re-exports zeroFingerprint

Was this page helpful?