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

[FEATURE]: Add an onBeforeImport hook to importDB

Đang mở
#68 0 bình luận 0 reaction 1 người được giao Được @rohans02 nhận Xem trên GitHub
enhancement
Ngôn ngữ chính
YAML
Star
7
Fork
3
Merge trung bình
3 ngày 55 phút
Pull request đã merge (30 ngày)
8

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.