@vpxa/aikit 0.1.91 → 0.1.92
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./lance-store-CQkljFy3.js";import{createRequire as t}from"node:module";import{AIKIT_PATHS as n}from"../../core/dist/index.js";import{execSync as r}from"node:child_process";import{existsSync as i,mkdirSync as a,readFileSync as o,writeFileSync as s}from"node:fs";import{dirname as c,join as l}from"node:path";var u=class{type=`better-sqlite3`;db=null;async open(e){let t=(await import(`better-sqlite3`)).default;this.db=new t(e)}exec(e){this.getDb().exec(e)}pragma(e){this.getDb().pragma(e)}queryAll(e,t=[]){return this.getDb().prepare(e).all(...t)}run(e,t=[]){this.getDb().prepare(e).run(...t)}flush(){}close(){this.db&&=(this.db.close(),null)}getDb(){if(!this.db)throw Error(`BetterSqliteAdapter: database not opened`);return this.db}},d=class{type=`sql.js`;db=null;dbPath=``;dirty=!1;inTransaction=!1;async open(e){this.dbPath=e;let t=(await import(`sql.js`)).default,n=await t();if(i(e)){let t=o(e);this.db=new n.Database(t)}else this.db=new n.Database}exec(e){let t=e.trimStart().toUpperCase();t.startsWith(`BEGIN`)?this.inTransaction=!0:(t.startsWith(`COMMIT`)||t.startsWith(`ROLLBACK`))&&(this.inTransaction=!1),this.getDb().run(e),this.dirty=!0}pragma(e){this.getDb().exec(`PRAGMA ${e}`)}queryAll(e,t=[]){let n=this.getDb().prepare(e);t.length>0&&n.bind(t);let r=[];for(;n.step();)r.push(n.getAsObject());return n.free(),r}run(e,t=[]){let n=this.getDb(),r=e.trimStart().toUpperCase(),i=!this.inTransaction&&(r.startsWith(`INSERT`)||r.startsWith(`UPDATE`));if(i&&n.run(`SAVEPOINT fk_check`),t.length>0){let r=n.prepare(e);try{r.bind(t),r.step()}finally{r.free()}}else n.run(e);if(i){if(n.exec(`PRAGMA foreign_key_check`).length>0)throw n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`),Error(`FOREIGN KEY constraint failed`);n.run(`RELEASE fk_check`)}this.dirty=!0}flush(){if(!this.dirty||!this.db)return;let e=this.db.export();s(this.dbPath,Buffer.from(e)),this.dirty=!1}close(){this.db&&=(this.flush(),this.db.close(),null)}getDb(){if(!this.db)throw Error(`SqlJsAdapter: database not opened`);return this.db}};function f(e){let t=e instanceof Error?e.message:String(e);return t.includes(`NODE_MODULE_VERSION`)||t.includes(`was compiled against a different Node.js version`)}function p(){try{let e=c(t(import.meta.url).resolve(`better-sqlite3/package.json`));
|
|
1
|
+
import{t as e}from"./lance-store-CQkljFy3.js";import{createRequire as t}from"node:module";import{AIKIT_PATHS as n}from"../../core/dist/index.js";import{execSync as r}from"node:child_process";import{existsSync as i,mkdirSync as a,readFileSync as o,writeFileSync as s}from"node:fs";import{dirname as c,join as l}from"node:path";var u=class{type=`better-sqlite3`;db=null;async open(e){let t=(await import(`better-sqlite3`)).default;this.db=new t(e)}exec(e){this.getDb().exec(e)}pragma(e){this.getDb().pragma(e)}queryAll(e,t=[]){return this.getDb().prepare(e).all(...t)}run(e,t=[]){this.getDb().prepare(e).run(...t)}flush(){}close(){this.db&&=(this.db.close(),null)}getDb(){if(!this.db)throw Error(`BetterSqliteAdapter: database not opened`);return this.db}},d=class{type=`sql.js`;db=null;dbPath=``;dirty=!1;inTransaction=!1;async open(e){this.dbPath=e;let t=(await import(`sql.js`)).default,n=await t();if(i(e)){let t=o(e);this.db=new n.Database(t)}else this.db=new n.Database}exec(e){let t=e.trimStart().toUpperCase();t.startsWith(`BEGIN`)?this.inTransaction=!0:(t.startsWith(`COMMIT`)||t.startsWith(`ROLLBACK`))&&(this.inTransaction=!1),this.getDb().run(e),this.dirty=!0}pragma(e){this.getDb().exec(`PRAGMA ${e}`)}queryAll(e,t=[]){let n=this.getDb().prepare(e);t.length>0&&n.bind(t);let r=[];for(;n.step();)r.push(n.getAsObject());return n.free(),r}run(e,t=[]){let n=this.getDb(),r=e.trimStart().toUpperCase(),i=!this.inTransaction&&(r.startsWith(`INSERT`)||r.startsWith(`UPDATE`));if(i&&n.run(`SAVEPOINT fk_check`),t.length>0){let r=n.prepare(e);try{r.bind(t),r.step()}finally{r.free()}}else n.run(e);if(i){if(n.exec(`PRAGMA foreign_key_check`).length>0)throw n.run(`ROLLBACK TO fk_check`),n.run(`RELEASE fk_check`),Error(`FOREIGN KEY constraint failed`);n.run(`RELEASE fk_check`)}this.dirty=!0}flush(){if(!this.dirty||!this.db)return;let e=this.db.export();s(this.dbPath,Buffer.from(e)),this.dirty=!1}close(){this.db&&=(this.flush(),this.db.close(),null)}getDb(){if(!this.db)throw Error(`SqlJsAdapter: database not opened`);return this.db}};function f(e){let t=e instanceof Error?e.message:String(e);return t.includes(`NODE_MODULE_VERSION`)||t.includes(`was compiled against a different Node.js version`)}function p(){try{let e=c(t(import.meta.url).resolve(`better-sqlite3/package.json`));console.error(`[aikit] Native module version mismatch detected — re-downloading prebuild for Node ${process.version}...`);let n=l(e,`node_modules`,`.bin`,`prebuild-install`);return r(i(n)?`${n} -r napi`:`npx --yes prebuild-install -r napi`,{cwd:e,stdio:`pipe`,timeout:6e4,env:{...process.env,npm_config_loglevel:`silent`}}),console.error(`[aikit] Prebuild re-downloaded successfully`),!0}catch(e){let t=e instanceof Error?e.message:String(e);return console.error(`[aikit] Auto-heal failed: ${t}`),!1}}async function m(e,t){let n=t?.primary??`better-sqlite3`,r=[n,n===`better-sqlite3`?`sql.js`:`better-sqlite3`],i=!1;for(let t of r)try{let r=t===`better-sqlite3`?new u:new d;return await r.open(e),t!==n&&console.error(`[aikit] SQLite adapter: primary "${n}" unavailable, using fallback "${t}"`),r}catch(n){let r=n instanceof Error?n.message:String(n);if(console.error(`[aikit] SQLite adapter "${t}" failed to load: ${r}`),t===`better-sqlite3`&&!i&&f(n)&&(i=!0,p()))try{let t=new u;return await t.open(e),console.error(`[aikit] SQLite adapter "better-sqlite3" loaded after auto-heal`),t}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[aikit] Retry after heal still failed: ${t}`)}}throw Error(`[aikit] No SQLite adapter available. Tried: ${r.join(`, `)}. Install either better-sqlite3 or sql.js.`)}var h=class{adapter=null;dbPath;adapterOptions;constructor(e){let t=e?.path??n.data;this.dbPath=l(t,`graph.db`),this.adapterOptions=e?.sqliteAdapter}async initialize(){let e=c(this.dbPath);i(e)||a(e,{recursive:!0}),this.adapter=await m(this.dbPath,this.adapterOptions),this.configureAdapter(this.adapter),this.createTables(this.adapter),this.migrateSchema(this.adapter),this.adapter.flush()}configureAdapter(e){e.pragma(`journal_mode = WAL`),e.pragma(`foreign_keys = ON`)}createTables(e){e.exec(`
|
|
2
2
|
CREATE TABLE IF NOT EXISTS nodes (
|
|
3
3
|
id TEXT PRIMARY KEY,
|
|
4
4
|
type TEXT NOT NULL,
|