Skip to content

settings-recovery

Device-local recovery copies of a plugin’s data.json, kept BEFORE anything could lose what the file held.

Two cases lose a user’s settings for good without one. A data.json that does not parse (truncated by a sync tool, a crash mid-write, a hand edit) reads as missing, because Obsidian’s Vault.readJson swallows the parse error (read from 1.15.1); and a record that parses but holds values the plugin drops or rewrites (an unknown key from a newer plugin version, a legacy migration) is normalized and saved back over the file on the initial load. A copy of the raw text is kept first, in a LocalDataStore, so no sync tool carries it to other devices and nothing is added to the vault.

Class Description
LocalSettingsRecoveryStore A SettingsRecoveryStore in a device-local LocalDataStore, keeping the newest few copies. It opens its database per call and closes it again: copies are kept and read rarely (a load that found a damaged file, a lossy first save, the user asking for the list), so holding a connection for the plugin’s lifetime would only add a resource to tie to an unload.
Interface Description
LocalSettingsRecoveryStoreConstructorParams Constructor parameters for LocalSettingsRecoveryStore.
SettingsRecoveryCopy One kept copy of a plugin’s data.json.
SettingsRecoveryStore Where recovery copies of a plugin’s data.json are kept.
SettingsRecoveryStoreKeepParams Parameters for SettingsRecoveryStore.keep.
Function Description
isSettingsRecoveryCopy Checks whether a value is a SettingsRecoveryCopy. A record of another shape (a later version’s, or a damaged one) is ignored rather than trusted.
Enum Description
SettingsRecoveryReason Why a recovery copy was kept.
Variable Description
DEFAULT_MAX_SETTINGS_RECOVERY_COPIES How many recovery copies a LocalSettingsRecoveryStore keeps per plugin by default. The oldest is dropped first.
SETTINGS_RECOVERY_STORE_ID The LocalDataStore store id the recovery copies live under. The -v1 names the record shape below.