import type { ServiceResult } from '../models/service-result.js'; import type { ISoqlQueryAdapter } from '../adapters/soql/soql-query-adapter.js'; import type { BulkExecutionOptions, BulkExecutionResult, ProgressCallback, IProfilingExecutor } from '../models/profiling-execution-types.js'; import type { ProfilingDefinition } from './ProfilingDefinitionService.js'; import type { PollingService } from './PollingService.js'; export type { BulkExecutionOptions, BulkExecutionResult, BulkExecutionSummary, DefinitionExecutionResult, BulkProgressUpdate, ProgressCallback, SkipReason, IProfilingExecutor, } from '../models/profiling-execution-types.js'; /** * Configuration for BulkExecutionService constructor. */ export type IBulkExecutionServiceConfig = { /** SOQL adapter for record count queries (skip-empty logic) */ soqlAdapter: ISoqlQueryAdapter; /** PollingService for waiting on individual request completion */ pollingService: PollingService; /** Optional logger for debug output */ logger?: Console; }; /** * Service for bulk execution of profiling definitions with controlled concurrency. * * Orchestrates parallel execution of multiple profiling definitions using a * semaphore-based concurrency model. Receives an `IProfilingExecutor` * callback object to decouple bulk orchestration from single-execution mechanics. * * Responsibilities: * - Semaphore-based concurrency control (1-10 parallel threads) * - Skip-empty logic (check record count before profiling) * - Progress reporting via callbacks * - Error resolution mapping for user-friendly guidance * - Aggregate result summary (successful, failed, skipped) * * @example * ```typescript * const bulkService = new BulkExecutionService({ * soqlAdapter, * pollingService, * }); * * const executor = { * execute: (defId: string) => executionService.execute(defId), * getStatus: (reqId: string) => executionService.getStatus(reqId), * }; * * const result = await bulkService.executeBulk( * definitions, * executor, * { parallel: 5, skipEmpty: true }, * (update) => console.log(`${update.index + 1}/${update.total}: ${update.message}`) * ); * ``` */ export declare class BulkExecutionService { private readonly soqlAdapter; private readonly pollingService; private readonly logger?; constructor(config: IBulkExecutionServiceConfig); /** * Maps an error message to user-friendly resolution guidance. * * Searches through known error patterns and returns appropriate resolution * guidance. If no pattern matches, returns undefined. * * @param errorMessage - The error message to analyze * @returns User-friendly resolution guidance or undefined */ private static getErrorResolution; /** * Reports progress update via callback. * * @param onProgress - Optional progress callback * @param definition - Current definition * @param status - Current status * @param index - Index in batch * @param total - Total count * @param summary - Running summary * @param message - Optional message */ private static reportProgress; /** * Executes profiling for multiple definitions in parallel with controlled concurrency. * * Implements semaphore-based concurrency control, progress callbacks, skip-empty * logic, and error resolution mapping. Returns an aggregated summary of results. * * @param definitions - Array of profiling definitions to execute * @param executor - Executor interface for triggering and monitoring profiling * @param options - Bulk execution options (parallel, skipEmpty, pollInterval) * @param onProgress - Optional callback for progress updates * @returns ServiceResult containing BulkExecutionResult with summary and per-definition results */ executeBulk(definitions: ProfilingDefinition[], executor: IProfilingExecutor, options?: BulkExecutionOptions, onProgress?: ProgressCallback): Promise>; /** * Checks the record count for an object. * * Used by skip-empty logic to determine if an object has records to profile. * * @param objectName - The Salesforce object API name * @returns Typed result distinguishing success, validation failure, and query failure */ private getRecordCount; /** * Checks if a definition should be skipped due to empty records. * * @param definition - The profiling definition to check * @returns Skip info if should be skipped, null otherwise */ private checkSkipEmpty; /** * Processes a single definition within bulk execution. * * Acquires a semaphore permit, executes the definition, waits for completion, * and releases the permit. Updates summary counts and calls progress callback. * * @param item - The definition and its position in the batch * @param ctx - Shared batch execution state (options, semaphore, counters) * @param callbacks - Caller-provided execution and status functions * @returns The execution result for this definition */ private processDefinition; }