Files
rea/src/sqlite/SqliteDatabaseLimits.ts
T
morluto ef475fcf8b fix(sqlite): distinguish query capacity and unavailable row sources
Use one bound JSON selection set for inventory metadata, keeping raw-name byte
comparison and filtering inside SQLite while preserving caller projection order
and repetition. Large requests reach native result-column capacity attribution.

Separate unavailable row sources from generated-expression failures. Preserve
SQLite's reason and selected table/path, offer schema-only recovery, and avoid
claiming corruption or recommending unreadable columns.

Validated UTF-8/UTF-16 identity, native inspection/worker tests and CLI/MCP failure
and recovery workflows. The large CLI selection uses the existing framed CLI
fixture to avoid host argv limits. Source bytes and identity remain unchanged.

Fixes #6855
Fixes #6604
2026-10-24 01:24:43 +08:00

54 lines
1.7 KiB
TypeScript

/** Bound frozen input, retained JSON and worker allocation before parsing untrusted files. */
export const SQLITE_DATABASE_LIMITS = {
concurrentInspections: 2,
inputBytes: 256 * 1024 * 1024,
outputBytes: 16 * 1024 * 1024,
diagnosticBytes: 1024 * 1024,
} as const;
/** Internal rejection retains the failed boundary without returning partial success. */
export class SqliteInspectionFailure extends Error {
constructor(
readonly reason:
| "format"
| "selection"
| "column-selection"
| "column-evaluation"
| "row-evaluation"
| "column-limit"
| "unsupported"
| "unavailable"
| "output-limit"
| "memory",
message: string,
) {
super(message);
}
}
/** Selected generated cells the private connection cannot compute; the database stays readable. */
export class SqliteColumnEvaluationFailure extends SqliteInspectionFailure {
constructor(
message: string,
/** Selected or stored columns that remain readable without the failed expressions. */
readonly readableColumns: readonly string[],
) {
super("column-evaluation", message);
}
}
/** A projection above this connection's result-column capacity; the database stays readable. */
export class SqliteColumnLimitFailure extends SqliteInspectionFailure {
constructor(
message: string,
readonly selectedColumns: number,
readonly engineColumnLimit: number,
) {
super("column-limit", message);
}
}
/** SQLite's primary result code for a native node:sqlite failure, if it carries one. */
export const sqlitePrimaryResultCode = (cause: unknown): number | undefined =>
cause instanceof Error &&
"errcode" in cause &&
typeof cause.errcode === "number"
? cause.errcode & 0xff
: undefined;