@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
105 lines • 5.73 kB
TypeScript
import type { PostgresAccessor } from '../../accessor/postgres.ts';
export interface ColumnInfo {
name: string;
type: string;
nullable: boolean;
}
export interface ForeignKey {
columns: string[];
references: {
schema: string;
table: string;
columns: string[];
};
}
export interface IndexInfo {
name: string;
columns: string[];
unique: boolean;
}
export interface Relationship {
from: {
schema: string;
table: string;
columns: string[];
};
to: {
schema: string;
table: string;
columns: string[];
};
kind: 'many_to_one';
}
export interface EnumInfo {
type: string;
labels: string[];
}
export interface ColumnStats {
n_distinct: number;
most_common_vals: string[];
}
export declare function quoteIdent(ident: string): string;
export declare function qualified(schema: string, name: string): string;
export declare function listSchemas(accessor: PostgresAccessor, allowlist: readonly string[] | null): Promise<string[]>;
export declare function listTables(accessor: PostgresAccessor, schema: string): Promise<string[]>;
export declare function listViews(accessor: PostgresAccessor, schema: string): Promise<string[]>;
export declare function listMatviews(accessor: PostgresAccessor, schema: string): Promise<string[]>;
export declare function countRows(accessor: PostgresAccessor, schema: string, name: string): Promise<number>;
export declare function estimateSize(accessor: PostgresAccessor, schema: string, name: string): Promise<[number, number]>;
export declare function estimatedRowCount(accessor: PostgresAccessor, schema: string, name: string): Promise<number>;
export declare function tableSizeBytes(accessor: PostgresAccessor, schema: string, name: string): Promise<number>;
/**
* A relation's rows in key order, as an `ORDER BY` clause. A relation with no
* primary key (a view, a keyless table) gets none and keeps the order its scan
* returns. Mirrors Python's `key_order`.
*/
export declare function keyOrder(pk: readonly string[], descending?: boolean): string;
export declare function fetchRows(accessor: PostgresAccessor, schema: string, name: string, options: {
limit: number;
offset: number;
}): Promise<Record<string, unknown>[]>;
/**
* A keyed relation's last `limit` rows, in key order, read off the end of its
* key with no count, and the exact key of the last one (`keyTexts`). Mirrors
* Python's `fetch_last_rows`.
*/
export declare function fetchLastRows(accessor: PostgresAccessor, schema: string, name: string, pk: readonly string[], limit: number, columns: ReadonlySet<string>): Promise<[Record<string, unknown>[], unknown[] | null]>;
/**
* A keyed relation's rows past a key, in key order, and the exact key of the
* last one (`keyTexts`); null for the rows when their database JSON passes
* `maxBytes`, which the database answers before sending any of them
* (`fetchBoundedQuery`). Mirrors Python's `fetch_rows_after`.
*/
export declare function fetchRowsAfter(accessor: PostgresAccessor, schema: string, name: string, pk: readonly string[], after: readonly unknown[] | null, limit: number, columns: ReadonlySet<string>, maxBytes: number): Promise<[Record<string, unknown>[] | null, readonly unknown[] | null]>;
/**
* Fetch native rows only when their database JSON fits the byte budget, in key
* order where the relation has a primary key.
*/
export declare function fetchBoundedRows(accessor: PostgresAccessor, schema: string, name: string, options: {
limit: number;
maxBytes: number;
}): Promise<Record<string, unknown>[] | null>;
/**
* Budget an internally generated, row-limited SELECT before transferring rows.
* `extra` adds columns to each answered row past the budget, computed from the
* row (`data`), so they never count against `maxBytes` (`keyTexts`).
*/
export declare function fetchBoundedQuery(accessor: PostgresAccessor, query: string, params: readonly unknown[], columns: ReadonlySet<string>, maxBytes: number, extra?: string): Promise<Record<string, unknown>[] | null>;
export declare function fetchColumns(accessor: PostgresAccessor, schema: string, name: string): Promise<ColumnInfo[]>;
export declare function fetchPrimaryKey(accessor: PostgresAccessor, schema: string, name: string): Promise<string[]>;
/**
* The columns a relation's rows are listed by: its primary key, when that key
* is unique over every row a plain read returns. A table with inheritance
* children reads their rows too, which its key does not cover, so it has none
* and keeps its scan order; a partitioned table's key covers every partition.
* Mirrors Python's `fetch_row_key`.
*/
export declare function fetchRowKey(accessor: PostgresAccessor, schema: string, name: string): Promise<string[]>;
export declare function fetchForeignKeys(accessor: PostgresAccessor, schema: string, name: string): Promise<ForeignKey[]>;
export declare function fetchIndexes(accessor: PostgresAccessor, schema: string, name: string): Promise<IndexInfo[]>;
export declare function fetchAllRelationships(accessor: PostgresAccessor, schemas: readonly string[]): Promise<Relationship[]>;
export declare function fetchTableComment(accessor: PostgresAccessor, schema: string, name: string): Promise<string | null>;
export declare function fetchColumnComments(accessor: PostgresAccessor, schema: string, name: string): Promise<Map<string, string>>;
export declare function fetchEnumColumns(accessor: PostgresAccessor, schema: string, name: string): Promise<Map<string, EnumInfo>>;
export declare function fetchColumnStats(accessor: PostgresAccessor, schema: string, name: string): Promise<Map<string, ColumnStats>>;
//# sourceMappingURL=client.d.ts.map