import { type OrgAuth } from "../auth/sf-auth.ts"; import type { DependencyGraph } from "../graph/build.ts"; /** * Low-level Salesforce REST calls used by `dry_run` and `run`. * * Everything here is allowed to touch record IDs and field values — * but the caller (the MCP tool handler) must never include returned * records / IDs in its `structuredContent` response to the LLM. * Records are persisted to session files on disk; only counts and * file paths are returned. */ /** `SELECT COUNT() FROM [WHERE ]` against `auth.instanceUrl`. */ export declare function queryCount(opts: { auth: OrgAuth; object: string; whereClause?: string; fetchFn?: typeof fetch; }): Promise; /** * Validate a user-supplied WHERE clause by asking Salesforce to count * matching rows. `MALFORMED_QUERY` (HTTP 400 with errorCode) surfaces * as a `UserError` so the AI can ask the user to fix their SOQL. */ export declare function validateWhereClause(opts: { auth: OrgAuth; object: string; whereClause: string; fetchFn?: typeof fetch; }): Promise; /** Pull IDs for a SOQL query, following `nextRecordsUrl` until done. */ export declare function queryIds(opts: { auth: OrgAuth; soql: string; fetchFn?: typeof fetch; }): Promise; /** Fetch full records for a SOQL query. Caller supplies explicit fields. */ export declare function queryRecords(opts: { auth: OrgAuth; soql: string; fetchFn?: typeof fetch; }): Promise>>; /** * Resolve how each object in `finalObjectList` relates to the root, so * we can compose a scope-filtered COUNT or SELECT per object. * * Kinds: * - root: the object equals root * - direct-parent: root has an FK to this object (1 hop up) * - direct-child: this object has an FK back to root (1 hop down) * - transitive: reached via a chain of parent FKs (2+ hops up). * Requires ID materialization, not a single subquery. * - unknown: no path from root in the graph — unseedable for this scope. */ export type ScopePathKind = "root" | "direct-parent" | "direct-child" | "transitive" | "child-lookup" | "unknown"; export type ScopePath = { object: string; kind: ScopePathKind; /** For direct-parent: the FK field on the root pointing to this object. */ rootFk?: string; /** For direct-child: the FK field on this object pointing back to the root. */ childFk?: string; /** For transitive: the chain of objects from this object up to the root. */ chain?: string[]; /** * For "child-lookup": the intermediate direct-child of root whose * user-selected lookup field reaches `object`. */ childObject?: string; /** For "child-lookup": the FK field on `childObject` pointing back to root. */ childFkToRoot?: string; /** * For "child-lookup": the reference field on `childObject` whose value * is the target Id of type `object`. */ lookupField?: string; }; export declare function computeScopePaths(graph: DependencyGraph, root: string, finalObjectList: string[], childLookups?: Record): ScopePath[]; /** * Default chunk size for embedding IDs in a SOQL `Id IN (...)` predicate * that will be issued via Salesforce's GET `/query` endpoint. * * `/query` accepts URIs up to ~16 KB. An 18-char ID with URL-encoded * quoting + comma is ~26 chars; 200 IDs ≈ 5 KB of IN list, leaving * comfortable headroom for the outer SOQL and the user's WHERE clause. * * Used by callers that compose SOQL with `IN (rootIds)` (or any other * caller-supplied ID list) and need to chunk the request to stay under * the URI limit. */ export declare const ROOT_ID_CHUNK = 200; /** * Chunk an ID list for SOQL `Id IN (...)` clauses. * * SOQL's hard `IN (...)` ceiling is ~4000 elements, but the practical bound * is URL length — 18-char IDs + quoting + the rest of the query easily * exceed Salesforce's ~16k request-URI limit well before 4000 IDs. The * default `chunkSize` here (500) is sized for non-URL contexts (e.g. the * `composite/sobjects` batch limit). Callers that build `IN` lists for * GET `/query` should pass `ROOT_ID_CHUNK` instead. */ export declare function chunkIds(ids: T[], chunkSize?: number): T[][]; /** Quote an ID (or any literal) for inclusion in a SOQL `IN (...)` clause. */ export declare function soqlIdList(ids: string[]): string;