@jini-ai/db 0.7.3-next.3 → 0.7.4

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.7.4
2
+
3
+ ### Changes
4
+
5
+ - Add an exclusive idle turn for single-connection kernels, typed mutation actors, and reusable database operation exports.
6
+ - Keep the original feature-connection error while closing both kernel logs, and refuse restore confirmation without a token.
7
+
1
8
  ## 0.7.2
2
9
 
3
10
  ### Patch Changes
package/README.md CHANGED
@@ -11,7 +11,7 @@ subpaths as deprecated re-export shims for one release; import db directly in ne
11
11
  | `./pglite` | Owner process, owner lock, private socket paths, low-memory settings, `PgliteSocketServer`, `PgliteClass` | Nothing |
12
12
  | `./postgres` | Structural pool/module types and `pgTypesFor` | Nothing |
13
13
  | `./kernel` | `StorageKernel`, `buildKernel`, `TurnLock`, dialect helpers, schema introspection and type generation, `StorageOps`, errors, `postgresLockKey` | `kysely` |
14
- | `./kernel/sqlite` | `sqliteKernel`, file/memory kernels, connection lookup/close, `sqliteOps` | `kysely` |
14
+ | `./kernel/sqlite` | `sqliteKernel`, file/memory kernels, connection lookup/close, `sqliteOps`, synchronous ledger/column/text reads and quick checks | `kysely` |
15
15
  | `./kernel/pglite` | `openPgliteKernel`, `PgKernel`, `PgliteDialect`, `pgliteOps`, served-data copy and restore types | `kysely` |
16
16
  | `./kernel/postgres` | `openPostgresKernel`, `openPgliteSocketKernel`, `postgresOps` | `kysely` |
17
17
  | `./migrate` | `runMigrations`, `assertValidSteps`, `hasLedger`, `sourceChecksum`, step/error types | `kysely` |
@@ -23,6 +23,25 @@ There is no `.` export. Each part loads only its own files and its explicitly sh
23
23
  The connection subpaths load no optional peer. Kernels need Kysely at load time, but all drivers
24
24
  are injected when a connection is opened. Transfer and database tools have their own isolated subpaths.
25
25
 
26
+ `@jini-ai/db/kernel/sqlite` also exports synchronous operations for callers that must stay
27
+ inside a synchronous admission lock:
28
+
29
+ - `readSqliteMigrationLedger({ open, path, table })` opens an existing file read-only, returns
30
+ validated `{ id, checksum }` rows ordered by `applied_at, id`, and always closes the handle.
31
+ - `sqliteHasColumn({ client, table, column })` probes a borrowed handle with bound names.
32
+ - `readSqliteTextColumn({ client, table, column })` quotes both identifiers and returns every
33
+ text value, including duplicates and empty strings, with no ordering promise. Missing columns
34
+ and non-text values refuse. The host filters empty references and owns closing the handle.
35
+ - `quickCheckSqlite({ open, path })` checks an existing file read-only and closes it.
36
+ `quickCheckSqlite({ client }, { maxErrors: 1 })` checks a borrowed handle without closing it.
37
+ Only one exact `ok` result succeeds; open/read failures throw redacted errors for the host's
38
+ existing refusal policy to translate. `maxErrors`, when set, must be a positive 32-bit integer.
39
+
40
+ The structural `SqliteReadClient`, `SqliteReadonlyOpener`, `SqliteMigrationLedgerEntry`, and
41
+ `SqliteQuickCheckSource` types are exported from that same entry. No driver is imported.
42
+ `openSqliteConnection` at `@jini-ai/db/sqlite` applies the caller's pragma list in its supplied
43
+ order and closes the newly opened handle on any pragma failure before rethrowing that failure.
44
+
26
45
  Each JavaScript subpath declares `types`, `import` and `default` export conditions.
27
46
  The `default` condition points to the same ESM file as `import`, so loaders such as
28
47
  the tsx CommonJS bootstrap can resolve the subpaths without an active `import` condition.
@@ -1,5 +1,5 @@
1
1
  /** Kysely's SQLite binding and kernel storage operations. */
2
2
  export { sqliteKernel, openSqliteFileKernel, openMemorySqliteKernel, closeSqliteConnection, sqliteClientOf, sqliteConnectionOf, type SqliteConnectionSource, type SqliteKernel } from "./driver.js";
3
- export { sqliteOps, copySqliteInto } from "./ops.js";
3
+ export { sqliteOps, copySqliteInto, readSqliteMigrationLedger, sqliteHasColumn, readSqliteTextColumn, quickCheckSqlite, type SqliteReadClient, type SqliteReadonlyOpener, type SqliteMigrationLedgerEntry, type SqliteQuickCheckSource } from "./ops.js";
4
4
  export { sqliteForeignKeyCheckedTransaction, sqliteSchemaObjects, sqliteTableExtendedInfo, sqliteTableInfo, type SqliteExtendedTableColumn, type SqliteForeignKeyViolation, type SqliteSchemaObject, type SqliteTableColumn } from "./sqlite-only.js";
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  /** Kysely's SQLite binding and kernel storage operations. */
2
2
  export { sqliteKernel, openSqliteFileKernel, openMemorySqliteKernel, closeSqliteConnection, sqliteClientOf, sqliteConnectionOf } from "./driver.js";
3
- export { sqliteOps, copySqliteInto } from "./ops.js";
3
+ export { sqliteOps, copySqliteInto, readSqliteMigrationLedger, sqliteHasColumn, readSqliteTextColumn, quickCheckSqlite } from "./ops.js";
4
4
  export { sqliteForeignKeyCheckedTransaction, sqliteSchemaObjects, sqliteTableExtendedInfo, sqliteTableInfo } from "./sqlite-only.js";
5
5
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,65 @@
1
1
  import { type KyselyKernel, type StorageOps } from "../index.js";
2
+ /** Minimal borrowed synchronous read handle; the caller keeps ownership. */
3
+ export interface SqliteReadClient {
4
+ prepare(source: string): {
5
+ all(...parameters: unknown[]): unknown[];
6
+ };
7
+ }
8
+ /** Host-owned driver acquisition; these operations never create a missing database. */
9
+ export type SqliteReadonlyOpener = (path: string, options: {
10
+ readonly: true;
11
+ fileMustExist: true;
12
+ }) => SqliteReadClient & {
13
+ close(): unknown;
14
+ };
15
+ export interface SqliteMigrationLedgerEntry {
16
+ id: string;
17
+ checksum: string;
18
+ }
19
+ /** Read a stopped file's ledger in applied_at, id order; validate every id/checksum and close.
20
+ * The host decides whether the returned steps belong to its migration history.
21
+ * @throws A redacted error on open/read/close failure or a malformed ledger row.
22
+ * @complexity O(n log n) database ordering and O(n) result storage.
23
+ */
24
+ export declare function readSqliteMigrationLedger({ open, path, table }: {
25
+ open: SqliteReadonlyOpener;
26
+ path: string;
27
+ table: string;
28
+ }, _optional?: {}): SqliteMigrationLedgerEntry[];
29
+ /** Synchronous column-presence probe on a borrowed handle; names are bound as values.
30
+ * @throws A redacted error on read failure. A missing table/column returns false.
31
+ * @complexity O(columns) catalog scan; no writes or connection lifecycle changes.
32
+ */
33
+ export declare function sqliteHasColumn({ client, table, column }: {
34
+ client: SqliteReadClient;
35
+ table: string;
36
+ column: string;
37
+ }, _optional?: {}): boolean;
38
+ /** Project a text column on a borrowed handle, preserving duplicates and empty strings.
39
+ * Each name is quoted as one identifier, never a SQL fragment. Hosts filter empty references.
40
+ * @throws A redacted error on missing tables/columns, non-text values or read failure.
41
+ * @complexity O(rows) time and result storage. No ordering is promised.
42
+ */
43
+ export declare function readSqliteTextColumn({ client, table, column }: {
44
+ client: SqliteReadClient;
45
+ table: string;
46
+ column: string;
47
+ }, _optional?: {}): string[];
48
+ /** A borrowed handle, or an owned read-only file opened and closed for this check. */
49
+ export type SqliteQuickCheckSource = {
50
+ client: SqliteReadClient;
51
+ } | {
52
+ open: SqliteReadonlyOpener;
53
+ path: string;
54
+ };
55
+ /** True only for SQLite's single exact 'ok' result. The optional limit bounds reported errors.
56
+ * Borrowed handles stay open; file sources use readonly + fileMustExist and always close.
57
+ * @throws A redacted error on open/read/close failure or an invalid limit. Hosts map refusals.
58
+ * @complexity O(database pages) SQLite work, O(reported errors) result storage.
59
+ */
60
+ export declare function quickCheckSqlite(source: SqliteQuickCheckSource, { maxErrors }?: {
61
+ maxErrors?: number;
62
+ }): boolean;
2
63
  /** Synchronous WAL-safe snapshot for admission code that must commit under a synchronous lock.
3
64
  * Accepts either the host's SQLite client or Node's built-in DatabaseSync; the caller owns it.
4
65
  * @throws SQLite errors, including an existing destination or an active transaction.
@@ -1,5 +1,87 @@
1
1
  import { outsideTransactionOf, StorageOpError } from "../index.js";
2
2
  import { sqliteConnectionOf } from "./driver.js";
3
+ function sqliteIdentifier({ name }, _optional = {}) {
4
+ if (name.length === 0 || name.includes("\0"))
5
+ throw new Error("A SQLite identifier must be non-empty and contain no null characters.");
6
+ return `"${name.replaceAll('"', '""')}"`;
7
+ }
8
+ function sqliteRow({ value }, _optional = {}) {
9
+ return typeof value === "object" && value !== null ? value : null;
10
+ }
11
+ function readRows({ client, statement }, { parameters = [] } = {}) {
12
+ try {
13
+ return client.prepare(statement).all(...parameters);
14
+ }
15
+ // Driver diagnostics may contain file paths or row contents. Hosts supply their own refusal.
16
+ catch {
17
+ throw new Error("The SQLite database could not be read.");
18
+ }
19
+ }
20
+ function readOwnedRows({ open, path, statement }, _optional = {}) {
21
+ try {
22
+ const client = open(path, { readonly: true, fileMustExist: true });
23
+ try {
24
+ return readRows({ client, statement });
25
+ }
26
+ finally {
27
+ client.close();
28
+ }
29
+ }
30
+ catch {
31
+ throw new Error("The SQLite database could not be read.");
32
+ }
33
+ }
34
+ /** Read a stopped file's ledger in applied_at, id order; validate every id/checksum and close.
35
+ * The host decides whether the returned steps belong to its migration history.
36
+ * @throws A redacted error on open/read/close failure or a malformed ledger row.
37
+ * @complexity O(n log n) database ordering and O(n) result storage.
38
+ */
39
+ export function readSqliteMigrationLedger({ open, path, table }, _optional = {}) {
40
+ const statement = `SELECT id, checksum FROM ${sqliteIdentifier({ name: table })} ORDER BY applied_at, id`;
41
+ return readOwnedRows({ open, path, statement }).map(row => {
42
+ const value = sqliteRow({ value: row });
43
+ if (typeof value?.id !== "string" || typeof value.checksum !== "string") {
44
+ throw new Error("The SQLite migration ledger contains an invalid row.");
45
+ }
46
+ return { id: value.id, checksum: value.checksum };
47
+ });
48
+ }
49
+ /** Synchronous column-presence probe on a borrowed handle; names are bound as values.
50
+ * @throws A redacted error on read failure. A missing table/column returns false.
51
+ * @complexity O(columns) catalog scan; no writes or connection lifecycle changes.
52
+ */
53
+ export function sqliteHasColumn({ client, table, column }, _optional = {}) {
54
+ const statement = "SELECT 1 FROM pragma_table_info(?) WHERE name = ?";
55
+ return readRows({ client, statement }, { parameters: [table, column] }).length > 0;
56
+ }
57
+ /** Project a text column on a borrowed handle, preserving duplicates and empty strings.
58
+ * Each name is quoted as one identifier, never a SQL fragment. Hosts filter empty references.
59
+ * @throws A redacted error on missing tables/columns, non-text values or read failure.
60
+ * @complexity O(rows) time and result storage. No ordering is promised.
61
+ */
62
+ export function readSqliteTextColumn({ client, table, column }, _optional = {}) {
63
+ // Qualifying the column prevents SQLite's legacy double-quoted-string fallback for a typo.
64
+ const statement = `SELECT source.${sqliteIdentifier({ name: column })} AS value FROM ${sqliteIdentifier({ name: table })} AS source`;
65
+ return readRows({ client, statement }).map(row => {
66
+ const value = sqliteRow({ value: row });
67
+ if (typeof value?.value !== "string")
68
+ throw new Error("The SQLite text column contains an invalid value.");
69
+ return value.value;
70
+ });
71
+ }
72
+ /** True only for SQLite's single exact 'ok' result. The optional limit bounds reported errors.
73
+ * Borrowed handles stay open; file sources use readonly + fileMustExist and always close.
74
+ * @throws A redacted error on open/read/close failure or an invalid limit. Hosts map refusals.
75
+ * @complexity O(database pages) SQLite work, O(reported errors) result storage.
76
+ */
77
+ export function quickCheckSqlite(source, { maxErrors } = {}) {
78
+ if (maxErrors !== undefined && (!Number.isInteger(maxErrors) || maxErrors < 1 || maxErrors > 2_147_483_647)) {
79
+ throw new Error("The SQLite quick-check error limit must be a positive 32-bit integer.");
80
+ }
81
+ const statement = maxErrors === undefined ? "PRAGMA quick_check" : `PRAGMA quick_check(${maxErrors})`;
82
+ const rows = "client" in source ? readRows({ client: source.client, statement }) : readOwnedRows({ ...source, statement });
83
+ return rows.length === 1 && sqliteRow({ value: rows[0] })?.quick_check === "ok";
84
+ }
3
85
  /** Synchronous WAL-safe snapshot for admission code that must commit under a synchronous lock.
4
86
  * Accepts either the host's SQLite client or Node's built-in DatabaseSync; the caller owns it.
5
87
  * @throws SQLite errors, including an existing destination or an active transaction.
@@ -39,8 +39,8 @@ export declare function assertValidSteps({ steps }: {
39
39
  steps: readonly MigrationStep<KyselyKernel<unknown>>[];
40
40
  }, _optional?: Record<string, never>): void;
41
41
  /** Object-input facade over the existing runner; all extensions remain opt-in. */
42
- export declare function migrate(required: {
43
- kernel: KyselyKernel<unknown>;
42
+ export declare function migrate<DB>(required: {
43
+ kernel: KyselyKernel<DB>;
44
44
  steps: readonly MigrationStep<KyselyKernel<unknown>>[];
45
45
  ledgerTable: string;
46
46
  }, optional?: Omit<MigrationOptions, "ledgerTable">): Promise<MigrationReport>;
@@ -52,7 +52,7 @@ export declare function migrate(required: {
52
52
  * @throws UnknownAppliedMigrationError / MigrationChecksumError before applying anything; whatever a
53
53
  * step throws (its transaction is rolled back, later steps are not attempted).
54
54
  */
55
- export declare function runMigrations(kernel: KyselyKernel<unknown>, steps: readonly MigrationStep<KyselyKernel<unknown>>[], options: MigrationOptions): Promise<MigrationReport>;
55
+ export declare function runMigrations<DB>(typedKernel: KyselyKernel<DB>, steps: readonly MigrationStep<KyselyKernel<unknown>>[], options: MigrationOptions): Promise<MigrationReport>;
56
56
  /** True when `kernel`'s database has the ledger `ledgerTable` (it has been through {@link runMigrations}). */
57
57
  export declare function hasLedger({ kernel, ledgerTable }: {
58
58
  kernel: KyselyKernel<unknown>;
@@ -140,7 +140,10 @@ export function migrate(required, optional = {}) {
140
140
  * @throws UnknownAppliedMigrationError / MigrationChecksumError before applying anything; whatever a
141
141
  * step throws (its transaction is rolled back, later steps are not attempted).
142
142
  */
143
- export async function runMigrations(kernel, steps, options) {
143
+ export async function runMigrations(typedKernel, steps, options) {
144
+ // Histories use schema-independent steps; erase only the table view and retain kernel identity
145
+ // so transaction ownership and the runner's private ledger view keep using the same connection.
146
+ const kernel = typedKernel;
144
147
  assertValidSteps({ steps });
145
148
  kernel.require("interactiveTransactions");
146
149
  validateExtensions({ options, steps });
@@ -8,7 +8,7 @@ export { ownerStoreDdl, ownerStoreMigration } from "./migrations/0000_owner_stor
8
8
  * @example const { entries, grants } = await countOwnerStoreRows({ kernel });
9
9
  */
10
10
  export async function countOwnerStoreRows({ kernel }, _options = {}) {
11
- const count = (table) => kernel.run(async (db) => Number((await db.selectFrom(table).select(eb => eb.fn.countAll().as("n")).executeTakeFirst())?.n ?? 0));
11
+ const count = (table) => kernel.run(async (db) => Number((await db.selectFrom(table).select(eb => eb.fn.countAll().as("n")).executeTakeFirstOrThrow()).n));
12
12
  return { entries: await count("secrets_vault"), grants: await count("owner_grants") };
13
13
  }
14
14
  /** The sealed entries of one workspace, in id order. The caller passes the legacy owner workspace.
@@ -1,5 +1,5 @@
1
1
  import { toolMetadata } from '@jini-ai/core/tool-metadata/database';
2
- import { AGENT_TOOL_PRINCIPAL_KIND, buildDomainRegistrations, indexCatalogById, isRecord, optionalBoolean, optionalNumber, optionalString, requireInputRecord, requireString, requireNoInput } from "@jini-ai/core";
2
+ import { AGENT_TOOL_PRINCIPAL_KIND, buildDomainRegistrations, indexCatalogById, isRecord, optionalBoolean, optionalString, requireInputRecord, requireString, requireNoInput } from "@jini-ai/core";
3
3
  import { requireToolPermission } from "@jini-ai/core";
4
4
  import {} from "@jini-ai/core/contracts/events";
5
5
  // `ToolInputError` specifically — the marker `@jini-ai/daemon`'s `ToolExecutor` reads to tag a
@@ -179,7 +179,6 @@ const databaseInputReaders = {
179
179
  isRecord: (input) => isRecord({ value: input }), inputRecord: input => requireInputRecord({ input }), noInput: input => requireNoInput({ input }),
180
180
  string: (input, key) => requireString({ input, key }),
181
181
  optionalString: (input, key) => optionalString({ input, key }),
182
- optionalNumber: (input, key) => optionalNumber({ input, key }),
183
182
  optionalBoolean: (input, key) => optionalBoolean({ input, key }),
184
183
  };
185
184
  //# sourceMappingURL=tool-registrations.js.map
@@ -62,9 +62,10 @@ export function verifyRewrite({ db, alreadyConverted }) {
62
62
  const [checkpoint] = db.pragma('wal_checkpoint(TRUNCATE)');
63
63
  if (checkpoint === undefined || checkpoint.busy !== 0)
64
64
  return `final WAL checkpoint reported busy=${checkpoint?.busy}`;
65
- const [integrity] = db.pragma('integrity_check');
66
- if (integrity?.integrity_check !== 'ok')
67
- return `integrity_check: ${integrity?.integrity_check ?? 'no answer'}`;
65
+ // SQLite integrity_check returns at least one row: "ok" or corruption details.
66
+ const [{ integrity_check: integrity }] = db.pragma('integrity_check');
67
+ if (integrity !== 'ok')
68
+ return `integrity_check: ${integrity}`;
68
69
  const mode = db.pragma('auto_vacuum', { simple: true });
69
70
  if (mode !== 2)
70
71
  return `auto_vacuum reads ${String(mode)} after the rewrite`;
@@ -96,18 +96,17 @@ export class SqliteDbOpsAdapter {
96
96
  * @complexity O(c) metadata operations for c collisions; no database bytes are copied here.
97
97
  */
98
98
  async function reserveRestorePoint(required, _options = {}) {
99
- for (let timestamp = required.timestamp;; timestamp++) {
100
- const artifactRef = path.join(required.targetDir, restorePointFilename({ ...required, timestamp }));
101
- try {
102
- const reservation = await fs.open(artifactRef, 'wx', 0o600);
103
- await reservation.close();
104
- return artifactRef;
105
- }
106
- catch (error) {
107
- if (error instanceof Error && 'code' in error && error.code === 'EEXIST')
108
- continue;
109
- throw error;
99
+ const artifactRef = path.join(required.targetDir, restorePointFilename(required));
100
+ try {
101
+ const reservation = await fs.open(artifactRef, 'wx', 0o600);
102
+ await reservation.close();
103
+ return artifactRef;
104
+ }
105
+ catch (error) {
106
+ if (error instanceof Error && 'code' in error && error.code === 'EEXIST') {
107
+ return reserveRestorePoint({ ...required, timestamp: required.timestamp + 1 });
110
108
  }
109
+ throw error;
111
110
  }
112
111
  }
113
112
  //# sourceMappingURL=db-ops.js.map
@@ -49,7 +49,8 @@ export declare const DEFAULT_PRAGMAS: readonly string[];
49
49
  * Opens (or creates) a SQLite database and applies pragmas.
50
50
  *
51
51
  * Returns the exact handle supplied by the injected `open`, preserving its structural type.
52
- * Recovery runs before opening; pragma policy runs immediately afterwards.
52
+ * Recovery runs before opening; pragma policy runs immediately afterwards. A pragma failure
53
+ * closes the partially configured handle; successful calls transfer ownership to the caller.
53
54
  * @throws Any error from the recovery hook, opener, or pragma application.
54
55
  * @complexity O(p) calls for p pragmas; storage costs belong to the injected driver.
55
56
  */
@@ -28,16 +28,26 @@ export const DEFAULT_PRAGMAS = [
28
28
  * Opens (or creates) a SQLite database and applies pragmas.
29
29
  *
30
30
  * Returns the exact handle supplied by the injected `open`, preserving its structural type.
31
- * Recovery runs before opening; pragma policy runs immediately afterwards.
31
+ * Recovery runs before opening; pragma policy runs immediately afterwards. A pragma failure
32
+ * closes the partially configured handle; successful calls transfer ownership to the caller.
32
33
  * @throws Any error from the recovery hook, opener, or pragma application.
33
34
  * @complexity O(p) calls for p pragmas; storage costs belong to the injected driver.
34
35
  */
35
36
  export function openSqliteConnection(required, options = {}) {
36
37
  options.recover?.({ filePath: required.filePath }, {});
37
38
  const connection = required.open({ filePath: required.filePath }, {});
38
- for (const pragma of options.pragmas ?? DEFAULT_PRAGMAS) {
39
- connection.pragma(pragma);
39
+ try {
40
+ for (const pragma of options.pragmas ?? DEFAULT_PRAGMAS)
41
+ connection.pragma(pragma);
42
+ return connection;
43
+ }
44
+ catch (error) {
45
+ // Preserve the setup failure even if cleanup also fails; the caller never received this handle.
46
+ try {
47
+ connection.close();
48
+ }
49
+ catch { /* Best effort: the original setup failure remains actionable. */ }
50
+ throw error;
40
51
  }
41
- return connection;
42
52
  }
43
53
  //# sourceMappingURL=open.js.map
@@ -12,7 +12,7 @@ export interface DatabasePermissionRequest {
12
12
  }
13
13
  export interface DatabaseReadToolPorts {
14
14
  workspaceId: string;
15
- readers: InputReaders;
15
+ readers: Pick<InputReaders, "isRecord" | "noInput" | "optionalString" | "optionalBoolean"> & Partial<InputReaders>;
16
16
  requirePermission(request: DatabasePermissionRequest): Promise<void>;
17
17
  introspection: {
18
18
  getHealth(): Promise<unknown>;
@@ -83,9 +83,7 @@ export function topologicalTableCopyOrder({ allExportNames, edges }, _optional =
83
83
  const order = [];
84
84
  const remaining = new Map(inDegree);
85
85
  while (ready.length) {
86
- const next = ready.shift(); // already sorted; shifting keeps output deterministic
87
- if (next === undefined)
88
- throw new Error("table copy order has an empty ready queue");
86
+ const next = ready.shift(); // Nonempty and sorted; shifting keeps output deterministic.
89
87
  order.push(next);
90
88
  for (const dependent of dependents.get(next) ?? []) {
91
89
  const updated = (remaining.get(dependent) ?? 0) - 1;
@@ -37,6 +37,20 @@ export declare class DestinationUnreadableError extends Error {
37
37
  * `findDefault`: 0012 copied legacy rows with is_default=false (the old table had no such column),
38
38
  * and a default-only read made an upgraded site's destination invisible (parity finding R1). */
39
39
  export type DatabaseDestinationRepoPort = VaultRepoPort & Required<Pick<VaultRepoPort, "findOne">>;
40
+ /** Refuses a vault context outside the destination's scope (another kind, owner, or any principal).
41
+ * Public since the 0.7 API baseline (`api-baseline/jini-ai__db.json`); an untested extraction
42
+ * snapshot (37eabd5cd0) dropped it, which would break hosts importing it in a patch release. */
43
+ export declare function authorizeDestinationVaultContext({ context, scope }: {
44
+ readonly context: {
45
+ readonly kind: string;
46
+ readonly ownerKey: string;
47
+ readonly principalId: string | null;
48
+ };
49
+ readonly scope: {
50
+ readonly kind: string;
51
+ readonly ownerKey: string;
52
+ };
53
+ }, _options?: {}): Promise<void>;
40
54
  export declare class SealedDatabaseDestinationStore implements DatabaseDestinationStorePort {
41
55
  private readonly deps;
42
56
  constructor(deps: {
@@ -5,6 +5,13 @@ export class DestinationUnreadableError extends Error {
5
5
  super("the saved destination database could not be unlocked (the site's key may have changed); save it again with database_transfer_set_destination");
6
6
  }
7
7
  }
8
+ /** Refuses a vault context outside the destination's scope (another kind, owner, or any principal).
9
+ * Public since the 0.7 API baseline (`api-baseline/jini-ai__db.json`); an untested extraction
10
+ * snapshot (37eabd5cd0) dropped it, which would break hosts importing it in a patch release. */
11
+ export async function authorizeDestinationVaultContext({ context, scope }, _options = {}) {
12
+ if (context.kind !== scope.kind || context.ownerKey !== scope.ownerKey || context.principalId !== null)
13
+ throw new VaultError({ code: "context" });
14
+ }
8
15
  export class SealedDatabaseDestinationStore {
9
16
  deps;
10
17
  constructor(deps, _optional = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/db",
3
- "version": "0.7.3-next.3",
3
+ "version": "0.7.4",
4
4
  "description": "Database ports, connection helpers, ownership, isolated Kysely kernels and migrations. All peers are optional; drivers are injected.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -305,6 +305,9 @@
305
305
  "site/repo.memory": [
306
306
  "./dist/site/repo.memory.d.ts"
307
307
  ],
308
+ "site/tool-registrations": [
309
+ "./dist/site/tool-registrations.d.ts"
310
+ ],
308
311
  "transfer/confirmation-ui": [
309
312
  "./dist/transfer/confirmation-ui.d.ts"
310
313
  ],
@@ -332,7 +335,7 @@
332
335
  },
333
336
  "dependencies": {
334
337
  "kysely": "^0.29.6",
335
- "@jini-ai/core": "^0.7.3-next.3"
338
+ "@jini-ai/core": "^0.7.4"
336
339
  },
337
340
  "peerDependencies": {
338
341
  "better-sqlite3": "^13.0.0",
@@ -355,8 +358,8 @@
355
358
  "@types/react-dom": "^19.2.0",
356
359
  "@testing-library/react": "^16.3.0",
357
360
  "jsdom": "^26.1.0",
358
- "@jini-ai/platform": "0.7.3-next.3",
359
- "@jini-ai/core": "0.7.3-next.3"
361
+ "@jini-ai/platform": "0.7.4",
362
+ "@jini-ai/core": "0.7.4"
360
363
  },
361
364
  "peerDependenciesMeta": {
362
365
  "better-sqlite3": {