Feature and its Use Cases
There is currently no point between parsing a backup and writing it where a caller can inspect or
reject it. importDB takes the parsed backupData and proceeds. Any validation therefore has to
happen in the caller, against the raw envelope, before the call.
What the feature is: an optional onBeforeImport?: (summary) => boolean | Promise<boolean> on
ImportOptions. Returning false aborts the import before anything is written.
The hook should receive a stable summary rather than the raw envelope, so the contract survives
envelope changes. Something along the lines of store names, per-store record counts, backupVersion,
databaseName and exportedAt.
Who benefits
- Any app where a backup is user-supplied and therefore untrusted. Importing the wrong file is
destructive under overwrite and merely confusing under merge, and today there is no
library-supported place to catch it.
- It lets callers confirm with the user before a destructive restore, which is the normal
expectation for an import flow.
- Fate Protocol would use it to verify a backup belongs to the currently connected wallet before
restoring, since portfolio records are keyed by address and restoring another wallet's data would
silently produce wrong balances and P&L.
Additional Context
The summary shape is the real design question here, more than the hook itself. Passing the raw
ExportFormat would be simpler but reintroduces the coupling this is meant to remove.
Related: pairs with storeNames on ImportOptions, filed separately as #67.
Code of Conduct
Feature and its Use Cases
There is currently no point between parsing a backup and writing it where a caller can inspect or
reject it.
importDBtakes the parsedbackupDataand proceeds. Any validation therefore has tohappen in the caller, against the raw envelope, before the call.
What the feature is: an optional
onBeforeImport?: (summary) => boolean | Promise<boolean>onImportOptions. Returningfalseaborts the import before anything is written.The hook should receive a stable summary rather than the raw envelope, so the contract survives
envelope changes. Something along the lines of store names, per-store record counts,
backupVersion,databaseNameandexportedAt.Who benefits
destructive under
overwriteand merely confusing undermerge, and today there is nolibrary-supported place to catch it.
expectation for an import flow.
restoring, since portfolio records are keyed by address and restoring another wallet's data would
silently produce wrong balances and P&L.
Additional Context
The summary shape is the real design question here, more than the hook itself. Passing the raw
ExportFormatwould be simpler but reintroduces the coupling this is meant to remove.Related: pairs with
storeNamesonImportOptions, filed separately as #67.Code of Conduct