@jini-ai/server 0.6.0 → 0.6.1
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/storage/legacy/sqlite.d.ts +16 -11
- package/dist/storage/legacy/sqlite.js +47 -38
- package/package.json +12 -12
|
@@ -8,19 +8,24 @@ import { type SqliteDb, type SqliteSyncOpener } from '@jini-ai/db/sqlite';
|
|
|
8
8
|
export declare function migrate({ db }: {
|
|
9
9
|
db: SqliteDb;
|
|
10
10
|
}): void;
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
/** Creates one owned connection cache; other hosts' paths and handles are independent.
|
|
12
|
+
* Returns lazy open/close ports; creation performs no I/O. @complexity O(1). */
|
|
13
|
+
export declare function createLegacySqliteStorage(_required: Record<string, never>, _optional?: Record<string, never>): {
|
|
14
|
+
openDatabase: ({ projectRoot, open }: {
|
|
15
|
+
projectRoot: string;
|
|
16
|
+
open: SqliteSyncOpener;
|
|
17
|
+
}, options?: {
|
|
18
|
+
dataDir?: string;
|
|
19
|
+
filesystem?: Pick<typeof fs, "mkdirSync">;
|
|
20
|
+
}) => SqliteDb;
|
|
21
|
+
closeDatabase: () => void;
|
|
22
|
+
};
|
|
23
|
+
export declare const openDatabase: ({ projectRoot, open }: {
|
|
18
24
|
projectRoot: string;
|
|
19
25
|
open: SqliteSyncOpener;
|
|
20
26
|
}, options?: {
|
|
21
27
|
dataDir?: string;
|
|
22
|
-
filesystem?: Pick<typeof fs,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
export declare function closeDatabase(): void;
|
|
28
|
+
filesystem?: Pick<typeof fs, "mkdirSync">;
|
|
29
|
+
}) => SqliteDb;
|
|
30
|
+
export declare const closeDatabase: () => void;
|
|
26
31
|
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Host-owned app.sqlite lifecycle; the host explicitly supplies its SQLite driver. */
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import { openSqliteConnection } from '@jini-ai/db/sqlite';
|
|
5
5
|
import { LEGACY_CHAT_DDL } from '@jini-ai/chat/store/legacy/sqlite';
|
|
6
6
|
import { LEGACY_AGENT_SESSIONS_DDL } from '@jini-ai/daemon/store/agent-sessions/sqlite';
|
|
7
7
|
import { LEGACY_PROJECTS_DDL } from '../../store/projects/sqlite.js';
|
|
8
|
-
let dbInstance = null;
|
|
9
|
-
let dbFile = null;
|
|
10
8
|
/**
|
|
11
9
|
* Explicit idempotent bootstrap of unchanged legacy tables; no versioned migration ledger.
|
|
12
10
|
* @param db Borrowed host handle; this operation neither opens nor closes it.
|
|
@@ -21,43 +19,54 @@ let dbFile = null;
|
|
|
21
19
|
export function migrate({ db }) {
|
|
22
20
|
db.exec(LEGACY_PROJECTS_DDL + LEGACY_CHAT_DDL + LEGACY_AGENT_SESSIONS_DDL);
|
|
23
21
|
}
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return db;
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
22
|
+
/** Creates one owned connection cache; other hosts' paths and handles are independent.
|
|
23
|
+
* Returns lazy open/close ports; creation performs no I/O. @complexity O(1). */
|
|
24
|
+
export function createLegacySqliteStorage(_required, _optional = {}) {
|
|
25
|
+
let dbInstance = null;
|
|
26
|
+
let dbFile = null;
|
|
27
|
+
/**
|
|
28
|
+
* Opens/caches <dataDir>/app.sqlite using the injected opener, WAL and foreign keys.
|
|
29
|
+
* A new path closes the previous handle owned by this storage instance; setup failure closes only the newly acquired handle.
|
|
30
|
+
* @throws The original host acquisition/schema failure, or a missing opener.
|
|
31
|
+
* @complexity O(1) acquisition/bootstrap calls, independent of stored row count.
|
|
32
|
+
*/
|
|
33
|
+
function openDatabase({ projectRoot, open }, options = {}) {
|
|
34
|
+
// Keep the historical refusal text for JavaScript callers that omit the required port.
|
|
35
|
+
if (!open)
|
|
36
|
+
throw new Error('openDatabase: inject options.open');
|
|
37
|
+
const dir = options.dataDir ? path.resolve(options.dataDir) : path.join(projectRoot, '.jini');
|
|
38
|
+
const file = path.join(dir, 'app.sqlite');
|
|
39
|
+
if (dbInstance && dbFile === file)
|
|
40
|
+
return dbInstance;
|
|
41
|
+
closeDatabase();
|
|
42
|
+
(options.filesystem ?? fs).mkdirSync(dir, { recursive: true });
|
|
43
|
+
let db;
|
|
49
44
|
try {
|
|
50
|
-
db
|
|
45
|
+
db = openSqliteConnection({ filePath: file, open({ filePath }, settings) { db = open(filePath, settings); return db; } }, { pragmas: ['journal_mode = WAL', 'foreign_keys = ON'] });
|
|
46
|
+
migrate({ db });
|
|
47
|
+
dbInstance = db;
|
|
48
|
+
dbFile = file;
|
|
49
|
+
return db;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
try {
|
|
53
|
+
db?.close();
|
|
54
|
+
}
|
|
55
|
+
catch { /* Keep the original bootstrap failure. */ }
|
|
56
|
+
throw error;
|
|
51
57
|
}
|
|
52
|
-
catch { /* Keep the original bootstrap failure. */ }
|
|
53
|
-
throw error;
|
|
54
58
|
}
|
|
59
|
+
/** Close the active owned handle once; clearing state first permits a clean retry after failure. */
|
|
60
|
+
function closeDatabase() {
|
|
61
|
+
const db = dbInstance;
|
|
62
|
+
dbInstance = null;
|
|
63
|
+
dbFile = null;
|
|
64
|
+
db?.close();
|
|
65
|
+
}
|
|
66
|
+
return { openDatabase, closeDatabase };
|
|
55
67
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
dbFile = null;
|
|
61
|
-
db?.close();
|
|
62
|
-
}
|
|
68
|
+
// Compatibility facade for existing hosts; new hosts inject their own storage instance.
|
|
69
|
+
const defaultStorage = createLegacySqliteStorage({});
|
|
70
|
+
export const openDatabase = defaultStorage.openDatabase;
|
|
71
|
+
export const closeDatabase = defaultStorage.closeDatabase;
|
|
63
72
|
//# sourceMappingURL=sqlite.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -65,27 +65,27 @@
|
|
|
65
65
|
"@vitest/coverage-v8": "^2.1.9",
|
|
66
66
|
"better-sqlite3": "^13.0.0",
|
|
67
67
|
"express": "^4.21.0",
|
|
68
|
-
"@jini-ai/agent-runtime": "0.4.
|
|
69
|
-
"@jini-ai/daemon": "0.6.0",
|
|
68
|
+
"@jini-ai/agent-runtime": "0.4.5",
|
|
70
69
|
"@jini-ai/sidecar": "0.4.1",
|
|
70
|
+
"@jini-ai/daemon": "0.6.1",
|
|
71
|
+
"@jini-ai/db": "0.3.2",
|
|
71
72
|
"@jini-ai/http-kit": "0.4.1",
|
|
72
|
-
"@jini-ai/core": "0.4.
|
|
73
|
-
"@jini-ai/
|
|
74
|
-
"@jini-ai/
|
|
75
|
-
"@jini-ai/chat": "0.5.7"
|
|
73
|
+
"@jini-ai/core": "0.4.3",
|
|
74
|
+
"@jini-ai/chat": "0.5.8",
|
|
75
|
+
"@jini-ai/registry": "0.5.2"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@jini-ai/core": "^0.4.
|
|
78
|
+
"@jini-ai/core": "^0.4.3"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"better-sqlite3": "^13.0.0",
|
|
82
|
-
"@jini-ai/agent-runtime": "^0.4.
|
|
83
|
-
"@jini-ai/daemon": "^0.6.
|
|
82
|
+
"@jini-ai/agent-runtime": "^0.4.5",
|
|
83
|
+
"@jini-ai/daemon": "^0.6.1",
|
|
84
84
|
"@jini-ai/http-kit": "^0.4.0",
|
|
85
85
|
"@jini-ai/sidecar": "^0.4.0",
|
|
86
86
|
"express": "^4.21.0",
|
|
87
|
-
"@jini-ai/db": "^0.3.
|
|
88
|
-
"@jini-ai/chat": "^0.5.
|
|
87
|
+
"@jini-ai/db": "^0.3.2",
|
|
88
|
+
"@jini-ai/chat": "^0.5.8",
|
|
89
89
|
"@jini-ai/registry": "^0.5.1"
|
|
90
90
|
},
|
|
91
91
|
"peerDependenciesMeta": {
|