@mc1global/opencode-jarvis 0.1.0 → 0.1.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.
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* SOLID: SRP - database connection management only
|
|
8
|
-
* SOLID: OCP - repositories extend behavior without modifying adapter
|
|
9
|
-
* SOLID: DIP - repositories depend on this adapter, not raw better-sqlite3
|
|
10
|
-
*/
|
|
11
|
-
import Database from "better-sqlite3";
|
|
12
|
-
import type { Statement } from "better-sqlite3";
|
|
1
|
+
import type { Statement as BunStatement } from "bun:sqlite";
|
|
2
|
+
/** Result returned by execute() — matches bun:sqlite's Changes shape. */
|
|
3
|
+
export interface RunResult {
|
|
4
|
+
readonly changes: number;
|
|
5
|
+
readonly lastInsertRowid: number | bigint;
|
|
6
|
+
}
|
|
13
7
|
/** Configuration for database initialization. */
|
|
14
8
|
export interface DatabaseConfig {
|
|
15
9
|
/** Path to SQLite file, or ":memory:" for in-memory DB. */
|
|
@@ -18,14 +12,18 @@ export interface DatabaseConfig {
|
|
|
18
12
|
readonly walMode?: boolean;
|
|
19
13
|
}
|
|
20
14
|
/**
|
|
21
|
-
* Thin adapter over
|
|
15
|
+
* Thin adapter over bun:sqlite.
|
|
22
16
|
*
|
|
23
17
|
* Provides typed query helpers and schema management.
|
|
24
18
|
* Each repository calls ensureSchema() to set up its tables.
|
|
19
|
+
*
|
|
20
|
+
* Uses `strict: true` so named parameters (@param) can be bound
|
|
21
|
+
* with unprefixed keys ({ param: value }) — matching our existing SQL.
|
|
25
22
|
*/
|
|
26
23
|
export declare class SqliteAdapter {
|
|
27
24
|
private readonly db;
|
|
28
25
|
private readonly initializedSchemas;
|
|
26
|
+
private closed;
|
|
29
27
|
constructor(config: DatabaseConfig);
|
|
30
28
|
/**
|
|
31
29
|
* Execute DDL schema idempotently.
|
|
@@ -37,11 +35,11 @@ export declare class SqliteAdapter {
|
|
|
37
35
|
/** Run a query that returns a single row or undefined. */
|
|
38
36
|
queryOne<T>(sql: string, params?: Record<string, unknown>): T | undefined;
|
|
39
37
|
/** Run a statement that modifies data (INSERT, UPDATE, DELETE). */
|
|
40
|
-
execute(sql: string, params?: Record<string, unknown>):
|
|
38
|
+
execute(sql: string, params?: Record<string, unknown>): RunResult;
|
|
41
39
|
/** Run multiple statements in a transaction. */
|
|
42
40
|
transaction<T>(fn: () => T): T;
|
|
43
41
|
/** Prepare a statement for repeated use. */
|
|
44
|
-
prepare(sql: string):
|
|
42
|
+
prepare(sql: string): BunStatement;
|
|
45
43
|
/** Get the last inserted rowid. */
|
|
46
44
|
get lastInsertRowid(): number | bigint;
|
|
47
45
|
/** Close the database connection. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-adapter.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/database/sqlite-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite-adapter.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/database/sqlite-adapter.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AAQ5D,yEAAyE;AACzE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3C;AAED,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAW;IAC9B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IACxD,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,cAAc;IAYlC;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAMlD,qCAAqC;IACrC,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE;IAM/D,0DAA0D;IAC1D,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS;IAQzE,mEAAmE;IACnE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAMjE,gDAAgD;IAChD,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAK9B,4CAA4C;IAC5C,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY;IAIlC,mCAAmC;IACnC,IAAI,eAAe,IAAI,MAAM,GAAG,MAAM,CAKrC;IAED,qCAAqC;IACrC,KAAK,IAAI,IAAI;IAOb,qCAAqC;IACrC,IAAI,MAAM,IAAI,OAAO,CAEpB;CACF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,aAAa,CAErD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,aAAa,CAGf"}
|
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SQLite Database Adapter
|
|
3
3
|
*
|
|
4
|
-
* Wraps
|
|
4
|
+
* Wraps bun:sqlite to provide a clean interface for repository use.
|
|
5
5
|
* Handles database lifecycle, schema execution, and typed queries.
|
|
6
6
|
*
|
|
7
7
|
* SOLID: SRP - database connection management only
|
|
8
8
|
* SOLID: OCP - repositories extend behavior without modifying adapter
|
|
9
|
-
* SOLID: DIP - repositories depend on this adapter, not raw
|
|
9
|
+
* SOLID: DIP - repositories depend on this adapter, not raw bun:sqlite
|
|
10
|
+
*
|
|
11
|
+
* NOTE: bun:sqlite is used because OpenCode runs plugins on Bun runtime.
|
|
12
|
+
* The `strict: true` option allows binding named parameters without prefix,
|
|
13
|
+
* so SQL using @param works with binding objects like { param: value }.
|
|
10
14
|
*/
|
|
11
|
-
import Database from "
|
|
15
|
+
import { Database } from "bun:sqlite";
|
|
12
16
|
/**
|
|
13
|
-
* Thin adapter over
|
|
17
|
+
* Thin adapter over bun:sqlite.
|
|
14
18
|
*
|
|
15
19
|
* Provides typed query helpers and schema management.
|
|
16
20
|
* Each repository calls ensureSchema() to set up its tables.
|
|
21
|
+
*
|
|
22
|
+
* Uses `strict: true` so named parameters (@param) can be bound
|
|
23
|
+
* with unprefixed keys ({ param: value }) — matching our existing SQL.
|
|
17
24
|
*/
|
|
18
25
|
export class SqliteAdapter {
|
|
19
26
|
db;
|
|
20
27
|
initializedSchemas = new Set();
|
|
28
|
+
closed = false;
|
|
21
29
|
constructor(config) {
|
|
22
|
-
this.db = new Database(config.path);
|
|
30
|
+
this.db = new Database(config.path, { strict: true });
|
|
23
31
|
// Enable WAL mode for better read concurrency (default: on)
|
|
24
32
|
if (config.walMode !== false) {
|
|
25
|
-
this.db.
|
|
33
|
+
this.db.run("PRAGMA journal_mode = WAL");
|
|
26
34
|
}
|
|
27
35
|
// Foreign keys enforcement
|
|
28
|
-
this.db.
|
|
36
|
+
this.db.run("PRAGMA foreign_keys = ON");
|
|
29
37
|
}
|
|
30
38
|
/**
|
|
31
39
|
* Execute DDL schema idempotently.
|
|
@@ -34,23 +42,28 @@ export class SqliteAdapter {
|
|
|
34
42
|
ensureSchema(schemaKey, ddl) {
|
|
35
43
|
if (this.initializedSchemas.has(schemaKey))
|
|
36
44
|
return;
|
|
37
|
-
this.db.
|
|
45
|
+
this.db.run(ddl);
|
|
38
46
|
this.initializedSchemas.add(schemaKey);
|
|
39
47
|
}
|
|
40
48
|
/** Run a query that returns rows. */
|
|
41
49
|
queryAll(sql, params) {
|
|
42
50
|
const stmt = this.db.prepare(sql);
|
|
43
|
-
|
|
51
|
+
const bindings = params;
|
|
52
|
+
return (bindings ? stmt.all(bindings) : stmt.all());
|
|
44
53
|
}
|
|
45
54
|
/** Run a query that returns a single row or undefined. */
|
|
46
55
|
queryOne(sql, params) {
|
|
47
56
|
const stmt = this.db.prepare(sql);
|
|
48
|
-
|
|
57
|
+
const bindings = params;
|
|
58
|
+
const result = bindings ? stmt.get(bindings) : stmt.get();
|
|
59
|
+
// bun:sqlite returns null for no rows; normalize to undefined
|
|
60
|
+
return (result ?? undefined);
|
|
49
61
|
}
|
|
50
62
|
/** Run a statement that modifies data (INSERT, UPDATE, DELETE). */
|
|
51
63
|
execute(sql, params) {
|
|
52
64
|
const stmt = this.db.prepare(sql);
|
|
53
|
-
|
|
65
|
+
const bindings = params;
|
|
66
|
+
return bindings ? stmt.run(bindings) : stmt.run();
|
|
54
67
|
}
|
|
55
68
|
/** Run multiple statements in a transaction. */
|
|
56
69
|
transaction(fn) {
|
|
@@ -63,18 +76,19 @@ export class SqliteAdapter {
|
|
|
63
76
|
}
|
|
64
77
|
/** Get the last inserted rowid. */
|
|
65
78
|
get lastInsertRowid() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
? this.db.prepare("SELECT last_insert_rowid() as id").get().id
|
|
69
|
-
: 0;
|
|
79
|
+
const row = this.db.prepare("SELECT last_insert_rowid() as id").get();
|
|
80
|
+
return row?.id ?? 0;
|
|
70
81
|
}
|
|
71
82
|
/** Close the database connection. */
|
|
72
83
|
close() {
|
|
73
|
-
this.
|
|
84
|
+
if (!this.closed) {
|
|
85
|
+
this.db.close();
|
|
86
|
+
this.closed = true;
|
|
87
|
+
}
|
|
74
88
|
}
|
|
75
89
|
/** Check if the database is open. */
|
|
76
90
|
get isOpen() {
|
|
77
|
-
return this.
|
|
91
|
+
return !this.closed;
|
|
78
92
|
}
|
|
79
93
|
}
|
|
80
94
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-adapter.js","sourceRoot":"","sources":["../../../src/infrastructure/database/sqlite-adapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sqlite-adapter.js","sourceRoot":"","sources":["../../../src/infrastructure/database/sqlite-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAuBtC;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAa;IACP,EAAE,CAAW;IACb,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;IAChD,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAY,MAAsB;QAChC,IAAI,CAAC,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAEtD,4DAA4D;QAC5D,IAAI,MAAM,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;QAC3C,CAAC;QAED,2BAA2B;QAC3B,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACH,YAAY,CAAC,SAAiB,EAAE,GAAW;QACzC,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,OAAO;QACnD,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACzC,CAAC;IAED,qCAAqC;IACrC,QAAQ,CAAI,GAAW,EAAE,MAAgC;QAC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AmC;IACnC,IAAI,eAAe;QACjB,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC,GAAG,EAE3D,CAAC;QACT,OAAO,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,qCAAqC;IACrC,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;IAED,qCAAqC;IACrC,IAAI,MAAM;QACR,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,aAAa,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAe,EACf,MAAc;IAEd,MAAM,IAAI,GAAG,GAAG,OAAO,IAAI,MAAM,EAAE,CAAC;IACpC,OAAO,IAAI,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AACrC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mc1global/opencode-jarvis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "JARVIS Framework - OpenCode native plugin for multi-agent development with DDD architecture",
|
|
5
5
|
"author": "Julio Fabio de O. Chagas <julio.fabio@mc1global.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@langchain/textsplitters": "^1.0.1",
|
|
44
|
-
"better-sqlite3": "^11.0.0",
|
|
45
44
|
"js-yaml": "^4.1.1",
|
|
46
45
|
"ollama": "^0.6.3",
|
|
47
46
|
"vectra": "^0.12.3"
|
|
@@ -49,9 +48,11 @@
|
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@opencode-ai/plugin": "^1.1.65",
|
|
51
50
|
"@types/better-sqlite3": "^7.6.8",
|
|
51
|
+
"@types/bun": "^1.3.9",
|
|
52
52
|
"@types/jest": "^29.5.12",
|
|
53
53
|
"@types/js-yaml": "^4.0.9",
|
|
54
54
|
"@types/node": "^20.11.0",
|
|
55
|
+
"better-sqlite3": "^11.0.0",
|
|
55
56
|
"jest": "^29.7.0",
|
|
56
57
|
"ts-jest": "^29.1.2",
|
|
57
58
|
"typescript": "^5.5.0"
|