supastash 0.2.5 → 0.2.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"tauri.d.ts","sourceRoot":"","sources":["../../../../src/shared/db/adapters/tauri.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAEtB,iBAAiB,EAClB,MAAM,mCAAmC,CAAC;AAG3C,eAAO,MAAM,kBAAkB,EAAE,sBAAsB,CAAC,iBAAiB,CAiJxE,CAAC"}
1
+ {"version":3,"file":"tauri.d.ts","sourceRoot":"","sources":["../../../../src/shared/db/adapters/tauri.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAEtB,iBAAiB,EAClB,MAAM,mCAAmC,CAAC;AAG3C,eAAO,MAAM,kBAAkB,EAAE,sBAAsB,CAAC,iBAAiB,CAsJxE,CAAC"}
@@ -2,6 +2,10 @@ import { interpolate, namedToPositional } from "../normalizer";
2
2
  export const SQLiteAdapterTauri = {
3
3
  async openDatabaseAsync(name, sqliteClient) {
4
4
  const db = await sqliteClient.load(`sqlite:${name}`);
5
+ // Enable WAL mode for concurrent read/write and set a busy timeout so
6
+ // writers wait instead of immediately returning SQLITE_BUSY (code 5).
7
+ await db.execute("PRAGMA journal_mode=WAL;", []);
8
+ await db.execute("PRAGMA busy_timeout=5000;", []);
5
9
  const normalizeParams = (params) => {
6
10
  return (params ?? []).map((v) => typeof v === "boolean" ? (v ? 1 : 0) : v);
7
11
  };
@@ -11,9 +11,11 @@ export declare const ADD_PK_TO_SYNC_MARKS_SQL = "\n ALTER TABLE supastash_sync_
11
11
  export declare const INDEX_SYNC_MARKS_SQL = "\n CREATE INDEX IF NOT EXISTS idx_supastash_marks_updated\n ON supastash_sync_marks(updated_at);\n";
12
12
  export declare const INDEX_SERVER_SYNC_MARKS_SQL = "\n CREATE INDEX IF NOT EXISTS idx_supastash_server_marks_updated\n ON supastash_server_sync_marks(updated_at);\n";
13
13
  /**
14
- * Creates the supastash_sync_marks table if it doesn't exist
15
- *
16
- * New table for sync marks
14
+ * Creates the supastash_sync_marks table if it doesn't exist.
15
+ * Guarded by a singleton promise so concurrent callers share one
16
+ * initialization pass instead of racing on DDL writes.
17
17
  */
18
18
  export declare function createSyncStatusTable(): Promise<void>;
19
+ /** Reset the singleton (useful for tests or after closeSupastashDb). */
20
+ export declare function resetSyncStatusTableCache(): void;
19
21
  //# sourceMappingURL=createSyncStatus.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createSyncStatus.d.ts","sourceRoot":"","sources":["../../../../src/shared/utils/schema/createSyncStatus.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAsB,wBAAwB,kBAE7C;AAED,eAAO,MAAM,sBAAsB,0ZAUhC,CAAC;AAEJ,eAAO,MAAM,6BAA6B,6eAezC,CAAC;AAEF,eAAO,MAAM,wBAAwB,mFAEpC,CAAC;AAEF,eAAO,MAAM,oBAAoB,2GAGhC,CAAC;AAEF,eAAO,MAAM,2BAA2B,yHAGvC,CAAC;AAIF;;;;GAIG;AACH,wBAAsB,qBAAqB,kBAkB1C"}
1
+ {"version":3,"file":"createSyncStatus.d.ts","sourceRoot":"","sources":["../../../../src/shared/utils/schema/createSyncStatus.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAsB,wBAAwB,kBAE7C;AAED,eAAO,MAAM,sBAAsB,0ZAUhC,CAAC;AAEJ,eAAO,MAAM,6BAA6B,6eAezC,CAAC;AAEF,eAAO,MAAM,wBAAwB,mFAEpC,CAAC;AAEF,eAAO,MAAM,oBAAoB,2GAGhC,CAAC;AAEF,eAAO,MAAM,2BAA2B,yHAGvC,CAAC;AAIF;;;;GAIG;AACH,wBAAsB,qBAAqB,kBAuB1C;AAED,wEAAwE;AACxE,wBAAgB,yBAAyB,SAExC"}
@@ -47,30 +47,36 @@ export const INDEX_SERVER_SYNC_MARKS_SQL = `
47
47
  CREATE INDEX IF NOT EXISTS idx_supastash_server_marks_updated
48
48
  ON supastash_server_sync_marks(updated_at);
49
49
  `;
50
- let addedPk = false;
50
+ let syncStatusTablePromise = null;
51
51
  /**
52
- * Creates the supastash_sync_marks table if it doesn't exist
53
- *
54
- * New table for sync marks
52
+ * Creates the supastash_sync_marks table if it doesn't exist.
53
+ * Guarded by a singleton promise so concurrent callers share one
54
+ * initialization pass instead of racing on DDL writes.
55
55
  */
56
56
  export async function createSyncStatusTable() {
57
- const db = await getSupastashDb();
58
- const cfg = getSupastashConfig();
59
- if (cfg.replicationMode === "server-side") {
60
- await db.execAsync(SERVER_SYNC_STATUS_TABLES_SQL);
61
- await db.execAsync(INDEX_SERVER_SYNC_MARKS_SQL);
62
- }
63
- else {
64
- await db.execAsync(SYNC_STATUS_TABLES_SQL);
65
- await db.execAsync(INDEX_SYNC_MARKS_SQL);
66
- }
67
- try {
68
- if (addedPk)
69
- return;
70
- addedPk = true;
71
- await db.execAsync(ADD_PK_TO_SYNC_MARKS_SQL);
72
- }
73
- catch (error) {
74
- // Ignore error if column already exists
75
- }
57
+ if (syncStatusTablePromise)
58
+ return syncStatusTablePromise;
59
+ syncStatusTablePromise = (async () => {
60
+ const db = await getSupastashDb();
61
+ const cfg = getSupastashConfig();
62
+ if (cfg.replicationMode === "server-side") {
63
+ await db.execAsync(SERVER_SYNC_STATUS_TABLES_SQL);
64
+ await db.execAsync(INDEX_SERVER_SYNC_MARKS_SQL);
65
+ }
66
+ else {
67
+ await db.execAsync(SYNC_STATUS_TABLES_SQL);
68
+ await db.execAsync(INDEX_SYNC_MARKS_SQL);
69
+ }
70
+ try {
71
+ await db.execAsync(ADD_PK_TO_SYNC_MARKS_SQL);
72
+ }
73
+ catch {
74
+ // Ignore column already exists
75
+ }
76
+ })();
77
+ return syncStatusTablePromise;
78
+ }
79
+ /** Reset the singleton (useful for tests or after closeSupastashDb). */
80
+ export function resetSyncStatusTableCache() {
81
+ syncStatusTablePromise = null;
76
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supastash",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",