@fudrouter/fsrouter 0.6.100 → 0.6.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -79,6 +79,14 @@ export async function getAdapter() {
79
79
  return state.initPromise;
80
80
  }
81
81
 
82
+ // Force re-open the underlying connection (used after an explicit close, e.g.
83
+ // during raw DB restore). Without this, getAdapter() would return the stale
84
+ // closed instance and every subsequent query throws "connection is not open".
85
+ export function resetAdapter() {
86
+ state.instance = null;
87
+ state.initPromise = null;
88
+ }
89
+
82
90
  export function getAdapterSync() {
83
91
  if (!state.instance) throw new Error("[DB] adapter not initialized — await getAdapter() first");
84
92
  return state.instance;
@@ -1,4 +1,4 @@
1
- import { getAdapter } from "../../lib/db/driver.js";
1
+ import { getAdapter, resetAdapter } from "../../lib/db/driver.js";
2
2
  import { exportDb, importDb } from "../../lib/db/index.js";
3
3
  import { DATA_DIR } from "../../lib/dataDir.js";
4
4
  import path from "path";
@@ -90,15 +90,10 @@ export async function POST_handler(req, res) {
90
90
  // state differs between machines. Keep raw-file restore below for old backups.
91
91
  const hasLogical = !!body.database;
92
92
  if (hasLogical) {
93
- progress(15, "Menutup koneksi database aktif...");
94
- const db0 = await getAdapter();
95
- if (db0 && typeof db0.close === "function") {
96
- try {
97
- db0.close();
98
- }
99
- catch { /* ignore */ }
100
- }
101
- progress(25, "Mengimpor data logical (provider, connections, proxy, api keys, combos)...");
93
+ progress(15, "Mengimpor data logical (provider, connections, proxy, api keys, combos)...");
94
+ // Import on the live connection — do NOT close it first, or getAdapter()
95
+ // would keep returning the stale closed instance and every query throws
96
+ // "The database connection is not open".
102
97
  await importDb(body.database);
103
98
  progress(40, "Flush WAL ke file database utama (checkpoint)...");
104
99
  const db = await getAdapter();
@@ -126,6 +121,8 @@ export async function POST_handler(req, res) {
126
121
  }
127
122
  catch { /* ignore */ }
128
123
  }
124
+ // Reset cached instance so the next getAdapter() re-opens a fresh connection.
125
+ resetAdapter();
129
126
  }
130
127
  // 2. Remove active -wal and -shm files to prevent corruption/mismatch.
131
128
  progress(50, "Membersihkan file WAL/SHM lock...");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fudrouter/fsrouter",
3
- "version": "0.6.100",
3
+ "version": "0.6.101",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "9Router v2 — Express Backend (API, SSE, DB, Auth, MITM)",