فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
fix(A03): separate atomic full-database reset from guarded transaction clear
davoodmehraban89 committed
Oct 16, 2026 at 23:33 UTC
0f3cb5acc461174f98e1bdb1d71cdf65b534a6c1
1 file changed
+20
-3
src/core/StorageService.js
+20
-3
@@ -328,9 +328,26 @@ class StorageServiceImpl {
328
return this._exec(store, 'readonly', s => s.count());
329
}
330
331
- clearAll() {
332
- return this.transaction(STORES, async tx => {
333
- await Promise.all(STORES.map(name => tx.clear(name)));
331
+ // Explicit full-database reset/maintenance is intentionally separate from
332
+ // the ordinary transaction API. That API must never permit clearing
333
+ // append-only audit or correction history on its own.
334
+ // Keep the full reset atomic and wait for IDB transaction completion.
335
+ async clearAll() {
336
+ if (globalThis.FINORA?.License) globalThis.FINORA.License.assertWritable();
337
+ const db = await this.init();
338
+ return new Promise((resolve, reject) => {
339
+ let tx;
340
+ try {
341
+ tx = db.transaction(STORES, 'readwrite');
342
+ tx.oncomplete = () => resolve();
343
+ tx.onabort = () => reject(tx.error || new Error('بازنشانی کامل پایگاه داده لغو شد'));
344
+ for (const name of STORES) tx.objectStore(name).clear();
345
+ } catch (err) {
346
+ if (tx) {
347
+ try { tx.abort(); } catch (_) { /* Transaction may already be inactive. */ }
348
+ }
349
+ reject(err);
350
+ }
351
});
352
}
353