@lythos/cold-pool 0.9.36 → 0.9.37
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 +2 -1
- package/src/db-helpers.ts +4 -73
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lythos/cold-pool",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.37",
|
|
4
4
|
"description": "Cold pool service layer — dedicated resource holder for skill repositories with intent/plan/execute primitives. Single owner of git side-effects; consumed by deck/curator/arena.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agent",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/lythos-labs/lythoskill/tree/main/packages/lythoskill-cold-pool#readme",
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@lythos/infra": "^0.9.36",
|
|
37
38
|
"simple-git": "^3.36.0"
|
|
38
39
|
},
|
|
39
40
|
"engines": {
|
package/src/db-helpers.ts
CHANGED
|
@@ -1,76 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Re-export SqliteDb from @lythos/infra for backward compatibility.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The canonical source is now packages/lythoskill-infra/src/sqlite-db.ts.
|
|
5
|
+
* This file will be removed in a future release once all consumers migrate.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
import { mkdirSync } from 'node:fs'
|
|
9
|
-
import { dirname } from 'node:path'
|
|
10
|
-
|
|
11
|
-
export abstract class SqliteDb {
|
|
12
|
-
protected abstract initSchema(): void
|
|
13
|
-
|
|
14
|
-
private dbPath: string
|
|
15
|
-
private _db: Database | null = null
|
|
16
|
-
|
|
17
|
-
constructor(dbPath: string) {
|
|
18
|
-
this.dbPath = dbPath
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** Lazy-open: first DB access triggers creation. */
|
|
22
|
-
protected get db(): Database {
|
|
23
|
-
if (this._db == null) {
|
|
24
|
-
try {
|
|
25
|
-
mkdirSync(dirname(this.dbPath), { recursive: true })
|
|
26
|
-
} catch {
|
|
27
|
-
// Parent dir may be read-only (e.g. test paths).
|
|
28
|
-
}
|
|
29
|
-
this._db = new Database(this.dbPath, { create: true })
|
|
30
|
-
this.initSchema()
|
|
31
|
-
}
|
|
32
|
-
return this._db
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected exec(sql: string, params?: Record<string, unknown>): void {
|
|
36
|
-
const stmt = this.db.query(sql)
|
|
37
|
-
stmt.run(params ?? {})
|
|
38
|
-
stmt.finalize()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected queryOne<T>(sql: string, params?: Record<string, unknown>): T | null {
|
|
42
|
-
return this.db.query(sql).get(params ?? {}) as T | null
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
protected queryAll<T>(sql: string, params?: Record<string, unknown>): T[] {
|
|
46
|
-
return this.db.query(sql).all(params ?? {}) as T[]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Schema version tracking: call from initSchema() to auto-migrate. */
|
|
50
|
-
protected migrateSchema(currentVersion: number, migrations: Array<{ version: number; sql: string }>): void {
|
|
51
|
-
this.exec(`CREATE TABLE IF NOT EXISTS _schema_version (version INTEGER NOT NULL)`)
|
|
52
|
-
let row = this.queryOne<{ version: number }>(`SELECT version FROM _schema_version`)
|
|
53
|
-
let dbVersion = row?.version ?? 0
|
|
54
|
-
|
|
55
|
-
for (const m of migrations.sort((a, b) => a.version - b.version)) {
|
|
56
|
-
if (m.version > dbVersion) {
|
|
57
|
-
try {
|
|
58
|
-
this.db.query(m.sql).run()
|
|
59
|
-
} catch {
|
|
60
|
-
// Migration may fail if column already exists — fine for idempotent ADD COLUMN.
|
|
61
|
-
}
|
|
62
|
-
dbVersion = m.version
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (dbVersion !== (row?.version ?? 0)) {
|
|
67
|
-
this.exec(`DELETE FROM _schema_version`)
|
|
68
|
-
this.exec(`INSERT INTO _schema_version (version) VALUES ($v)`, { $v: dbVersion })
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
close(): void {
|
|
73
|
-
this._db?.close()
|
|
74
|
-
this._db = null
|
|
75
|
-
}
|
|
76
|
-
}
|
|
7
|
+
export { SqliteDb } from '@lythos/infra'
|