zam-core 0.3.0 → 0.3.2

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.
package/dist/cli/index.js CHANGED
@@ -8,7 +8,7 @@ import { Command } from "commander";
8
8
 
9
9
  // src/kernel/db/connection.ts
10
10
  import Database from "libsql";
11
- import { existsSync, mkdirSync } from "fs";
11
+ import { existsSync, mkdirSync, rmSync } from "fs";
12
12
  import { homedir } from "os";
13
13
  import { dirname, join } from "path";
14
14
 
@@ -136,6 +136,13 @@ function openDatabase(options = {}) {
136
136
  const dbOpts = {};
137
137
  if (options.syncUrl) {
138
138
  dbOpts.syncUrl = options.syncUrl;
139
+ const metaPath = `${dbPath}.meta`;
140
+ if (existsSync(dbPath) && !existsSync(metaPath)) {
141
+ for (const suffix of ["", "-wal", "-shm"]) {
142
+ const f = `${dbPath}${suffix}`;
143
+ if (existsSync(f)) rmSync(f);
144
+ }
145
+ }
139
146
  }
140
147
  if (options.authToken) {
141
148
  dbOpts.authToken = options.authToken;
@@ -158,6 +165,8 @@ function openDatabaseWithSync(options = {}) {
158
165
  const syncUrl = db.prepare("SELECT value FROM user_config WHERE key = ?").get("turso.url");
159
166
  const authToken = db.prepare("SELECT value FROM user_config WHERE key = ?").get("turso.token");
160
167
  if (!syncUrl || !authToken) return db;
168
+ db.pragma("wal_checkpoint(TRUNCATE)");
169
+ db.pragma("journal_mode = DELETE");
161
170
  db.close();
162
171
  return openDatabase({ ...options, syncUrl: syncUrl.value, authToken: authToken.value });
163
172
  }