@jini-ai/db 0.7.2 → 0.7.3-next.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.
- package/CHANGELOG.md +1 -7
- package/README.md +33 -17
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.js +0 -1
- package/dist/core/pg-types.d.ts +4 -1
- package/dist/core/pg-types.js +1 -1
- package/dist/core/row-values.d.ts +0 -30
- package/dist/core/row-values.js +1 -41
- package/dist/data-modules/data-module.d.ts +260 -4
- package/dist/data-modules/data-module.js +105 -83
- package/dist/data-modules/disk-headroom.js +1 -1
- package/dist/data-modules/index.d.ts +2 -2
- package/dist/data-modules/index.js +2 -2
- package/dist/data-modules/migration-journal.js +6 -6
- package/dist/data-modules/migration-recovery.js +2 -2
- package/dist/data-modules/plugin-identity.js +5 -5
- package/dist/data-modules/plugin-store.d.ts +4 -4
- package/dist/data-modules/restore.js +5 -5
- package/dist/data-modules/snapshot.d.ts +1 -1
- package/dist/data-modules/snapshot.js +3 -3
- package/dist/events/change-set-repo.sql.d.ts +70 -0
- package/dist/events/change-set-repo.sql.js +72 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +3 -0
- package/dist/events/outbox-repo.sql.d.ts +91 -0
- package/dist/events/outbox-repo.sql.js +108 -0
- package/dist/events/repo.rows.d.ts +44 -0
- package/dist/events/repo.rows.js +59 -0
- package/dist/gated-mutations/index.d.ts +3 -0
- package/dist/gated-mutations/index.js +2 -0
- package/dist/gated-mutations/repo.rows.d.ts +19 -0
- package/dist/gated-mutations/repo.rows.js +23 -0
- package/dist/gated-mutations/repo.sql.d.ts +67 -0
- package/dist/gated-mutations/repo.sql.js +71 -0
- package/dist/kernel/dialect.d.ts +53 -31
- package/dist/kernel/dialect.js +14 -36
- package/dist/kernel/index.d.ts +2 -2
- package/dist/kernel/index.js +1 -7
- package/dist/kernel/kernel-core.d.ts +7 -3
- package/dist/kernel/kernel-core.js +75 -66
- package/dist/kernel/ops.d.ts +9 -3
- package/dist/kernel/ops.js +2 -2
- package/dist/kernel/owned-transaction.d.ts +7 -7
- package/dist/kernel/owned-transaction.js +2 -2
- package/dist/kernel/pglite/driver.d.ts +2 -2
- package/dist/kernel/pglite/driver.js +18 -18
- package/dist/kernel/pglite/ops.d.ts +8 -3
- package/dist/kernel/pglite/ops.js +5 -5
- package/dist/kernel/port.d.ts +9 -76
- package/dist/kernel/port.js +1 -10
- package/dist/kernel/postgres/driver.d.ts +4 -2
- package/dist/kernel/postgres/driver.js +17 -17
- package/dist/kernel/postgres/ops.d.ts +5 -3
- package/dist/kernel/postgres/ops.js +3 -3
- package/dist/kernel/postgres/pglite-socket.d.ts +2 -2
- package/dist/kernel/postgres/pglite-socket.js +13 -13
- package/dist/kernel/schema-scope.d.ts +5 -2
- package/dist/kernel/schema-scope.js +1 -1
- package/dist/kernel/schema-shape.d.ts +7 -3
- package/dist/kernel/schema-shape.js +2 -2
- package/dist/kernel/session-lock.d.ts +6 -6
- package/dist/kernel/sqlite/driver.d.ts +16 -8
- package/dist/kernel/sqlite/driver.js +38 -38
- package/dist/kernel/sqlite/index.d.ts +1 -0
- package/dist/kernel/sqlite/index.js +1 -0
- package/dist/kernel/sqlite/ops.d.ts +4 -2
- package/dist/kernel/sqlite/ops.js +3 -3
- package/dist/kernel/sqlite/sqlite-only.d.ts +81 -0
- package/dist/kernel/sqlite/sqlite-only.js +58 -0
- package/dist/kernel/store-copy.d.ts +7 -7
- package/dist/kernel/store-copy.js +22 -14
- package/dist/kernel/typegen.d.ts +5 -3
- package/dist/kernel/typegen.js +1 -1
- package/dist/migrate/checksum.d.ts +3 -1
- package/dist/migrate/checksum.js +1 -1
- package/dist/migrate/index.d.ts +1 -1
- package/dist/migrate/legacy-ledger.d.ts +4 -4
- package/dist/migrate/runner.d.ts +12 -7
- package/dist/migrate/runner.js +7 -6
- package/dist/migrate/step.d.ts +3 -28
- package/dist/migrate/step.js +3 -3
- package/dist/owner-store/index.d.ts +47 -1
- package/dist/owner-store/index.js +28 -1
- package/dist/owner-store/migrations/0000_owner_store.d.ts +3 -2
- package/dist/owner-store/migrations/index.d.ts +1 -1
- package/dist/pglite/owner.d.ts +12 -4
- package/dist/pglite/owner.js +33 -27
- package/dist/pglite/socket-server.d.ts +5 -1
- package/dist/pglite/socket-server.js +5 -4
- package/dist/recovery/deep-link.d.ts +3 -3
- package/dist/recovery/degraded-banners.d.ts +3 -3
- package/dist/recovery/degraded-banners.js +3 -3
- package/dist/recovery/disclosure.d.ts +6 -6
- package/dist/recovery/disclosure.js +6 -6
- package/dist/recovery/evaluate-boot-migration-policy.d.ts +5 -5
- package/dist/recovery/evaluate-boot-migration-policy.js +5 -5
- package/dist/recovery/lookup-adapters.d.ts +1 -1
- package/dist/recovery/lookup-adapters.js +1 -1
- package/dist/recovery/migrate-forward-execute.d.ts +1 -1
- package/dist/recovery/migrate-forward-execute.js +5 -5
- package/dist/recovery/migrate-forward-hooks.d.ts +6 -6
- package/dist/recovery/migrate-forward-hooks.js +5 -5
- package/dist/recovery/operation-lock.d.ts +11 -11
- package/dist/recovery/operation-lock.js +3 -3
- package/dist/recovery/reconcile-interrupted-migration.d.ts +7 -7
- package/dist/recovery/reconcile-interrupted-migration.js +7 -7
- package/dist/recovery/recovery-orchestrator.d.ts +21 -21
- package/dist/recovery/recovery-orchestrator.js +9 -9
- package/dist/recovery/restore-hooks.d.ts +8 -8
- package/dist/recovery/restore-hooks.js +7 -7
- package/dist/recovery/restore-point-create.d.ts +3 -3
- package/dist/secrets-vault/repo.sql.d.ts +3 -3
- package/dist/secrets-vault/repo.sql.js +5 -4
- package/dist/settings/index.d.ts +3 -0
- package/dist/settings/index.js +2 -0
- package/dist/settings/repo.rows.d.ts +117 -0
- package/dist/settings/repo.rows.js +106 -0
- package/dist/settings/repo.sql.d.ts +99 -0
- package/dist/settings/repo.sql.js +219 -0
- package/dist/sqlite/checked-client.d.ts +1 -1
- package/dist/sqlite/checked-state.d.ts +3 -3
- package/dist/sqlite/db-ops.d.ts +1 -1
- package/dist/sqlite/db-ops.js +1 -1
- package/dist/sqlite/index.d.ts +1 -3
- package/dist/sqlite/index.js +2 -0
- package/dist/sqlite/inspect.d.ts +2 -2
- package/dist/sqlite/inspect.js +1 -1
- package/dist/sqlite/open.d.ts +1 -2
- package/dist/sqlite/stopped.d.ts +46 -0
- package/dist/sqlite/stopped.js +86 -0
- package/dist/sqlite/transaction.d.ts +2 -2
- package/dist/tools/database-catalog.d.ts +2 -2
- package/dist/tools/database-catalog.js +13 -3
- package/dist/tools/read-tools.js +70 -59
- package/dist/tools/restore-points.d.ts +1 -1
- package/dist/tools/transfer-tools.d.ts +0 -1
- package/dist/tools/transfer-tools.js +5 -4
- package/dist/transfer/copy-engine.js +10 -10
- package/dist/transfer/copy-order.d.ts +47 -0
- package/dist/transfer/copy-order.js +103 -0
- package/dist/transfer/index.d.ts +1 -0
- package/dist/transfer/index.js +1 -0
- package/dist/transfer/internal-ddl.d.ts +28 -6
- package/dist/transfer/internal-ddl.js +15 -15
- package/dist/transfer/postgres-ddl.js +6 -6
- package/dist/transfer/sqlite-source.d.ts +2 -3
- package/dist/transfer/sqlite-source.js +1 -1
- package/dist/verified-origin/index.d.ts +4 -0
- package/dist/verified-origin/index.js +3 -0
- package/dist/verified-origin/register.d.ts +43 -0
- package/dist/verified-origin/register.js +51 -0
- package/dist/verified-origin/repo.rows.d.ts +42 -0
- package/dist/verified-origin/repo.rows.js +47 -0
- package/dist/verified-origin/repo.sql.d.ts +67 -0
- package/dist/verified-origin/repo.sql.js +34 -0
- package/package.json +38 -11
- package/dist/sqlite/restore-types.d.ts +0 -46
- package/dist/sqlite/restore-types.js +0 -2
- package/dist/sqlite/sync-types.d.ts +0 -34
- package/dist/sqlite/sync-types.js +0 -2
- package/dist/sqlite/types.d.ts +0 -37
- package/dist/sqlite/types.js +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
## 0.7.2
|
|
2
|
-
|
|
3
|
-
### Patch Changes
|
|
4
|
-
|
|
5
|
-
- @jini-ai/core@0.7.2
|
|
6
|
-
|
|
7
1
|
## 0.7.1
|
|
8
2
|
|
|
9
3
|
### Patch Changes
|
|
@@ -134,7 +128,7 @@
|
|
|
134
128
|
|
|
135
129
|
## 0.3.1 — 2026-10-08
|
|
136
130
|
|
|
137
|
-
-
|
|
131
|
+
- Host clean-up release: code the first host moved into Jini, plus the Jini clean-up (see the commit log).
|
|
138
132
|
|
|
139
133
|
## 0.3.0 — 2026-10-05
|
|
140
134
|
|
package/README.md
CHANGED
|
@@ -29,14 +29,29 @@ the tsx CommonJS bootstrap can resolve the subpaths without an active `import` c
|
|
|
29
29
|
|
|
30
30
|
## Import and driver isolation
|
|
31
31
|
|
|
32
|
-
`@jini-ai/db/secrets-vault`
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`
|
|
39
|
-
|
|
32
|
+
`@jini-ai/db/secrets-vault` takes its credential validation and error contracts from `@jini-ai/core/contracts/vault`
|
|
33
|
+
(plus Kysely for SQL); it no longer needs `@jini-ai/platform`, which is not a peer of this package.
|
|
34
|
+
|
|
35
|
+
`@jini-ai/db/settings` is the Kysely adapter (`SqlSettingsRepo`) for the settings repository port declared in
|
|
36
|
+
`@jini-ai/core/settings`. It takes the kernel and five host-owned table names; it owns no schema, no default table name and no
|
|
37
|
+
migration. Value writes are unconditional last-write-wins upserts and every revision append serializes on the
|
|
38
|
+
one install-wide `setting_revisions` lock.
|
|
39
|
+
|
|
40
|
+
`@jini-ai/db/gated-mutations` is the Kysely adapter (`SqlTokenStore`) for the confirmation-token store port declared in
|
|
41
|
+
`@jini-ai/core/gated-mutations`. It takes the kernel and one host-owned table name; redemption is single-use under a
|
|
42
|
+
per-token lock, and the plan binding is checked by the core service, not the store.
|
|
43
|
+
|
|
44
|
+
`@jini-ai/db/verified-origin` is the Kysely adapter (`SqlOriginSettingRepo`) for the verified-origin port declared in
|
|
45
|
+
`@jini-ai/core/contracts/server/verified-origin`, plus `registerConfiguredOrigin`, the insert-or-correct writer for an
|
|
46
|
+
operator-declared origin (origin columns only, under a per-workspace lock). It takes the kernel and one host-owned table name.
|
|
47
|
+
|
|
48
|
+
`@jini-ai/db/events` holds the Kysely adapters for the event ports declared in `@jini-ai/core/contracts/events`:
|
|
49
|
+
`SqlChangeSetRepo` (change sets, with the optional outbox event written in the same transaction), `SqlOutboxAdapter`
|
|
50
|
+
(claim as a lease under one install-wide lock) and `outboxEventValues`, the one definition of the stored outbox row.
|
|
51
|
+
They take the kernel and the host-owned table names; the outbox adapter also requires `claimLeaseMs`.
|
|
52
|
+
|
|
53
|
+
`kysely` is an optional peer (`^0.29.6`), imported as a value or type only under `src/kernel/`,
|
|
54
|
+
`src/migrate/`, `src/settings/`, `src/gated-mutations/`, `src/events/`, `src/verified-origin/` and `src/secrets-vault/`. `better-sqlite3`, `pg` and `@electric-sql/pglite` are also optional peers.
|
|
40
55
|
Production code never imports a driver at runtime. PGlite type imports are confined to
|
|
41
56
|
`src/pglite/` and `src/kernel/pglite/`; SQLite and Postgres use structural types.
|
|
42
57
|
|
|
@@ -64,7 +79,7 @@ const connection = openSqliteConnection({
|
|
|
64
79
|
filePath: 'app.db',
|
|
65
80
|
open: (filePath, options) => new Database(filePath, options),
|
|
66
81
|
});
|
|
67
|
-
const local = sqliteKernel<MyDb>(connection);
|
|
82
|
+
const local = sqliteKernel<MyDb>({ source: connection });
|
|
68
83
|
const embedded = openPgliteKernel<MyDb>({ PGlite }, { dataDir: './pgdata' });
|
|
69
84
|
const server = openPostgresKernel<MyDb>({ pg, connectionString: process.env.DATABASE_URL! });
|
|
70
85
|
await runMigrations(local, steps, { ledgerTable: 'app_migrations', appName: 'My app' });
|
|
@@ -91,8 +106,8 @@ application name, owner lock filename, run directory name, driver modules and wa
|
|
|
91
106
|
- `runMigrations(kernel, steps, { ledgerTable, appName })`: the ledger name is required.
|
|
92
107
|
- `startPgliteOwner({ dataDir, PGlite, lockFileName, runDirName })`: both filesystem names belong to
|
|
93
108
|
the consumer. The socket uses a private short Unix path rather than TCP.
|
|
94
|
-
- `pgliteOps(kernel,
|
|
95
|
-
`postgresOps(kernel,
|
|
109
|
+
- `pgliteOps({ kernel, PGlite, ledgerTable, ownerLockFileName }, { pgliteOwner })` and
|
|
110
|
+
`postgresOps({ kernel, ledgerTable })`: compaction verifies the host's ledger.
|
|
96
111
|
|
|
97
112
|
`DbOpsPort` is the restore-point contract with an injected watermark reader. `StorageOps` is the
|
|
98
113
|
kernel copy/compaction contract. They remain distinct because their operations and inputs differ.
|
|
@@ -146,7 +161,7 @@ file/table/integrity reports. Neither opens a connection. `./core` exports the g
|
|
|
146
161
|
## Transfer and assistant tools (j03)
|
|
147
162
|
|
|
148
163
|
`@jini-ai/db/transfer` imports without Kysely, a driver, or core. Supply an opener to
|
|
149
|
-
`openSqliteSnapshotSource({ bytes
|
|
164
|
+
`openSqliteSnapshotSource({ bytes, open })`. A consumer owns its table layouts, order,
|
|
150
165
|
exclusion reasons and all four required `TransferNaming` fields (`defaultSchema`, `markerTable`,
|
|
151
166
|
`unvalidatedTable`, `schemaPrefix`). `planTransfer({ sources })` raises
|
|
152
167
|
`IncompleteTransferPlanError` for every source table lacking a copied layout or a nonblank
|
|
@@ -175,7 +190,7 @@ independent risk checks and error adapters around the returned registrations.
|
|
|
175
190
|
|
|
176
191
|
`DatabaseReadToolPorts.clock` uses `Clock` from `@jini-ai/core/primitives` and exposes
|
|
177
192
|
`nowMs()`. Restore-point timestamps use the canonical `nowIso({ clock })` helper.
|
|
178
|
-
`databaseFile<DB>(kernel: StorageKernel<DB>)` accepts a typed kernel without erasing
|
|
193
|
+
`databaseFile<DB>({ kernel }: { kernel: StorageKernel<DB> }, _optional = {})` accepts a typed kernel without erasing
|
|
179
194
|
its database schema; SQLite file lookup and null results are unchanged.
|
|
180
195
|
|
|
181
196
|
Interactive transfer handlers follow core's two-object invocation contract:
|
|
@@ -216,7 +231,7 @@ declare function withSqliteTransaction<T>(
|
|
|
216
231
|
```
|
|
217
232
|
|
|
218
233
|
The host's `database` must support `statement.safeIntegers(true)`. The factory memoizes one
|
|
219
|
-
borrowed wrapper per handle; `sqliteKernel(client)` supplies its matching kernel. Safe bigint
|
|
234
|
+
borrowed wrapper per handle; `sqliteKernel({ source: client })` supplies its matching kernel. Safe bigint
|
|
220
235
|
cells and write metadata become numbers; overflow throws `SqliteClientError` with code
|
|
221
236
|
`unsafe_integer`. Blobs and floats retain their values. Iteration decodes one row at a time.
|
|
222
237
|
The wrapper's `close()` does nothing. Mixing raw and checked kernel ownership is refused.
|
|
@@ -281,9 +296,10 @@ missing-source-table/column formatter subset. Messages never select a schema or
|
|
|
281
296
|
Persisted `TransferNaming` remains required with no fallback; its display-only catalog
|
|
282
297
|
examples still default to `app` / `app_`. Keep each host's existing wire names explicit.
|
|
283
298
|
|
|
284
|
-
`@jini-ai/db/owner-store` exports the independent owner schema and pinned migration history
|
|
285
|
-
|
|
286
|
-
`
|
|
299
|
+
`@jini-ai/db/owner-store` exports the independent owner schema and pinned migration history, plus its
|
|
300
|
+
read-only row queries (`countOwnerStoreRows`, `listOwnerEntryRows`, `listOwnerDestinations`). Decryption lives
|
|
301
|
+
in `@jini-ai/platform/secrets/legacy-owner`; the file wiring (`countLegacyOwnerStore`, `readLegacyOwnerStore`)
|
|
302
|
+
lives in `@jini-ai/server/owner-store`.
|
|
287
303
|
|
|
288
304
|
**Migration (breaking, next release):** replace
|
|
289
305
|
`import { openOwnerStore, OwnerStoreService, exportOwnerStore, restoreOwnerStore, OwnerStoreBackupError, OwnerStoreRecoveryError } from '@jini-ai/db/owner-store'`
|
package/dist/core/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export { restorePointFilename, sanitizeForFilename } from "./artifact-naming.js"
|
|
|
3
3
|
export type { DbOpsPort, RestorePoint, RestoreCapability, RestoreCostClass, RestoreKind, WatermarkReader } from "./ports.js";
|
|
4
4
|
export { PGLITE_SOCKET_FILE } from "./socket.js";
|
|
5
5
|
export { PG_OID, PG_PARSERS, parseInt8 } from "./pg-types.js";
|
|
6
|
-
export {
|
|
7
|
-
export type { DbRow, JsonObject } from "./row-values.js";
|
|
6
|
+
export type { JsonObject } from "./row-values.js";
|
|
8
7
|
export type { TransferNaming } from './transfer-naming.js';
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.js
CHANGED
|
@@ -6,5 +6,4 @@
|
|
|
6
6
|
export { restorePointFilename, sanitizeForFilename } from "./artifact-naming.js";
|
|
7
7
|
export { PGLITE_SOCKET_FILE } from "./socket.js";
|
|
8
8
|
export { PG_OID, PG_PARSERS, parseInt8 } from "./pg-types.js";
|
|
9
|
-
export { parseJsonOrUndef, row, rows } from "./row-values.js";
|
|
10
9
|
//# sourceMappingURL=index.js.map
|
package/dist/core/pg-types.d.ts
CHANGED
|
@@ -72,5 +72,8 @@ export interface PgModule {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
/** node-postgres type parsing aligned with PGlite's (`PG_PARSERS`), for one pool only. */
|
|
75
|
-
export declare function pgTypesFor(pg
|
|
75
|
+
export declare function pgTypesFor({ pg, parsers }: {
|
|
76
|
+
pg: PgModule;
|
|
77
|
+
parsers: Readonly<Record<number, (text: string) => unknown>>;
|
|
78
|
+
}, _optional?: Record<string, never>): NonNullable<PgPoolOptions["types"]>;
|
|
76
79
|
//# sourceMappingURL=pg-types.d.ts.map
|
package/dist/core/pg-types.js
CHANGED
|
@@ -24,7 +24,7 @@ export const PG_PARSERS = {
|
|
|
24
24
|
[PG_OID.jsonb]: compactJson,
|
|
25
25
|
};
|
|
26
26
|
/** node-postgres type parsing aligned with PGlite's (`PG_PARSERS`), for one pool only. */
|
|
27
|
-
export function pgTypesFor(pg, parsers) {
|
|
27
|
+
export function pgTypesFor({ pg, parsers }, _optional = {}) {
|
|
28
28
|
return {
|
|
29
29
|
getTypeParser(oid, format) {
|
|
30
30
|
return parsers[oid] ?? pg.types.getTypeParser(oid, format);
|
|
@@ -1,32 +1,2 @@
|
|
|
1
|
-
/** Generic legacy row shapes and tolerant JSON narrowing; no driver or SQL dependencies. */
|
|
2
|
-
export type DbRow = Record<string, any>;
|
|
3
1
|
export type JsonObject = Record<string, unknown>;
|
|
4
|
-
/** @module db/core/json
|
|
5
|
-
* Pure JSON parsing utility that converts SQLite TEXT columns to JS values without throwing.
|
|
6
|
-
* Imports no sibling subdirectory.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Safely parse a SQLite TEXT column value to a JS value.
|
|
10
|
-
* Returns `undefined` instead of throwing for non-string, empty, or malformed JSON —
|
|
11
|
-
* callers should narrow the return type before use.
|
|
12
|
-
* @param s - raw column value as stored in SQLite (typically `string | null`)
|
|
13
|
-
* @returns parsed value, or `undefined` if the input is absent or unparseable
|
|
14
|
-
*/
|
|
15
|
-
export declare function parseJsonOrUndef(s: unknown): any;
|
|
16
|
-
/** @module db/core/rows
|
|
17
|
-
* Helpers that normalize raw better-sqlite3 query results to typed `DbRow` values.
|
|
18
|
-
* Imports no sibling subdirectory; depends only on `core/types`.
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Narrow a single `db.prepare(…).get()` result to `DbRow | null`.
|
|
22
|
-
* Returns `null` for falsy or non-object returns so callers can distinguish "no row" from an empty row.
|
|
23
|
-
* @param value - raw return from better-sqlite3's `.get()`
|
|
24
|
-
*/
|
|
25
|
-
export declare function row(value: unknown): DbRow | null;
|
|
26
|
-
/**
|
|
27
|
-
* Map a `db.prepare(…).all()` result array to `DbRow[]`, replacing any falsy or non-object
|
|
28
|
-
* entries with an empty object so the array length is always preserved.
|
|
29
|
-
* @param value - raw return from better-sqlite3's `.all()`
|
|
30
|
-
*/
|
|
31
|
-
export declare function rows(value: unknown[]): DbRow[];
|
|
32
2
|
//# sourceMappingURL=row-values.d.ts.map
|
package/dist/core/row-values.js
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Pure JSON parsing utility that converts SQLite TEXT columns to JS values without throwing.
|
|
3
|
-
* Imports no sibling subdirectory.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Safely parse a SQLite TEXT column value to a JS value.
|
|
7
|
-
* Returns `undefined` instead of throwing for non-string, empty, or malformed JSON —
|
|
8
|
-
* callers should narrow the return type before use.
|
|
9
|
-
* @param s - raw column value as stored in SQLite (typically `string | null`)
|
|
10
|
-
* @returns parsed value, or `undefined` if the input is absent or unparseable
|
|
11
|
-
*/
|
|
12
|
-
export function parseJsonOrUndef(s) {
|
|
13
|
-
if (typeof s !== 'string' || !s)
|
|
14
|
-
return undefined;
|
|
15
|
-
try {
|
|
16
|
-
return JSON.parse(s);
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/** @module db/core/rows
|
|
23
|
-
* Helpers that normalize raw better-sqlite3 query results to typed `DbRow` values.
|
|
24
|
-
* Imports no sibling subdirectory; depends only on `core/types`.
|
|
25
|
-
*/
|
|
26
|
-
/**
|
|
27
|
-
* Narrow a single `db.prepare(…).get()` result to `DbRow | null`.
|
|
28
|
-
* Returns `null` for falsy or non-object returns so callers can distinguish "no row" from an empty row.
|
|
29
|
-
* @param value - raw return from better-sqlite3's `.get()`
|
|
30
|
-
*/
|
|
31
|
-
export function row(value) {
|
|
32
|
-
return value && typeof value === 'object' ? value : null;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Map a `db.prepare(…).all()` result array to `DbRow[]`, replacing any falsy or non-object
|
|
36
|
-
* entries with an empty object so the array length is always preserved.
|
|
37
|
-
* @param value - raw return from better-sqlite3's `.all()`
|
|
38
|
-
*/
|
|
39
|
-
export function rows(value) {
|
|
40
|
-
return value.map((item) => row(item) ?? {});
|
|
41
|
-
}
|
|
1
|
+
export {};
|
|
42
2
|
//# sourceMappingURL=row-values.js.map
|
|
@@ -1,5 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The core-mediated plugin dataModule engine.
|
|
3
|
+
*
|
|
4
|
+
* A plugin DECLARES its desired tables as data; CORE alone executes the DDL. A plugin never
|
|
5
|
+
* authors a migration and never holds a raw DB handle. The flow, in order:
|
|
6
|
+
* 1. validate the declaration (namespace `p_{pluginId}__*` §5, column shape, tier §3/T6) —
|
|
7
|
+
* before any I/O;
|
|
8
|
+
* 2. skip tables that already exist (idempotent, state-based reconciliation §2);
|
|
9
|
+
* 3. disk-headroom preflight (§3/T4) — fails closed before any file is touched;
|
|
10
|
+
* 4. namespace-adoption guard (§5/§6/T5) — fails closed on an unresolved provenance mismatch;
|
|
11
|
+
* 5. **snapshot the whole db FIRST** (§4) — the never-brick anchor;
|
|
12
|
+
* 6. open a durable phase-journal entry (§2/T3);
|
|
13
|
+
* 7. run all DDL, the post-DDL verification, AND the journal's own COMMITTED transition inside
|
|
14
|
+
* ONE transaction (see this file's POST-COMMIT DATA-LOSS WINDOW section for why verification
|
|
15
|
+
* and the journal write are in-transaction too, not just the DDL) so a failure rolls the live
|
|
16
|
+
* db AND the journal back together to a working, truthfully-recorded state (§9: recoverable,
|
|
17
|
+
* not zero-loss) — SQLite's own transaction rollback handles this same-process, non-crash
|
|
18
|
+
* case; the snapshot/journal exist for the CRASH case, recovered at next boot by
|
|
19
|
+
* `migration-recovery.ts` (see that file and `restore.ts` for why restore only ever runs
|
|
20
|
+
* there, never live).
|
|
21
|
+
*
|
|
22
|
+
* IN-MEMORY `dbPath` (BUG FIX, 2026-07-28): steps 3, 5, and 6 above are conditionally skipped for an
|
|
23
|
+
* in-memory (or SQLite's other non-file) `dbPath` — see `snapshot.ts`'s `isInMemoryDbPath`. Disk
|
|
24
|
+
* headroom (step 3, via `disk-headroom.ts`) and the whole snapshot/journal apparatus (steps 5-6)
|
|
25
|
+
* exist specifically to make "recovery at next boot" possible; for `:memory:` there IS no next
|
|
26
|
+
* boot — the database is discarded in full the instant the process ends, so "recoverable" and
|
|
27
|
+
* "not recoverable" are the same outcome regardless of whether a snapshot/journal entry exists.
|
|
28
|
+
* Skipping them for this case isn't a weakened guarantee, it's recognizing the guarantee doesn't
|
|
29
|
+
* apply. Step 7's same-process transaction rollback is UNAFFECTED and remains the full safety net
|
|
30
|
+
* for an in-memory db, because it is the only failure mode that can ever occur for one (there is no
|
|
31
|
+
* separate process to crash-and-restart into that could observe a different, corrupted state).
|
|
32
|
+
*
|
|
33
|
+
* COLUMN-LEVEL RECONCILIATION (BUG FIX, 2026-08-12): §2's own text is "Core diffs declared-state
|
|
34
|
+
* against live-state and executes the DDL itself" — but the first implementation of step 2 only
|
|
35
|
+
* diffed *table names*, not table *contents*. A plugin whose v2 manifest added a column to an
|
|
36
|
+
* already-existing table got `{ ok: true, created: [] }` back — the table-name presence check saw
|
|
37
|
+
* the table, concluded there was nothing to do, and took the early no-op path — and the new column
|
|
38
|
+
* silently never existed. The failure then surfaced far from its cause: at query time, against
|
|
39
|
+
* whatever repository call first touched the missing column, with no link back to the manifest
|
|
40
|
+
* that declared it. Step 2 now diffs declared columns against `PRAGMA table_info` for every table
|
|
41
|
+
* that already exists, not just the table's name. A declared-but-missing column on an existing
|
|
42
|
+
* table has three possible outcomes: (a) a plain nullable, non-PRIMARY-KEY column is safely
|
|
43
|
+
* addable via `ALTER TABLE ADD COLUMN` and gets queued as an alteration; (b) a `NOT NULL` column
|
|
44
|
+
* cannot — SQLite refuses `ADD COLUMN` with a `NOT NULL` constraint unless a non-NULL default is
|
|
45
|
+
* also supplied, and this declaration grammar (`ColumnDecl`) has no default field to supply one,
|
|
46
|
+
* so this fails closed with `COLUMN_ADD_NOT_NULL_WITHOUT_DEFAULT`; (c) a `PRIMARY KEY` column can
|
|
47
|
+
* never be added to an existing table via `ALTER TABLE` at all — SQLite has no such statement,
|
|
48
|
+
* only a full create-copy-drop-rename table rebuild, which is a materially larger and riskier
|
|
49
|
+
* change than this fix and stays explicitly out of scope — so this fails closed with
|
|
50
|
+
* `COLUMN_ADD_PRIMARY_KEY`. A live column whose type no longer matches its declaration also fails
|
|
51
|
+
* closed (`COLUMN_TYPE_MISMATCH`) for the same reason: a type change is a rebuild, not an `ALTER`.
|
|
52
|
+
*
|
|
53
|
+
* CONSTRAINT-LEVEL RECONCILIATION (BUG FIX, 2026-08-12): the reconciliation above diffed an
|
|
54
|
+
* existing column's `type` but not its `notNull`/`primaryKey` declarations — a plugin author
|
|
55
|
+
* tightening either constraint on an already-existing column (e.g. a v2 manifest marking a
|
|
56
|
+
* previously-nullable column `notNull: true`) got `{ ok: true, altered: [] }` back with the live
|
|
57
|
+
* column completely unchanged: the identical silent-non-enforcement bug class the type-mismatch
|
|
58
|
+
* fix above closed, just for two different fields on the same struct. `assertColumnNotNullMatches`
|
|
59
|
+
* and `assertColumnPrimaryKeyMatches` now run alongside `assertColumnTypeMatches` for every
|
|
60
|
+
* existing column a declaration mentions, each failing closed (`COLUMN_NOT_NULL_MISMATCH` /
|
|
61
|
+
* `COLUMN_PRIMARY_KEY_MISMATCH`) on disagreement, for the same reason as the type case: SQLite's
|
|
62
|
+
* `ALTER TABLE` cannot change either constraint on an existing column — no `ALTER COLUMN`, no way
|
|
63
|
+
* to add or drop a `NOT NULL` or `PRIMARY KEY` short of the same create-copy-drop-rename rebuild
|
|
64
|
+
* this file stays out of scope of everywhere else.
|
|
65
|
+
*
|
|
66
|
+
* Both checks are DIRECTION-AGNOSTIC — declared-stricter-than-live and declared-looser-than-live
|
|
67
|
+
* both fail closed — deliberately mirroring `COLUMN_TYPE_MISMATCH`'s own symmetric behavior rather
|
|
68
|
+
* than only catching the tightening direction the bug report above led with. The two directions
|
|
69
|
+
* are not equally *dangerous* (tightening risks silent bad data creeping in past a constraint the
|
|
70
|
+
* app believes SQLite is enforcing; loosening at most risks a write later hitting a live
|
|
71
|
+
* constraint the current manifest doesn't mention, which SQLite itself rejects loudly at write
|
|
72
|
+
* time, not silently) — but both are still a manifest that disagrees with the database it
|
|
73
|
+
* describes, and this module's whole job is to surface that disagreement at `declare()` time,
|
|
74
|
+
* next to the manifest, rather than let either direction surface later at some unrelated write
|
|
75
|
+
* site with no link back to the manifest. `COLUMN_TYPE_MISMATCH` never special-cased "safe"
|
|
76
|
+
* directions either (e.g. widening `INTEGER` to `REAL` isn't unsafe the way `TEXT`→`INTEGER` is)
|
|
77
|
+
* for the same underlying reason, so this stays consistent with the established fail-closed
|
|
78
|
+
* default rather than inventing a narrower rule for these two fields alone.
|
|
79
|
+
*
|
|
80
|
+
* `assertColumnPrimaryKeyMatches` compares against `getExistingColumns`'s already-boolean
|
|
81
|
+
* `primaryKey` field (`pk !== 0`, not `pk === 1`) so a column that is part of a *composite*
|
|
82
|
+
* primary key (`PRAGMA table_info`'s `pk` is an ordinal position, 1-based, not a 0/1 flag) is
|
|
83
|
+
* still read correctly as "is a primary key column" rather than only the first component
|
|
84
|
+
* matching. Whether that scenario can even arise given this engine's own DDL is a separate
|
|
85
|
+
* question: `ColumnDecl.primaryKey` is a single-column boolean with no table-level composite-key
|
|
86
|
+
* grammar, and `CREATE TABLE` with two columns each carrying a column-level `PRIMARY KEY`
|
|
87
|
+
* constraint is rejected by SQLite itself ("table has more than one primary key") before this
|
|
88
|
+
* code ever runs — so this engine cannot *create* a composite-PK table through its own DDL. A
|
|
89
|
+
* live table could still carry one from outside this engine's DDL entirely (the §0 access-control
|
|
90
|
+
* caveat below: a Tier-3 plugin holding a raw handle, or a table that predates this engine) — the
|
|
91
|
+
* ordinal-aware read guards against exactly that case rather than assuming it can't happen.
|
|
92
|
+
*
|
|
93
|
+
* A live column the CURRENT declaration no longer mentions is deliberately left alone rather than
|
|
94
|
+
* dropped — this engine never authors a `DROP COLUMN` on a plugin's behalf; an operator who rolled
|
|
95
|
+
* a plugin back to an older manifest, or a manifest that stopped mentioning a column on purpose,
|
|
96
|
+
* should not lose that column's data to a silent, unrequested `DROP`. When an existing table needs
|
|
97
|
+
* one or more columns added, the full snapshot/journal/single-transaction apparatus below still
|
|
98
|
+
* runs for it exactly as it does for a brand-new table — only the fully-reconciled no-op case
|
|
99
|
+
* (every declared table exists with every declared column already present and matching) skips it.
|
|
100
|
+
*
|
|
101
|
+
* INDEX-LEVEL RECONCILIATION (BUG FIX, 2026-08-12): the column-level reconciliation above still
|
|
102
|
+
* built `toAlter` from `columnsToAdd` alone — a declared `IndexDecl` on an already-existing table
|
|
103
|
+
* was reconciled only on the CREATE path (`table.indexes` was only ever walked inside the
|
|
104
|
+
* `plan.toCreate` loop), so a v2 manifest that added an index to an existing table got
|
|
105
|
+
* `{ ok: true, altered: [...] }` back (truthfully reporting the column work, if any) with the
|
|
106
|
+
* index itself silently never created — the identical bug class one level up. The kernel's `listIndexes`
|
|
107
|
+
* reads `fqTableName`'s live indexes via `PRAGMA index_list` + `PRAGMA index_info`, filtered to
|
|
108
|
+
* `origin: 'c'` rows only: SQLite also auto-creates an implicit index per `UNIQUE` column
|
|
109
|
+
* constraint (`origin: 'u'`) and one for most `PRIMARY KEY` shapes (`origin: 'pk'`, e.g.
|
|
110
|
+
* `sqlite_autoindex_*`), neither of which was ever declared through `IndexDecl` or created by this
|
|
111
|
+
* module's own `indexSql` — diffing against those would be comparing against something the
|
|
112
|
+
* declaration grammar can't even express. `planIndexReconciliation` then diffs declared indexes
|
|
113
|
+
* (matched by the SAME generated name `indexSql` already uses to create one) against that live
|
|
114
|
+
* set: a declared index missing live is queued in `indexesToAdd`, safely creatable via a plain
|
|
115
|
+
* `CREATE INDEX` — unlike the column NOT NULL/PRIMARY KEY cases above, an index carries no data
|
|
116
|
+
* for `ALTER` semantics to conflict with, so there is no "SQLite literally cannot express this"
|
|
117
|
+
* case here to fail closed on. A declared index whose live shape (column list, in order, or
|
|
118
|
+
* uniqueness) no longer matches is queued in `indexesToRecreate` (`DROP INDEX` then `CREATE INDEX`,
|
|
119
|
+
* both inside this call's single transaction, so a mid-way failure rolls back exactly like any
|
|
120
|
+
* other DDL here) — a deliberate choice, not an oversight: an index is pure derived structure with
|
|
121
|
+
* no data of its own, so dropping and rebuilding it risks nothing a rollback wouldn't already
|
|
122
|
+
* protect, in sharp contrast to a column whose type/constraint this file explicitly refuses to
|
|
123
|
+
* touch because doing so risks the column's actual data. The one way this CAN still fail is a
|
|
124
|
+
* `CREATE UNIQUE INDEX` rejected by genuine live duplicate values — that surfaces exactly like any
|
|
125
|
+
* other DDL failure in this transaction (rollback, `DDL_FAILED`, snapshot kept as the recovery
|
|
126
|
+
* point), needing no special-casing. A live index the CURRENT declaration no longer mentions is
|
|
127
|
+
* left alone, mirroring the column-drop policy directly above. `assertIdentifierFits` already
|
|
128
|
+
* covers every declared index's generated name unconditionally, for both the create and alter
|
|
129
|
+
* paths — `validate()` walks `table.indexes` for every table in the declaration up front, before
|
|
130
|
+
* reconciliation ever runs, so no separate length check is needed in this new path.
|
|
131
|
+
*
|
|
132
|
+
* POST-COMMIT JOURNAL INTEGRITY (BUG FIX, 2026-08-12): the catch block below used to write
|
|
133
|
+
* `ROLLED_BACK` unconditionally on ANY failure inside the DDL try block — but a failure can occur
|
|
134
|
+
* either BEFORE the `db.transaction()` call resolves (SQLite's own rollback truly undid every
|
|
135
|
+
* write; `ROLLED_BACK` is accurate) or AFTER it already committed (`verifyPostDdl` throwing, or
|
|
136
|
+
* even the `advancePhaseIfJournaled(..., "COMMITTED")` write itself throwing) — and for that second
|
|
137
|
+
* case, the DDL is live and durable, so `ROLLED_BACK` was a lie: the journal claimed a rollback
|
|
138
|
+
* that never happened. `migration-recovery.ts` only ever restores NON-terminal entries
|
|
139
|
+
* (`ROLLED_BACK`/`COMMITTED` are both terminal, see `migration-journal.ts`'s `TERMINAL_PHASES`), so
|
|
140
|
+
* a next-boot crash recovery would see this mislabeled entry, conclude there is nothing to do, and
|
|
141
|
+
* skip it — leaving the live db and the journal's account of it permanently disagreeing, with
|
|
142
|
+
* nothing left to ever reconcile them. `declareDataModule` now tracks `transactionCommitted`,
|
|
143
|
+
* flipped to `true` the instant `db.transaction(() => { ... })()` returns without throwing, and
|
|
144
|
+
* `recordFailurePhase` uses it to decide: pre-commit, write `ROLLED_BACK` as before (truthful,
|
|
145
|
+
* unchanged); post-commit, write NOTHING and leave the journal at whatever non-terminal phase it
|
|
146
|
+
* already reached (`VERIFYING`, set immediately after the transaction resolves, before either of
|
|
147
|
+
* the two post-commit throw sites) — non-terminal is exactly what makes next-boot recovery pick it
|
|
148
|
+
* up and restore from the pre-DDL snapshot. **CORRECTED below, same day**: leaving a non-terminal
|
|
149
|
+
* phase behind turned out to trade one bug for a worse one — see POST-COMMIT DATA-LOSS WINDOW
|
|
150
|
+
* immediately following this section for why "restore from the pre-DDL snapshot" is NOT the correct
|
|
151
|
+
* outcome for this case, and what replaced `transactionCommitted`/`recordFailurePhase` instead.
|
|
152
|
+
*
|
|
153
|
+
* POST-COMMIT DATA-LOSS WINDOW (BUG FIX, 2026-08-12, same-day follow-up to the fix immediately
|
|
154
|
+
* above): the fix above stopped LYING about a post-commit failure, but stopping the lie did not
|
|
155
|
+
* stop the underlying failure from existing. A post-commit `verifyPostDdl` failure correctly wrote
|
|
156
|
+
* nothing and left the entry at `VERIFYING` — but `VERIFYING` is non-terminal, and
|
|
157
|
+
* `migration-recovery.ts` treats every non-terminal entry as a crash-interrupted attempt requiring
|
|
158
|
+
* restore, indistinguishably from an actual process crash. The scenario this opened: DDL commits,
|
|
159
|
+
* verification fails (a normal, catchable, in-process failure — the process does NOT crash),
|
|
160
|
+
* `declareDataModule` returns `{ ok: false }`, and the site keeps running and serving traffic —
|
|
161
|
+
* nothing about a caught, in-process exception stops that. Every write the site accepts from that
|
|
162
|
+
* moment on, by ANY table, not just this plugin's, is exposed: the recovery snapshot is a
|
|
163
|
+
* WHOLE-FILE backup (§4), and `restoreFromSnapshot` (`restore.ts`) is a whole-file copy back over
|
|
164
|
+
* `dbPath`. The next time anything restarts the process — an operator's routine deploy, not a
|
|
165
|
+
* crash — boot-time `recoverIncompleteDataModuleMigrations` finds the still-`VERIFYING` entry,
|
|
166
|
+
* restores the whole db file to its pre-DDL state, and every write since is gone, with no crash and
|
|
167
|
+
* no operator warning to explain why. Direct reproduction (both as a fault-injected `:memory:` case
|
|
168
|
+
* and as a full write-after-failure/restart/verify-survival end-to-end case, see
|
|
169
|
+
* `data-module.test.ts`) confirmed both the live-column retention AND the eventual data loss on
|
|
170
|
+
* recovery; this was not a hypothetical.
|
|
171
|
+
*
|
|
172
|
+
* The root cause both this fix and the one above were reacting to is the same: `verifyPostDdl` ran
|
|
173
|
+
* AFTER `db.transaction()` had already committed, so there was always going to be SOME failure mode
|
|
174
|
+
* in that gap that a post-hoc phase label could describe accurately but never close. The actual fix
|
|
175
|
+
* is to remove the gap: `verifyPostDdl` now runs as the LAST statement INSIDE the same
|
|
176
|
+
* `db.transaction()` that runs the DDL, and a failure throws from inside that callback — the exact
|
|
177
|
+
* same mechanism `applyTableCreate`/`applyTableAlteration` already use to fail the transaction, so
|
|
178
|
+
* better-sqlite3's own automatic `ROLLBACK` undoes the DDL right along with it. There is no longer a
|
|
179
|
+
* state where the DDL is live but unverified; verified-and-committed and rolled-back-entirely are
|
|
180
|
+
* now the only two reachable outcomes. (Verification's own `PRAGMA table_info`/`index_list` reads
|
|
181
|
+
* are unaffected by running mid-transaction — a SQLite connection sees its own uncommitted writes
|
|
182
|
+
* within the same transaction exactly like committed ones, confirmed directly for this repo's
|
|
183
|
+
* better-sqlite3 build; it is not merely inferred from general SQL semantics.)
|
|
184
|
+
*
|
|
185
|
+
* The journal's own `COMMITTED` transition moves inside the same transaction too, via
|
|
186
|
+
* `migration-journal.ts`'s `stageJournalPhase` — a checkpoint-free write, because
|
|
187
|
+
* `advanceJournalPhase` CANNOT be reused here: it calls `PRAGMA wal_checkpoint(FULL)`, and a
|
|
188
|
+
* checkpoint issued by the SAME connection that holds an open write transaction throws `database
|
|
189
|
+
* table is locked` (confirmed directly, not assumed — SQLite's own docs do not call out
|
|
190
|
+
* same-connection mid-transaction checkpoint behavior at all, so this needed a real probe, not a
|
|
191
|
+
* reading). Writing `COMMITTED` inside the DDL transaction means a crash at the worst possible
|
|
192
|
+
* instant — literally between SQLite's internal commit and this function's `db.transaction()` call
|
|
193
|
+
* returning to JS — still leaves the journal reading `COMMITTED`, because that write committed WITH
|
|
194
|
+
* the DDL, as one indivisible unit; there is no instant at which live state and journal state can
|
|
195
|
+
* disagree. `stagePhaseIfJournaled` no-ops for the in-memory case exactly like
|
|
196
|
+
* `advancePhaseIfJournaled` does, matching this file's existing in-memory convention throughout.
|
|
197
|
+
*
|
|
198
|
+
* `declareDataModule`'s catch block goes back to unconditionally writing `ROLLED_BACK` — the
|
|
199
|
+
* `transactionCommitted` flag and `recordFailurePhase`'s pre/post-commit fork the previous fix
|
|
200
|
+
* introduced are gone, not because that reasoning was wrong but because it is now unreachable: with
|
|
201
|
+
* verification and the `COMMITTED` write both inside the transaction, `db.transaction()` throwing
|
|
202
|
+
* means SQLite really did roll everything back in every remaining case, so `ROLLED_BACK` is once
|
|
203
|
+
* again always truthful — the same simplicity the very first version of this file had, restored
|
|
204
|
+
* without reintroducing the bug that simplicity originally hid. The one sliver of risk that
|
|
205
|
+
* remains — the belt-and-suspenders `advancePhaseIfJournaled(db, journalId, "COMMITTED")` checkpoint
|
|
206
|
+
* call (re-writing the already-`COMMITTED` row purely to force its WAL merge), or
|
|
207
|
+
* `discardSnapshotIfFileBacked`, throwing AFTER the transaction has already committed everything
|
|
208
|
+
* that matters — is deliberately kept OUT of the catch path entirely: both calls run in their own
|
|
209
|
+
* swallow-all block after the transaction succeeds, because by that point the migration is already
|
|
210
|
+
* correct and durable, and reporting `{ ok: false }` for a housekeeping hiccup would itself be a lie
|
|
211
|
+
* in the other direction (the same principle `discardCommittedSnapshot` already documents: "must
|
|
212
|
+
* not turn a successful migration into a reported failure").
|
|
213
|
+
*
|
|
214
|
+
* T2 (the exclusive cross-process lock) is DELIBERATELY NOT acquired here — correction
|
|
215
|
+
* (2026-07-16), superseding the original implementation. The original design scopes T2's
|
|
216
|
+
* purpose narrowly: "The SQLite online backup API is safe under concurrent writers during
|
|
217
|
+
* snapshot creation — that step needs no change here. Restore is a different, less-safe
|
|
218
|
+
* operation" — the lock exists to guard RESTORE, not the live snapshot+DDL window. `restore.ts`'s
|
|
219
|
+
* own header already establishes that restore never runs live in this codebase's actual topology
|
|
220
|
+
* (single-process, single long-lived connection; restore only runs at boot-time recovery, before
|
|
221
|
+
* any other connection exists) — so T2's stated danger literally cannot occur here. Holding a
|
|
222
|
+
* real `PRAGMA locking_mode=EXCLUSIVE` during the live window instead caused a genuine,
|
|
223
|
+
* deterministic production bug: a live multi-boot smoke test against the real server found the
|
|
224
|
+
* store plugin's own separate `content.db` connection (`store plugin bootstrap`) failing
|
|
225
|
+
* boot with "database is locked" every time, confirmed via A/B testing (disabling the lock calls
|
|
226
|
+
* made the failure disappear immediately) — the exact interleaving mechanism was not fully
|
|
227
|
+
* root-caused (multiple fire-and-forget dataModule declares and other writers share one
|
|
228
|
+
* long-lived connection in the real composition, unlike any isolated repro), but the causal link
|
|
229
|
+
* to `locking_mode=EXCLUSIVE` was empirically conclusive. Removing an unneeded lock whose own
|
|
230
|
+
* ADR-stated justification doesn't apply here, rather than debugging a specific interleaving
|
|
231
|
+
* further, is the correct call.
|
|
232
|
+
*
|
|
233
|
+
* The dataModule design is ACCEPTED (2026-07-11) after a 3-round external audit whose T1-T8 findings are now
|
|
234
|
+
* ALL reflected in code across this file, `migration-journal.ts`, `disk-headroom.ts`,
|
|
235
|
+
* `plugin-identity.ts`, `migration-recovery.ts`, and `restore.ts` — see the original specs for the
|
|
236
|
+
* full record of which finding lives where. This engine exists ahead of the "v1 ships seams
|
|
237
|
+
* only" schedule: §12's own last line permits shipping it early "against a concrete demand
|
|
238
|
+
* plugin," and Newsletter (a host module) is exactly that — a real
|
|
239
|
+
* production consumer already calling this engine before this file's safety mechanics existed.
|
|
240
|
+
*
|
|
241
|
+
* STORAGE KERNEL (2026-09-28, storage plan P1): the engine runs on the storage kernel, so the same
|
|
242
|
+
* declaration installs on SQLite, PGlite and Postgres. DDL text is unchanged on SQLite (column types
|
|
243
|
+
* via `columnTypeSql`; Postgres gets text/bigint/double precision/bytea); live state is read through
|
|
244
|
+
* the kernel's `listTables`/`listColumns`/`listIndexes` instead of `PRAGMA`s, with the same meaning.
|
|
245
|
+
* The snapshot, disk-headroom check and phase journal run only for a file-backed SQLite database
|
|
246
|
+
* (`recoverable` below): they exist for next-boot restore of a whole file. On Postgres/PGlite the DDL
|
|
247
|
+
* and its bookkeeping commit in one crash-safe transaction, so an interrupted attempt leaves nothing
|
|
248
|
+
* behind to restore — the same reasoning as the in-memory case above.
|
|
249
|
+
*
|
|
250
|
+
* NOTE (§0 access-control caveat): a Tier-3 in-process plugin could bypass this by opening the db
|
|
251
|
+
* file directly. The RECOVERABILITY guarantee here (who snapshots + who runs DDL = core) holds
|
|
252
|
+
* unconditionally for core-mediated DDL; the access-control framing is advisory until
|
|
253
|
+
* Rung 2 (capability sandbox) ships — see the original design for the full, precise wording.
|
|
254
|
+
*/
|
|
255
|
+
import { type Logger } from "@jini-ai/core/primitives";
|
|
1
256
|
import { type HeadroomCheck } from "./disk-headroom.js";
|
|
2
|
-
import type
|
|
257
|
+
import { type PluginProvenance } from "./plugin-identity.js";
|
|
3
258
|
import { type PluginStore } from "./plugin-store.js";
|
|
4
259
|
export type ColumnType = "TEXT" | "INTEGER" | "REAL" | "BLOB";
|
|
5
260
|
export type PluginTier = "tier-1" | "tier-2" | "tier-3";
|
|
@@ -10,11 +265,11 @@ export interface ColumnDecl {
|
|
|
10
265
|
readonly primaryKey?: boolean;
|
|
11
266
|
}
|
|
12
267
|
/**
|
|
13
|
-
*
|
|
268
|
+
* Declared FKs / the SDK stress-test finding — the dataModule seam's
|
|
14
269
|
* declared-index grammar. Comments' moderation-queue query pattern
|
|
15
270
|
* (`workspace_id, entry_id, status`) is the concrete demand this grows the seam against, per
|
|
16
271
|
* OQ-1's own instruction not to silently work around the gap. Deliberately NOT a foreign-key
|
|
17
|
-
* declaration seam too —
|
|
272
|
+
* declaration seam too — the original design says referential integrity to `entries`/parent
|
|
18
273
|
* comments is "chokepoint-validated, not FK-enforced (v1)", so only indexes are the real,
|
|
19
274
|
* load-bearing need; adding FK-declaration grammar with no consumer would be speculative.
|
|
20
275
|
*/
|
|
@@ -82,9 +337,10 @@ export declare function declareDataModule(required: {
|
|
|
82
337
|
db: PluginStore;
|
|
83
338
|
dbPath: string;
|
|
84
339
|
decl: DataModuleDecl;
|
|
85
|
-
}, { checkHeadroom }?: {
|
|
340
|
+
}, { checkHeadroom, report: logger }?: {
|
|
86
341
|
checkHeadroom?: (required: {
|
|
87
342
|
dbPath: string;
|
|
88
343
|
}, optional?: Record<string, never>) => HeadroomCheck;
|
|
344
|
+
report?: Pick<Logger, "warn" | "error">;
|
|
89
345
|
}): Promise<DeclareResult>;
|
|
90
346
|
//# sourceMappingURL=data-module.d.ts.map
|