import type { IConnectionFacade, QueryResult } from '../connection-facade.js'; import type { ServiceResult } from '../../models/service-result.js'; import type { RetryConfig } from '../retry.js'; import type { ChunkOptions } from './types.js'; /** * Configuration for SoqlQueryAdapter. */ export type SoqlQueryAdapterConfig = { /** Optional logger for debug output */ logger?: Console; /** * Whether to emit @salesforce/core Lifecycle events for telemetry. * When enabled, emits events like 'adapter:query:start', 'adapter:query:complete'. * Default: false */ emitLifecycleEvents?: boolean; /** * Retry configuration for transient failures. * If not specified, retries are disabled. */ retry?: RetryConfig; }; /** * Interface for SOQL query operations. * * Provides methods for executing SOQL queries with pagination * and chunking support. */ export type ISoqlQueryAdapter = { /** * Executes a SOQL query and returns the first page of results. * * @template T The type of records being queried * @param soql - The SOQL query string * @returns ServiceResult containing query results */ query(soql: string): Promise>>; /** * Executes a SOQL query and retrieves all results, handling pagination automatically. * * @template T The type of records being queried * @param soql - The SOQL query string * @returns ServiceResult containing all query results */ queryAll(soql: string): Promise>>; /** * Executes a SOQL query and processes results in chunks. * * @template T The type of records being queried * @param soql - The SOQL query string * @param options - Chunking options including chunk size and callback * @returns ServiceResult containing all query results */ queryChunked(soql: string, options?: ChunkOptions): Promise>>; }; /** * Adapter for executing SOQL queries against Salesforce. * * Provides pagination handling and chunked processing for efficient * retrieval of large datasets. * * @example * ```typescript * const adapter = new SoqlQueryAdapter(connectionFacade); * * // Simple query * const result = await adapter.query('SELECT Id, Name FROM Account LIMIT 10'); * * // Query all records with pagination * const allAccounts = await adapter.queryAll('SELECT Id, Name FROM Account'); * * // Process in chunks * await adapter.queryChunked('SELECT Id, Name FROM Account', { * chunkSize: 1000, * onChunk: (records, index) => console.log(`Processing chunk ${index}`), * }); * ``` */ export declare class SoqlQueryAdapter implements ISoqlQueryAdapter { private readonly connection; private readonly logger?; private readonly lifecycle; private readonly retryConfig?; /** * Creates a new SoqlQueryAdapter. * * @param connection - The connection facade to use for API calls * @param config - Optional configuration */ constructor(connection: IConnectionFacade, config?: SoqlQueryAdapterConfig); /** * Executes a SOQL query and returns the first page of results. * * @template T The type of records being queried * @param soql - The SOQL query string * @returns ServiceResult containing query results */ query(soql: string): Promise>>; /** * Executes a SOQL query and retrieves all results, handling pagination automatically. * * Uses an async generator internally for memory efficiency when dealing * with large result sets. * * @template T The type of records being queried * @param soql - The SOQL query string * @returns ServiceResult containing all query results */ queryAll(soql: string): Promise>>; /** * Executes a SOQL query and processes results in chunks. * * @template T The type of records being queried * @param soql - The SOQL query string * @param options - Chunking options * @returns ServiceResult containing all query results */ queryChunked(soql: string, options?: ChunkOptions): Promise>>; /** * Async generator that fetches all pages of a query result. * * Uses retry logic for both initial query and pagination calls to handle * transient failures during large result set retrieval. * * @template T The type of records being queried * @param soql - The SOQL query string * @yields Each page of query results */ private fetchAllPages; /** * Handles query errors and maps them to appropriate error codes. * * Accepts SfError, jsforce errors, or unknown error types. Extracts Salesforce * error codes when available and maps them to adapter-specific error codes. * * @param error - The caught error (SfError, jsforce error, or unknown) * @param startTime - The query start time for duration calculation * @returns ServiceResult with success=false, empty QueryResult, and mapped error code */ private handleQueryError; }