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

Defined in: packages/common/src/local-first/Evolu.ts:197

Configuration for createEvolu.

Properties

appName

readonly appName: string & Brand<"UrlSafeString"> & Brand<"AppName">;

Defined in: packages/common/src/local-first/Evolu.ts:229

An application name used in logs and local database names.

Evolu combines appName with the AppOwner identity to identify the local database. Changing either opens a different database. Keep appName stable across ordinary application updates.

Stored instances that share an appName and AppOwner open the same database and must use the same schema. Evolu applies the schema of the first instance and later instances join it. Each memory instance has its own database; see EvoluConfig.memoryOnly.

A different app name lets you create a separate local replica for the same AppOwner—for example, to test a different SQLite implementation or index configuration, or rebuild a replica for debugging while preserving the existing database.

Evolu supports running these databases concurrently. Their local separation does not isolate synchronization: replicas synchronizing the same owners through the same relay can still exchange changes. Changing appName neither migrates existing local data nor isolates incompatible schemas.

Example

import { AppName, assertEqual } from "@evolu/common";

const appName = AppName.orThrow("MyApp");
assertEqual(appName, "MyApp");

appOwner

readonly appOwner: AppOwner;

Defined in: packages/common/src/local-first/Evolu.ts:270

AppOwner used to create this Evolu instance.

Exposed as Evolu.appOwner. Create an AppOwner before the first run, or restore one from secure storage before creating Evolu.

AppOwner controls access to the encrypted local SQLite database. If its secret material (Owner secret / Mnemonic) is not stored safely, data written by that instance is permanently inaccessible.

Best onboarding UX is accountless first use: create an AppOwner, let users try a ready-to-use app, then prompt backup of evolu.appOwner.

An app whose AppOwners Evolu keeps uses createEvoluApp, which creates, stores, and opens them. createEvolu with an appOwner is for an app with AppOwners of its own, such as from a hardware wallet.


evolu7Name?

readonly evolu7Name?: string & Brand<"UrlSafeString"> & Brand<"Name">;

Defined in: packages/common/src/local-first/Evolu.ts:251

The name of the Evolu 7 database to migrate. Evolu 7 named its database by the name option of its config, which Evolu 8 renamed to EvoluConfig.appName, so it defaults to appName. When the two differ, pass Evolu 7's name.

When that database exists and holds the instance's AppOwner, Evolu imports it into the AppOwner's database before the instance gets any data and then deletes it. A database of another owner stays as it is. Evolu opens a database of that name to tell, on the web any OPFS directory .<name>, so keep no database or directory of the app's own under it.

With EvoluAppConfig.createFirstAppOwner and instant start, createEvoluApp starts with the Evolu 7 owner instead of a new one, when it creates the device database. Evolu 7 kept the owner's secret unprotected, so an app with a DeviceSecret gets a new AppOwner, and a device whose device database an earlier release created keeps the AppOwners it has. There, the Evolu 7 database stays until EvoluApp.add adds its owner, whose database then imports it.


indexes?

readonly indexes?: IndexesConfig;

Defined in: packages/common/src/local-first/Evolu.ts:356

Use the indexes option to define SQLite indexes.

Unique indexes are rejected with an assertion because concurrent offline writes can violate uniqueness during synchronization. See Uniqueness.

Table and column names are not typed because Kysely doesn't support it.

https://medium.com/@JasonWyatt/squeezing-performance-from-sqlite-indexes-indexes-c4e175f3c346

Example

import { createEvolu, id, testAppName, testAppOwner } from "@evolu/common";

const Schema = {
  todo: { id: id("Todo") },
  todoCategory: { id: id("TodoCategory") },
};

const _createTodoEvolu = createEvolu(Schema, {
  appName: testAppName,
  appOwner: testAppOwner,
  transports: [],
  indexes: (create) => [
    create("todoCreatedAt").on("todo").column("createdAt"),
    create("todoCategoryCreatedAt").on("todoCategory").column("createdAt"),
  ],
});

memoryOnly?

readonly memoryOnly?: boolean;

Defined in: packages/common/src/local-first/Evolu.ts:315

Keep the database in memory instead of persisting it on this device.

This option controls device persistence independently of synchronization. When synchronization is enabled, data can still be synchronized and persisted remotely.

A database kept in memory, with this option or where the platform offers no persistent storage, has a name of its own, so it never shares a local database, lock, or files with the stored database of the same AppOwner. Each memory instance gets a random name and its own database for its lifetime.

On the web, a memory instance exchanges changes with every other instance, stored instances of the same owner included, only through relays, so not offline. Its own tab hosts its workers. Closing or reloading its tab, or entering the back-forward cache, ends the instance and loses its data.

Web dependencies check storage once when they are created. If storage is available, they start the stored worker even when every instance uses this option, and Evolu may then reload the whole page: when another tab loads a new version of the app, when Safari relaunches the stored worker, or, in a page that also stores databases, when one was written by a newer version. The reload ends every instance in the page, memory instances too, losing their unsynced changes. When the browser refuses storage, the stored worker never starts and Evolu never reloads the page for these reasons. Returning from the back-forward cache and the default reload after Evolu.deleteDatabase still apply.

On in-process platforms such as React Native, the shared worker forwards each change one running database uploads to the others that synchronize the owner, even offline. A database started later gets earlier changes only from a relay.

Memory and stored instances can still synchronize the same owner, so changes made in memory can reach a stored database too. To keep nothing on the device, dispose the stored instances of the owner first.

Useful for testing or temporary sessions. Data that exists only in this database is lost when the database closes.

The default value is: false.


onDatabaseDeleted?

readonly onDatabaseDeleted?: () => void;

Defined in: packages/common/src/local-first/Evolu.ts:367

Called when Evolu.deleteDatabase deletes this instance's local database, whether this or another instance in any tab asked, right before this instance disposes itself.

Without it, the app reloads, because rendering a disposed instance throws. An app that can replace the instance, such as by remounting the part of its UI that uses it, can do that instead.


onOwnerDeleted?

readonly onOwnerDeleted?: (ownerId: string & Brand<"Id"> & Brand<"OwnerId">) => void;

Defined in: packages/common/src/local-first/Evolu.ts:381

Called when Evolu.deleteOwner deletes an owner's rows from this instance's local database, whether this or another instance in any tab asked.

The owner then syncs in no instance of the database, so the app stops showing it here, such as by leaving a screen of its data, whichever tab deleted it. It runs once per deletion, so an owner deleted twice, such as from two tabs at once, gets two calls. A deletion by UseOwnerOptions.deleteWhenUnused doesn't call it, because nothing uses that owner then.


transports?

readonly transports?: readonly OwnerWebSocketTransport[];

Defined in: packages/common/src/local-first/Evolu.ts:474

Transport configuration for sync and backup.

If not specified, Evolu uses the default Evolu relay. Pass one or more transports to override it with your own relays. They must be distinct, as Evolu.useOwner requires. Pass an empty array to disable sync, which is useful when sync should be configured later.

Empty transports start the instance without sync. In that case, Evolu.useOwner must be called with explicit non-empty transports to enable sync for any Owner, including the AppOwner.

Redundancy: The ideal setup uses at least two completely independent relays - for example, a home relay and a geographically separate relay. Data is sent to both relays simultaneously, providing true redundancy similar to using two independent clouds. This eliminates vendor lock-in and ensures your app continues working regardless of circumstances - whether home relay hardware fails or disappears, or a remote relay provider shuts down.

Currently supports:

  • WebSocket: Real-time bidirectional communication with relay servers

Use createOwnerWebSocketTransport to create WebSocket transport configurations with proper URL formatting and OwnerId inclusion. The OwnerId in the URL lets a relay's isOwnerAllowed admit or reject the connection, but an admitted connection can sync any owner, and anyone who knows an OwnerId can name it, so a private relay needs access control beyond the OwnerId, as Relay describes.

The default value is:

[{ type: "WebSocket", url: "wss://free.evoluhq.com/" }].

It's a testing relay that admits anyone and may delete data, so set your own relays before release, as Relay describes.

Example

import {
  assertEqual,
  createOwnerWebSocketTransport,
  RelayUrl,
  testAppOwner,
  WebSocketUrl,
  type OwnerTransport,
} from "@evolu/common";

// Use one relay.
const _singleRelay = [
  {
    type: "WebSocket",
    url: WebSocketUrl.orThrow("wss://relay1.example.com/"),
  },
] satisfies ReadonlyArray<OwnerTransport>;

// Use independent relays for redundancy.
const _redundantRelays = [
  {
    type: "WebSocket",
    url: WebSocketUrl.orThrow("wss://relay1.example.com/"),
  },
  {
    type: "WebSocket",
    url: WebSocketUrl.orThrow("wss://relay2.example.com/"),
  },
] satisfies ReadonlyArray<OwnerTransport>;

// Start local-only before authentication. After authentication, pass an
// owner-scoped transport to evolu.useOwner.
const _localOnlyBeforeAuthentication =
  [] satisfies ReadonlyArray<OwnerTransport>;

// Include the OwnerId when the relay admits owners by it.
const authenticatedRelay = [
  createOwnerWebSocketTransport({
    url: RelayUrl.orThrow("wss://relay.example.com/"),
    ownerId: testAppOwner.id,
  }),
];

assertEqual(
  authenticatedRelay[0]?.url,
  `wss://relay.example.com/?ownerId=${testAppOwner.id}`,
);