/** * postgres-mcp - Query Helpers * * Shared utilities for tool handlers and resource files. * Eliminates duplicated limit-coercion, default-limit, and type-coercion logic. */ /** Default maximum rows returned when no limit is specified */ export declare const DEFAULT_QUERY_LIMIT = 100; /** * Safe numeric coercion for z.preprocess() in SchemaBase definitions. * * z.coerce.number() converts "abc" → NaN, which Zod rejects at the SDK * boundary with a raw MCP -32602 error before the handler's try/catch. * This helper converts non-numeric values to undefined so the * .optional() chain kicks in and the handler receives undefined instead. * * Usage: `z.preprocess(coerceNumber, z.number().optional())` */ export declare function coerceNumber(val: unknown, _ctx?: unknown): unknown; /** * Strict numeric coercion for z.preprocess() in schemas where silent defaulting is not desired. * Returns the original invalid value so Zod can catch it and yield a type error. */ export declare function coerceStrictNumber(val: unknown, _ctx?: unknown): unknown; /** * Coerce a database row value to a JS number. * Handles BIGINT strings returned by the pg driver as strings. * Returns null for null/undefined inputs. */ export declare const toNum: (val: unknown) => number | null; /** * Row-count threshold below which index recommendations are suppressed. * Used by resource handlers (vector, postgis) to skip index suggestions * on tables too small to benefit from them. */ export declare const SMALL_TABLE_THRESHOLD = 1000; /** * Safely coerce an unknown database row value to a string. * Handles string, number, null/undefined, and object values. */ export declare function toStr(value: unknown): string; /** * Coerce a raw limit parameter into a usable value. * * MCP clients may pass limits as strings, numbers, undefined, or 0. * This helper normalizes all cases: * - `undefined` → defaultLimit * - `NaN` / non-numeric strings → defaultLimit * - `0` → `null` (no limit — return all rows) * - Positive number → that number * - Negative / other → defaultLimit * * @param raw - Raw limit value from parsed Zod schema (may be any type) * @param defaultLimit - Fallback limit (default: DEFAULT_QUERY_LIMIT) * @returns The resolved limit, or `null` for unlimited */ export declare function coerceLimit(raw: unknown, defaultLimit?: number): number | null; /** * Build a SQL LIMIT clause from a coerced limit value. * * @param limitVal - Resolved limit from coerceLimit(), or null for unlimited * @returns ` LIMIT N` string, or empty string for unlimited */ export declare function buildLimitClause(limitVal: number | null): string; //# sourceMappingURL=query-helpers.d.ts.map