Skip to content

Commit e4a671e

Browse files
committed
chore(miner): migrate batch 4.8 highest-fan-in lib modules to TypeScript
Convert governor-ledger, event-ledger, portfolio-queue, and cli-error from hand-maintained .js + .d.ts to real TypeScript, compiled in place via the package's existing tsc pipeline (#7290 Phase 4, batch 4.8 — the final, highest fan-in batch). Public API is preserved exactly and the compiled .js output is behavior-identical; only type annotations, identity row-cast helpers, and tsc formatting differ. Adds tests for the branches the migration newly tracks so all four files are at 100% line + branch + function coverage. Closes #7316
1 parent efe451e commit e4a671e

15 files changed

Lines changed: 1854 additions & 770 deletions
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
export function reportCliFailure(wantsJson: boolean, message: string, exitCode?: number): number;
2-
export function argsWantJson(args: readonly string[]): boolean;
3-
export function describeCliError(error: unknown): string;
1+
/** Shared CLI failure output (#4836): when `--json` is set, emit a parseable `{ ok: false, error }` object on
2+
* stdout (matching each command's success-path JSON stream); otherwise log plain text to stderr. */
3+
export declare function reportCliFailure(wantsJson: boolean, message: string, exitCode?: number): number;
4+
/** True when argv includes `--json` (used on parse-error paths before a full parse result exists). */
5+
export declare function argsWantJson(args: readonly string[]): boolean;
6+
/** Normalize a thrown value to a safe error string for CLI output. */
7+
export declare function describeCliError(error: unknown): string;

packages/loopover-miner/lib/cli-error.js

Lines changed: 10 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** Shared CLI failure output (#4836): when `--json` is set, emit a parseable `{ ok: false, error }` object on
2+
* stdout (matching each command's success-path JSON stream); otherwise log plain text to stderr. */
3+
4+
export function reportCliFailure(wantsJson: boolean, message: string, exitCode = 2): number {
5+
if (wantsJson) {
6+
console.log(JSON.stringify({ ok: false, error: message }, null, 2));
7+
} else {
8+
console.error(message);
9+
}
10+
return exitCode;
11+
}
12+
13+
/** True when argv includes `--json` (used on parse-error paths before a full parse result exists). */
14+
export function argsWantJson(args: readonly string[]): boolean {
15+
return args.includes("--json");
16+
}
17+
18+
/** Normalize a thrown value to a safe error string for CLI output. */
19+
export function describeCliError(error: unknown): string {
20+
return error instanceof Error ? error.message : String(error);
21+
}
Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
export type LedgerEntry = {
2-
id: number;
3-
seq: number;
4-
type: string;
5-
repoFullName: string | null;
6-
payload: Record<string, unknown>;
7-
createdAt: string;
2+
id: number;
3+
seq: number;
4+
type: string;
5+
repoFullName: string | null;
6+
payload: Record<string, unknown>;
7+
createdAt: string;
88
};
9-
109
export type AppendEventInput = {
11-
type: string;
12-
repoFullName?: string;
13-
payload: Record<string, unknown>;
10+
type: string;
11+
repoFullName?: string;
12+
payload: Record<string, unknown>;
1413
};
15-
1614
export type ReadEventsFilter = {
17-
repoFullName?: string | null;
18-
since?: number | null;
15+
repoFullName?: string | null;
16+
since?: number | null;
1917
};
20-
2118
export type EventLedger = {
22-
dbPath: string;
23-
appendEvent(event: AppendEventInput): LedgerEntry;
24-
readEvents(filter?: ReadEventsFilter): LedgerEntry[];
25-
purgeByRepo(repoFullName: string): number;
26-
close(): void;
19+
dbPath: string;
20+
appendEvent(event: AppendEventInput): LedgerEntry;
21+
readEvents(filter?: ReadEventsFilter): LedgerEntry[];
22+
purgeByRepo(repoFullName: string): number;
23+
close(): void;
2724
};
28-
29-
export function resolveEventLedgerDbPath(env?: Record<string, string | undefined>): string;
30-
31-
export function initEventLedger(dbPath?: string): EventLedger;
32-
33-
export function appendEvent(event: AppendEventInput): LedgerEntry;
34-
35-
export function readEvents(filter?: ReadEventsFilter): LedgerEntry[];
36-
37-
export function closeDefaultEventLedger(): void;
25+
export declare function resolveEventLedgerDbPath(env?: Record<string, string | undefined>): string;
26+
/**
27+
* Opens the local append-only event ledger, creating the table on first use. `seq` is a monotonically increasing
28+
* counter maintained by this module (next = current MAX(seq) + 1) rather than relying on `AUTOINCREMENT`'s
29+
* reuse-after-vacuum behavior, so consumers get a stable ordering guarantee. Rows read back in `seq ASC` order.
30+
* (#2290)
31+
*/
32+
export declare function initEventLedger(dbPath?: string): EventLedger;
33+
export declare function appendEvent(event: AppendEventInput): LedgerEntry;
34+
export declare function readEvents(filter?: ReadEventsFilter): LedgerEntry[];
35+
export declare function closeDefaultEventLedger(): void;

0 commit comments

Comments
 (0)