Configurate is the central class in tauri-plugin-configurate. It ties a schema to a storage location and a provider, and exposes a consistent builder-style API for every config operation. You create one instance per config file and reuse it throughout your app.
Constructor
Required options
Schema object created with
defineConfig(). TypeScript infers all value types from this. All keyring() IDs in the schema must be unique — the constructor throws if any are duplicated.The config file name. Must not contain path separators (
/ or \) and must not be "." or "..".Tauri
BaseDirectory enum value that sets the root of the resolved path (e.g. BaseDirectory.AppConfig, BaseDirectory.AppData, BaseDirectory.Desktop).Storage provider created by one of the provider functions:
JsonProvider(), YmlProvider(), TomlProvider(), BinaryProvider(), or SqliteProvider(). See the providers reference.Path options
Replaces the app-identifier directory segment when it is the last segment of the
baseDir path; otherwise appended as a sub-directory. Must not contain empty or special segments (., ..).Sub-directory appended after the
dirName root. Must not contain empty or special segments.Validation options
When
true, full schema validation runs before every create or save operation. Throws if the data does not match the schema.When
true, full schema validation runs after every load or unlock operation. Throws if the loaded data does not match the schema.When
true, keys not declared in the schema are permitted and do not cause validation to fail.Defaults, versioning, and backups
Default values to fill in when loading a config that has missing keys. Applied after migrations, before returning data to the caller.
Current schema version. When set, a
__configurate_version__ field is stored alongside the data and used to detect configs that need migration.Ordered list of migration steps applied automatically when loading an older config. Each step has a
version number (the version it upgrades from) and an up function that transforms the data. See MigrationStep in result types.When
true, a rolling backup (.bak1–.bak3) is created before each write and deleted automatically when the application exits. Applies only to file-based providers — has no effect with SqliteProvider.Constructor example
src/lib/config.ts
Instance methods
create(data)
Creates a new config file with the provided data. If the schema has keyring() fields, you must chain .lock(keyringOpts) before .run().
Full config data to write. All required fields must be present.
LazyConfigEntry<S> — a deferred entry with the following methods:
| Method | Returns | Description |
|---|---|---|
.run() | Promise<LockedConfig<S>> | Execute and return locked data (keyring fields are null) |
.lock(opts).run() | Promise<LockedConfig<S>> | Store secrets in keyring, return locked data |
.unlock(opts) | Promise<UnlockedConfig<S>> | Store secrets in keyring, return unlocked data |
load()
Loads an existing config file. Without unlocking, keyring fields come back as null.
Returns: LazyConfigEntry<S>
defaults and migrations are applied automatically on every load() call. If a migration runs, the migrated data is auto-saved back to storage.save(data)
Overwrites the entire config file with the provided data. All keys are replaced — omitted keys are removed.
Full config data to write. Replaces all existing content.
LazyConfigEntry<S>
patch(partial)
Deep-merges partial into the existing config. Only provided keys are updated — omitted keys are left unchanged. Uses JSON Merge Patch semantics (RFC 7396): setting a key to null overwrites the stored value with null.
Partial config data to merge. Only the keys you provide are updated.
LazyPatchEntry<S> — a deferred entry with the following methods:
| Method | Returns | Description |
|---|---|---|
.run() | Promise<PatchedConfig<S>> | Execute patch, return locked result |
.lock(opts).run() | Promise<PatchedConfig<S>> | Patch with keyring, return locked result |
.createIfMissing() | this | Create the config if it does not exist instead of throwing |
.unlock(opts) | Promise<UnlockedConfig<S>> | Patch with keyring, return unlocked result |
delete(keyringOpts?)
Deletes the config file and wipes all associated keyring entries.
Keyring credentials. Required when the schema has
keyring() fields so that their stored secrets are wiped from the OS keyring on deletion.Promise<void>
exists()
Checks whether the config entry exists in storage.
Returns: Promise<boolean>
list()
Lists config file names in the resolved root directory.
- For file-based providers (JSON, YAML, TOML, Binary): scans the directory for files matching the provider’s extension. Backup files (
.bak*) and temp files are excluded. - For SQLite: returns all
config_keyvalues in the table.
Promise<string[]>
reset(data)
Deletes the existing config and re-creates it with the provided data. Equivalent to delete() followed by create(), but executed as a single atomic operation.
Full config data to write after deletion.
LazyResetEntry<S> — a deferred entry with the following methods:
| Method | Returns | Description |
|---|---|---|
.run() | Promise<LockedConfig<S>> | Reset and return locked data |
.lock(opts).run() | Promise<LockedConfig<S>> | Reset with keyring, return locked data |
.unlock(opts) | Promise<UnlockedConfig<S>> | Reset with keyring, return unlocked data |
exportAs(format, keyringOpts?)
Exports the stored config data as a formatted string. Optionally unlocks keyring fields before exporting so that secrets are included in the output.
Target serialization format for the exported string.
When provided, keyring fields are unlocked from the OS keyring before serialization, so the exported string includes the decrypted secret values.
Promise<string>
importFrom(content, format, keyringOpts?)
Imports config data from a string, replacing the current stored config.
Serialized config string to import.
Source format of the string.
Required when importing data that contains values for
keyring() fields, so that the imported secrets are stored in the OS keyring instead of being written to disk.Promise<void>
validate(data)
Validates full config data against the schema without writing to storage. Throws a descriptive error on failure.
Full config data to validate.
void — throws on validation failure.
validatePartial(data)
Validates partial config data against the schema without writing to storage. Only the provided keys are checked.
Partial config data to validate.
void — throws on validation failure.
watchExternal(callback)
Starts watching the config file for changes made by external processes. File-based providers only — throws if called with SqliteProvider.
Function called whenever an external change is detected. Receives a
ConfigChangeEvent with operation: "external_change".Promise<() => Promise<void>> — an async stop function. Call it to unregister the listener and stop the file watcher.
onChange(callback)
Registers a callback that fires whenever this config is changed by any in-app operation: create, save, patch, delete, reset, or import.
Function called after any in-app config change. Receives a
ConfigChangeEvent describing the operation.Promise<() => void> — a synchronous unlisten function. Call it to deregister the callback.
Static batch methods
Batch methods send multiple config operations in a single IPC round-trip. A failure in one entry does not abort the batch — each entry reports its own success or failure in the result.Configurate.loadAll(entries)
Loads multiple configs in a single IPC call. Applies defaults and migrations to each entry after loading.
Array of entries to load. Each entry has a unique string
id and a Configurate instance.LoadAllRunner with:
.unlock(id, opts)— unlock a specific entry by ID.unlockAll(opts)— unlock all entries with the same keyring options.run()— execute and returnPromise<BatchRunResult>
Configurate.saveAll(entries)
Saves multiple configs in a single IPC call.
Array of entries to save. Each entry has a unique
id, a Configurate instance, and the data to write.SaveAllRunner with:
.lock(id, opts)— lock a specific entry by ID.lockAll(opts)— lock all entries with the same keyring options.run()— execute and returnPromise<BatchRunResult>
Configurate.patchAll(entries)
Patches multiple configs in a single IPC call.
Array of entries to patch. Each entry has a unique
id, a Configurate instance, and the partial data to merge.PatchAllRunner with:
.lock(id, opts)— lock a specific entry by ID.lockAll(opts)— lock all entries with the same keyring options.run()— execute and returnPromise<BatchRunResult>