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

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 (89) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +46 -1
  3. package/dist/core/ports.d.ts +2 -2
  4. package/dist/core/ports.js +2 -2
  5. package/dist/data-modules/data-module.d.ts +2 -46
  6. package/dist/data-modules/plugin-identity.d.ts +2 -11
  7. package/dist/data-modules/snapshot.d.ts +5 -3
  8. package/dist/data-modules/snapshot.js +5 -3
  9. package/dist/events/change-set-repo.sql.d.ts +18 -5
  10. package/dist/events/change-set-repo.sql.js +25 -8
  11. package/dist/events/index.d.ts +1 -1
  12. package/dist/events/outbox-repo.sql.d.ts +26 -1
  13. package/dist/events/outbox-repo.sql.js +36 -2
  14. package/dist/events/repo.rows.d.ts +22 -4
  15. package/dist/events/repo.rows.js +32 -4
  16. package/dist/kernel/idle-turn.d.ts +62 -0
  17. package/dist/kernel/idle-turn.js +32 -0
  18. package/dist/kernel/index.d.ts +1 -0
  19. package/dist/kernel/index.js +1 -0
  20. package/dist/kernel/kernel-core.js +28 -0
  21. package/dist/kernel/schema-scope.js +2 -0
  22. package/dist/kernel/sqlite/driver.js +2 -0
  23. package/dist/kernel/turn-lock.d.ts +2 -0
  24. package/dist/kernel/turn-lock.js +7 -0
  25. package/dist/pglite/copy-source.d.ts +45 -0
  26. package/dist/pglite/copy-source.js +36 -0
  27. package/dist/pglite/index.d.ts +1 -0
  28. package/dist/pglite/index.js +1 -0
  29. package/dist/react/recovery/Recovery.d.ts +205 -0
  30. package/dist/react/recovery/Recovery.js +141 -0
  31. package/dist/react/recovery/Recovery.restore-steps.d.ts +10 -0
  32. package/dist/react/recovery/Recovery.restore-steps.js +71 -0
  33. package/dist/recovery/agent-tools.d.ts +33 -0
  34. package/dist/recovery/agent-tools.js +166 -0
  35. package/dist/recovery/drift.d.ts +47 -0
  36. package/dist/recovery/drift.js +51 -0
  37. package/dist/recovery/journal-kernel.d.ts +80 -0
  38. package/dist/recovery/journal-kernel.js +40 -0
  39. package/dist/recovery/journal-repo.sql.d.ts +154 -0
  40. package/dist/recovery/journal-repo.sql.js +303 -0
  41. package/dist/recovery/journal-schema.d.ts +37 -0
  42. package/dist/recovery/journal-schema.js +110 -0
  43. package/dist/recovery/migrate-forward-hooks.d.ts +2 -1
  44. package/dist/recovery/migrate-forward-hooks.js +3 -3
  45. package/dist/recovery/operation-lock.d.ts +2 -17
  46. package/dist/recovery/reconcile-interrupted-migration.d.ts +2 -5
  47. package/dist/recovery/reconcile-interrupted-migration.js +0 -30
  48. package/dist/recovery/restore-hooks.d.ts +4 -0
  49. package/dist/recovery/restore-hooks.js +1 -1
  50. package/dist/recovery/tool-registrations.d.ts +175 -0
  51. package/dist/recovery/tool-registrations.js +295 -0
  52. package/dist/site/repo.memory.d.ts +149 -0
  53. package/dist/site/repo.memory.js +162 -0
  54. package/dist/site/tool-registrations.d.ts +130 -0
  55. package/dist/site/tool-registrations.js +185 -0
  56. package/dist/sqlite/backup-policy.d.ts +14 -0
  57. package/dist/sqlite/backup-policy.js +47 -3
  58. package/dist/sqlite/compaction-steps.d.ts +43 -0
  59. package/dist/sqlite/compaction-steps.js +73 -0
  60. package/dist/sqlite/compaction.d.ts +63 -0
  61. package/dist/sqlite/compaction.js +263 -0
  62. package/dist/sqlite/index.d.ts +2 -1
  63. package/dist/sqlite/index.js +2 -1
  64. package/dist/tools/index.d.ts +2 -0
  65. package/dist/tools/index.js +2 -0
  66. package/dist/tools/plan-store.d.ts +1 -1
  67. package/dist/tools/plan-store.js +10 -6
  68. package/dist/tools/site-db-messages.d.ts +10 -0
  69. package/dist/tools/site-db-messages.js +23 -0
  70. package/dist/tools/site-transfer-messages.d.ts +9 -0
  71. package/dist/tools/site-transfer-messages.js +20 -0
  72. package/dist/transfer/confirmation-ui.d.ts +19 -0
  73. package/dist/transfer/confirmation-ui.js +39 -0
  74. package/dist/transfer/copy-engine.js +11 -11
  75. package/dist/transfer/destination-store.d.ts +69 -0
  76. package/dist/transfer/destination-store.js +75 -0
  77. package/dist/transfer/index.d.ts +2 -0
  78. package/dist/transfer/index.js +2 -0
  79. package/dist/transfer/internal-ddl.d.ts +6 -2
  80. package/dist/transfer/internal-ddl.js +15 -15
  81. package/dist/transfer/postgres-ddl.js +2 -2
  82. package/dist/transfer/schema-catalog.d.ts +148 -0
  83. package/dist/transfer/schema-catalog.js +141 -0
  84. package/dist/transfer/sqlite-backup.d.ts +27 -0
  85. package/dist/transfer/sqlite-backup.js +31 -0
  86. package/dist/transfer/table-catalog.js +1 -0
  87. package/dist/watermark/kernel.d.ts +64 -0
  88. package/dist/watermark/kernel.js +45 -0
  89. package/package.json +105 -10
@@ -0,0 +1,32 @@
1
+ const controls = new WeakMap();
2
+ /** Records the control of a kernel built by `buildKernel`. Not exported from the package. */
3
+ export function registerIdleTurn({ kernel, control }, _optional = {}) {
4
+ controls.set(kernel, control);
5
+ }
6
+ /** A wrapper kernel (schema-scoped, owned connection) shares its source's lock and control. */
7
+ export function inheritIdleTurn({ from, to }, _optional = {}) {
8
+ const control = controls.get(from);
9
+ if (control !== undefined)
10
+ controls.set(to, control);
11
+ }
12
+ /**
13
+ * Run `body` in an exclusive turn on a one-connection kernel, only if the kernel is idle right now.
14
+ * Never queues (I2), never joins a transaction (I3), always releases (I5).
15
+ * @complexity O(1) admission plus the body.
16
+ */
17
+ export async function withIdleTurn({ kernel, body }, _optional = {}) {
18
+ const control = controls.get(kernel);
19
+ if (control === undefined)
20
+ return { ran: false, reason: "unsupported" };
21
+ await kernel.ready;
22
+ const taken = control.tryTake();
23
+ if ("refusal" in taken)
24
+ return { ran: false, reason: taken.refusal };
25
+ try {
26
+ return { ran: true, value: await control.runHeld(body) };
27
+ }
28
+ finally {
29
+ taken.release();
30
+ }
31
+ }
32
+ //# sourceMappingURL=idle-turn.js.map
@@ -6,6 +6,7 @@
6
6
  export type { DbTransport, KyselyKernel } from "./port.js";
7
7
  export { buildKernel, type KernelDriver } from "./kernel-core.js";
8
8
  export { TurnLock } from "./turn-lock.js";
9
+ export { withIdleTurn, type IdleTurnRefusal, type IdleTurnResult } from "./idle-turn.js";
9
10
  export { autoIdColumnSql, checkpointWal, type ColumnAffinity, columnTypeSql, type IndexInfo, jsonScalarEquals, jsonSet, jsonSortKey, jsonText, listColumns, listIndexes, listTables, nowIso, tableExists, } from "./dialect.js";
10
11
  export { scopeToSchema } from "./schema-scope.js";
11
12
  export { databaseFile, readSchemaShape, type SchemaShape, type TableShape } from "./schema-shape.js";
@@ -1,5 +1,6 @@
1
1
  export { buildKernel } from "./kernel-core.js";
2
2
  export { TurnLock } from "./turn-lock.js";
3
+ export { withIdleTurn } from "./idle-turn.js";
3
4
  export { autoIdColumnSql, checkpointWal, columnTypeSql, jsonScalarEquals, jsonSet, jsonSortKey, jsonText, listColumns, listIndexes, listTables, nowIso, tableExists, } from "./dialect.js";
4
5
  export { scopeToSchema } from "./schema-scope.js";
5
6
  export { databaseFile, readSchemaShape } from "./schema-shape.js";
@@ -4,6 +4,7 @@ import {} from "./port.js";
4
4
  import { UnsupportedCapabilityError, } from "@jini-ai/core/contracts/storage";
5
5
  import { TurnLock } from "./turn-lock.js";
6
6
  import { registerOwnedTransaction } from "./owned-transaction.js";
7
+ import { registerIdleTurn } from "./idle-turn.js";
7
8
  /** The turn locks the caller's async context holds, across every kernel in the process. */
8
9
  const heldLocks = new AsyncLocalStorage();
9
10
  /**
@@ -121,7 +122,34 @@ export function buildKernel({ driver }, _optional = {}) {
121
122
  assertAvailable: () => assertOwnedAvailable({ rt }),
122
123
  transaction: (work, optional = {}) => transaction(work, optional),
123
124
  } });
125
+ registerIdleTurn({ kernel: kernel, control: idleTurnControl({ rt }) });
124
126
  registerKernelSessionDatabase({ kernel: kernel, database: driver.base, ...(driver.poolMax === undefined ? {} : { poolMax: driver.poolMax }) });
125
127
  return kernel;
126
128
  }
129
+ /**
130
+ * Admission for `withIdleTurn`. The turn lock is checked BEFORE the transaction state: an owned
131
+ * transaction holds the lock, so it is ordinary kernel work that clears by itself and answers
132
+ * "busy" (invariant I2). "transaction-open" is left for a transaction the kernel does not own —
133
+ * a raw `BEGIN` on the shared handle — which only the connection itself can reveal. A refusal
134
+ * after the lock was taken releases it before returning.
135
+ */
136
+ function idleTurnControl({ rt }) {
137
+ return {
138
+ tryTake() {
139
+ const { lock, scope } = rt;
140
+ if (lock === undefined)
141
+ return { refusal: "unsupported" };
142
+ if (scope.getStore() !== undefined || heldLocks.getStore()?.has(lock) === true)
143
+ return { refusal: "in-scope" };
144
+ if (!lock.tryAcquire("exclusive"))
145
+ return { refusal: "busy" };
146
+ if (rt.own.transactions > 0 || rt.driver.foreignTransactionOpen?.() === true) {
147
+ lock.release("exclusive");
148
+ return { refusal: "transaction-open" };
149
+ }
150
+ return { release: () => lock.release("exclusive") };
151
+ },
152
+ runHeld: (body) => heldLocks.run(new Set([...(heldLocks.getStore() ?? []), ...(rt.lock ? [rt.lock] : [])]), body),
153
+ };
154
+ }
127
155
  //# sourceMappingURL=kernel-core.js.map
@@ -1,5 +1,6 @@
1
1
  import { inheritKernelSessionDatabase } from "./session-lock.js";
2
2
  import { inheritOwnedTransaction } from "./owned-transaction.js";
3
+ import { inheritIdleTurn } from "./idle-turn.js";
3
4
  /**
4
5
  * @file A kernel whose query-builder statements address one Postgres schema: every `run()` body gets
5
6
  * `db.withSchema(schema)` (Kysely's own plugin prefixes each table it names). Used when one
@@ -19,6 +20,7 @@ export function scopeToSchema({ kernel, schema }, _optional = {}) {
19
20
  run: (fn) => kernel.run((db) => fn(db.withSchema(schema))),
20
21
  };
21
22
  inheritOwnedTransaction({ from: kernel, to: scoped });
23
+ inheritIdleTurn({ from: kernel, to: scoped });
22
24
  inheritKernelSessionDatabase({ from: kernel, to: scoped });
23
25
  return scoped;
24
26
  }
@@ -4,6 +4,7 @@ import { Kysely, SqliteDialect } from "kysely";
4
4
  import { buildKernel, TurnLock } from "../index.js";
5
5
  import { checkedClients, checkedStates, connectionsByKernel, rawKernelClients } from "../../sqlite/checked-state.js";
6
6
  import { inheritOwnedTransaction } from "../owned-transaction.js";
7
+ import { inheritIdleTurn } from "../idle-turn.js";
7
8
  const kernels = new WeakMap();
8
9
  /** One turn lock per database FILE, shared by every connection to it in this process. */
9
10
  const fileTurnLocks = new Map();
@@ -135,6 +136,7 @@ export function openSqliteFileKernel(required, optional = {}) {
135
136
  };
136
137
  connectionsByKernel.set(owned, client);
137
138
  inheritOwnedTransaction({ from: kernel, to: owned });
139
+ inheritIdleTurn({ from: kernel, to: owned });
138
140
  return owned;
139
141
  }
140
142
  /**
@@ -13,6 +13,8 @@ export declare class TurnLock {
13
13
  private exclusive;
14
14
  private readonly waiting;
15
15
  acquire(kind: Kind): Promise<void>;
16
+ /** Take the lock only if it is free AND nobody is queued; never waits, so queued callers are never overtaken. O(1). */
17
+ tryAcquire(kind: Kind): boolean;
16
18
  release(kind: Kind): void;
17
19
  private fits;
18
20
  private take;
@@ -18,6 +18,13 @@ export class TurnLock {
18
18
  }
19
19
  return new Promise((grant) => this.waiting.push({ kind, grant }));
20
20
  }
21
+ /** Take the lock only if it is free AND nobody is queued; never waits, so queued callers are never overtaken. O(1). */
22
+ tryAcquire(kind) {
23
+ if (this.waiting.length > 0 || !this.fits(kind))
24
+ return false;
25
+ this.take(kind);
26
+ return true;
27
+ }
21
28
  release(kind) {
22
29
  if (kind === "exclusive")
23
30
  this.exclusive = false;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @file The served-versus-stopped copy lifecycle of a PGlite data dir.
3
+ *
4
+ * Reaching the source: when THIS process serves it (copying the store you are running), through its owner's
5
+ * exclusive window; otherwise the source must be stopped — the copy takes the data dir's owner lock for the
6
+ * duration, so nothing writes to it meanwhile. A source served by another live process is refused by the
7
+ * lock port (its owner is the only one who may open it); the host maps that refusal to its own error.
8
+ */
9
+ /** What the host supplies: the concrete PGlite owner/kernel/storage operations and the lock-refusal mapping. */
10
+ export interface PgliteSourceCopyPorts<Owner, Source extends {
11
+ close(): Promise<void>;
12
+ }> {
13
+ runningOwner(required: {
14
+ dataDir: string;
15
+ }): Owner | undefined;
16
+ copyServed(required: {
17
+ owner: Owner;
18
+ targetPath: string;
19
+ }): Promise<void>;
20
+ /** Takes the data dir's owner lock and returns its release; throws the host's error when another process holds it. */
21
+ acquireOwnerLock(required: {
22
+ dataDir: string;
23
+ }): () => void;
24
+ /** May throw synchronously. */
25
+ openStopped(required: {
26
+ dataDir: string;
27
+ }): Source;
28
+ copyStopped(required: {
29
+ source: Source;
30
+ targetPath: string;
31
+ }): Promise<void>;
32
+ }
33
+ /**
34
+ * Copies the source data dir to `targetDataDir` through the right door (see this file's header).
35
+ * @throws Whatever a port throws (the lock refusal, an open or copy failure); the owner lock is always released.
36
+ * @complexity One dump + restore of the whole data dir, bounded by the site's size.
37
+ */
38
+ export declare function copyPgliteSourceTo<Owner, Source extends {
39
+ close(): Promise<void>;
40
+ }>({ sourceDataDir, targetDataDir, ports }: {
41
+ sourceDataDir: string;
42
+ targetDataDir: string;
43
+ ports: PgliteSourceCopyPorts<Owner, Source>;
44
+ }, _optional?: {}): Promise<void>;
45
+ //# sourceMappingURL=copy-source.d.ts.map
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @file The served-versus-stopped copy lifecycle of a PGlite data dir.
3
+ *
4
+ * Reaching the source: when THIS process serves it (copying the store you are running), through its owner's
5
+ * exclusive window; otherwise the source must be stopped — the copy takes the data dir's owner lock for the
6
+ * duration, so nothing writes to it meanwhile. A source served by another live process is refused by the
7
+ * lock port (its owner is the only one who may open it); the host maps that refusal to its own error.
8
+ */
9
+ /**
10
+ * Copies the source data dir to `targetDataDir` through the right door (see this file's header).
11
+ * @throws Whatever a port throws (the lock refusal, an open or copy failure); the owner lock is always released.
12
+ * @complexity One dump + restore of the whole data dir, bounded by the site's size.
13
+ */
14
+ export async function copyPgliteSourceTo({ sourceDataDir, targetDataDir, ports }, _optional = {}) {
15
+ const owner = ports.runningOwner({ dataDir: sourceDataDir });
16
+ if (owner !== undefined) {
17
+ await ports.copyServed({ owner, targetPath: targetDataDir });
18
+ return;
19
+ }
20
+ const release = ports.acquireOwnerLock({ dataDir: sourceDataDir });
21
+ // Nested so the lock is released however the open, the copy or the close fails: the open can
22
+ // throw synchronously, and a rejected close must not skip `release()` for the process's life.
23
+ try {
24
+ const source = ports.openStopped({ dataDir: sourceDataDir });
25
+ try {
26
+ await ports.copyStopped({ source, targetPath: targetDataDir });
27
+ }
28
+ finally {
29
+ await source.close();
30
+ }
31
+ }
32
+ finally {
33
+ release();
34
+ }
35
+ }
36
+ //# sourceMappingURL=copy-source.js.map
@@ -2,4 +2,5 @@
2
2
  export { startPgliteOwner, runningPgliteOwner, acquireOwnerLock, defaultPgliteSocketDir, assertSocketPathFits, ensurePrivateDir, PgliteOwnerLockedError, PGLITE_LOW_MEMORY_SETTINGS, pgliteLowMemoryStartParams, type PgliteOwner } from "./owner.js";
3
3
  export { PgliteSocketServer, errorResponseFrame, type PgliteSocketServerOptions } from "./socket-server.js";
4
4
  export type { PgliteClass } from "./types.js";
5
+ export { copyPgliteSourceTo, type PgliteSourceCopyPorts } from "./copy-source.js";
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,5 @@
1
1
  /** PGlite ownership and socket serving. The consumer supplies its PGlite class. */
2
2
  export { startPgliteOwner, runningPgliteOwner, acquireOwnerLock, defaultPgliteSocketDir, assertSocketPathFits, ensurePrivateDir, PgliteOwnerLockedError, PGLITE_LOW_MEMORY_SETTINGS, pgliteLowMemoryStartParams } from "./owner.js";
3
3
  export { PgliteSocketServer, errorResponseFrame } from "./socket-server.js";
4
+ export { copyPgliteSourceTo } from "./copy-source.js";
4
5
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,205 @@
1
+ import type { ComponentType, ReactNode } from "react";
2
+ import type { AdminRecoveryStatusEnvelope as AdminRecoveryStatus } from "@jini-ai/core/contracts/site/cms-recovery";
3
+ import { type Translate } from "@jini-ai/core/text";
4
+ type Empty = Record<string, never>;
5
+ interface AdminRestorePoint {
6
+ readonly id: string;
7
+ /** What caused this point to be captured (e.g. `"manual"`, `"pre-migration"`) — host-defined. */
8
+ readonly trigger: string;
9
+ readonly costClass: string;
10
+ readonly kind: string;
11
+ /** Null when the host has no watermark concept or none was available at capture time. */
12
+ readonly watermarkAtCapture: number | null;
13
+ readonly createdAt: string;
14
+ }
15
+ interface AdminDisclosureResult {
16
+ readonly partial: true;
17
+ /** `false` means the disclosure could not establish a watermark baseline to diff against — the
18
+ * `counts` below may be less trustworthy than usual, and a panel should say so rather than
19
+ * present them with the same confidence as a normal disclosure. */
20
+ readonly watermarkBaselineAvailable: boolean;
21
+ readonly counts: Readonly<Record<string, number | "unknown">>;
22
+ }
23
+ interface RecoveryController {
24
+ /** `null` until the initial load settles — the caller renders a loading state. */
25
+ status: AdminRecoveryStatus | null;
26
+ points: AdminRestorePoint[] | null;
27
+ error: string | null;
28
+ /** `creating` reflects the in-flight no-argument restore-point creation request. */
29
+ creating: boolean;
30
+ createRestorePoint: () => Promise<void>;
31
+ /** The restore point a "Restore…" row action selected, or the one a resolved deep link matched —
32
+ * `null` shows the plain list, non-null swaps in `RestoreFlow` (design-spec.md §0.1: a full
33
+ * inline swap, never a modal-over-list). */
34
+ selected: AdminRestorePoint | null;
35
+ setSelected: (point: AdminRestorePoint | null) => void;
36
+ /** Bound translator — `key` already resolved against the caller's locale, so `Recovery.tsx` never
37
+ * imports `useAdminLocale`/`recovery-i18n` for the top-level screen. See this file's header. */
38
+ t: Translate;
39
+ /** Raw resolved locale — `Recovery.tsx`'s local `DegradedBannerView`/`RestorePointsList`
40
+ * subcomponents take `locale` directly rather than a bound translator. See this file's header. */
41
+ locale: string;
42
+ }
43
+ interface RestoreFlowController {
44
+ disclosure: AdminDisclosureResult | null;
45
+ error: string | null;
46
+ acknowledged: boolean;
47
+ setAcknowledged: (checked: boolean) => void;
48
+ step: CeremonyStep;
49
+ busy: boolean;
50
+ ceremonyError: string | null;
51
+ plan: {
52
+ planId: string;
53
+ planHash: string;
54
+ } | null;
55
+ confirmationToken: string | null;
56
+ result: {
57
+ restoreRunId: string;
58
+ state: string;
59
+ restartRequired?: boolean | undefined;
60
+ } | null;
61
+ startPlan: () => Promise<void>;
62
+ doConfirm: () => Promise<void>;
63
+ doExecute: () => Promise<void>;
64
+ /** Bound translator — `key` already resolved against the caller's locale, so `RestoreFlow` never
65
+ * imports `useAdminLocale`/`recovery-i18n` itself. See this file's header. */
66
+ t: Translate;
67
+ /** Raw resolved locale — `RestoreFlow`'s own local step subcomponents and several
68
+ * `recovery-i18n.tsx` helpers take `locale` directly rather than a bound translator. See this
69
+ * file's header. */
70
+ locale: string;
71
+ }
72
+ type CeremonyStep = "idle" | "planned" | "confirmed" | "done";
73
+ export interface RecoveryProps {
74
+ /** The `?tab=` query value from `panels.tsx`'s `recovery` route (`URLSearchParams.get` returns
75
+ * `null` when the param is absent). Validated by `useRecoveryNavigation`. */
76
+ tabId?: string | null;
77
+ /**
78
+ * Dependency injection seam for tests — the same convention `@jini-ai/ui`'s `CustomSelect` uses
79
+ * for `useCustomSelect`. The host supplies its wired hook. See `PostsProps.usePostsHook` for the full rationale.
80
+ */
81
+ useRecoveryHook: () => RecoveryController;
82
+ useRestoreFlowHook: (required: {
83
+ point: AdminRestorePoint;
84
+ }, options?: Empty) => RestoreFlowController;
85
+ useRecoveryNavigationHook: (required: {
86
+ tabId?: string | null | undefined;
87
+ setSelected: (point: AdminRestorePoint | null) => void;
88
+ port: RecoveryProps["navigationPort"];
89
+ }, options?: Empty) => {
90
+ activeTabId: string;
91
+ onTabChange: (nextTabId: string) => void;
92
+ onSelectPoint: (point: AdminRestorePoint) => void;
93
+ onBackFromFlow: () => void;
94
+ };
95
+ navigationPort: {
96
+ navigate: (required: {
97
+ routePath: string;
98
+ }, options: {
99
+ replace?: boolean;
100
+ }) => void;
101
+ };
102
+ kit: {
103
+ DataTable: ComponentType<{
104
+ rows: readonly AdminRestorePoint[];
105
+ rowKey: (row: AdminRestorePoint, index: number) => string;
106
+ empty: ReactNode;
107
+ columns: readonly {
108
+ key: string;
109
+ header?: ReactNode;
110
+ headerLabel?: string;
111
+ cell: (row: AdminRestorePoint, index: number) => ReactNode;
112
+ }[];
113
+ }>;
114
+ I18nProvider: ComponentType<{
115
+ initialLocale: string;
116
+ dictionaries: RecoveryProps["dictionaries"];
117
+ fallbackLocale: "en";
118
+ syncDocumentAttributes: false;
119
+ children: ReactNode;
120
+ }>;
121
+ SettingsDialogShell: ComponentType<{
122
+ tabs: readonly {
123
+ id: string;
124
+ label: string;
125
+ title: string;
126
+ panel: ReactNode;
127
+ }[];
128
+ activeTabId: string;
129
+ onActiveTabIdChange: (tabId: string) => void;
130
+ presentation: "inline";
131
+ className: string;
132
+ fullscreenEnabled: false;
133
+ dialogAriaLabelledBy: string;
134
+ labels: {
135
+ kicker: string;
136
+ sidebarAriaLabel: string;
137
+ };
138
+ }>;
139
+ };
140
+ ServerLabel: ComponentType<{
141
+ value: string;
142
+ }>;
143
+ dictionaries: Partial<Record<string, Record<string, string>>>;
144
+ viewerTimeZone: string;
145
+ copy: {
146
+ t: (required: {
147
+ locale: string;
148
+ key: string;
149
+ }, options?: Empty) => string;
150
+ sinceDiscardMessage: (required: {
151
+ locale: string;
152
+ createdAt: string;
153
+ }, options?: Empty) => ReactNode;
154
+ discardCountLine: (required: {
155
+ locale: string;
156
+ count: number | "unknown";
157
+ categoryLabelText: string;
158
+ classNames: {
159
+ row: string;
160
+ quantity: string;
161
+ category: string;
162
+ };
163
+ }, options?: Empty) => ReactNode;
164
+ baselineUnavailableMessage: (required: {
165
+ locale: string;
166
+ }, options?: Empty) => ReactNode;
167
+ restorePlanReadyMessage: (required: {
168
+ locale: string;
169
+ planId: string;
170
+ }, options?: Empty) => ReactNode;
171
+ restoreDoneMessage: (required: {
172
+ locale: string;
173
+ restoreRunId: string;
174
+ stateNode: ReactNode;
175
+ }, options?: Empty) => ReactNode;
176
+ categoryLabel: (required: {
177
+ category: string;
178
+ locale: string;
179
+ }, options?: Empty) => string;
180
+ costClassLabel: (required: {
181
+ costClass: string;
182
+ locale: string;
183
+ }, options?: Empty) => string;
184
+ isAssertiveRecoveryBanner: (banner: NonNullable<AdminRecoveryStatus["banner"]>) => boolean;
185
+ recoveryBannerTone: (banner: NonNullable<AdminRecoveryStatus["banner"]>) => "error" | "warning" | "";
186
+ restoreButtonAccessibleName: (required: {
187
+ locale: string;
188
+ point: Pick<AdminRestorePoint, "createdAt">;
189
+ viewerTimeZone: string;
190
+ }, options?: Empty) => string;
191
+ };
192
+ }
193
+ export interface RestoreFlowProps {
194
+ point: AdminRestorePoint;
195
+ onBack: () => void;
196
+ /** Dependency injection seam for tests — see `PostsProps.usePostsHook` for the convention.
197
+ * The host supplies its wired restore hook. */
198
+ useRestoreFlowHook: RecoveryProps["useRestoreFlowHook"];
199
+ copy: RecoveryProps["copy"];
200
+ ServerLabel: RecoveryProps["ServerLabel"];
201
+ viewerTimeZone: string;
202
+ }
203
+ export declare function Recovery({ useRecoveryHook, tabId, useRecoveryNavigationHook, useRestoreFlowHook, navigationPort, kit: { I18nProvider, SettingsDialogShell }, kit, ServerLabel, dictionaries, copy, viewerTimeZone }: RecoveryProps): import("react").JSX.Element;
204
+ export {};
205
+ //# sourceMappingURL=Recovery.d.ts.map
@@ -0,0 +1,141 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { agentHandle, buildAgentListHandles } from "@jini-ai/core/agent-handles";
3
+ import { formatTimestamp } from "@jini-ai/core/text";
4
+ import { RestoreFlowBody } from "./Recovery.restore-steps.js";
5
+ /**
6
+ * @file Recovery screen (design-spec.md §4, ADR-045) — the `/admin/recovery` route.
7
+ *
8
+ * Per design-spec.md §0.1: one screen, holding every restore-point capability — never a separate
9
+ * "Backups" route (ADR-045 explicitly rejects that shape). `development/todos.md`'s "Recovery vs
10
+ * Database's Restore Points tab" entry (owner, 2026-09-10, superseded same morning) is the reason
11
+ * this now has two tabs rather than Database's old three: Database's `RestorePointsSection`
12
+ * (list + create, no restore action) moved here in full, and Database's own `restore-points` tab
13
+ * was removed — restore points were never a "database" concern per the owner's own call. This
14
+ * still applies §6's own recommendation (a full swap, not a modal-over-list) — the swap is now
15
+ * between the two tabs below instead of an untabbed inline ternary.
16
+ *
17
+ * ## Tabs (2026-09-10)
18
+ *
19
+ * The initial implementation chose `TabBar` because this is a list-plus-ceremony operational
20
+ * surface, the same shape as Database, rather than a settings form. The owner's explicit
21
+ * `SettingsDialogShell` requirement takes precedence (2026-10-04 cleanup): the inline shell now
22
+ * matches Agent Plugins, while retaining `?tab=` deep-linking and replace-history navigation.
23
+ * Two tabs: **Restore points** (`RestorePointsPanel` — the list, the create action, and
24
+ * the entry point into a restore) and **Restore** (`RestoreTabPanel` — `RestoreFlow` for whichever
25
+ * point is selected, or a prompt back to the list when nothing is selected yet). Selecting a row
26
+ * and confirming/cancelling the ceremony both navigate between the two tabs explicitly (see
27
+ * `use-recovery-navigation.hooks.ts`) rather than deriving the active tab from `selected` — both
28
+ * sections stay independently reachable either way, same as Database's URL-owned tabs.
29
+ *
30
+ * The restore ceremony (`plan`/`confirm`/`execute`, SPEC-019 C-301/C-302/C-303) is wired to the
31
+ * real `core/gated-mutations`-backed routes (Session 5-6 backend gap closure). `executeRestore`
32
+ * now physically swaps `content.db` (2026-07-16, `DbOpsPort.restoreFromArtifact` — an atomic
33
+ * same-filesystem rename, closing the previously-disclosed "ledger-only" gap). Restart-based, by
34
+ * design, not a live hot-swap: the already-running process keeps its own open file handle to the
35
+ * pre-restore data until an operator restarts it — `restartRequired: true` on the response is
36
+ * that signal, surfaced below rather than silently implied.
37
+ *
38
+ * ## Markup only
39
+ *
40
+ * `Recovery`'s own list/status/create state lives in `hooks/use-recovery.hooks.ts`; `RestoreFlow`'s
41
+ * ceremony state lives in `hooks/use-restore-flow.hooks.ts` — independent state with its own
42
+ * lifecycle, keyed to whichever restore point is selected. `DegradedBannerView`,
43
+ * `RestorePointsList`, `RestorePointsPanel`, and `DisclosurePanel` hold no state of their own and
44
+ * stay as plain, props-driven presentation with no hook. Pure logic (category labels, cost-class
45
+ * badge text/tone, the banner urgency check and severity, the deep-link envelope parse) lives in
46
+ * `rules.ts`.
47
+ *
48
+ * `src/__tests__/unit/admin-nav-recovery-acs.unit.test.ts` reads this file's source directly
49
+ * (`readFileSync`) to assert AC-32 against the `page-description` copy below — keep that
50
+ * `className="page-description">...</p>` line intact if editing the header copy.
51
+ *
52
+ * `locale`/`t`: `Recovery` and `RestoreFlow` each have their own hook (`useRecovery`,
53
+ * `useRestoreFlow`), and each hook already independently calls `useAdminLocale()` for its own
54
+ * error-string translations — so each component now gets `t`/`locale` from its OWN hook rather than
55
+ * `Recovery` threading a single resolved `locale` down as a prop, per the standing i18n rule. This
56
+ * adds no new fetch (see each hook's own file header). `DegradedBannerView`/`RestorePointsList`/
57
+ * `RestorePointsPanel` have no hook of their own, so they keep receiving `locale` as a prop from
58
+ * `Recovery` and receive the unbound translator from the host.
59
+ */
60
+ function DegradedBannerView(props) {
61
+ const { locale, status, copy: { t, isAssertiveRecoveryBanner, recoveryBannerTone } } = props;
62
+ const banner = status.banner;
63
+ if (!banner)
64
+ return null;
65
+ // AC-27/EC-06/INV-07: `pending-migration`'s action always deep-links to Database's own
66
+ // migration ceremony, never a Recovery restore action — restoring to an older snapshot does not
67
+ // resolve schema drift against the current runtime.
68
+ const assertive = isAssertiveRecoveryBanner(banner);
69
+ // Not every degraded state is equally bad — see `recoveryBannerTone`'s own doc comment.
70
+ const tone = recoveryBannerTone(banner);
71
+ return (_jsxs("div", { className: `notice ${tone} recovery-degraded-banner recovery-plain-notice`, role: assertive ? "alert" : undefined, "aria-live": assertive ? "assertive" : "polite", children: [_jsx("span", { children: banner.accessibleText }), banner.actionKind === "deep-link-to-database-migration" ? (_jsx("a", { className: "btn-secondary", href: "/admin/database", ...agentHandle({ handle: "recovery-banner-go-to-database" }, { role: "link", label: "Go to Database to resolve the pending migration" }), children: t({ locale: locale, key: "Go to Database" }) })) : null, banner.actionKind === "unblock-interrupted-migration" ? (_jsx("button", { type: "button", disabled: true, title: t({ locale: locale, key: "No unblock route exists yet — see this screen's file header." }), ...agentHandle({ handle: "recovery-banner-unblock" }, { role: "button", label: "Unblock an interrupted migration (not yet available)" }), children: t({ locale: locale, key: "Unblock (not yet available)" }) })) : null] }));
72
+ }
73
+ function RestorePointsList(props) {
74
+ const { locale, kit: { DataTable }, copy: { t, costClassLabel, restoreButtonAccessibleName }, viewerTimeZone: VIEWER_TIME_ZONE } = props;
75
+ // Restore-point ids are stable and unique, same per-row-handle derivation every other list on
76
+ // this workstream uses (`buildAgentListHandles`) — needed because `DataTable`'s `cell` callback
77
+ // only receives the row, not its index.
78
+ const rowHandles = buildAgentListHandles({ prefix: "recovery-row", ids: props.points.map((p) => p.id) });
79
+ const rowHandleById = new Map(props.points.map((p, index) => [p.id, rowHandles[index]]));
80
+ return (_jsx(DataTable, { rows: props.points, rowKey: (p) => p.id, empty: _jsx("div", { className: "card", children: _jsx("div", { className: "empty-state", children: _jsx("p", { children: t({ locale: locale, key: "No restore points yet." }) }) }) }), columns: [
81
+ { key: "timestamp", header: t({ locale: locale, key: "Timestamp" }), cell: (p) => formatTimestamp({ iso: p.createdAt }, { viewerTimeZone: VIEWER_TIME_ZONE }) },
82
+ { key: "trigger", header: t({ locale: locale, key: "Trigger" }), cell: (p) => p.trigger },
83
+ {
84
+ key: "cost-class",
85
+ header: t({ locale: locale, key: "Cost class" }),
86
+ cell: (p) => _jsx("span", { className: `status status-${p.costClass}`, children: costClassLabel({ costClass: p.costClass, locale: locale }) }),
87
+ },
88
+ {
89
+ key: "restore",
90
+ cell: (p) => p.costClass === "unavailable" ? (_jsx("span", { className: "muted-cell", children: t({ locale: locale, key: "No restore-point mechanism available — see the runbook." }) })) : (_jsx("button", { type: "button", onClick: () => props.onSelect(p), "aria-label": restoreButtonAccessibleName({ locale: locale, point: p, viewerTimeZone: VIEWER_TIME_ZONE }), ...agentHandle({ handle: `${rowHandleById.get(p.id)}-restore` }, { role: "button", label: "Begin the restore ceremony for this restore point" }), children: t({ locale: locale, key: "Restore…" }) })),
91
+ },
92
+ ] }));
93
+ }
94
+ /** The "Restore points" tab's full panel — `RestorePointsList` (unchanged from before the tabs
95
+ * pass) plus the create action Database's own `RestorePointsSection` used to own
96
+ * (`development/todos.md`'s "Recovery vs Database's Restore Points tab" entry, 2026-09-10). Split
97
+ * out from `RestorePointsList` itself, rather than folding the header/button into it, so the bare
98
+ * list stays reusable exactly as it already is for anything that only needs the table (there is no
99
+ * such caller today, but the split cost nothing and matches how `Database.tsx`'s own
100
+ * `RestorePointsSection` kept its header separate from its `DataTable` call). */
101
+ function RestorePointsPanel(props) {
102
+ const { locale, kit, copy, viewerTimeZone, copy: { t } } = props;
103
+ return (_jsxs("div", { children: [_jsxs("div", { className: "editor-header", children: [_jsx("h2", { children: t({ locale: locale, key: "Restore points" }) }), _jsx("button", { type: "button", onClick: () => props.onCreate(), disabled: props.creating, ...agentHandle({ handle: "recovery-create-restore-point" }, { role: "button", label: "Create a new restore point now" }), children: props.creating ? t({ locale: locale, key: "Creating…" }) : t({ locale: locale, key: "Create restore point" }) })] }), _jsx(RestorePointsList, { locale: locale, points: props.points, onSelect: props.onSelect, kit: kit, copy: copy, viewerTimeZone: viewerTimeZone })] }));
104
+ }
105
+ function RestoreFlow({ point, onBack, useRestoreFlowHook, copy, ServerLabel, viewerTimeZone }) {
106
+ const controller = useRestoreFlowHook({ point });
107
+ return _jsx(RestoreFlowBody, { point: point, onBack: onBack, controller: controller, copy: copy, ServerLabel: ServerLabel, viewerTimeZone: viewerTimeZone });
108
+ }
109
+ /** The "Restore" tab's own panel — `RestoreFlow` for whichever point is selected, or a prompt back
110
+ * to the "Restore points" tab when nothing is selected yet (a direct `?tab=restore` visit, or the
111
+ * ceremony was already backed out of via `onBack`). Originally split out so `recoveryTabPanel`
112
+ * stayed a flat dispatch (Database's same complexity-gate reason). The shared shell now owns
113
+ * that dispatch; this component keeps the selected-point guard out of the page's markup. */
114
+ function RestoreTabPanel(props) {
115
+ if (!props.selected) {
116
+ return (_jsx("div", { className: "notice", children: _jsx("p", { children: props.copy.t({ locale: props.locale, key: "Select a restore point from the Restore points tab to begin." }) }) }));
117
+ }
118
+ return _jsx(RestoreFlow, { point: props.selected, onBack: props.onBack, useRestoreFlowHook: props.useRestoreFlowHook, copy: props.copy, ServerLabel: props.ServerLabel, viewerTimeZone: props.viewerTimeZone });
119
+ }
120
+ export function Recovery({ useRecoveryHook, tabId, useRecoveryNavigationHook, useRestoreFlowHook, navigationPort, kit: { I18nProvider, SettingsDialogShell }, kit, ServerLabel, dictionaries, copy, viewerTimeZone }) {
121
+ const { status, points, error, creating, createRestorePoint, selected, setSelected, t, locale } = useRecoveryHook();
122
+ const { activeTabId, onTabChange, onSelectPoint, onBackFromFlow } = useRecoveryNavigationHook({ tabId, setSelected, port: navigationPort });
123
+ if (error && !points)
124
+ return _jsx("div", { className: "notice error", children: error });
125
+ if (!points || !status)
126
+ return _jsx("div", { className: "notice", children: t("Loading restore points…") });
127
+ // The former recoveryTabPanel used a flat dispatch to avoid nested JSX branch complexity.
128
+ // The shell now owns that dispatch: each tab supplies one presentation-only panel.
129
+ const tabs = [
130
+ {
131
+ id: "restore-points", label: t("Restore points"), title: t("Recovery"),
132
+ panel: _jsx(RestorePointsPanel, { kit: kit, copy: copy, viewerTimeZone: viewerTimeZone, locale: locale, points: points, creating: creating, onCreate: createRestorePoint, onSelect: onSelectPoint }),
133
+ },
134
+ {
135
+ id: "restore", label: t("Restore"), title: t("Recovery"),
136
+ panel: _jsx(RestoreTabPanel, { useRestoreFlowHook: useRestoreFlowHook, copy: copy, ServerLabel: ServerLabel, viewerTimeZone: viewerTimeZone, locale: locale, selected: selected, onBack: onBackFromFlow }),
137
+ },
138
+ ];
139
+ return (_jsxs("div", { className: "page", children: [_jsx("div", { className: "page-header", children: _jsxs("div", { className: "page-header-text", children: [_jsx("p", { className: "page-kicker", children: t("Operations") }), _jsx("h1", { className: "page-title", children: t("Recovery") }), _jsx("p", { className: "page-description", children: t("Restore this site to a previous point in time using a captured restore point.") })] }) }), error ? _jsx("div", { className: "notice error", children: error }) : null, _jsx(DegradedBannerView, { locale: locale, status: status, copy: copy }), _jsx(I18nProvider, { initialLocale: locale, dictionaries: dictionaries, fallbackLocale: "en", syncDocumentAttributes: false, children: _jsx("div", { className: "settings-ui-section settings-ui-section--page-flow recovery-section", ...agentHandle({ handle: "recovery-tab-bar" }, { role: "region", label: t("Recovery") }), children: _jsx(SettingsDialogShell, { tabs: tabs, activeTabId: activeTabId, onActiveTabIdChange: onTabChange, presentation: "inline", className: "jini-tabbed-dialog--inline", fullscreenEnabled: false, dialogAriaLabelledBy: "recovery-shell-title", labels: { kicker: "", sidebarAriaLabel: t("Recovery") } }) }) })] }));
140
+ }
141
+ //# sourceMappingURL=Recovery.js.map
@@ -0,0 +1,10 @@
1
+ import type { RecoveryProps, RestoreFlowProps } from "./Recovery.js";
2
+ export declare function RestoreFlowBody({ point, onBack, controller, copy, ServerLabel, viewerTimeZone: VIEWER_TIME_ZONE }: {
3
+ point: RestoreFlowProps["point"];
4
+ onBack: () => void;
5
+ controller: ReturnType<RecoveryProps["useRestoreFlowHook"]>;
6
+ copy: RecoveryProps["copy"];
7
+ ServerLabel: RecoveryProps["ServerLabel"];
8
+ viewerTimeZone: string;
9
+ }): import("react").JSX.Element;
10
+ //# sourceMappingURL=Recovery.restore-steps.d.ts.map