@agimon-ai/po-db 0.0.0-alpha.100 → 0.0.0-alpha.102

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,4 +1,4 @@
1
- import { r as PO_DB_SERVICE } from "./poDb-D6K38Gpu.mjs";
1
+ import { r as PO_DB_SERVICE } from "./poDb-iHdPDH6l.mjs";
2
2
  import { defineServiceContract } from "@agimon-ai/po-core/extensionFile";
3
3
  //#region src/schemas/contracts.ts
4
4
  /** Bound once at the global level; every workspace and session resolves the same connection. */
@@ -12,4 +12,4 @@ function requirePoDb(context) {
12
12
  //#endregion
13
13
  export { requirePoDb as n, PO_DB_CONTRACT as t };
14
14
 
15
- //# sourceMappingURL=contracts-Bv9-_vyc.mjs.map
15
+ //# sourceMappingURL=contracts-BXplc0jW.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"contracts-Bv9-_vyc.mjs","names":[],"sources":["../src/schemas/contracts.ts"],"sourcesContent":["import { defineServiceContract } from '@agimon-ai/po-core/extensionFile';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport { PO_DB_SERVICE } from '../constants/db';\nimport type { PoDb } from '../services/poDb/type';\n\n/** Bound once at the global level; every workspace and session resolves the same connection. */\nexport const PO_DB_CONTRACT = defineServiceContract<PoDb>(PO_DB_SERVICE, { scope: 'global' });\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/db': PoDb;\n }\n}\n\n/** The shared database, for a caller that injected `po/db`; throws when no global root bound one. */\nexport function requirePoDb(context: Context): PoDb {\n const db = context.get(PO_DB_SERVICE) as PoDb | undefined;\n if (db === undefined)\n throw new Error('The Po database is unavailable. Install @agimon-ai/po-db at the global scope.');\n return db;\n}\n"],"mappings":";;;;AAOA,MAAa,iBAAiB,sBAA4B,eAAe,EAAE,OAAO,SAAS,CAAC;;AAS5F,SAAgB,YAAY,SAAwB;CAClD,MAAM,KAAK,QAAQ,IAAI,aAAa;CACpC,IAAI,OAAO,KAAA,GACT,MAAM,IAAI,MAAM,+EAA+E;CACjG,OAAO;AACT"}
1
+ {"version":3,"file":"contracts-BXplc0jW.mjs","names":[],"sources":["../src/schemas/contracts.ts"],"sourcesContent":["import { defineServiceContract } from '@agimon-ai/po-core/extensionFile';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport { PO_DB_SERVICE } from '../constants/db';\nimport type { PoDb } from '../services/poDb/type';\n\n/** Bound once at the global level; every workspace and session resolves the same connection. */\nexport const PO_DB_CONTRACT = defineServiceContract<PoDb>(PO_DB_SERVICE, { scope: 'global' });\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/db': PoDb;\n }\n}\n\n/** The shared database, for a caller that injected `po/db`; throws when no global root bound one. */\nexport function requirePoDb(context: Context): PoDb {\n const db = context.get(PO_DB_SERVICE) as PoDb | undefined;\n if (db === undefined)\n throw new Error('The Po database is unavailable. Install @agimon-ai/po-db at the global scope.');\n return db;\n}\n"],"mappings":";;;;AAOA,MAAa,iBAAiB,sBAA4B,eAAe,EAAE,OAAO,SAAS,CAAC;;AAS5F,SAAgB,YAAY,SAAwB;CAClD,MAAM,KAAK,QAAQ,IAAI,aAAa;CACpC,IAAI,OAAO,KAAA,GACT,MAAM,IAAI,MAAM,+EAA+E;CACjG,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- const require_poDb = require("./poDb-BKBXJbTa.cjs");
1
+ const require_poDb = require("./poDb-BSWMYd_x.cjs");
2
2
  //#region src/schemas/contracts.ts
3
3
  /** Bound once at the global level; every workspace and session resolves the same connection. */
4
4
  const PO_DB_CONTRACT = (0, require("@agimon-ai/po-core/extensionFile").defineServiceContract)(require_poDb.PO_DB_SERVICE, { scope: "global" });
@@ -22,4 +22,4 @@ Object.defineProperty(exports, "requirePoDb", {
22
22
  }
23
23
  });
24
24
 
25
- //# sourceMappingURL=contracts-C9sToxiM.cjs.map
25
+ //# sourceMappingURL=contracts-CU15VsfR.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"contracts-C9sToxiM.cjs","names":["defineServiceContract","PO_DB_SERVICE"],"sources":["../src/schemas/contracts.ts"],"sourcesContent":["import { defineServiceContract } from '@agimon-ai/po-core/extensionFile';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport { PO_DB_SERVICE } from '../constants/db';\nimport type { PoDb } from '../services/poDb/type';\n\n/** Bound once at the global level; every workspace and session resolves the same connection. */\nexport const PO_DB_CONTRACT = defineServiceContract<PoDb>(PO_DB_SERVICE, { scope: 'global' });\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/db': PoDb;\n }\n}\n\n/** The shared database, for a caller that injected `po/db`; throws when no global root bound one. */\nexport function requirePoDb(context: Context): PoDb {\n const db = context.get(PO_DB_SERVICE) as PoDb | undefined;\n if (db === undefined)\n throw new Error('The Po database is unavailable. Install @agimon-ai/po-db at the global scope.');\n return db;\n}\n"],"mappings":";;;AAOA,MAAa,kBAAA,6CAAiBA,CAAAA,CAAAA,sBAAAA,CAA4BC,aAAAA,eAAe,EAAE,OAAO,SAAS,CAAC;;AAS5F,SAAgB,YAAY,SAAwB;CAClD,MAAM,KAAK,QAAQ,IAAIA,aAAAA,aAAa;CACpC,IAAI,OAAO,KAAA,GACT,MAAM,IAAI,MAAM,+EAA+E;CACjG,OAAO;AACT"}
1
+ {"version":3,"file":"contracts-CU15VsfR.cjs","names":["defineServiceContract","PO_DB_SERVICE"],"sources":["../src/schemas/contracts.ts"],"sourcesContent":["import { defineServiceContract } from '@agimon-ai/po-core/extensionFile';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport { PO_DB_SERVICE } from '../constants/db';\nimport type { PoDb } from '../services/poDb/type';\n\n/** Bound once at the global level; every workspace and session resolves the same connection. */\nexport const PO_DB_CONTRACT = defineServiceContract<PoDb>(PO_DB_SERVICE, { scope: 'global' });\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/db': PoDb;\n }\n}\n\n/** The shared database, for a caller that injected `po/db`; throws when no global root bound one. */\nexport function requirePoDb(context: Context): PoDb {\n const db = context.get(PO_DB_SERVICE) as PoDb | undefined;\n if (db === undefined)\n throw new Error('The Po database is unavailable. Install @agimon-ai/po-db at the global scope.');\n return db;\n}\n"],"mappings":";;;AAOA,MAAa,kBAAA,6CAAiBA,CAAAA,CAAAA,sBAAAA,CAA4BC,aAAAA,eAAe,EAAE,OAAO,SAAS,CAAC;;AAS5F,SAAgB,YAAY,SAAwB;CAClD,MAAM,KAAK,QAAQ,IAAIA,aAAAA,aAAa;CACpC,IAAI,OAAO,KAAA,GACT,MAAM,IAAI,MAAM,+EAA+E;CACjG,OAAO;AACT"}
@@ -24,8 +24,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
  //#endregion
27
- const require_poDb = require("../poDb-BKBXJbTa.cjs");
28
- const require_contracts = require("../contracts-C9sToxiM.cjs");
27
+ const require_poDb = require("../poDb-BSWMYd_x.cjs");
28
+ const require_contracts = require("../contracts-CU15VsfR.cjs");
29
29
  let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
30
30
  let _agimon_ai_po_core_serverPlugin = require("@agimon-ai/po-core/serverPlugin");
31
31
  let node_path = require("node:path");
@@ -1,5 +1,5 @@
1
- import { n as PO_DB_FILE, t as createPoDb } from "../poDb-D6K38Gpu.mjs";
2
- import { t as PO_DB_CONTRACT } from "../contracts-Bv9-_vyc.mjs";
1
+ import { n as PO_DB_FILE, t as createPoDb } from "../poDb-iHdPDH6l.mjs";
2
+ import { t as PO_DB_CONTRACT } from "../contracts-BXplc0jW.mjs";
3
3
  import { composeRootHooks, composeRootInjects, defineRoot } from "@agimon-ai/po-core/extensionFile";
4
4
  import { PO_SERVER_SCOPE_SERVICE, composeServerProviderOverrides, defineServerPlugin, requirePoServerScope } from "@agimon-ai/po-core/serverPlugin";
5
5
  import path from "node:path";
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_poDb = require("./poDb-BKBXJbTa.cjs");
3
- const require_contracts = require("./contracts-C9sToxiM.cjs");
2
+ const require_poDb = require("./poDb-BSWMYd_x.cjs");
3
+ const require_contracts = require("./contracts-CU15VsfR.cjs");
4
4
  exports.PO_DB_CONTRACT = require_contracts.PO_DB_CONTRACT;
5
5
  exports.PO_DB_FILE = require_poDb.PO_DB_FILE;
6
6
  exports.PO_DB_SERVICE = require_poDb.PO_DB_SERVICE;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/constants/db.ts","../src/schemas/contracts.ts","../src/services/poDb/index.ts"],"mappings":";;;qBAAa;;qBAEA;;;;qBCKA,0DAAc,kBAAA;;YAGf;IACR,SAAS;;;;wBAKG,YAAY,SAAS,UAAU;;;wBCyD/B,WAAW,SAAS,oBAAoB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/constants/db.ts","../src/schemas/contracts.ts","../src/services/poDb/index.ts"],"mappings":";;;qBAAa;;qBAEA;;;;qBCKA,0DAAc,kBAAA;;YAGf;IACR,SAAS;;;;wBAKG,YAAY,SAAS,UAAU;;;wBC0D/B,WAAW,SAAS,oBAAoB"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as PO_DB_FILE, r as PO_DB_SERVICE, t as createPoDb } from "./poDb-D6K38Gpu.mjs";
2
- import { n as requirePoDb, t as PO_DB_CONTRACT } from "./contracts-Bv9-_vyc.mjs";
1
+ import { n as PO_DB_FILE, r as PO_DB_SERVICE, t as createPoDb } from "./poDb-iHdPDH6l.mjs";
2
+ import { n as requirePoDb, t as PO_DB_CONTRACT } from "./contracts-BXplc0jW.mjs";
3
3
  export { PO_DB_CONTRACT, PO_DB_FILE, PO_DB_SERVICE, createPoDb, requirePoDb };
@@ -26,6 +26,7 @@ function sharedView(database) {
26
26
  return {
27
27
  exec: (sql) => database.exec(sql),
28
28
  run: (sql, ...params) => database.run(sql, ...params),
29
+ runCounted: (sql, ...params) => database.runCounted(sql, ...params),
29
30
  get: (sql, ...params) => database.get(sql, ...params),
30
31
  all: (sql, ...params) => database.all(sql, ...params),
31
32
  transaction: (callback) => database.transaction(callback),
@@ -90,4 +91,4 @@ Object.defineProperty(exports, "createPoDb", {
90
91
  }
91
92
  });
92
93
 
93
- //# sourceMappingURL=poDb-BKBXJbTa.cjs.map
94
+ //# sourceMappingURL=poDb-BSWMYd_x.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poDb-BSWMYd_x.cjs","names":["applySqliteMigrations"],"sources":["../src/constants/db.ts","../src/services/poDb/index.ts"],"sourcesContent":["export const PO_DB_SERVICE = 'po/db';\n/** The database file, as path segments under the Po home. */\nexport const PO_DB_FILE = ['db', 'po.sqlite'] as const;\n/** Owner-only: the folder holds every package's rows, secrets included. */\nexport const PO_DB_DIRECTORY_MODE = 0o700;\n/** A table prefix: lowercase words joined by single underscores, never sqlite's own namespace. */\nexport const PO_DB_PREFIX_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;\nexport const PO_DB_PREFIX_MAX_LENGTH = 48;\n","import { applySqliteMigrations, type SqliteDatabase, type SqliteExecutor } from '@earendil-works/chord/sqlite';\n\nimport { PO_DB_PREFIX_MAX_LENGTH, PO_DB_PREFIX_PATTERN } from '../../constants/db';\nimport type { CreatePoDbOptions, PoDbHandle, PoDbMigration } from './type';\n\ninterface SchemaObject {\n readonly type: string;\n readonly name: string;\n}\n\n/** sqlite names its own automatic indexes `sqlite_autoindex_*`; nobody owns those. */\nconst SQLITE_INTERNAL = 'sqlite_';\n\nfunction assertPrefix(prefix: string): void {\n if (\n prefix.length > PO_DB_PREFIX_MAX_LENGTH ||\n !PO_DB_PREFIX_PATTERN.test(prefix) ||\n prefix === 'sqlite' ||\n prefix.startsWith(SQLITE_INTERNAL)\n ) {\n throw new Error(`Invalid po-db table prefix ${JSON.stringify(prefix)}.`);\n }\n}\n\nasync function schemaNames(executor: SqliteExecutor): Promise<Set<string>> {\n const rows = await executor.all<SchemaObject>('SELECT type, name FROM sqlite_master');\n return new Set(rows.map((row) => `${row.type}\\0${row.name}`));\n}\n\n/**\n * A view of the shared connection that cannot close it.\n *\n * Consumers such as the calendar store call `close()` on the database they were given. One\n * connection serves every package in the process, so only the owning handle may end it.\n */\nfunction sharedView(database: SqliteDatabase): SqliteDatabase {\n return {\n exec: (sql) => database.exec(sql),\n run: (sql, ...params) => database.run(sql, ...params),\n runCounted: (sql, ...params) => database.runCounted(sql, ...params),\n get: (sql, ...params) => database.get(sql, ...params),\n all: (sql, ...params) => database.all(sql, ...params),\n transaction: (callback) => database.transaction(callback),\n close: async () => undefined,\n };\n}\n\n/**\n * Runs chord's migrator with every transaction it opens checking the schema it leaves.\n *\n * The check runs inside the migration's own transaction, so a migration that creates an\n * object outside its prefix rolls back with everything else it did.\n */\nfunction prefixGuarded(database: SqliteDatabase, prefix: string): SqliteDatabase {\n const owned = `${prefix}_`;\n return {\n ...sharedView(database),\n transaction: (callback) =>\n database.transaction(async (transaction) => {\n const before = await schemaNames(transaction);\n const result = await callback(transaction);\n for (const entry of await schemaNames(transaction)) {\n if (before.has(entry)) continue;\n const [type, name = ''] = entry.split('\\0');\n if (name.startsWith(owned) || name.startsWith(SQLITE_INTERNAL)) continue;\n throw new Error(\n `po-db migration for ${JSON.stringify(prefix)} created ${type} ${JSON.stringify(name)} outside its prefix.`,\n );\n }\n return result;\n }),\n };\n}\n\nexport function createPoDb(options: CreatePoDbOptions): PoDbHandle {\n const { database } = options;\n let closing: Promise<void> | undefined;\n return {\n database: sharedView(database),\n async migrate(prefix: string, migrations: readonly PoDbMigration[]): Promise<void> {\n assertPrefix(prefix);\n await applySqliteMigrations(prefixGuarded(database, prefix), migrations, { table: `${prefix}_migrations` });\n },\n close(): Promise<void> {\n closing ??= database.close();\n return closing;\n },\n };\n}\n"],"mappings":";;AAAA,MAAa,gBAAgB;;AAE7B,MAAa,aAAa,CAAC,MAAM,WAAW;;AAI5C,MAAa,uBAAuB;;;;ACKpC,MAAM,kBAAkB;AAExB,SAAS,aAAa,QAAsB;CAC1C,IACE,OAAO,SAAA,MACP,CAAC,qBAAqB,KAAK,MAAM,KACjC,WAAW,YACX,OAAO,WAAW,eAAe,GAEjC,MAAM,IAAI,MAAM,8BAA8B,KAAK,UAAU,MAAM,EAAE,EAAE;AAE3E;AAEA,eAAe,YAAY,UAAgD;CACzE,MAAM,OAAO,MAAM,SAAS,IAAkB,sCAAsC;CACpF,OAAO,IAAI,IAAI,KAAK,KAAK,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC;AAC9D;;;;;;;AAQA,SAAS,WAAW,UAA0C;CAC5D,OAAO;EACL,OAAO,QAAQ,SAAS,KAAK,GAAG;EAChC,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,aAAa,KAAK,GAAG,WAAW,SAAS,WAAW,KAAK,GAAG,MAAM;EAClE,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,cAAc,aAAa,SAAS,YAAY,QAAQ;EACxD,OAAO,YAAY,KAAA;CACrB;AACF;;;;;;;AAQA,SAAS,cAAc,UAA0B,QAAgC;CAC/E,MAAM,QAAQ,GAAG,OAAO;CACxB,OAAO;EACL,GAAG,WAAW,QAAQ;EACtB,cAAc,aACZ,SAAS,YAAY,OAAO,gBAAgB;GAC1C,MAAM,SAAS,MAAM,YAAY,WAAW;GAC5C,MAAM,SAAS,MAAM,SAAS,WAAW;GACzC,KAAK,MAAM,SAAS,MAAM,YAAY,WAAW,GAAG;IAClD,IAAI,OAAO,IAAI,KAAK,GAAG;IACvB,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,MAAM,IAAI;IAC1C,IAAI,KAAK,WAAW,KAAK,KAAK,KAAK,WAAW,eAAe,GAAG;IAChE,MAAM,IAAI,MACR,uBAAuB,KAAK,UAAU,MAAM,EAAE,WAAW,KAAK,GAAG,KAAK,UAAU,IAAI,EAAE,qBACxF;GACF;GACA,OAAO;EACT,CAAC;CACL;AACF;AAEA,SAAgB,WAAW,SAAwC;CACjE,MAAM,EAAE,aAAa;CACrB,IAAI;CACJ,OAAO;EACL,UAAU,WAAW,QAAQ;EAC7B,MAAM,QAAQ,QAAgB,YAAqD;GACjF,aAAa,MAAM;GACnB,OAAA,GAAMA,6BAAAA,sBAAAA,CAAsB,cAAc,UAAU,MAAM,GAAG,YAAY,EAAE,OAAO,GAAG,OAAO,aAAa,CAAC;EAC5G;EACA,QAAuB;GACrB,YAAY,SAAS,MAAM;GAC3B,OAAO;EACT;CACF;AACF"}
@@ -26,6 +26,7 @@ function sharedView(database) {
26
26
  return {
27
27
  exec: (sql) => database.exec(sql),
28
28
  run: (sql, ...params) => database.run(sql, ...params),
29
+ runCounted: (sql, ...params) => database.runCounted(sql, ...params),
29
30
  get: (sql, ...params) => database.get(sql, ...params),
30
31
  all: (sql, ...params) => database.all(sql, ...params),
31
32
  transaction: (callback) => database.transaction(callback),
@@ -73,4 +74,4 @@ function createPoDb(options) {
73
74
  //#endregion
74
75
  export { PO_DB_FILE as n, PO_DB_SERVICE as r, createPoDb as t };
75
76
 
76
- //# sourceMappingURL=poDb-D6K38Gpu.mjs.map
77
+ //# sourceMappingURL=poDb-iHdPDH6l.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poDb-iHdPDH6l.mjs","names":[],"sources":["../src/constants/db.ts","../src/services/poDb/index.ts"],"sourcesContent":["export const PO_DB_SERVICE = 'po/db';\n/** The database file, as path segments under the Po home. */\nexport const PO_DB_FILE = ['db', 'po.sqlite'] as const;\n/** Owner-only: the folder holds every package's rows, secrets included. */\nexport const PO_DB_DIRECTORY_MODE = 0o700;\n/** A table prefix: lowercase words joined by single underscores, never sqlite's own namespace. */\nexport const PO_DB_PREFIX_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;\nexport const PO_DB_PREFIX_MAX_LENGTH = 48;\n","import { applySqliteMigrations, type SqliteDatabase, type SqliteExecutor } from '@earendil-works/chord/sqlite';\n\nimport { PO_DB_PREFIX_MAX_LENGTH, PO_DB_PREFIX_PATTERN } from '../../constants/db';\nimport type { CreatePoDbOptions, PoDbHandle, PoDbMigration } from './type';\n\ninterface SchemaObject {\n readonly type: string;\n readonly name: string;\n}\n\n/** sqlite names its own automatic indexes `sqlite_autoindex_*`; nobody owns those. */\nconst SQLITE_INTERNAL = 'sqlite_';\n\nfunction assertPrefix(prefix: string): void {\n if (\n prefix.length > PO_DB_PREFIX_MAX_LENGTH ||\n !PO_DB_PREFIX_PATTERN.test(prefix) ||\n prefix === 'sqlite' ||\n prefix.startsWith(SQLITE_INTERNAL)\n ) {\n throw new Error(`Invalid po-db table prefix ${JSON.stringify(prefix)}.`);\n }\n}\n\nasync function schemaNames(executor: SqliteExecutor): Promise<Set<string>> {\n const rows = await executor.all<SchemaObject>('SELECT type, name FROM sqlite_master');\n return new Set(rows.map((row) => `${row.type}\\0${row.name}`));\n}\n\n/**\n * A view of the shared connection that cannot close it.\n *\n * Consumers such as the calendar store call `close()` on the database they were given. One\n * connection serves every package in the process, so only the owning handle may end it.\n */\nfunction sharedView(database: SqliteDatabase): SqliteDatabase {\n return {\n exec: (sql) => database.exec(sql),\n run: (sql, ...params) => database.run(sql, ...params),\n runCounted: (sql, ...params) => database.runCounted(sql, ...params),\n get: (sql, ...params) => database.get(sql, ...params),\n all: (sql, ...params) => database.all(sql, ...params),\n transaction: (callback) => database.transaction(callback),\n close: async () => undefined,\n };\n}\n\n/**\n * Runs chord's migrator with every transaction it opens checking the schema it leaves.\n *\n * The check runs inside the migration's own transaction, so a migration that creates an\n * object outside its prefix rolls back with everything else it did.\n */\nfunction prefixGuarded(database: SqliteDatabase, prefix: string): SqliteDatabase {\n const owned = `${prefix}_`;\n return {\n ...sharedView(database),\n transaction: (callback) =>\n database.transaction(async (transaction) => {\n const before = await schemaNames(transaction);\n const result = await callback(transaction);\n for (const entry of await schemaNames(transaction)) {\n if (before.has(entry)) continue;\n const [type, name = ''] = entry.split('\\0');\n if (name.startsWith(owned) || name.startsWith(SQLITE_INTERNAL)) continue;\n throw new Error(\n `po-db migration for ${JSON.stringify(prefix)} created ${type} ${JSON.stringify(name)} outside its prefix.`,\n );\n }\n return result;\n }),\n };\n}\n\nexport function createPoDb(options: CreatePoDbOptions): PoDbHandle {\n const { database } = options;\n let closing: Promise<void> | undefined;\n return {\n database: sharedView(database),\n async migrate(prefix: string, migrations: readonly PoDbMigration[]): Promise<void> {\n assertPrefix(prefix);\n await applySqliteMigrations(prefixGuarded(database, prefix), migrations, { table: `${prefix}_migrations` });\n },\n close(): Promise<void> {\n closing ??= database.close();\n return closing;\n },\n };\n}\n"],"mappings":";;AAAA,MAAa,gBAAgB;;AAE7B,MAAa,aAAa,CAAC,MAAM,WAAW;;AAI5C,MAAa,uBAAuB;;;;ACKpC,MAAM,kBAAkB;AAExB,SAAS,aAAa,QAAsB;CAC1C,IACE,OAAO,SAAA,MACP,CAAC,qBAAqB,KAAK,MAAM,KACjC,WAAW,YACX,OAAO,WAAW,eAAe,GAEjC,MAAM,IAAI,MAAM,8BAA8B,KAAK,UAAU,MAAM,EAAE,EAAE;AAE3E;AAEA,eAAe,YAAY,UAAgD;CACzE,MAAM,OAAO,MAAM,SAAS,IAAkB,sCAAsC;CACpF,OAAO,IAAI,IAAI,KAAK,KAAK,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC;AAC9D;;;;;;;AAQA,SAAS,WAAW,UAA0C;CAC5D,OAAO;EACL,OAAO,QAAQ,SAAS,KAAK,GAAG;EAChC,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,aAAa,KAAK,GAAG,WAAW,SAAS,WAAW,KAAK,GAAG,MAAM;EAClE,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,cAAc,aAAa,SAAS,YAAY,QAAQ;EACxD,OAAO,YAAY,KAAA;CACrB;AACF;;;;;;;AAQA,SAAS,cAAc,UAA0B,QAAgC;CAC/E,MAAM,QAAQ,GAAG,OAAO;CACxB,OAAO;EACL,GAAG,WAAW,QAAQ;EACtB,cAAc,aACZ,SAAS,YAAY,OAAO,gBAAgB;GAC1C,MAAM,SAAS,MAAM,YAAY,WAAW;GAC5C,MAAM,SAAS,MAAM,SAAS,WAAW;GACzC,KAAK,MAAM,SAAS,MAAM,YAAY,WAAW,GAAG;IAClD,IAAI,OAAO,IAAI,KAAK,GAAG;IACvB,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,MAAM,IAAI;IAC1C,IAAI,KAAK,WAAW,KAAK,KAAK,KAAK,WAAW,eAAe,GAAG;IAChE,MAAM,IAAI,MACR,uBAAuB,KAAK,UAAU,MAAM,EAAE,WAAW,KAAK,GAAG,KAAK,UAAU,IAAI,EAAE,qBACxF;GACF;GACA,OAAO;EACT,CAAC;CACL;AACF;AAEA,SAAgB,WAAW,SAAwC;CACjE,MAAM,EAAE,aAAa;CACrB,IAAI;CACJ,OAAO;EACL,UAAU,WAAW,QAAQ;EAC7B,MAAM,QAAQ,QAAgB,YAAqD;GACjF,aAAa,MAAM;GACnB,MAAM,sBAAsB,cAAc,UAAU,MAAM,GAAG,YAAY,EAAE,OAAO,GAAG,OAAO,aAAa,CAAC;EAC5G;EACA,QAAuB;GACrB,YAAY,SAAS,MAAM;GAC3B,OAAO;EACT;CACF;AACF"}
package/dist/testing.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_poDb = require("./poDb-BKBXJbTa.cjs");
2
+ const require_poDb = require("./poDb-BSWMYd_x.cjs");
3
3
  let _agimon_ai_po_core_nodePlatform = require("@agimon-ai/po-core/nodePlatform");
4
4
  //#region src/services/testPoDb/index.ts
5
5
  /**
package/dist/testing.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createPoDb } from "./poDb-D6K38Gpu.mjs";
1
+ import { t as createPoDb } from "./poDb-iHdPDH6l.mjs";
2
2
  import { openNodeSqliteDatabase } from "@agimon-ai/po-core/nodePlatform";
3
3
  //#region src/services/testPoDb/index.ts
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po-db",
3
- "version": "0.0.0-alpha.100",
3
+ "version": "0.0.0-alpha.102",
4
4
  "description": "One shared sqlite database for the Po packages that need one",
5
5
  "keywords": [
6
6
  "ai",
@@ -61,13 +61,13 @@
61
61
  "access": "public"
62
62
  },
63
63
  "dependencies": {
64
- "@agimon-ai/po-core": "0.0.0-alpha.100",
64
+ "@agimon-ai/po-core": "0.0.0-alpha.102",
65
65
  "@deepseek-ai/cordis": "4.0.5",
66
- "@earendil-works/chord": "1.4.0"
66
+ "@earendil-works/chord": "1.5.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@agimon-ai/po-build": "0.0.0-alpha.100",
70
- "@agimon-ai/vibe-lint-plugin-po-extension": "0.0.0-alpha.100",
69
+ "@agimon-ai/po-build": "0.0.0-alpha.102",
70
+ "@agimon-ai/vibe-lint-plugin-po-extension": "0.0.0-alpha.102",
71
71
  "@types/node": "26.6.5",
72
72
  "@vitest/coverage-v8": "5.0.4",
73
73
  "tsdown": "0.23.1",
@@ -1 +0,0 @@
1
- {"version":3,"file":"poDb-BKBXJbTa.cjs","names":["applySqliteMigrations"],"sources":["../src/constants/db.ts","../src/services/poDb/index.ts"],"sourcesContent":["export const PO_DB_SERVICE = 'po/db';\n/** The database file, as path segments under the Po home. */\nexport const PO_DB_FILE = ['db', 'po.sqlite'] as const;\n/** Owner-only: the folder holds every package's rows, secrets included. */\nexport const PO_DB_DIRECTORY_MODE = 0o700;\n/** A table prefix: lowercase words joined by single underscores, never sqlite's own namespace. */\nexport const PO_DB_PREFIX_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;\nexport const PO_DB_PREFIX_MAX_LENGTH = 48;\n","import { applySqliteMigrations, type SqliteDatabase, type SqliteExecutor } from '@earendil-works/chord/sqlite';\n\nimport { PO_DB_PREFIX_MAX_LENGTH, PO_DB_PREFIX_PATTERN } from '../../constants/db';\nimport type { CreatePoDbOptions, PoDbHandle, PoDbMigration } from './type';\n\ninterface SchemaObject {\n readonly type: string;\n readonly name: string;\n}\n\n/** sqlite names its own automatic indexes `sqlite_autoindex_*`; nobody owns those. */\nconst SQLITE_INTERNAL = 'sqlite_';\n\nfunction assertPrefix(prefix: string): void {\n if (\n prefix.length > PO_DB_PREFIX_MAX_LENGTH ||\n !PO_DB_PREFIX_PATTERN.test(prefix) ||\n prefix === 'sqlite' ||\n prefix.startsWith(SQLITE_INTERNAL)\n ) {\n throw new Error(`Invalid po-db table prefix ${JSON.stringify(prefix)}.`);\n }\n}\n\nasync function schemaNames(executor: SqliteExecutor): Promise<Set<string>> {\n const rows = await executor.all<SchemaObject>('SELECT type, name FROM sqlite_master');\n return new Set(rows.map((row) => `${row.type}\\0${row.name}`));\n}\n\n/**\n * A view of the shared connection that cannot close it.\n *\n * Consumers such as the calendar store call `close()` on the database they were given. One\n * connection serves every package in the process, so only the owning handle may end it.\n */\nfunction sharedView(database: SqliteDatabase): SqliteDatabase {\n return {\n exec: (sql) => database.exec(sql),\n run: (sql, ...params) => database.run(sql, ...params),\n get: (sql, ...params) => database.get(sql, ...params),\n all: (sql, ...params) => database.all(sql, ...params),\n transaction: (callback) => database.transaction(callback),\n close: async () => undefined,\n };\n}\n\n/**\n * Runs chord's migrator with every transaction it opens checking the schema it leaves.\n *\n * The check runs inside the migration's own transaction, so a migration that creates an\n * object outside its prefix rolls back with everything else it did.\n */\nfunction prefixGuarded(database: SqliteDatabase, prefix: string): SqliteDatabase {\n const owned = `${prefix}_`;\n return {\n ...sharedView(database),\n transaction: (callback) =>\n database.transaction(async (transaction) => {\n const before = await schemaNames(transaction);\n const result = await callback(transaction);\n for (const entry of await schemaNames(transaction)) {\n if (before.has(entry)) continue;\n const [type, name = ''] = entry.split('\\0');\n if (name.startsWith(owned) || name.startsWith(SQLITE_INTERNAL)) continue;\n throw new Error(\n `po-db migration for ${JSON.stringify(prefix)} created ${type} ${JSON.stringify(name)} outside its prefix.`,\n );\n }\n return result;\n }),\n };\n}\n\nexport function createPoDb(options: CreatePoDbOptions): PoDbHandle {\n const { database } = options;\n let closing: Promise<void> | undefined;\n return {\n database: sharedView(database),\n async migrate(prefix: string, migrations: readonly PoDbMigration[]): Promise<void> {\n assertPrefix(prefix);\n await applySqliteMigrations(prefixGuarded(database, prefix), migrations, { table: `${prefix}_migrations` });\n },\n close(): Promise<void> {\n closing ??= database.close();\n return closing;\n },\n };\n}\n"],"mappings":";;AAAA,MAAa,gBAAgB;;AAE7B,MAAa,aAAa,CAAC,MAAM,WAAW;;AAI5C,MAAa,uBAAuB;;;;ACKpC,MAAM,kBAAkB;AAExB,SAAS,aAAa,QAAsB;CAC1C,IACE,OAAO,SAAA,MACP,CAAC,qBAAqB,KAAK,MAAM,KACjC,WAAW,YACX,OAAO,WAAW,eAAe,GAEjC,MAAM,IAAI,MAAM,8BAA8B,KAAK,UAAU,MAAM,EAAE,EAAE;AAE3E;AAEA,eAAe,YAAY,UAAgD;CACzE,MAAM,OAAO,MAAM,SAAS,IAAkB,sCAAsC;CACpF,OAAO,IAAI,IAAI,KAAK,KAAK,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC;AAC9D;;;;;;;AAQA,SAAS,WAAW,UAA0C;CAC5D,OAAO;EACL,OAAO,QAAQ,SAAS,KAAK,GAAG;EAChC,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,cAAc,aAAa,SAAS,YAAY,QAAQ;EACxD,OAAO,YAAY,KAAA;CACrB;AACF;;;;;;;AAQA,SAAS,cAAc,UAA0B,QAAgC;CAC/E,MAAM,QAAQ,GAAG,OAAO;CACxB,OAAO;EACL,GAAG,WAAW,QAAQ;EACtB,cAAc,aACZ,SAAS,YAAY,OAAO,gBAAgB;GAC1C,MAAM,SAAS,MAAM,YAAY,WAAW;GAC5C,MAAM,SAAS,MAAM,SAAS,WAAW;GACzC,KAAK,MAAM,SAAS,MAAM,YAAY,WAAW,GAAG;IAClD,IAAI,OAAO,IAAI,KAAK,GAAG;IACvB,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,MAAM,IAAI;IAC1C,IAAI,KAAK,WAAW,KAAK,KAAK,KAAK,WAAW,eAAe,GAAG;IAChE,MAAM,IAAI,MACR,uBAAuB,KAAK,UAAU,MAAM,EAAE,WAAW,KAAK,GAAG,KAAK,UAAU,IAAI,EAAE,qBACxF;GACF;GACA,OAAO;EACT,CAAC;CACL;AACF;AAEA,SAAgB,WAAW,SAAwC;CACjE,MAAM,EAAE,aAAa;CACrB,IAAI;CACJ,OAAO;EACL,UAAU,WAAW,QAAQ;EAC7B,MAAM,QAAQ,QAAgB,YAAqD;GACjF,aAAa,MAAM;GACnB,OAAA,GAAMA,6BAAAA,sBAAAA,CAAsB,cAAc,UAAU,MAAM,GAAG,YAAY,EAAE,OAAO,GAAG,OAAO,aAAa,CAAC;EAC5G;EACA,QAAuB;GACrB,YAAY,SAAS,MAAM;GAC3B,OAAO;EACT;CACF;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"poDb-D6K38Gpu.mjs","names":[],"sources":["../src/constants/db.ts","../src/services/poDb/index.ts"],"sourcesContent":["export const PO_DB_SERVICE = 'po/db';\n/** The database file, as path segments under the Po home. */\nexport const PO_DB_FILE = ['db', 'po.sqlite'] as const;\n/** Owner-only: the folder holds every package's rows, secrets included. */\nexport const PO_DB_DIRECTORY_MODE = 0o700;\n/** A table prefix: lowercase words joined by single underscores, never sqlite's own namespace. */\nexport const PO_DB_PREFIX_PATTERN = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;\nexport const PO_DB_PREFIX_MAX_LENGTH = 48;\n","import { applySqliteMigrations, type SqliteDatabase, type SqliteExecutor } from '@earendil-works/chord/sqlite';\n\nimport { PO_DB_PREFIX_MAX_LENGTH, PO_DB_PREFIX_PATTERN } from '../../constants/db';\nimport type { CreatePoDbOptions, PoDbHandle, PoDbMigration } from './type';\n\ninterface SchemaObject {\n readonly type: string;\n readonly name: string;\n}\n\n/** sqlite names its own automatic indexes `sqlite_autoindex_*`; nobody owns those. */\nconst SQLITE_INTERNAL = 'sqlite_';\n\nfunction assertPrefix(prefix: string): void {\n if (\n prefix.length > PO_DB_PREFIX_MAX_LENGTH ||\n !PO_DB_PREFIX_PATTERN.test(prefix) ||\n prefix === 'sqlite' ||\n prefix.startsWith(SQLITE_INTERNAL)\n ) {\n throw new Error(`Invalid po-db table prefix ${JSON.stringify(prefix)}.`);\n }\n}\n\nasync function schemaNames(executor: SqliteExecutor): Promise<Set<string>> {\n const rows = await executor.all<SchemaObject>('SELECT type, name FROM sqlite_master');\n return new Set(rows.map((row) => `${row.type}\\0${row.name}`));\n}\n\n/**\n * A view of the shared connection that cannot close it.\n *\n * Consumers such as the calendar store call `close()` on the database they were given. One\n * connection serves every package in the process, so only the owning handle may end it.\n */\nfunction sharedView(database: SqliteDatabase): SqliteDatabase {\n return {\n exec: (sql) => database.exec(sql),\n run: (sql, ...params) => database.run(sql, ...params),\n get: (sql, ...params) => database.get(sql, ...params),\n all: (sql, ...params) => database.all(sql, ...params),\n transaction: (callback) => database.transaction(callback),\n close: async () => undefined,\n };\n}\n\n/**\n * Runs chord's migrator with every transaction it opens checking the schema it leaves.\n *\n * The check runs inside the migration's own transaction, so a migration that creates an\n * object outside its prefix rolls back with everything else it did.\n */\nfunction prefixGuarded(database: SqliteDatabase, prefix: string): SqliteDatabase {\n const owned = `${prefix}_`;\n return {\n ...sharedView(database),\n transaction: (callback) =>\n database.transaction(async (transaction) => {\n const before = await schemaNames(transaction);\n const result = await callback(transaction);\n for (const entry of await schemaNames(transaction)) {\n if (before.has(entry)) continue;\n const [type, name = ''] = entry.split('\\0');\n if (name.startsWith(owned) || name.startsWith(SQLITE_INTERNAL)) continue;\n throw new Error(\n `po-db migration for ${JSON.stringify(prefix)} created ${type} ${JSON.stringify(name)} outside its prefix.`,\n );\n }\n return result;\n }),\n };\n}\n\nexport function createPoDb(options: CreatePoDbOptions): PoDbHandle {\n const { database } = options;\n let closing: Promise<void> | undefined;\n return {\n database: sharedView(database),\n async migrate(prefix: string, migrations: readonly PoDbMigration[]): Promise<void> {\n assertPrefix(prefix);\n await applySqliteMigrations(prefixGuarded(database, prefix), migrations, { table: `${prefix}_migrations` });\n },\n close(): Promise<void> {\n closing ??= database.close();\n return closing;\n },\n };\n}\n"],"mappings":";;AAAA,MAAa,gBAAgB;;AAE7B,MAAa,aAAa,CAAC,MAAM,WAAW;;AAI5C,MAAa,uBAAuB;;;;ACKpC,MAAM,kBAAkB;AAExB,SAAS,aAAa,QAAsB;CAC1C,IACE,OAAO,SAAA,MACP,CAAC,qBAAqB,KAAK,MAAM,KACjC,WAAW,YACX,OAAO,WAAW,eAAe,GAEjC,MAAM,IAAI,MAAM,8BAA8B,KAAK,UAAU,MAAM,EAAE,EAAE;AAE3E;AAEA,eAAe,YAAY,UAAgD;CACzE,MAAM,OAAO,MAAM,SAAS,IAAkB,sCAAsC;CACpF,OAAO,IAAI,IAAI,KAAK,KAAK,QAAQ,GAAG,IAAI,KAAK,IAAI,IAAI,MAAM,CAAC;AAC9D;;;;;;;AAQA,SAAS,WAAW,UAA0C;CAC5D,OAAO;EACL,OAAO,QAAQ,SAAS,KAAK,GAAG;EAChC,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,MAAM,KAAK,GAAG,WAAW,SAAS,IAAI,KAAK,GAAG,MAAM;EACpD,cAAc,aAAa,SAAS,YAAY,QAAQ;EACxD,OAAO,YAAY,KAAA;CACrB;AACF;;;;;;;AAQA,SAAS,cAAc,UAA0B,QAAgC;CAC/E,MAAM,QAAQ,GAAG,OAAO;CACxB,OAAO;EACL,GAAG,WAAW,QAAQ;EACtB,cAAc,aACZ,SAAS,YAAY,OAAO,gBAAgB;GAC1C,MAAM,SAAS,MAAM,YAAY,WAAW;GAC5C,MAAM,SAAS,MAAM,SAAS,WAAW;GACzC,KAAK,MAAM,SAAS,MAAM,YAAY,WAAW,GAAG;IAClD,IAAI,OAAO,IAAI,KAAK,GAAG;IACvB,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,MAAM,IAAI;IAC1C,IAAI,KAAK,WAAW,KAAK,KAAK,KAAK,WAAW,eAAe,GAAG;IAChE,MAAM,IAAI,MACR,uBAAuB,KAAK,UAAU,MAAM,EAAE,WAAW,KAAK,GAAG,KAAK,UAAU,IAAI,EAAE,qBACxF;GACF;GACA,OAAO;EACT,CAAC;CACL;AACF;AAEA,SAAgB,WAAW,SAAwC;CACjE,MAAM,EAAE,aAAa;CACrB,IAAI;CACJ,OAAO;EACL,UAAU,WAAW,QAAQ;EAC7B,MAAM,QAAQ,QAAgB,YAAqD;GACjF,aAAa,MAAM;GACnB,MAAM,sBAAsB,cAAc,UAAU,MAAM,GAAG,YAAY,EAAE,OAAO,GAAG,OAAO,aAAa,CAAC;EAC5G;EACA,QAAuB;GACrB,YAAY,SAAS,MAAM;GAC3B,OAAO;EACT;CACF;AACF"}