AOSSIE-Org / AOSSIE-Org/IndexedDB-Import-Export

[FEATURE]: Add an onBeforeImport hook to importDB

オープン
#68 コメント 0 件 リアクション 0 件 担当者 1 名 @rohans02 が担当を希望しています GitHub で見る
enhancement
主要言語
YAML
スター
7
フォーク
3
平均マージ
3日 55分
マージ済み PR(30日)
8

説明

### 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` 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

- [x] I have joined the [Discord server](https://discord.gg/hjUhu33uAn) and will post updates there
- [x] I have searched existing issues to avoid duplicates

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。