tsunami-memory 1.0.1 → 1.0.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/package.json +1 -1
- package/src/bun_memory_store.ts +1 -27
- package/src/db.ts +41 -0
- package/src/tsunami_graph_runtime.ts +1 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsunami-memory",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "TSUNAMI — Bun-native oceanic memory system with basin/current flow, storm center, hot+cold retrieval, knowledge graph sync, and evidence linking.",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
package/src/bun_memory_store.ts
CHANGED
|
@@ -5,36 +5,10 @@
|
|
|
5
5
|
* and content fingerprinting for deduplication. Schema managed by migration runner.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import { existsSync, mkdirSync } from 'fs';
|
|
10
|
-
import { dirname } from 'path';
|
|
8
|
+
import { getDb } from './db';
|
|
11
9
|
import { BUN_MEMORY_DB_PATH } from './tsunami_storage_paths';
|
|
12
|
-
import { runMigrations, getMigrations } from './migration';
|
|
13
10
|
export { BUN_MEMORY_DB_PATH };
|
|
14
11
|
|
|
15
|
-
// ── Database initialization ──────────────────────────────────
|
|
16
|
-
|
|
17
|
-
function ensureDbDir(): void {
|
|
18
|
-
const dir = dirname(BUN_MEMORY_DB_PATH);
|
|
19
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let _db: Database | null = null;
|
|
23
|
-
|
|
24
|
-
function getDb(): Database {
|
|
25
|
-
if (_db) return _db;
|
|
26
|
-
ensureDbDir();
|
|
27
|
-
_db = new Database(BUN_MEMORY_DB_PATH);
|
|
28
|
-
_db.run('PRAGMA journal_mode = WAL');
|
|
29
|
-
const applied = runMigrations(_db, getMigrations());
|
|
30
|
-
if (applied > 0) {
|
|
31
|
-
// First-run or upgrade — log for observability
|
|
32
|
-
const v = (_db.prepare('SELECT MAX(version) as v FROM schema_version').get() as any)?.v ?? 0;
|
|
33
|
-
console.log(`[TSUNAMI] migrations applied: ${applied}, now at v${v}`);
|
|
34
|
-
}
|
|
35
|
-
return _db;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
12
|
// ── ID Generation ────────────────────────────────────────────
|
|
39
13
|
|
|
40
14
|
function generateId(): string {
|
package/src/db.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TSUNAMI shared database connection.
|
|
3
|
+
*
|
|
4
|
+
* Single WAL-mode SQLite connection shared by all modules.
|
|
5
|
+
* Schema is managed by the migration runner.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Database } from 'bun:sqlite';
|
|
9
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
10
|
+
import { dirname } from 'node:path';
|
|
11
|
+
import { BUN_MEMORY_DB_PATH } from './tsunami_storage_paths';
|
|
12
|
+
import { runMigrations, getMigrations } from './migration';
|
|
13
|
+
|
|
14
|
+
let _db: Database | null = null;
|
|
15
|
+
|
|
16
|
+
/** Get or create the shared database connection. Thread-safe via module-level singleton. */
|
|
17
|
+
export function getDb(): Database {
|
|
18
|
+
if (_db) return _db;
|
|
19
|
+
|
|
20
|
+
const dir = dirname(BUN_MEMORY_DB_PATH);
|
|
21
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
22
|
+
|
|
23
|
+
_db = new Database(BUN_MEMORY_DB_PATH);
|
|
24
|
+
_db.run('PRAGMA journal_mode = WAL');
|
|
25
|
+
|
|
26
|
+
const applied = runMigrations(_db, getMigrations());
|
|
27
|
+
if (applied > 0) {
|
|
28
|
+
const v = (_db.prepare('SELECT MAX(version) as v FROM schema_version').get() as any)?.v ?? 0;
|
|
29
|
+
console.log(`[TSUNAMI] migrations applied: ${applied}, now at v${v}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return _db;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Close the database connection. Mainly useful in tests. */
|
|
36
|
+
export function closeDb(): void {
|
|
37
|
+
if (_db) {
|
|
38
|
+
_db.close();
|
|
39
|
+
_db = null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -6,21 +6,7 @@
|
|
|
6
6
|
* BFS traversal, and cross-wing tunnel discovery.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import { BUN_MEMORY_DB_PATH } from './tsunami_storage_paths';
|
|
11
|
-
import { runMigrations, getMigrations } from './migration';
|
|
12
|
-
|
|
13
|
-
// ── Database initialization ──────────────────────────────────
|
|
14
|
-
|
|
15
|
-
let _db: Database | null = null;
|
|
16
|
-
|
|
17
|
-
function getDb(): Database {
|
|
18
|
-
if (_db) return _db;
|
|
19
|
-
_db = new Database(BUN_MEMORY_DB_PATH);
|
|
20
|
-
_db.run('PRAGMA journal_mode = WAL');
|
|
21
|
-
runMigrations(_db, getMigrations()); // idempotent — applies only pending
|
|
22
|
-
return _db;
|
|
23
|
-
}
|
|
9
|
+
import { getDb } from './db';
|
|
24
10
|
|
|
25
11
|
// ── ID Generation ────────────────────────────────────────────
|
|
26
12
|
|