API reference › @evolu/common › local‑first/Evolu

Local-first platform.

Core

NameDescription
EvoluA local-first SQL database.
EvoluDisposedErrorThe Evolu instance was disposed before an operation it started ended.
LoadQueryOptionsOptions of Evolu.loadQuery.
OwnerStorageUsageHow much an owner's synced data takes in a database; see Evolu.loadOwnerUsage.
UseOwnerOptionsOptions of Evolu.useOwner.
DeleteDatabaseErrorAn error of Evolu.deleteDatabase.
DeleteOwnerErrorAn error of Evolu.deleteOwner.
DevicePersistenceWhether this device keeps an Evolu database, stating only what Evolu knows for sure.
EvoluErrorRepresents app-level errors that can occur in Evolu.
LoadOwnerUsageErrorAn error of Evolu.loadOwnerUsage.
UnuseOwnerFunction returned by Evolu.useOwner to stop using an Owner for sync.
maxMutationSizeThe largest Mutation, in bytes.
isDatabaseDeletedWhether the deletion of the database of the Evolu instance disposed it; see Evolu.deleteDatabase. It's also true for an AppOwner's instance that createEvoluApp disposed after a removal of the AppOwner; see EvoluApp.remove. A framework binding checks it before it uses the instance, so a component the app has not replaced yet doesn't throw: React's suspends, and Vue's and Svelte's show no rows.

Configuration

NameDescription
AppNameErrorError produced when a value is not a valid AppName.
EvoluConfigConfiguration for createEvolu.
AppNameApplication name.
AppNameApplication name.

Construction

NameDescription
AppOwnerEntryAn AppOwner the app can open on this device, without its secret.
AppOwnerEvoluAn Evolu instance without disposal, for code that uses an instance it doesn't own, such as one createEvoluApp opened, which the app disposes.
CurrentAppOwnerThe AppOwner this tab has open and its instance. evolu is the same promise until this tab opens another AppOwner, or the AppOwner again after a removal or a deletion of its database, so React's use can read it. It never rejects. It never settles when the app is disposed while the instance opens, and when the AppOwner is removed meanwhile, it resolves with the instance disposed, for which isDatabaseDeleted is true.
DeviceEvoluThe instance of an app's device database, for the app's data that belongs to this device rather than to an AppOwner, such as settings. Its own owner is the device owner, which never syncs, so it has no Evolu.appOwner: local-only tables keep their rows on this device, and a mutation of a synced table must pass, as its owner, an owner the app syncs with Evolu.useOwner, such as one for settings shared by every AppOwner. An AppOwner's data lives only in its own database, which EvoluApp.remove deletes, so neither takes an AppOwner. The app's EvoluConfig.onOwnerDeleted also runs for an owner deleted in it, in any tab.
DevicePersistenceDepTells what the platform can promise about the databases it stores.
EvoluAppAn app whose AppOwners Evolu creates and keeps on this device. Each tab opens one AppOwner, starting with the one opened most recently. An AppOwner's instance stays open and keeps syncing after the tab opens another AppOwner, until the app is disposed or a removal of the AppOwner or a deletion of its database, in any tab, ends it.
EvoluAppConfigConfiguration for createEvoluApp. The other options apply to every AppOwner's instance, and appName, evolu7Name, and onOwnerDeleted also to the device database. Every AppOwner syncs through the same transports, so a transport made for one AppOwner, such as with createOwnerWebSocketTransport, goes to Evolu.useOwner of that AppOwner's instance instead.
EvoluAppDeviceConfigThe app's own tables in the device database and their indexes. The schema can't define Evolu's table, _evolu_appOwner, in any letter case.
EvoluErrorDepDependency wrapper for the shared EvoluError store.
NoAppOwnerStateNo AppOwner is open in this tab, such as on a device without one or after the open one's removal.
OpenAppOwnerStateThe tab has an AppOwner open, with its instance.
OpeningAppOwnerStateThe tab has an AppOwner open, whose instance opens.
RequestPersistentStorageDepAsks the platform to keep stored databases until the user deletes them.
StoredWorkerDepThe worker CreateStoredWorkerDep started, once the platform's storage check answers.
SyncStateDepDependency wrapper for the shared SyncState store.
AppOwnerStateThe AppOwner a tab has open, as subscribeAppOwnerState follows it: none open, its instance opening, or open with its instance.
DeviceMutationA Mutation of a DeviceEvolu. The device owner never syncs, so a mutation of a synced table, one whose name doesn't start with _, takes options with the owner the app syncs that table's rows with, which isn't an AppOwner. A local-only table's rows stay on this device, so its mutations need no owner.
EmptyEvoluSchemaAn EvoluSchema without tables, the device schema of an app without device tables. It has no table to write, so app.device.insert("todo", {}) doesn't compile, and it matches no other schema, so neither does a query of the app's own tables, such as app.device.loadQuery(allTodos).
EvoluDepsShared platform dependencies for creating Evolu instances.
EvoluPlatformDepsPlatform-specific dependencies createEvoluDeps passes to every createEvolu instance.
RemoveAppOwnerErrorAn error of EvoluApp.remove: a DeleteDatabaseError of the AppOwner's database, or the refusal of the device database, which can also be an UnsupportedDbVersionError.
createEvoluCreates an Evolu instance from EvoluSchema and EvoluConfig.
createEvoluAppCreates an EvoluApp: Evolu creates and keeps the app's AppOwners in a device database that EvoluAppConfig.auth unlocks, and opens an instance of each AppOwner a tab opens. An app that brings its own AppOwners, such as one deriving them from a hardware wallet, calls createEvolu instead. It fails with UnknownError when SQLite fails to read the AppOwners or the device database is refused, as EvoluErrorDep.evoluError reports too. It throws, before returning its Task, for a schema, indexes, transports, or DeviceSecret that Evolu rejects.
createEvoluDepsCreates shared dependencies used by all createEvolu instances on a platform.
subscribeAppOwnerStateFollows current, such as EvoluApp.current, as an AppOwnerState, and calls onChange with the state at once and whenever it changes. Another instance, as when the tab opens another AppOwner, or the AppOwner again after a removal and restore or its database's deletion, is Opening until its promise resolves, and then Open, so a UI keyed by the instance remounts. Another CurrentAppOwner with the same instance keeps the state's type and instance, with the new current. An instance that opens after the tab moved on changes nothing, and one that never opens, as an aborted open's, leaves the state Opening. Once unsubscribed, an instance that opens changes nothing.

Auth

FunctionDescription
forgetWrappedDeviceSecretForgets the app's stored WrappedDeviceSecret, or a setup's pending key, so the next unlockWrappedDeviceSecret is a first use, with another key and another DeviceSecret. It's how an app starts over when the key is gone for good, such as a deleted passkey, which the provider reports like a dismissed prompt, or after a DeviceSecretUnwrapError. Evolu never calls it on its own.
hasWrappedDeviceSecretWhether the app has a stored WrappedDeviceSecret, without a prompt, such as to label a button "Create account" or "Unlock". A setup that stopped before storing it doesn't count, and where the platform keeps nothing, it's false. It fails with UnknownError when SQLite fails to read it or its database is refused. Like createEvoluApp, it stays pending while another build of the app keeps it waiting or the shared worker fails to load. See unlockWrappedDeviceSecret.
unlockWrappedDeviceSecretUnlocks the app's DeviceSecret with a key from the DeviceSecretKeyProvider, and on the first use creates them: a key, a DeviceSecret, and its WrappedDeviceSecret, which Evolu stores in a database of its own whose key is public. Before it stores a new wrapped secret, it gets the key, also one it just created, so the first use can prompt twice. Pass the DeviceSecret to createEvoluApp as DeviceSecretAuth. On the web, createPasskeyAuth calls it with a passkey.

Testing

VariableDescription
testAppNameStable valid AppName for tests and examples.