@jini-ai/db 0.7.1 → 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.
Files changed (162) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +33 -17
  3. package/dist/core/index.d.ts +1 -2
  4. package/dist/core/index.js +0 -1
  5. package/dist/core/pg-types.d.ts +4 -1
  6. package/dist/core/pg-types.js +1 -1
  7. package/dist/core/row-values.d.ts +0 -30
  8. package/dist/core/row-values.js +1 -41
  9. package/dist/data-modules/data-module.d.ts +260 -4
  10. package/dist/data-modules/data-module.js +105 -83
  11. package/dist/data-modules/disk-headroom.js +1 -1
  12. package/dist/data-modules/index.d.ts +2 -2
  13. package/dist/data-modules/index.js +2 -2
  14. package/dist/data-modules/migration-journal.js +6 -6
  15. package/dist/data-modules/migration-recovery.js +2 -2
  16. package/dist/data-modules/plugin-identity.js +5 -5
  17. package/dist/data-modules/plugin-store.d.ts +4 -4
  18. package/dist/data-modules/restore.js +5 -5
  19. package/dist/data-modules/snapshot.d.ts +1 -1
  20. package/dist/data-modules/snapshot.js +3 -3
  21. package/dist/events/change-set-repo.sql.d.ts +70 -0
  22. package/dist/events/change-set-repo.sql.js +72 -0
  23. package/dist/events/index.d.ts +4 -0
  24. package/dist/events/index.js +3 -0
  25. package/dist/events/outbox-repo.sql.d.ts +91 -0
  26. package/dist/events/outbox-repo.sql.js +108 -0
  27. package/dist/events/repo.rows.d.ts +44 -0
  28. package/dist/events/repo.rows.js +59 -0
  29. package/dist/gated-mutations/index.d.ts +3 -0
  30. package/dist/gated-mutations/index.js +2 -0
  31. package/dist/gated-mutations/repo.rows.d.ts +19 -0
  32. package/dist/gated-mutations/repo.rows.js +23 -0
  33. package/dist/gated-mutations/repo.sql.d.ts +67 -0
  34. package/dist/gated-mutations/repo.sql.js +71 -0
  35. package/dist/kernel/dialect.d.ts +53 -31
  36. package/dist/kernel/dialect.js +14 -36
  37. package/dist/kernel/index.d.ts +2 -2
  38. package/dist/kernel/index.js +1 -7
  39. package/dist/kernel/kernel-core.d.ts +7 -3
  40. package/dist/kernel/kernel-core.js +75 -66
  41. package/dist/kernel/ops.d.ts +9 -3
  42. package/dist/kernel/ops.js +2 -2
  43. package/dist/kernel/owned-transaction.d.ts +7 -7
  44. package/dist/kernel/owned-transaction.js +2 -2
  45. package/dist/kernel/pglite/driver.d.ts +2 -2
  46. package/dist/kernel/pglite/driver.js +18 -18
  47. package/dist/kernel/pglite/ops.d.ts +8 -3
  48. package/dist/kernel/pglite/ops.js +5 -5
  49. package/dist/kernel/port.d.ts +9 -76
  50. package/dist/kernel/port.js +1 -10
  51. package/dist/kernel/postgres/driver.d.ts +4 -2
  52. package/dist/kernel/postgres/driver.js +17 -17
  53. package/dist/kernel/postgres/ops.d.ts +5 -3
  54. package/dist/kernel/postgres/ops.js +3 -3
  55. package/dist/kernel/postgres/pglite-socket.d.ts +2 -2
  56. package/dist/kernel/postgres/pglite-socket.js +13 -13
  57. package/dist/kernel/schema-scope.d.ts +5 -2
  58. package/dist/kernel/schema-scope.js +1 -1
  59. package/dist/kernel/schema-shape.d.ts +7 -3
  60. package/dist/kernel/schema-shape.js +2 -2
  61. package/dist/kernel/session-lock.d.ts +6 -6
  62. package/dist/kernel/sqlite/driver.d.ts +16 -8
  63. package/dist/kernel/sqlite/driver.js +38 -38
  64. package/dist/kernel/sqlite/index.d.ts +1 -0
  65. package/dist/kernel/sqlite/index.js +1 -0
  66. package/dist/kernel/sqlite/ops.d.ts +4 -2
  67. package/dist/kernel/sqlite/ops.js +3 -3
  68. package/dist/kernel/sqlite/sqlite-only.d.ts +81 -0
  69. package/dist/kernel/sqlite/sqlite-only.js +58 -0
  70. package/dist/kernel/store-copy.d.ts +7 -7
  71. package/dist/kernel/store-copy.js +22 -14
  72. package/dist/kernel/typegen.d.ts +5 -3
  73. package/dist/kernel/typegen.js +1 -1
  74. package/dist/migrate/checksum.d.ts +3 -1
  75. package/dist/migrate/checksum.js +1 -1
  76. package/dist/migrate/index.d.ts +1 -1
  77. package/dist/migrate/legacy-ledger.d.ts +4 -4
  78. package/dist/migrate/runner.d.ts +12 -7
  79. package/dist/migrate/runner.js +7 -6
  80. package/dist/migrate/step.d.ts +3 -28
  81. package/dist/migrate/step.js +3 -3
  82. package/dist/owner-store/index.d.ts +47 -1
  83. package/dist/owner-store/index.js +28 -1
  84. package/dist/owner-store/migrations/0000_owner_store.d.ts +3 -2
  85. package/dist/owner-store/migrations/index.d.ts +1 -1
  86. package/dist/pglite/owner.d.ts +12 -4
  87. package/dist/pglite/owner.js +33 -27
  88. package/dist/pglite/socket-server.d.ts +5 -1
  89. package/dist/pglite/socket-server.js +5 -4
  90. package/dist/recovery/deep-link.d.ts +3 -3
  91. package/dist/recovery/degraded-banners.d.ts +3 -3
  92. package/dist/recovery/degraded-banners.js +3 -3
  93. package/dist/recovery/disclosure.d.ts +6 -6
  94. package/dist/recovery/disclosure.js +6 -6
  95. package/dist/recovery/evaluate-boot-migration-policy.d.ts +5 -5
  96. package/dist/recovery/evaluate-boot-migration-policy.js +5 -5
  97. package/dist/recovery/lookup-adapters.d.ts +1 -1
  98. package/dist/recovery/lookup-adapters.js +1 -1
  99. package/dist/recovery/migrate-forward-execute.d.ts +1 -1
  100. package/dist/recovery/migrate-forward-execute.js +5 -5
  101. package/dist/recovery/migrate-forward-hooks.d.ts +6 -6
  102. package/dist/recovery/migrate-forward-hooks.js +5 -5
  103. package/dist/recovery/operation-lock.d.ts +11 -11
  104. package/dist/recovery/operation-lock.js +3 -3
  105. package/dist/recovery/reconcile-interrupted-migration.d.ts +7 -7
  106. package/dist/recovery/reconcile-interrupted-migration.js +7 -7
  107. package/dist/recovery/recovery-orchestrator.d.ts +21 -21
  108. package/dist/recovery/recovery-orchestrator.js +9 -9
  109. package/dist/recovery/restore-hooks.d.ts +8 -8
  110. package/dist/recovery/restore-hooks.js +7 -7
  111. package/dist/recovery/restore-point-create.d.ts +3 -3
  112. package/dist/secrets-vault/repo.sql.d.ts +3 -3
  113. package/dist/secrets-vault/repo.sql.js +5 -4
  114. package/dist/settings/index.d.ts +3 -0
  115. package/dist/settings/index.js +2 -0
  116. package/dist/settings/repo.rows.d.ts +117 -0
  117. package/dist/settings/repo.rows.js +106 -0
  118. package/dist/settings/repo.sql.d.ts +99 -0
  119. package/dist/settings/repo.sql.js +219 -0
  120. package/dist/sqlite/checked-client.d.ts +1 -1
  121. package/dist/sqlite/checked-state.d.ts +3 -3
  122. package/dist/sqlite/db-ops.d.ts +1 -1
  123. package/dist/sqlite/db-ops.js +1 -1
  124. package/dist/sqlite/index.d.ts +1 -3
  125. package/dist/sqlite/index.js +2 -0
  126. package/dist/sqlite/inspect.d.ts +2 -2
  127. package/dist/sqlite/inspect.js +1 -1
  128. package/dist/sqlite/open.d.ts +1 -2
  129. package/dist/sqlite/stopped.d.ts +46 -0
  130. package/dist/sqlite/stopped.js +86 -0
  131. package/dist/sqlite/transaction.d.ts +2 -2
  132. package/dist/tools/database-catalog.d.ts +2 -2
  133. package/dist/tools/database-catalog.js +13 -3
  134. package/dist/tools/read-tools.js +70 -59
  135. package/dist/tools/restore-points.d.ts +1 -1
  136. package/dist/tools/transfer-tools.d.ts +0 -1
  137. package/dist/tools/transfer-tools.js +5 -4
  138. package/dist/transfer/copy-engine.js +10 -10
  139. package/dist/transfer/copy-order.d.ts +47 -0
  140. package/dist/transfer/copy-order.js +103 -0
  141. package/dist/transfer/index.d.ts +1 -0
  142. package/dist/transfer/index.js +1 -0
  143. package/dist/transfer/internal-ddl.d.ts +28 -6
  144. package/dist/transfer/internal-ddl.js +15 -15
  145. package/dist/transfer/postgres-ddl.js +6 -6
  146. package/dist/transfer/sqlite-source.d.ts +2 -3
  147. package/dist/transfer/sqlite-source.js +1 -1
  148. package/dist/verified-origin/index.d.ts +4 -0
  149. package/dist/verified-origin/index.js +3 -0
  150. package/dist/verified-origin/register.d.ts +43 -0
  151. package/dist/verified-origin/register.js +51 -0
  152. package/dist/verified-origin/repo.rows.d.ts +42 -0
  153. package/dist/verified-origin/repo.rows.js +47 -0
  154. package/dist/verified-origin/repo.sql.d.ts +67 -0
  155. package/dist/verified-origin/repo.sql.js +34 -0
  156. package/package.json +38 -11
  157. package/dist/sqlite/restore-types.d.ts +0 -46
  158. package/dist/sqlite/restore-types.js +0 -2
  159. package/dist/sqlite/sync-types.d.ts +0 -34
  160. package/dist/sqlite/sync-types.js +0 -2
  161. package/dist/sqlite/types.d.ts +0 -37
  162. package/dist/sqlite/types.js +0 -8
@@ -1,23 +1,23 @@
1
1
  /**
2
- * @file SPEC-017 C-106 / CIC U-004 / REQ-15 / AC-17 — boot-time crash reconciliation
3
- * (ADR-041 §3).
2
+ * @file Boot-time crash reconciliation.
3
+ *
4
4
  *
5
5
  * Purpose:
6
6
  * A boot scanner that converts any non-terminal `migration_runs` row (read from the sidecar ops
7
- * journal — the only place guaranteed to survive a mid-crash restore of `content.db`, ADR-041 §2)
7
+ * journal — the only place guaranteed to survive a mid-crash restore of `content.db`)
8
8
  * into a `migration.interrupted` ledger row, and blocks normal site open until an operator
9
9
  * resolves it via Recovery. This is a real, accepted downtime vector, traded deliberately for
10
- * "never boot into a half-migrated schema" (ADR-041 §3).
10
+ * "never boot into a half-migrated schema".
11
11
  *
12
12
  * How it relates to the project:
13
13
  * The boot composition root calls this BEFORE `evaluate-boot-migration-policy.ts`'s
14
- * `evaluateBootMigrationPolicy` (C-107) every boot cycle (U-004-ORD1) — that ordering is a
14
+ * `evaluateBootMigrationPolicy` every boot cycle — that ordering is a
15
15
  * composition-root wiring concern this module cannot itself enforce; the sibling `defensive`
16
16
  * precondition check lives in `evaluate-boot-migration-policy.ts` instead.
17
17
  *
18
- * ADR-041/043/044/045 re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, Finding 2 — hard
18
+ * Recovery re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, Finding 2 — hard
19
19
  * blocker fix): this function is now actually invoked, by `server/runtime/boot/bootstrap.ts`'s
20
- * `database-migration-reconciliation` boot module (a CRITICAL ADR-046 Phase 2 boot module, runs
20
+ * `database-migration-reconciliation` boot module (a CRITICAL Phase 2 boot module, runs
21
21
  * first), before the real server accepts any traffic. It was previously fully built and
22
22
  * unit-tested but never called by any composition root — a real, live gap (not just a "seams
23
23
  * only" v1 disclosure) this fix closes. `evaluate-boot-migration-policy.ts`'s
@@ -1,23 +1,23 @@
1
1
  /**
2
- * @file SPEC-017 C-106 / CIC U-004 / REQ-15 / AC-17 — boot-time crash reconciliation
3
- * (ADR-041 §3).
2
+ * @file Boot-time crash reconciliation.
3
+ *
4
4
  *
5
5
  * Purpose:
6
6
  * A boot scanner that converts any non-terminal `migration_runs` row (read from the sidecar ops
7
- * journal — the only place guaranteed to survive a mid-crash restore of `content.db`, ADR-041 §2)
7
+ * journal — the only place guaranteed to survive a mid-crash restore of `content.db`)
8
8
  * into a `migration.interrupted` ledger row, and blocks normal site open until an operator
9
9
  * resolves it via Recovery. This is a real, accepted downtime vector, traded deliberately for
10
- * "never boot into a half-migrated schema" (ADR-041 §3).
10
+ * "never boot into a half-migrated schema".
11
11
  *
12
12
  * How it relates to the project:
13
13
  * The boot composition root calls this BEFORE `evaluate-boot-migration-policy.ts`'s
14
- * `evaluateBootMigrationPolicy` (C-107) every boot cycle (U-004-ORD1) — that ordering is a
14
+ * `evaluateBootMigrationPolicy` every boot cycle — that ordering is a
15
15
  * composition-root wiring concern this module cannot itself enforce; the sibling `defensive`
16
16
  * precondition check lives in `evaluate-boot-migration-policy.ts` instead.
17
17
  *
18
- * ADR-041/043/044/045 re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, Finding 2 — hard
18
+ * Recovery re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, Finding 2 — hard
19
19
  * blocker fix): this function is now actually invoked, by `server/runtime/boot/bootstrap.ts`'s
20
- * `database-migration-reconciliation` boot module (a CRITICAL ADR-046 Phase 2 boot module, runs
20
+ * `database-migration-reconciliation` boot module (a CRITICAL Phase 2 boot module, runs
21
21
  * first), before the real server accepts any traffic. It was previously fully built and
22
22
  * unit-tested but never called by any composition root — a real, live gap (not just a "seams
23
23
  * only" v1 disclosure) this fix closes. `evaluate-boot-migration-policy.ts`'s
@@ -1,33 +1,33 @@
1
1
  import type { Clock } from "@jini-ai/core/primitives";
2
2
  /**
3
- * @file SPEC-019 C-301/C-302/C-303 — the Recovery restore ceremony (ADR-045 §3, CIC U-001/U-002/
4
- * U-003).
3
+ * @file The Recovery restore ceremony.
4
+ *
5
5
  *
6
6
  * Purpose:
7
7
  * `planRestore` / `confirmRestore` / `executeRestore` — three separate exports, never a combined
8
8
  * single-call restore endpoint (AC-12, REQ-06). Each is a thin orchestration wrapper around the
9
- * SPEC-016 `core/gated-mutations` gateway (injected here as `deps.gateway`, since that module's
9
+ * `core/gated-mutations` gateway (injected here as `deps.gateway`, since that module's
10
10
  * real binding is a composition-root concern outside this domain's own certified test suite) plus
11
11
  * this domain's own binding constraints:
12
12
  *
13
- * - `planRestore` (CIC U-003): re-checks `costClass` FRESH at call time via `db-ops.getCapabilities()`
13
+ * - `planRestore`: re-checks `costClass` FRESH at call time via `db-ops.getCapabilities()`
14
14
  * — never a cached value — and refuses to reach the gateway at all once `costClass==='unavailable'`
15
- * is freshly confirmed (U-003-ORD1, REQ-12).
16
- * - `confirmRestore` (CIC U-002): rejects (mints no token) unless `disclosureAcknowledged===true`
15
+ * is freshly confirmed.
16
+ * - `confirmRestore`: rejects (mints no token) unless `disclosureAcknowledged===true`
17
17
  * STRICTLY (not merely truthy) — the composite of "the client claims acknowledgment" AND "the
18
18
  * `planId` resolves to a plan the server's own `planRestore` actually minted," the latter half
19
19
  * delegated entirely to the injected gateway's own plan-provenance verification.
20
- * - `executeRestore` (CIC U-001-ORD1): acquires the shared, cross-domain `core/operation-lock`
20
+ * - `executeRestore`: acquires the shared, cross-domain `core/operation-lock`
21
21
  * BEFORE the gateway's own `execute()` runs — the same primitive `features/database`'s
22
- * `executeMigrateForward` acquires, never an independent Recovery-local check (GOV-ADR-002) —
22
+ * `executeMigrateForward` acquires, never an independent Recovery-local check —
23
23
  * and always releases it afterward, success or failure. Never itself clears `PENDING_MIGRATION`
24
24
  * (REQ-18/EC-07 — restoring to an older snapshot does not resolve schema drift against the
25
- * current runtime, ADR-045 §4). A successful `RESTORED` completion attaches a deep-link back to
26
- * the Database Timeline (REQ-16/AC-26) — the incident thread's closing hop (ADR-041 §7).
25
+ * current runtime). A successful `RESTORED` completion attaches a deep-link back to
26
+ * the Database Timeline — the incident thread's closing hop.
27
27
  *
28
28
  * How it relates to the project:
29
29
  * `deps.gateway` stands in for a composition root's binding over the real
30
- * `core/gated-mutations.plan/confirm/execute` (SPEC-016) plus this domain's own hooks
30
+ * `core/gated-mutations.plan/confirm/execute` plus this domain's own hooks
31
31
  * (`domain="backup.restore"`); this file owns none of that gateway's own fixed check-sequence
32
32
  * (authorize -> token state -> actor-class -> plan-hash -> redeem), only this domain's binding
33
33
  * constraints layered around it.
@@ -71,9 +71,9 @@ export interface PlanRestoreRequired {
71
71
  };
72
72
  }
73
73
  /**
74
- * C-301/CIC U-003 — `plan()` step. Never reaches the gateway when a fresh `costClass` recheck
75
- * reports `'unavailable'` (U-003-ORD1); `'expensive'` still reaches it (only `'unavailable'`
76
- * short-circuits, per ADR-041 §2's "no attestation override" carried into this domain).
74
+ * `plan()` step. Never reaches the gateway when a fresh `costClass` recheck
75
+ * reports `'unavailable'`; `'expensive'` still reaches it (only `'unavailable'`
76
+ * short-circuits, per the "no attestation override" rule carried into this domain).
77
77
  *
78
78
  * @complexity O(1) plus one `getCapabilities()` call and, when not short-circuited, one
79
79
  * `gateway.plan()` call.
@@ -98,11 +98,11 @@ export interface ConfirmRestoreRequired {
98
98
  };
99
99
  }
100
100
  /**
101
- * C-302/CIC U-002 — `confirm()` step. `disclosureAcknowledged` must be exactly `true` (a truthy
102
- * non-boolean, e.g. the string `"true"`, is rejected — U-002-B1's exact wording) before the
101
+ * `confirm()` step. `disclosureAcknowledged` must be exactly `true` (a truthy
102
+ * non-boolean, e.g. the string `"true"`, is rejected) before the
103
103
  * gateway is ever consulted; plan provenance (whether `planId` was actually minted by this
104
104
  * server's own `planRestore`) is verified entirely by the injected gateway, never re-derived or
105
- * short-circuit-trusted here (U-002-ORD1).
105
+ * short-circuit-trusted here.
106
106
  *
107
107
  * @complexity O(1) plus, when the acknowledgment gate passes, one `gateway.confirm()` call.
108
108
  */
@@ -170,7 +170,7 @@ export interface ExecuteRestoreRequired {
170
170
  confirmationToken: string;
171
171
  siteId: string;
172
172
  /** Required only for `principalKind==='agent'` — the agent's current delegator, used as the
173
- * confirmer identity the gateway's own actor-class rule compares against (SPEC-016 REQ-13). */
173
+ * confirmer identity the gateway's own actor-class rule compares against. */
174
174
  delegatedByPrincipalId?: string;
175
175
  };
176
176
  }
@@ -178,7 +178,7 @@ export interface ExecuteRestoreValue {
178
178
  restoreRunId: string;
179
179
  state: string;
180
180
  /** Attached only on `state==='RESTORED'` (REQ-16/AC-26) — the deep-link back to the Database
181
- * Timeline that closes the incident thread ADR-041 §7 describes. */
181
+ * Timeline that closes the incident thread. */
182
182
  databaseTimelineDeepLink?: {
183
183
  v: 1;
184
184
  siteId: string;
@@ -191,11 +191,11 @@ export interface ExecuteRestoreValue {
191
191
  restartRequired?: boolean;
192
192
  }
193
193
  /**
194
- * C-303/CIC U-001-ORD1 — `execute()` step. Acquires the shared cross-domain operation lock BEFORE
194
+ * `execute()` step. Acquires the shared cross-domain operation lock BEFORE
195
195
  * the gateway's own `execute()` runs, and releases it in a `finally` regardless of outcome (never
196
196
  * leaks a held lock). Never calls `pendingMigrationTracker.clearPendingMigration()` — a restore to
197
197
  * an older snapshot does not, by itself, resolve schema drift against the current runtime
198
- * (ADR-045 §4).
198
+ *
199
199
  *
200
200
  * @complexity O(1) plus one lock acquire/release pair and one `gateway.execute()` call.
201
201
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
- * C-301/CIC U-003 — `plan()` step. Never reaches the gateway when a fresh `costClass` recheck
3
- * reports `'unavailable'` (U-003-ORD1); `'expensive'` still reaches it (only `'unavailable'`
4
- * short-circuits, per ADR-041 §2's "no attestation override" carried into this domain).
2
+ * `plan()` step. Never reaches the gateway when a fresh `costClass` recheck
3
+ * reports `'unavailable'`; `'expensive'` still reaches it (only `'unavailable'`
4
+ * short-circuits, per the "no attestation override" rule carried into this domain).
5
5
  *
6
6
  * @complexity O(1) plus one `getCapabilities()` call and, when not short-circuited, one
7
7
  * `gateway.plan()` call.
@@ -26,11 +26,11 @@ export async function planRestore(required, _optional = {}) {
26
26
  });
27
27
  }
28
28
  /**
29
- * C-302/CIC U-002 — `confirm()` step. `disclosureAcknowledged` must be exactly `true` (a truthy
30
- * non-boolean, e.g. the string `"true"`, is rejected — U-002-B1's exact wording) before the
29
+ * `confirm()` step. `disclosureAcknowledged` must be exactly `true` (a truthy
30
+ * non-boolean, e.g. the string `"true"`, is rejected) before the
31
31
  * gateway is ever consulted; plan provenance (whether `planId` was actually minted by this
32
32
  * server's own `planRestore`) is verified entirely by the injected gateway, never re-derived or
33
- * short-circuit-trusted here (U-002-ORD1).
33
+ * short-circuit-trusted here.
34
34
  *
35
35
  * @complexity O(1) plus, when the acknowledgment gate passes, one `gateway.confirm()` call.
36
36
  */
@@ -48,11 +48,11 @@ export async function confirmRestore(required, _optional = {}) {
48
48
  return deps.gateway.confirm({ planId: input.planId, planHash: input.planHash });
49
49
  }
50
50
  /**
51
- * C-303/CIC U-001-ORD1 — `execute()` step. Acquires the shared cross-domain operation lock BEFORE
51
+ * `execute()` step. Acquires the shared cross-domain operation lock BEFORE
52
52
  * the gateway's own `execute()` runs, and releases it in a `finally` regardless of outcome (never
53
53
  * leaks a held lock). Never calls `pendingMigrationTracker.clearPendingMigration()` — a restore to
54
54
  * an older snapshot does not, by itself, resolve schema drift against the current runtime
55
- * (ADR-045 §4).
55
+ *
56
56
  *
57
57
  * @complexity O(1) plus one lock acquire/release pair and one `gateway.execute()` call.
58
58
  */
@@ -67,7 +67,7 @@ export async function executeRestore(required, _optional = {}) {
67
67
  ok: false,
68
68
  error: {
69
69
  code: "RESTORE_OPERATION_IN_FLIGHT",
70
- message: acquireResult.error.message ?? `an operation is already in flight for site '${input.siteId}'`,
70
+ message: `an operation is already in flight for site '${input.siteId}'`,
71
71
  },
72
72
  };
73
73
  }
@@ -4,7 +4,7 @@ import type { RecoveryHookPolicy } from "./hook-policy.js";
4
4
  import type { MigrationRunsRepoPort, SiteStatusPort } from "./reconcile-interrupted-migration.js";
5
5
  import type { LedgerAppendPort } from "./migrate-forward-hooks.js";
6
6
  /**
7
- * @file Recovery's `GatedMutationHooks` factory for the `restore` ceremony (SPEC-019 C-301/C-303),
7
+ * @file Recovery's `GatedMutationHooks` factory for the `restore` ceremony,
8
8
  * plus `toRecoveryResult` (the throwing-gateway-to-`Result` adapter `recovery-orchestrator.ts`'s
9
9
  * ports declare) — the domain-specific quarter of what used to be
10
10
  * `server/gated-mutations-composition.ts`, split out so Recovery no longer needs a back-edge into
@@ -32,7 +32,7 @@ export interface BuildRestoreHooksInput extends RecoveryHookPolicy {
32
32
  }>>;
33
33
  };
34
34
  databaseLedgerRepo: LedgerAppendPort;
35
- /** SPEC-016 `DbOpsPort` — real (SQLite) composition performs the physical file swap;
35
+ /** `DbOpsPort` — real (SQLite) composition performs the physical file swap;
36
36
  * hermetic-test composition's in-memory double is a no-op (`restartRequired: false`). */
37
37
  dbOps: {
38
38
  restoreFromArtifact(required: {
@@ -51,29 +51,29 @@ export declare class RestorePointNotFoundError extends Error {
51
51
  constructor(message: string);
52
52
  }
53
53
  /**
54
- * SPEC-019 C-301/C-303 — the Recovery `restore` ceremony's `GatedMutationHooks`.
54
+ * The Recovery `restore` ceremony's `GatedMutationHooks`.
55
55
  *
56
56
  * `executeMutation()` is a deliberately, disclosedly SCOPED implementation: it validates the
57
57
  * target restore point still exists and records a real `restore.executed` `database_ledger` row —
58
58
  * the honest, auditable half of a restore. It does NOT physically overwrite the live `content.db`
59
59
  * file. This codebase has no mechanism to hot-swap the shared, already-open `content.db`
60
- * connection every other repo across `server/deps.ts` holds a reference to (doing so would either
60
+ * connection every other repo across a host module holds a reference to (doing so would either
61
61
  * crash every other in-flight request against a closed handle, or silently leave every existing
62
62
  * repo instance reading the stale pre-restore file) — inventing an unreviewed live-swap or
63
63
  * process-restart mechanism here is exactly the kind of unrequested architecture this dispatch's
64
- * own guardrails warn against, and ADR-041/ADR-045 do not pin a specific mechanism for it either.
64
+ * own guardrails warn against, and the original designs do not pin a specific mechanism for it either.
65
65
  * `[CIC_REQUESTED]` Unit=gated-mutations-composition Trigger=recovery restore execute
66
66
  * Property=REQ-06/AC-XX "a confirmed restore actually replaces content.db's data"
67
67
  * PlausibleWrong=silently faking a full hot restore, or crashing the process mid-request
68
68
  * MissingConstraint=a defined live-swap-or-restart mechanism for the shared `content.db`
69
- * connection Evidence=ADR-041 §2 (`content.db` restore = whole-file copy), ADR-045 §3, this file.
69
+ * connection Evidence=the original design (`content.db` restore = whole-file copy), this file.
70
70
  * The plan -> confirm -> execute ceremony itself (token flow, authorize, operation-lock,
71
71
  * disclosure-acknowledgment gate) is fully real and this file's own test coverage exercises it
72
72
  * end-to-end; only the final byte-for-byte file replacement is the disclosed gap.
73
73
  *
74
74
  * `scopeKind: "instance"` (internal audit, 2026-08-12): `dbOps.restoreFromArtifact` (`db/sqlite/
75
75
  * db-ops.ts`) physically swaps the entire `content.db` file, and a `content.db` can hold more
76
- * than one workspace row (`site-dir/resolve-workspace.ts`, ADR-007, SPEC-044's admin CRUD). A
76
+ * than one workspace row (`site-dir/resolve-workspace.ts`, the host's admin CRUD). A
77
77
  * principal authorized only within one workspace has no standing to replace data belonging to
78
78
  * every OTHER workspace that file also holds — the ordinary workspace-scoped `authorize()` this
79
79
  * hook used before would either deny every principal (no real workspace ever matches a
@@ -82,7 +82,7 @@ export declare class RestorePointNotFoundError extends Error {
82
82
  * composition.ts`'s `buildOwnerOnlyInstanceAuthorize` for the evaluator this now routes through.
83
83
  *
84
84
  * @complexity O(n) in the number of restore points (one `list()` scan per `computePlan` and per
85
- * `executeMutation` — low-volume, ADR-041 §2).
85
+ * `executeMutation` — low-volume).
86
86
  */
87
87
  export declare function buildRestoreHooks(input: BuildRestoreHooksInput, _optional?: Record<string, never>): GatedMutationHooks<{
88
88
  restorePointId: string;
@@ -8,29 +8,29 @@ export class RestorePointNotFoundError extends Error {
8
8
  }
9
9
  }
10
10
  /**
11
- * SPEC-019 C-301/C-303 — the Recovery `restore` ceremony's `GatedMutationHooks`.
11
+ * The Recovery `restore` ceremony's `GatedMutationHooks`.
12
12
  *
13
13
  * `executeMutation()` is a deliberately, disclosedly SCOPED implementation: it validates the
14
14
  * target restore point still exists and records a real `restore.executed` `database_ledger` row —
15
15
  * the honest, auditable half of a restore. It does NOT physically overwrite the live `content.db`
16
16
  * file. This codebase has no mechanism to hot-swap the shared, already-open `content.db`
17
- * connection every other repo across `server/deps.ts` holds a reference to (doing so would either
17
+ * connection every other repo across a host module holds a reference to (doing so would either
18
18
  * crash every other in-flight request against a closed handle, or silently leave every existing
19
19
  * repo instance reading the stale pre-restore file) — inventing an unreviewed live-swap or
20
20
  * process-restart mechanism here is exactly the kind of unrequested architecture this dispatch's
21
- * own guardrails warn against, and ADR-041/ADR-045 do not pin a specific mechanism for it either.
21
+ * own guardrails warn against, and the original designs do not pin a specific mechanism for it either.
22
22
  * `[CIC_REQUESTED]` Unit=gated-mutations-composition Trigger=recovery restore execute
23
23
  * Property=REQ-06/AC-XX "a confirmed restore actually replaces content.db's data"
24
24
  * PlausibleWrong=silently faking a full hot restore, or crashing the process mid-request
25
25
  * MissingConstraint=a defined live-swap-or-restart mechanism for the shared `content.db`
26
- * connection Evidence=ADR-041 §2 (`content.db` restore = whole-file copy), ADR-045 §3, this file.
26
+ * connection Evidence=the original design (`content.db` restore = whole-file copy), this file.
27
27
  * The plan -> confirm -> execute ceremony itself (token flow, authorize, operation-lock,
28
28
  * disclosure-acknowledgment gate) is fully real and this file's own test coverage exercises it
29
29
  * end-to-end; only the final byte-for-byte file replacement is the disclosed gap.
30
30
  *
31
31
  * `scopeKind: "instance"` (internal audit, 2026-08-12): `dbOps.restoreFromArtifact` (`db/sqlite/
32
32
  * db-ops.ts`) physically swaps the entire `content.db` file, and a `content.db` can hold more
33
- * than one workspace row (`site-dir/resolve-workspace.ts`, ADR-007, SPEC-044's admin CRUD). A
33
+ * than one workspace row (`site-dir/resolve-workspace.ts`, the host's admin CRUD). A
34
34
  * principal authorized only within one workspace has no standing to replace data belonging to
35
35
  * every OTHER workspace that file also holds — the ordinary workspace-scoped `authorize()` this
36
36
  * hook used before would either deny every principal (no real workspace ever matches a
@@ -39,7 +39,7 @@ export class RestorePointNotFoundError extends Error {
39
39
  * composition.ts`'s `buildOwnerOnlyInstanceAuthorize` for the evaluator this now routes through.
40
40
  *
41
41
  * @complexity O(n) in the number of restore points (one `list()` scan per `computePlan` and per
42
- * `executeMutation` — low-volume, ADR-041 §2).
42
+ * `executeMutation` — low-volume).
43
43
  */
44
44
  export function buildRestoreHooks(input, _optional = {}) {
45
45
  return {
@@ -78,7 +78,7 @@ export function buildRestoreHooks(input, _optional = {}) {
78
78
  createdAt: now,
79
79
  });
80
80
  // Round-5 re-audit (TM-adr041-043-044-045-audit-001, R5-F2 fix): a successful restore is the
81
- // ceremony ADR-041 §3's own text names as how an operator "resolves" a crash-interrupted
81
+ // ceremony the original design names as how an operator "resolves" a crash-interrupted
82
82
  // migration -- so it must actually exit BLOCKED_PENDING_RECOVERY, not just record a ledger
83
83
  // row. Terminalize whatever non-terminal migration_runs row exists for this site (if any --
84
84
  // a restore can also be run for reasons unrelated to a crash-interrupted migration, in which
@@ -1,13 +1,13 @@
1
1
  import type { PrincipalKind, Result } from "./recovery-orchestrator.js";
2
2
  /**
3
- * @file SPEC-019 C-304 / REQ-05 — `createRestorePoint`, an ordinary `authorize()`-gated mutation
4
- * (ADR-045 §3, "backup.create" independent of any migration).
3
+ * @file `createRestorePoint`, an ordinary `authorize()`-gated mutation
4
+ * ("backup.create" independent of any migration).
5
5
  *
6
6
  * Purpose:
7
7
  * Structurally distinct from the gated restore ceremony (`recovery-orchestrator.ts`): this never
8
8
  * calls the gateway's `plan()`/`confirm()`/`execute()` at all (AC-10) — it mints a restore point
9
9
  * directly once `authorize()` and the shared-lock "no operation in flight" check both pass.
10
- * `authorize()` runs on EVERY call, before the idempotency short-circuit (AC-11, SPEC-016 REQ-14)
10
+ * `authorize()` runs on EVERY call, before the idempotency short-circuit
11
11
  * — a repeated idempotency key never skips re-authorization, only re-creation.
12
12
  *
13
13
  * How it relates to the project:
@@ -1,5 +1,5 @@
1
- import { type VaultBatchOp, type VaultBatchResult, type VaultDefaultQuery, type VaultSingletonQuery, type VaultMeta, type VaultOptions, type VaultQuery, type VaultRecord, type VaultRepoPort } from "@jini-ai/platform/secrets/credential-sets/contracts";
2
- import type { StorageKernel } from "../kernel/port.js";
1
+ import { type VaultBatchOp, type VaultBatchResult, type VaultDefaultQuery, type VaultSingletonQuery, type VaultMeta, type VaultOptions, type VaultQuery, type VaultRecord, type VaultRepoPort } from "@jini-ai/core/contracts/vault";
2
+ import type { KyselyKernel } from "../kernel/port.js";
3
3
  /** Fixed columns consumed by the adapter; hosts own DDL, foreign keys and migration provenance.
4
4
  * A partial unique default index and label index use the same scope as VaultRepoPort.
5
5
  * Nullable principal/provider scope columns must be normalized in those index expressions, spelled
@@ -35,7 +35,7 @@ export interface SecretsVaultDatabase {
35
35
  export declare class SqlSecretsVaultRepo implements VaultRepoPort {
36
36
  private readonly kernel;
37
37
  constructor({ kernel }: {
38
- kernel: StorageKernel<SecretsVaultDatabase>;
38
+ kernel: KyselyKernel<SecretsVaultDatabase>;
39
39
  }, _options?: VaultOptions);
40
40
  private write;
41
41
  private group;
@@ -1,6 +1,7 @@
1
1
  import { sql } from "kysely";
2
- import { assertVaultReplacement, VaultError } from "@jini-ai/platform/secrets/credential-sets/contracts";
3
- import { jsonSet, toBool } from "../kernel/dialect.js";
2
+ import { assertVaultReplacement, VaultError, } from "@jini-ai/core/contracts/vault";
3
+ import { jsonSet } from "../kernel/dialect.js";
4
+ import { toBool } from "@jini-ai/core/contracts/storage";
4
5
  function fromRow(row) {
5
6
  const parts = [row.sealed_key_id, row.sealed_ciphertext, row.sealed_nonce, row.sealed_alg];
6
7
  if (parts.some(v => v === null) && !parts.every(v => v === null))
@@ -14,7 +15,7 @@ function fromRow(row) {
14
15
  }
15
16
  return { workspaceId: row.workspace_id, id: row.id, kind: row.kind, ownerKey: row.owner_key,
16
17
  principalId: row.principal_id, binding: row.binding, provider: row.provider, label: row.label,
17
- isDefault: toBool(row.is_default) ?? false, revision: Number(row.revision),
18
+ isDefault: toBool({ value: row.is_default }) ?? false, revision: Number(row.revision),
18
19
  sealed: row.sealed_key_id === null ? null : { keyId: row.sealed_key_id, ciphertext: row.sealed_ciphertext, nonce: row.sealed_nonce, alg: row.sealed_alg },
19
20
  last4: row.last4, tokenLength: row.token_length,
20
21
  meta,
@@ -173,7 +174,7 @@ export class SqlSecretsVaultRepo {
173
174
  const row = await this.kernel.run(db => db.updateTable("secrets_vault").set(eb => {
174
175
  let meta = eb.ref("meta");
175
176
  for (const [key, value] of Object.entries(input.patch))
176
- meta = jsonSet(this.kernel.dialect, meta, [key], value);
177
+ meta = jsonSet({ dialect: this.kernel.dialect, column: meta, path: [key], value });
177
178
  return { meta: meta, revision: eb("revision", "+", 1), updated_at: input.updatedAt };
178
179
  }).where("workspace_id", "=", input.workspaceId).where("id", "=", input.id)
179
180
  .where("revision", "=", input.expectedRevision).returningAll().executeTakeFirst());
@@ -0,0 +1,3 @@
1
+ export { SqlSettingsRepo, type SettingsSqlRequired, type SettingsTables } from "./repo.sql.js";
2
+ export type { SettingDefinitionsTable, SettingRevisionsTable, SettingValuesGlobalTable, SettingValuesUserTable, SettingValuesWorkspaceTable, } from "./repo.rows.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { SqlSettingsRepo } from "./repo.sql.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,117 @@
1
+ import type { Generated, Insertable, Selectable } from "kysely";
2
+ import type { DefinitionStatus, SettingDefinitionRecord, SettingRevisionRecord, SettingScope, SettingValueRecord, ValueState } from "@jini-ai/core/settings";
3
+ /** Stored column shapes, copied without schema changes; table names are host-owned (see `SettingsTables`). */
4
+ export interface SettingDefinitionsTable {
5
+ setting_id: string;
6
+ version: Generated<number>;
7
+ workspace_id: string | null;
8
+ namespace: string;
9
+ key: string;
10
+ owner_kind: string;
11
+ owner_id: string | null;
12
+ schema_json: string;
13
+ default_json: string | null;
14
+ scopes: number;
15
+ secret: Generated<number>;
16
+ status: string;
17
+ alias_of_key: string | null;
18
+ alias_of_ns: string | null;
19
+ coercion_json: string | null;
20
+ created_at: string;
21
+ updated_at: string;
22
+ }
23
+ export interface SettingRevisionsTable {
24
+ seq: Generated<number>;
25
+ entity_kind: string;
26
+ setting_id: string;
27
+ scope: string | null;
28
+ workspace_id: string | null;
29
+ principal_id: string | null;
30
+ op: string;
31
+ before_json: string | null;
32
+ after_json: string | null;
33
+ def_version: number;
34
+ actor: string;
35
+ origin_plugin_id: string | null;
36
+ change_set_id: string | null;
37
+ created_at: string;
38
+ }
39
+ export interface SettingValuesGlobalTable {
40
+ setting_id: string;
41
+ value_json: string | null;
42
+ state: Generated<string>;
43
+ def_version: number;
44
+ seq: number;
45
+ updated_by: string;
46
+ updated_at: string;
47
+ origin_plugin_id: string | null;
48
+ }
49
+ export interface SettingValuesWorkspaceTable {
50
+ setting_id: string;
51
+ workspace_id: string;
52
+ value_json: string | null;
53
+ state: Generated<string>;
54
+ def_version: number;
55
+ seq: number;
56
+ updated_by: string;
57
+ updated_at: string;
58
+ origin_plugin_id: string | null;
59
+ }
60
+ export interface SettingValuesUserTable {
61
+ setting_id: string;
62
+ workspace_id: string;
63
+ principal_id: string;
64
+ value_json: string | null;
65
+ state: Generated<string>;
66
+ def_version: number;
67
+ seq: number;
68
+ updated_by: string;
69
+ updated_at: string;
70
+ origin_plugin_id: string | null;
71
+ }
72
+ /** The columns every value table shares. */
73
+ export type ValueRow = Pick<Selectable<SettingValuesGlobalTable>, "setting_id" | "value_json" | "state" | "def_version" | "seq" | "updated_by" | "updated_at" | "origin_plugin_id">;
74
+ export declare function toDefinitionRecord(row: Selectable<SettingDefinitionsTable>): SettingDefinitionRecord;
75
+ /** Every definition column an upsert may rewrite: all but the identity (`setting_id`, `version`) and `created_at`. */
76
+ export declare function toDefinitionUpdate({ record }: {
77
+ record: SettingDefinitionRecord;
78
+ }, _optional?: Record<string, never>): {
79
+ workspace_id: string | null;
80
+ namespace: string;
81
+ key: string;
82
+ owner_kind: import("@jini-ai/core/settings").SettingOwnerKind;
83
+ owner_id: string | null;
84
+ schema_json: string;
85
+ default_json: string | null;
86
+ scopes: number;
87
+ secret: number;
88
+ status: DefinitionStatus;
89
+ alias_of_key: string | null;
90
+ alias_of_ns: string | null;
91
+ coercion_json: string | null;
92
+ updated_at: string;
93
+ };
94
+ export declare function toDefinitionRow({ record }: {
95
+ record: SettingDefinitionRecord;
96
+ }, _optional?: Record<string, never>): Insertable<SettingDefinitionsTable>;
97
+ export declare function toValueRecord({ row, scope, workspaceId, principalId }: {
98
+ row: ValueRow;
99
+ scope: SettingScope;
100
+ workspaceId: string | null;
101
+ principalId: string | null;
102
+ }, _optional?: Record<string, never>): SettingValueRecord;
103
+ /** The columns every value table shares, as written. `state='set'` always serializes the value (even
104
+ * JSON `null`) as text so it's distinguishable from a SQL-NULL 'cleared' row. */
105
+ export declare function valueColumns({ record }: {
106
+ record: SettingValueRecord;
107
+ }, _optional?: Record<string, never>): {
108
+ value_json: string | null;
109
+ state: ValueState;
110
+ def_version: number;
111
+ seq: number;
112
+ updated_by: string;
113
+ updated_at: string;
114
+ origin_plugin_id: string | null;
115
+ };
116
+ export declare function toRevisionRecord(row: Selectable<SettingRevisionsTable>): SettingRevisionRecord;
117
+ //# sourceMappingURL=repo.rows.d.ts.map
@@ -0,0 +1,106 @@
1
+ /**
2
+ * `coercion_json` holds the coercer tag as a JSON string (`"identity"`): the column is jsonb on
3
+ * Postgres, which rejects a bare tag. A SQLite row written before that holds the bare tag itself;
4
+ * migration `0003_coercion_json_as_json` rewrites those, and this still reads one as-is.
5
+ */
6
+ function decodeCoercionTag({ text }, _optional = {}) {
7
+ if (text == null)
8
+ return null;
9
+ try {
10
+ const parsed = JSON.parse(text);
11
+ return typeof parsed === "string" ? parsed : text;
12
+ }
13
+ catch {
14
+ return text;
15
+ }
16
+ }
17
+ export function toDefinitionRecord(row) {
18
+ return {
19
+ settingId: row.setting_id,
20
+ version: row.version,
21
+ workspaceId: row.workspace_id,
22
+ namespace: row.namespace,
23
+ key: row.key,
24
+ ownerKind: row.owner_kind,
25
+ ownerId: row.owner_id,
26
+ schema: JSON.parse(row.schema_json),
27
+ defaultValue: row.default_json == null ? null : JSON.parse(row.default_json),
28
+ scopes: row.scopes,
29
+ secret: Number(row.secret) === 1,
30
+ status: row.status,
31
+ aliasOfNamespace: row.alias_of_ns,
32
+ aliasOfKey: row.alias_of_key,
33
+ coercionTag: decodeCoercionTag({ text: row.coercion_json }),
34
+ createdAt: row.created_at,
35
+ updatedAt: row.updated_at,
36
+ };
37
+ }
38
+ /** Every definition column an upsert may rewrite: all but the identity (`setting_id`, `version`) and `created_at`. */
39
+ export function toDefinitionUpdate({ record }, _optional = {}) {
40
+ return {
41
+ workspace_id: record.workspaceId,
42
+ namespace: record.namespace,
43
+ key: record.key,
44
+ owner_kind: record.ownerKind,
45
+ owner_id: record.ownerId,
46
+ schema_json: JSON.stringify(record.schema),
47
+ default_json: record.defaultValue == null ? null : JSON.stringify(record.defaultValue),
48
+ scopes: record.scopes,
49
+ secret: record.secret ? 1 : 0,
50
+ status: record.status,
51
+ alias_of_key: record.aliasOfKey,
52
+ alias_of_ns: record.aliasOfNamespace,
53
+ coercion_json: record.coercionTag == null ? null : JSON.stringify(record.coercionTag),
54
+ updated_at: record.updatedAt,
55
+ };
56
+ }
57
+ export function toDefinitionRow({ record }, _optional = {}) {
58
+ return { setting_id: record.settingId, version: record.version, created_at: record.createdAt, ...toDefinitionUpdate({ record }) };
59
+ }
60
+ export function toValueRecord({ row, scope, workspaceId, principalId }, _optional = {}) {
61
+ return {
62
+ settingId: row.setting_id,
63
+ scope,
64
+ workspaceId,
65
+ principalId,
66
+ valueJson: row.value_json == null ? null : JSON.parse(row.value_json),
67
+ state: row.state,
68
+ defVersion: row.def_version,
69
+ seq: row.seq,
70
+ updatedBy: row.updated_by,
71
+ updatedAt: row.updated_at,
72
+ originPluginId: row.origin_plugin_id,
73
+ };
74
+ }
75
+ /** The columns every value table shares, as written. `state='set'` always serializes the value (even
76
+ * JSON `null`) as text so it's distinguishable from a SQL-NULL 'cleared' row. */
77
+ export function valueColumns({ record }, _optional = {}) {
78
+ return {
79
+ value_json: record.state === "cleared" ? null : JSON.stringify(record.valueJson),
80
+ state: record.state,
81
+ def_version: record.defVersion,
82
+ seq: record.seq,
83
+ updated_by: record.updatedBy,
84
+ updated_at: record.updatedAt,
85
+ origin_plugin_id: record.originPluginId,
86
+ };
87
+ }
88
+ export function toRevisionRecord(row) {
89
+ return {
90
+ seq: row.seq,
91
+ entityKind: row.entity_kind,
92
+ settingId: row.setting_id,
93
+ scope: row.scope,
94
+ workspaceId: row.workspace_id,
95
+ principalId: row.principal_id,
96
+ op: row.op,
97
+ beforeJson: row.before_json == null ? null : JSON.parse(row.before_json),
98
+ afterJson: row.after_json == null ? null : JSON.parse(row.after_json),
99
+ defVersion: row.def_version,
100
+ actor: row.actor,
101
+ originPluginId: row.origin_plugin_id,
102
+ changeSetId: row.change_set_id,
103
+ createdAt: row.created_at,
104
+ };
105
+ }
106
+ //# sourceMappingURL=repo.rows.js.map