Skip to content

[FEATURE]: Add an onBeforeImport hook to importDB #68

Description

@rohans02

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

  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions