@jini-ai/db 0.2.0 → 0.3.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 +26 -10
- package/dist/core/artifact-naming.d.ts +4 -1
- package/dist/core/artifact-naming.js +3 -4
- package/dist/core/index.d.ts +1 -0
- package/dist/core/messages.d.ts +1 -1
- package/dist/core/pg-types.d.ts +52 -0
- package/dist/core/pg-types.js +8 -0
- package/dist/core/transfer-naming.d.ts +10 -0
- package/dist/core/transfer-naming.js +2 -0
- package/dist/kernel/dialect.d.ts +2 -1
- package/dist/kernel/dialect.js +5 -2
- package/dist/kernel/postgres/driver.d.ts +1 -1
- package/dist/kernel/postgres/driver.js +1 -1
- package/dist/kernel/postgres/pglite-socket.d.ts +1 -1
- package/dist/kernel/postgres/pglite-socket.js +1 -1
- package/dist/pg-fixture.d.ts +50 -0
- package/dist/pg-fixture.js +84 -0
- package/dist/pglite/owner.js +7 -0
- package/dist/postgres/index.d.ts +1 -1
- package/dist/postgres/index.js +1 -1
- package/dist/postgres/types.d.ts +1 -52
- package/dist/postgres/types.js +2 -13
- package/dist/recovery/deep-link.d.ts +60 -0
- package/dist/recovery/deep-link.js +16 -0
- package/dist/recovery/degraded-banners.d.ts +40 -0
- package/dist/recovery/degraded-banners.js +69 -0
- package/dist/recovery/disclosure.d.ts +58 -0
- package/dist/recovery/disclosure.js +55 -0
- package/dist/recovery/evaluate-boot-migration-policy.d.ts +41 -0
- package/dist/recovery/evaluate-boot-migration-policy.js +50 -0
- package/dist/recovery/hook-policy.d.ts +9 -0
- package/dist/recovery/hook-policy.js +2 -0
- package/dist/recovery/index.d.ts +15 -0
- package/dist/recovery/index.js +13 -0
- package/dist/recovery/lookup-adapters.d.ts +40 -0
- package/dist/recovery/lookup-adapters.js +44 -0
- package/dist/recovery/migrate-forward-execute.d.ts +65 -0
- package/dist/recovery/migrate-forward-execute.js +68 -0
- package/dist/recovery/migrate-forward-hooks.d.ts +118 -0
- package/dist/recovery/migrate-forward-hooks.js +85 -0
- package/dist/recovery/operation-lock.d.ts +78 -0
- package/dist/recovery/operation-lock.js +58 -0
- package/dist/recovery/reconcile-interrupted-migration.d.ts +73 -0
- package/dist/recovery/reconcile-interrupted-migration.js +47 -0
- package/dist/recovery/recovery-orchestrator.d.ts +204 -0
- package/dist/recovery/recovery-orchestrator.js +96 -0
- package/dist/recovery/restore-hooks.d.ts +105 -0
- package/dist/recovery/restore-hooks.js +154 -0
- package/dist/recovery/restore-point-create.d.ts +80 -0
- package/dist/recovery/restore-point-create.js +37 -0
- package/dist/sqlite/open.d.ts +1 -1
- package/dist/sqlite/open.js +3 -3
- package/dist/sqlite/restore-types.d.ts +7 -3
- package/dist/tools/read-tools.js +7 -4
- package/dist/tools/restore-points.d.ts +3 -0
- package/dist/tools/restore-points.js +2 -2
- package/dist/tools/surface-port.d.ts +11 -29
- package/dist/tools/timeline.d.ts +4 -0
- package/dist/tools/timeline.js +8 -2
- package/dist/tools/transfer-tools.js +36 -37
- package/dist/transfer/internal-ddl.d.ts +3 -0
- package/dist/transfer/internal-ddl.js +6 -2
- package/dist/transfer/types.d.ts +3 -9
- package/package.json +48 -6
- package/dist/kernel/pg-types.d.ts +0 -22
- package/dist/kernel/pg-types.js +0 -26
- package/dist/kernel/socket.d.ts +0 -8
- package/dist/kernel/socket.js +0 -8
- package/dist/pglite/dialect.d.ts +0 -11
- package/dist/pglite/dialect.js +0 -88
- package/dist/pglite/driver.d.ts +0 -30
- package/dist/pglite/driver.js +0 -46
- package/dist/pglite/ops.d.ts +0 -39
- package/dist/pglite/ops.js +0 -78
- package/dist/postgres/driver.d.ts +0 -23
- package/dist/postgres/driver.js +0 -41
- package/dist/postgres/ops.d.ts +0 -12
- package/dist/postgres/ops.js +0 -46
- package/dist/postgres/pglite-socket.d.ts +0 -23
- package/dist/postgres/pglite-socket.js +0 -51
- package/dist/sqlite/driver.d.ts +0 -71
- package/dist/sqlite/driver.js +0 -132
- package/dist/sqlite/ops.d.ts +0 -12
- package/dist/sqlite/ops.js +0 -40
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SPEC-019 C-308 / behavior.spec.md §1.1 — degraded-state banner precedence resolver
|
|
3
|
+
* (ADR-045 §4).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Fixed precedence, highest to lowest: `migration.interrupted` > `PENDING_MIGRATION` >
|
|
7
|
+
* operation-in-flight > `costClass:'unavailable'` > watermark-baseline-unavailable. Only the
|
|
8
|
+
* PRIMARY banner selection is this resolver's contract (EC-06) — "an interrupted-run banner stays
|
|
9
|
+
* visible beneath a superseded pending-migration banner" is a rendering-layer composition concern
|
|
10
|
+
* this function does not own.
|
|
11
|
+
*
|
|
12
|
+
* `PENDING_MIGRATION`'s action always deep-links to the Database Timeline's own migration ceremony, never a
|
|
13
|
+
* Recovery restore-flow action (AC-27/INV-07, ADR-045 §4) — restoring to an older snapshot does
|
|
14
|
+
* not resolve schema drift against the current runtime.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* AC-27/AC-29/EC-06/INV-07 — resolves the single primary degraded banner per the fixed precedence
|
|
18
|
+
* order, or `null` when no degraded condition holds.
|
|
19
|
+
*
|
|
20
|
+
* @complexity O(1) — a fixed sequence of independent comparisons, no loop.
|
|
21
|
+
*/
|
|
22
|
+
export function resolveDegradedBanner(required, _optional = {}) {
|
|
23
|
+
const { capabilities } = required;
|
|
24
|
+
if (capabilities.migrationInterrupted) {
|
|
25
|
+
return {
|
|
26
|
+
kind: "migration-interrupted",
|
|
27
|
+
accessibleText: "A migration was interrupted mid-run. This is a real, accepted planned downtime vector, not a bug — resolve it to reopen normal Database/Recovery navigation.",
|
|
28
|
+
actionKind: "unblock-interrupted-migration",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (capabilities.pendingMigration) {
|
|
32
|
+
return {
|
|
33
|
+
kind: "pending-migration",
|
|
34
|
+
accessibleText: "This site is pending a schema migration before normal public serving can resume. Resolve it from the Database Timeline's own migration ceremony.",
|
|
35
|
+
actionKind: "deep-link-to-database-migration",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (capabilities.operationInFlight) {
|
|
39
|
+
return {
|
|
40
|
+
kind: "operation-in-flight",
|
|
41
|
+
accessibleText: "An operation is already in progress for this site. A second migrate or restore cannot start until it finishes.",
|
|
42
|
+
actionKind: "none",
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (capabilities.costClass === "unavailable") {
|
|
46
|
+
return {
|
|
47
|
+
kind: "cost-unavailable",
|
|
48
|
+
accessibleText: "No restore-point mechanism is available for this site. See the runbook for external backup guidance.",
|
|
49
|
+
actionKind: "none",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (!capabilities.watermarkBaselineAvailable) {
|
|
53
|
+
return {
|
|
54
|
+
kind: "watermark-baseline-unavailable",
|
|
55
|
+
// Rewritten (web-design pass): the prior copy said "right now", which frames this as a
|
|
56
|
+
// transient blip an operator might retry — but `watermarkBaselineAvailable` is currently a
|
|
57
|
+
// hardcoded `false` (an "honest stub", see both `disclosure.ts` and this route's own
|
|
58
|
+
// `status.ts`), not a live computation that can fail-then-succeed. "Right now" is therefore
|
|
59
|
+
// actively misleading about the site's real state. This text also avoids the internal terms
|
|
60
|
+
// "discarded-write-window"/"watermark baseline" and says what still works (restoring) and
|
|
61
|
+
// what the operator will see instead (counts marked "unknown", not a verified zero — the
|
|
62
|
+
// same word `DisclosurePanel`'s own per-point disclosure uses, so the two stay consistent).
|
|
63
|
+
accessibleText: "This site can't show exactly what a restore would discard. Restoring still works — the counts you'll see are marked \"unknown\" rather than a confirmed number.",
|
|
64
|
+
actionKind: "none",
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=degraded-banners.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SPEC-019 C-305 / REQ-09-REQ-11 / INV-05 — the discarded-write-window disclosure
|
|
3
|
+
* computation (ADR-045 §2, Step 2 of the restore ceremony).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Never asserts a numeric count for a category outside the versioned `coveredCategories` constant
|
|
7
|
+
* (INV-05) — a category not yet migrated onto the watermark chokepoint (ADR-041 §5's evolving
|
|
8
|
+
* write-path inventory) simply never appears in the output, even if a caller-supplied count source
|
|
9
|
+
* happens to have data for it (AC-17's `entries` case: Collections' write path is not yet
|
|
10
|
+
* watermark-stamped, so it must never be disclosed as covered here regardless of what any count
|
|
11
|
+
* source reports). Renders `"unknown"` — never `0` — for every covered category whenever the
|
|
12
|
+
* watermark baseline itself could not be established, whether because `content.db` was entirely
|
|
13
|
+
* unreadable (AC-19/EC-08) or because the specific restore point predates the
|
|
14
|
+
* `watermarkAtCapture` column (EC-02) — a null baseline must never be silently treated as a
|
|
15
|
+
* zero-baseline (matches SPEC-016 EC-06's identical rule).
|
|
16
|
+
*
|
|
17
|
+
* `result.partial` is always `true` — this disclosure is never claimed exhaustive (ADR-041 §5's
|
|
18
|
+
* own "no exhaustiveness claim until the automated write-path inventory runs clean" carried
|
|
19
|
+
* verbatim into this domain, ADR-045 §2).
|
|
20
|
+
*
|
|
21
|
+
* How it relates to the project:
|
|
22
|
+
* `coveredCategories` is the single, auditable edit point ADR-PIPE-019's File Map names this file
|
|
23
|
+
* for — a new category is added here only once its own write path is confirmed watermark-stamped,
|
|
24
|
+
* never inferred from whatever a count source happens to return.
|
|
25
|
+
*/
|
|
26
|
+
export type CategoryCount = number | "unknown";
|
|
27
|
+
export interface WatermarkBaseline {
|
|
28
|
+
available: boolean;
|
|
29
|
+
watermarkAtCapture?: number | null;
|
|
30
|
+
currentWatermark?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface DisclosureWatermarkSourcePort {
|
|
33
|
+
getBaseline(): Promise<WatermarkBaseline>;
|
|
34
|
+
getCategoryCounts(): Promise<Record<string, number>>;
|
|
35
|
+
}
|
|
36
|
+
export interface ComputeDisclosureRequired {
|
|
37
|
+
deps: {
|
|
38
|
+
watermarkSource: DisclosureWatermarkSourcePort;
|
|
39
|
+
coveredCategories: readonly string[];
|
|
40
|
+
};
|
|
41
|
+
input: {
|
|
42
|
+
restorePointId: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export interface DisclosureResult {
|
|
46
|
+
partial: true;
|
|
47
|
+
watermarkBaselineAvailable: boolean;
|
|
48
|
+
counts: Record<string, CategoryCount>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* AC-16/AC-17/AC-19/EC-02/EC-08/INV-05 — computes the disclosure's per-category counts, restricted
|
|
52
|
+
* to `coveredCategories` and rendered as `"unknown"` whenever the baseline isn't usable.
|
|
53
|
+
*
|
|
54
|
+
* @complexity O(coveredCategories.length) plus one `getBaseline()` call and, when the baseline is
|
|
55
|
+
* usable, one `getCategoryCounts()` call.
|
|
56
|
+
*/
|
|
57
|
+
export declare function computeDisclosure(required: ComputeDisclosureRequired, _optional?: Record<string, never>): Promise<DisclosureResult>;
|
|
58
|
+
//# sourceMappingURL=disclosure.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SPEC-019 C-305 / REQ-09-REQ-11 / INV-05 — the discarded-write-window disclosure
|
|
3
|
+
* computation (ADR-045 §2, Step 2 of the restore ceremony).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Never asserts a numeric count for a category outside the versioned `coveredCategories` constant
|
|
7
|
+
* (INV-05) — a category not yet migrated onto the watermark chokepoint (ADR-041 §5's evolving
|
|
8
|
+
* write-path inventory) simply never appears in the output, even if a caller-supplied count source
|
|
9
|
+
* happens to have data for it (AC-17's `entries` case: Collections' write path is not yet
|
|
10
|
+
* watermark-stamped, so it must never be disclosed as covered here regardless of what any count
|
|
11
|
+
* source reports). Renders `"unknown"` — never `0` — for every covered category whenever the
|
|
12
|
+
* watermark baseline itself could not be established, whether because `content.db` was entirely
|
|
13
|
+
* unreadable (AC-19/EC-08) or because the specific restore point predates the
|
|
14
|
+
* `watermarkAtCapture` column (EC-02) — a null baseline must never be silently treated as a
|
|
15
|
+
* zero-baseline (matches SPEC-016 EC-06's identical rule).
|
|
16
|
+
*
|
|
17
|
+
* `result.partial` is always `true` — this disclosure is never claimed exhaustive (ADR-041 §5's
|
|
18
|
+
* own "no exhaustiveness claim until the automated write-path inventory runs clean" carried
|
|
19
|
+
* verbatim into this domain, ADR-045 §2).
|
|
20
|
+
*
|
|
21
|
+
* How it relates to the project:
|
|
22
|
+
* `coveredCategories` is the single, auditable edit point ADR-PIPE-019's File Map names this file
|
|
23
|
+
* for — a new category is added here only once its own write path is confirmed watermark-stamped,
|
|
24
|
+
* never inferred from whatever a count source happens to return.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* AC-16/AC-17/AC-19/EC-02/EC-08/INV-05 — computes the disclosure's per-category counts, restricted
|
|
28
|
+
* to `coveredCategories` and rendered as `"unknown"` whenever the baseline isn't usable.
|
|
29
|
+
*
|
|
30
|
+
* @complexity O(coveredCategories.length) plus one `getBaseline()` call and, when the baseline is
|
|
31
|
+
* usable, one `getCategoryCounts()` call.
|
|
32
|
+
*/
|
|
33
|
+
export async function computeDisclosure(required, _optional = {}) {
|
|
34
|
+
const { deps } = required;
|
|
35
|
+
const baseline = await deps.watermarkSource.getBaseline();
|
|
36
|
+
const baselineUsable = baseline.available && baseline.watermarkAtCapture !== null && baseline.watermarkAtCapture !== undefined;
|
|
37
|
+
const counts = {};
|
|
38
|
+
if (baselineUsable) {
|
|
39
|
+
const rawCounts = await deps.watermarkSource.getCategoryCounts();
|
|
40
|
+
for (const category of deps.coveredCategories) {
|
|
41
|
+
counts[category] = rawCounts[category] ?? 0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
for (const category of deps.coveredCategories) {
|
|
46
|
+
counts[category] = "unknown";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
partial: true,
|
|
51
|
+
watermarkBaselineAvailable: baseline.available,
|
|
52
|
+
counts,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=disclosure.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { MigrationRunsRepoPort, SiteStatusPort } from "./reconcile-interrupted-migration.js";
|
|
2
|
+
/**
|
|
3
|
+
* @file SPEC-017 C-107 / CIC U-004 / INV-08 / REQ-28 / REQ-29 — cost-gated `SERVE_SITE` auto-
|
|
4
|
+
* migrate policy (ADR-041 §10, amends SPEC-003).
|
|
5
|
+
*
|
|
6
|
+
* Purpose:
|
|
7
|
+
* Routes serve-time migration through the same snapshot-anchored ceremony as an interactive
|
|
8
|
+
* migration, gated by `costClass`: `'cheap'` (the common SQLite whole-file-snapshot case)
|
|
9
|
+
* auto-migrates under a reserved no-token boot policy attributed to the seeded `kind='system'`
|
|
10
|
+
* principal; `'expensive'`/`'unavailable'` refuse to auto-migrate and instead enter the site into
|
|
11
|
+
* `PENDING_MIGRATION`, requiring an interactive plan/confirm/execute before normal serving
|
|
12
|
+
* resumes.
|
|
13
|
+
*
|
|
14
|
+
* How it relates to the project:
|
|
15
|
+
* Must only ever run AFTER `reconcile-interrupted-migration.ts`'s `reconcileInterruptedMigrationOnBoot`
|
|
16
|
+
* has resolved for this boot cycle (U-004-ORD1) — the boot composition root's own call-site
|
|
17
|
+
* ordering is what actually enforces that sequencing; this function additionally refuses,
|
|
18
|
+
* defense-in-depth, if it ever observes a still-non-terminal `migration_runs` row itself (U-004-B1),
|
|
19
|
+
* so an out-of-order wiring bug fails closed rather than silently auto-migrating over an unresolved
|
|
20
|
+
* crash.
|
|
21
|
+
*
|
|
22
|
+
* Architectural role:
|
|
23
|
+
* `features/database` domain logic. Depends only on the injected ports.
|
|
24
|
+
*/
|
|
25
|
+
/** Thrown when a non-terminal `migration_runs` row still exists — defense-in-depth against out-of-order boot wiring (U-004-B1). */
|
|
26
|
+
export declare class UnresolvedInterruptedMigrationError extends Error {
|
|
27
|
+
constructor(message: string);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Evaluates and applies the cost-gated `SERVE_SITE` auto-migrate policy for one boot cycle.
|
|
31
|
+
*
|
|
32
|
+
* @complexity O(1) plus one repo read and either one `runAutoMigrate()` call or one status write.
|
|
33
|
+
*/
|
|
34
|
+
export declare function evaluateBootMigrationPolicy(required: {
|
|
35
|
+
siteId: string;
|
|
36
|
+
costClass: "cheap" | "expensive" | "unavailable";
|
|
37
|
+
siteStatus: SiteStatusPort;
|
|
38
|
+
migrationRuns: MigrationRunsRepoPort;
|
|
39
|
+
runAutoMigrate: () => Promise<void>;
|
|
40
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
41
|
+
//# sourceMappingURL=evaluate-boot-migration-policy.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SPEC-017 C-107 / CIC U-004 / INV-08 / REQ-28 / REQ-29 — cost-gated `SERVE_SITE` auto-
|
|
3
|
+
* migrate policy (ADR-041 §10, amends SPEC-003).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Routes serve-time migration through the same snapshot-anchored ceremony as an interactive
|
|
7
|
+
* migration, gated by `costClass`: `'cheap'` (the common SQLite whole-file-snapshot case)
|
|
8
|
+
* auto-migrates under a reserved no-token boot policy attributed to the seeded `kind='system'`
|
|
9
|
+
* principal; `'expensive'`/`'unavailable'` refuse to auto-migrate and instead enter the site into
|
|
10
|
+
* `PENDING_MIGRATION`, requiring an interactive plan/confirm/execute before normal serving
|
|
11
|
+
* resumes.
|
|
12
|
+
*
|
|
13
|
+
* How it relates to the project:
|
|
14
|
+
* Must only ever run AFTER `reconcile-interrupted-migration.ts`'s `reconcileInterruptedMigrationOnBoot`
|
|
15
|
+
* has resolved for this boot cycle (U-004-ORD1) — the boot composition root's own call-site
|
|
16
|
+
* ordering is what actually enforces that sequencing; this function additionally refuses,
|
|
17
|
+
* defense-in-depth, if it ever observes a still-non-terminal `migration_runs` row itself (U-004-B1),
|
|
18
|
+
* so an out-of-order wiring bug fails closed rather than silently auto-migrating over an unresolved
|
|
19
|
+
* crash.
|
|
20
|
+
*
|
|
21
|
+
* Architectural role:
|
|
22
|
+
* `features/database` domain logic. Depends only on the injected ports.
|
|
23
|
+
*/
|
|
24
|
+
/** Thrown when a non-terminal `migration_runs` row still exists — defense-in-depth against out-of-order boot wiring (U-004-B1). */
|
|
25
|
+
export class UnresolvedInterruptedMigrationError extends Error {
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = "UnresolvedInterruptedMigrationError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Evaluates and applies the cost-gated `SERVE_SITE` auto-migrate policy for one boot cycle.
|
|
33
|
+
*
|
|
34
|
+
* @complexity O(1) plus one repo read and either one `runAutoMigrate()` call or one status write.
|
|
35
|
+
*/
|
|
36
|
+
export async function evaluateBootMigrationPolicy(required, _optional = {}) {
|
|
37
|
+
const { siteId, costClass, siteStatus, migrationRuns, runAutoMigrate } = required;
|
|
38
|
+
const nonTerminal = await migrationRuns.findNonTerminalForSite(siteId);
|
|
39
|
+
if (nonTerminal) {
|
|
40
|
+
throw new UnresolvedInterruptedMigrationError(`refusing to evaluate boot migration policy for site '${siteId}' while migration_runs row '${nonTerminal.id}' is still non-terminal`);
|
|
41
|
+
}
|
|
42
|
+
if (costClass === "cheap") {
|
|
43
|
+
await runAutoMigrate();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// REQ-29/REQ-30: 'expensive' or 'unavailable' never auto-migrate; the site boots degraded,
|
|
47
|
+
// admin-reachable, public serving refused, until an interactive execute resolves it.
|
|
48
|
+
await siteStatus.set(siteId, "PENDING_MIGRATION");
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=evaluate-boot-migration-policy.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GatedMutationHooks } from "@jini-ai/core/gated-mutations";
|
|
2
|
+
/** Host-owned hash and fresh actor-identity policy, shared with every other gated ceremony. */
|
|
3
|
+
export interface RecoveryHookPolicy {
|
|
4
|
+
planHashOf(required: {
|
|
5
|
+
details: unknown;
|
|
6
|
+
}, optional?: Record<string, never>): string;
|
|
7
|
+
resolveActorClassIdentity: GatedMutationHooks<unknown, unknown>["resolveActorClassIdentity"];
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=hook-policy.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./recovery-orchestrator.js";
|
|
2
|
+
export * from "./disclosure.js";
|
|
3
|
+
export * from "./deep-link.js";
|
|
4
|
+
export * from "./restore-point-create.js";
|
|
5
|
+
export * from "./degraded-banners.js";
|
|
6
|
+
export * from "./lookup-adapters.js";
|
|
7
|
+
export * from "./migrate-forward-execute.js";
|
|
8
|
+
export * from "./reconcile-interrupted-migration.js";
|
|
9
|
+
export * from "./evaluate-boot-migration-policy.js";
|
|
10
|
+
export * from "./operation-lock.js";
|
|
11
|
+
export * from "./migrate-forward-hooks.js";
|
|
12
|
+
export { buildRestoreHooks, RestorePointNotFoundError, toRecoveryResult } from "./restore-hooks.js";
|
|
13
|
+
export type { BuildRestoreHooksInput } from "./restore-hooks.js";
|
|
14
|
+
export type { RecoveryHookPolicy } from "./hook-policy.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./recovery-orchestrator.js";
|
|
2
|
+
export * from "./disclosure.js";
|
|
3
|
+
export * from "./deep-link.js";
|
|
4
|
+
export * from "./restore-point-create.js";
|
|
5
|
+
export * from "./degraded-banners.js";
|
|
6
|
+
export * from "./lookup-adapters.js";
|
|
7
|
+
export * from "./migrate-forward-execute.js";
|
|
8
|
+
export * from "./reconcile-interrupted-migration.js";
|
|
9
|
+
export * from "./evaluate-boot-migration-policy.js";
|
|
10
|
+
export * from "./operation-lock.js";
|
|
11
|
+
export * from "./migrate-forward-hooks.js";
|
|
12
|
+
export { buildRestoreHooks, RestorePointNotFoundError, toRecoveryResult } from "./restore-hooks.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { DeepLinkRestorePointLookupPort } from "./deep-link.js";
|
|
2
|
+
import type { DisclosureWatermarkSourcePort, WatermarkBaseline } from "./disclosure.js";
|
|
3
|
+
import type { RestorePointListPort } from "../tools/restore-points.js";
|
|
4
|
+
/**
|
|
5
|
+
* @file Admin-UI backend-gap closure (design-spec.md §4.8) — honest, disclosed stand-ins for two
|
|
6
|
+
* Recovery ports this dispatch cannot back with a real implementation yet, plus one adapter that
|
|
7
|
+
* IS real (backed by the same restore-points persistence Database's own routes use).
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* `DisclosureWatermarkSourcePort` stand-in that always reports the watermark baseline as
|
|
11
|
+
* unavailable. This is the SAFE default per `disclosure.ts`'s own binding rule (never coerce
|
|
12
|
+
* `"unknown"` to `0` when the baseline can't be established) — no per-restore-point,
|
|
13
|
+
* per-category write-count tracker exists anywhere in this codebase yet (a real one would need to
|
|
14
|
+
* diff `database_write_watermark` against each covered write path's own row-level attribution,
|
|
15
|
+
* which is future work, not something safe to fabricate). Reporting `available: true` with a
|
|
16
|
+
* stubbed-zero count would be the exact false-reassurance failure mode ADR-045's Failure modes
|
|
17
|
+
* section names as this feature's highest-stakes UX risk — this class deliberately does not do
|
|
18
|
+
* that.
|
|
19
|
+
*/
|
|
20
|
+
export declare class AlwaysUnavailableWatermarkSource implements DisclosureWatermarkSourcePort {
|
|
21
|
+
getBaseline(): Promise<WatermarkBaseline>;
|
|
22
|
+
getCategoryCounts(): Promise<Record<string, number>>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `DeepLinkRestorePointLookupPort` adapter over the real restore-points list
|
|
26
|
+
* (`database/restore-points.ts`'s `RestorePointListPort`, the same source Database's own
|
|
27
|
+
* restore-points route reads). O(n) over the restore-points list per lookup — an accepted
|
|
28
|
+
* complexity tradeoff (see this dispatch's Style Notes) given restore points are an
|
|
29
|
+
* operator-curated, low-volume list, not a high-churn collection; `findById`-shaped storage would
|
|
30
|
+
* be the fix if that assumption stops holding.
|
|
31
|
+
*/
|
|
32
|
+
export declare class RestorePointDeepLinkLookup implements DeepLinkRestorePointLookupPort {
|
|
33
|
+
private readonly restorePoints;
|
|
34
|
+
constructor(restorePoints: RestorePointListPort);
|
|
35
|
+
findRestorePointById(id: string): Promise<{
|
|
36
|
+
restorePointId: string;
|
|
37
|
+
capturedAt: string;
|
|
38
|
+
} | null>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=lookup-adapters.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Admin-UI backend-gap closure (design-spec.md §4.8) — honest, disclosed stand-ins for two
|
|
3
|
+
* Recovery ports this dispatch cannot back with a real implementation yet, plus one adapter that
|
|
4
|
+
* IS real (backed by the same restore-points persistence Database's own routes use).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* `DisclosureWatermarkSourcePort` stand-in that always reports the watermark baseline as
|
|
8
|
+
* unavailable. This is the SAFE default per `disclosure.ts`'s own binding rule (never coerce
|
|
9
|
+
* `"unknown"` to `0` when the baseline can't be established) — no per-restore-point,
|
|
10
|
+
* per-category write-count tracker exists anywhere in this codebase yet (a real one would need to
|
|
11
|
+
* diff `database_write_watermark` against each covered write path's own row-level attribution,
|
|
12
|
+
* which is future work, not something safe to fabricate). Reporting `available: true` with a
|
|
13
|
+
* stubbed-zero count would be the exact false-reassurance failure mode ADR-045's Failure modes
|
|
14
|
+
* section names as this feature's highest-stakes UX risk — this class deliberately does not do
|
|
15
|
+
* that.
|
|
16
|
+
*/
|
|
17
|
+
export class AlwaysUnavailableWatermarkSource {
|
|
18
|
+
async getBaseline() {
|
|
19
|
+
return { available: false };
|
|
20
|
+
}
|
|
21
|
+
async getCategoryCounts() {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* `DeepLinkRestorePointLookupPort` adapter over the real restore-points list
|
|
27
|
+
* (`database/restore-points.ts`'s `RestorePointListPort`, the same source Database's own
|
|
28
|
+
* restore-points route reads). O(n) over the restore-points list per lookup — an accepted
|
|
29
|
+
* complexity tradeoff (see this dispatch's Style Notes) given restore points are an
|
|
30
|
+
* operator-curated, low-volume list, not a high-churn collection; `findById`-shaped storage would
|
|
31
|
+
* be the fix if that assumption stops holding.
|
|
32
|
+
*/
|
|
33
|
+
export class RestorePointDeepLinkLookup {
|
|
34
|
+
restorePoints;
|
|
35
|
+
constructor(restorePoints) {
|
|
36
|
+
this.restorePoints = restorePoints;
|
|
37
|
+
}
|
|
38
|
+
async findRestorePointById(id) {
|
|
39
|
+
const items = await this.restorePoints.list();
|
|
40
|
+
const match = items.find((row) => row.id === id);
|
|
41
|
+
return match ? { restorePointId: match.id, capturedAt: match.createdAt } : null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=lookup-adapters.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Clock as ClockPort } from "@jini-ai/core/primitives";
|
|
2
|
+
export interface OperationLockAcquireResult {
|
|
3
|
+
ok: true;
|
|
4
|
+
value: {
|
|
5
|
+
siteId: string;
|
|
6
|
+
operationKind: string;
|
|
7
|
+
acquiredAt: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface OperationLockAcquireFailure {
|
|
11
|
+
ok: false;
|
|
12
|
+
error: {
|
|
13
|
+
code: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface OperationLockPort {
|
|
18
|
+
acquireOperationLock(params: {
|
|
19
|
+
deps: {
|
|
20
|
+
clock: ClockPort;
|
|
21
|
+
};
|
|
22
|
+
input: {
|
|
23
|
+
siteId: string;
|
|
24
|
+
operationKind: "migration" | "restore";
|
|
25
|
+
};
|
|
26
|
+
}): Promise<OperationLockAcquireResult | OperationLockAcquireFailure>;
|
|
27
|
+
releaseOperationLock(params: {
|
|
28
|
+
deps: {
|
|
29
|
+
clock: ClockPort;
|
|
30
|
+
};
|
|
31
|
+
input: {
|
|
32
|
+
siteId: string;
|
|
33
|
+
handle: unknown;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
/** Thrown when the shared cross-domain operation lock rejects the acquire (site already has a migration/restore in flight). */
|
|
38
|
+
export declare class MigrationAlreadyInFlightError extends Error {
|
|
39
|
+
constructor(message: string);
|
|
40
|
+
}
|
|
41
|
+
/** Thrown when `costClass === 'unavailable'` — the in-product migrate is refused with no bypass. */
|
|
42
|
+
export declare class RestorePointUnavailableError extends Error {
|
|
43
|
+
constructor(message: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Orchestrates a forward-migrate execution: refuses `costClass: 'unavailable'` outright, acquires
|
|
47
|
+
* the shared cross-domain lock (U-003-ORD1), runs the caller's gated mutation, and always releases
|
|
48
|
+
* the lock afterward.
|
|
49
|
+
*
|
|
50
|
+
* @complexity O(1) plus the lock acquire/release and the injected `gatewayExecute()` call.
|
|
51
|
+
*/
|
|
52
|
+
export declare function executeMigrateForward(required: {
|
|
53
|
+
siteId: string;
|
|
54
|
+
confirmationToken: string;
|
|
55
|
+
costClass: "cheap" | "expensive" | "unavailable";
|
|
56
|
+
operationLock: OperationLockPort;
|
|
57
|
+
gatewayExecute: () => Promise<{
|
|
58
|
+
migrated: true;
|
|
59
|
+
}>;
|
|
60
|
+
}, { clock }?: {
|
|
61
|
+
clock?: ClockPort;
|
|
62
|
+
}): Promise<{
|
|
63
|
+
migrated: true;
|
|
64
|
+
}>;
|
|
65
|
+
//# sourceMappingURL=migrate-forward-execute.d.ts.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file SPEC-017 C-105 / CIC U-003 (binding reference to SPEC-019 CIC U-001) / REQ-08 / AC-09 /
|
|
3
|
+
* AC-41 / AC-42 — the `executeMigrateForward` orchestration wrapper (ADR-041 §3).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Wires the cross-domain shared operation lock (`core/operation-lock.ts`, designated/tested by
|
|
7
|
+
* SPEC-019) and the `costClass: 'unavailable'` refusal (REQ-08) around the actual gated mutation.
|
|
8
|
+
* This module does not implement or test the lock primitive itself, nor the state machine or
|
|
9
|
+
* `core/gated-mutations.execute()` sequence — `gatewayExecute` is the caller's own composition of
|
|
10
|
+
* those (typically closing over the state machine's `advance()` and the gateway's `execute()`).
|
|
11
|
+
*
|
|
12
|
+
* How it relates to the project:
|
|
13
|
+
* `costClass === 'unavailable'` is checked BEFORE the lock is ever consulted (AC-09) — refusing
|
|
14
|
+
* before any side effect runs, so no lock is ever left held for a migration that was always going
|
|
15
|
+
* to be refused. The lock is acquired strictly before `gatewayExecute()` runs (U-003-ORD1) and
|
|
16
|
+
* released in a `finally`, so a mutation failure never leaks a held site-wide lock.
|
|
17
|
+
*
|
|
18
|
+
* Architectural role:
|
|
19
|
+
* `features/database` domain logic, composing `core/operation-lock.ts`'s port shape. No clock is
|
|
20
|
+
* supplied by this module's own caller contract, so a plain wall-clock default is used for the
|
|
21
|
+
* lock's own timestamping, using the shared millisecond clock port so the lock can format its
|
|
22
|
+
* timestamp through the kernel's ISO helper.
|
|
23
|
+
*/
|
|
24
|
+
const defaultClock = { nowMs: () => Date.now() };
|
|
25
|
+
/** Thrown when the shared cross-domain operation lock rejects the acquire (site already has a migration/restore in flight). */
|
|
26
|
+
export class MigrationAlreadyInFlightError extends Error {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = "MigrationAlreadyInFlightError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Thrown when `costClass === 'unavailable'` — the in-product migrate is refused with no bypass. */
|
|
33
|
+
export class RestorePointUnavailableError extends Error {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "RestorePointUnavailableError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Orchestrates a forward-migrate execution: refuses `costClass: 'unavailable'` outright, acquires
|
|
41
|
+
* the shared cross-domain lock (U-003-ORD1), runs the caller's gated mutation, and always releases
|
|
42
|
+
* the lock afterward.
|
|
43
|
+
*
|
|
44
|
+
* @complexity O(1) plus the lock acquire/release and the injected `gatewayExecute()` call.
|
|
45
|
+
*/
|
|
46
|
+
export async function executeMigrateForward(required, { clock = defaultClock } = {}) {
|
|
47
|
+
const { siteId, costClass, operationLock, gatewayExecute } = required;
|
|
48
|
+
if (costClass === "unavailable") {
|
|
49
|
+
throw new RestorePointUnavailableError(`site '${siteId}' has costClass 'unavailable' — the in-product forward migrate is refused with no attestation override`);
|
|
50
|
+
}
|
|
51
|
+
const acquireResult = await operationLock.acquireOperationLock({
|
|
52
|
+
deps: { clock },
|
|
53
|
+
input: { siteId, operationKind: "migration" },
|
|
54
|
+
});
|
|
55
|
+
if (!acquireResult.ok) {
|
|
56
|
+
throw new MigrationAlreadyInFlightError(`site '${siteId}': ${acquireResult.error.message ?? acquireResult.error.code} — a migration or restore is already in flight`);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return await gatewayExecute();
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
await operationLock.releaseOperationLock({
|
|
63
|
+
deps: { clock },
|
|
64
|
+
input: { siteId, handle: acquireResult.value },
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=migrate-forward-execute.js.map
|