import type { ServiceResult } from '../models/service-result.js'; import type { ProfilingStatus, ProfilingResult, ExecuteOptions, BulkExecutionOptions, BulkExecutionResult, ProgressCallback } from '../models/profiling-execution-types.js'; import type { IRestApiAdapter } from '../adapters/rest/rest-api-adapter.js'; import type { ISoqlQueryAdapter } from '../adapters/soql/soql-query-adapter.js'; import type { ProfilingDefinitionService, ProfilingDefinition } from './ProfilingDefinitionService.js'; import { PollingService } from './PollingService.js'; import { BulkExecutionService } from './BulkExecutionService.js'; export type { PollingConfig } from './PollingService.js'; export type { ProfilingRequestStatus, ProfilingStatus, ProfilingResult, ExecuteOptions, BulkExecutionOptions, BulkExecutionResult, BulkExecutionSummary, DefinitionExecutionResult, DefinitionExecutionStatus, SkipReason, BulkProgressUpdate, ProgressCallback, IProfilingExecutor, } from '../models/profiling-execution-types.js'; /** * Configuration for ProfilingExecutionService. */ export type IProfilingExecutionServiceConfig = { /** REST API adapter for triggering profiling via Apex REST endpoints */ restAdapter: IRestApiAdapter; /** SOQL adapter for querying profiling requests */ soqlAdapter: ISoqlQueryAdapter; /** Optional ProfilingDefinitionService for definition validation */ profilingDefinitionService?: ProfilingDefinitionService; /** Optional polling configuration (used to auto-create PollingService if pollingService not provided) */ pollingConfig?: import('./PollingService.js').PollingConfig; /** Optional pre-configured PollingService (overrides pollingConfig when provided) */ pollingService?: PollingService; /** Optional pre-configured BulkExecutionService (auto-created if not provided) */ bulkExecutionService?: BulkExecutionService; /** Optional logger for debug output */ logger?: Console; }; /** * Service for executing and monitoring Cuneiform profiling operations. * * Triggers profiling via the Cuneiform REST API, monitors progress through status polling, * and supports cancellation and deletion of requests. Bulk execution is delegated to * BulkExecutionService for semaphore-based concurrency, skip-empty logic, and error resolution. * * @design * **Two-Phase Polling**: Status polling delegates to PollingService with a two-phase * strategy: fixed-interval fast polling for the first 30s, then exponential backoff * with a 1.2x multiplier (configurable via pollingConfig). * * @example * ```typescript * const service = new ProfilingExecutionService({ * restAdapter, * soqlAdapter, * profilingDefinitionService, * pollingConfig: { timeoutMs: 600000 }, // 10 minute timeout * logger: console, * }); * * // Trigger profiling and wait for completion * const executeResult = await service.execute('a0B000000000001'); * if (executeResult.success) { * const requestId = executeResult.data; * const completionResult = await service.waitForCompletion(requestId); * if (completionResult.success && completionResult.data.success) { * console.log('Profiling completed successfully'); * } * } * ``` */ export declare class ProfilingExecutionService { private readonly restAdapter; private readonly soqlAdapter; private readonly profilingDefinitionService?; private readonly pollingService; private readonly bulkExecutionService; private readonly logger?; constructor(config: IProfilingExecutionServiceConfig); /** * Maps a raw pnova__Profiling_Request__c record to ProfilingStatus. * * Transforms Salesforce field naming conventions (underscores, __c suffix) * to TypeScript camelCase for consistent API consumer experience. * * @param record - The raw SOQL record * @returns Mapped ProfilingStatus */ private static mapToProfilingStatus; /** * Executes profiling for a given definition. * * Triggers profiling via Apex and returns the request ID. * * @param definitionId - The profiling definition ID * @param options - Optional execution options (e.g., skipValidation) * @returns ServiceResult containing the request ID */ execute(definitionId: string, options?: ExecuteOptions): Promise>; /** * Gets the current status of a profiling request. * * @param requestId - The profiling request ID * @returns ServiceResult containing ProfilingStatus */ getStatus(requestId: string): Promise>; /** * Waits for a profiling request to reach a terminal status. * * Uses a two-phase polling strategy: fixed-interval polling during the fast-poll * phase (first `fastPollDurationMs`), then exponential backoff for longer operations. * With default 1s interval, completion is detected within 1 polling cycle (~1s latency). * * @param requestId - The profiling request ID * @returns ServiceResult containing ProfilingResult */ waitForCompletion(requestId: string): Promise>; /** * Executes profiling for multiple definitions in parallel with controlled concurrency. * * Delegates to BulkExecutionService for semaphore-based concurrency control, * progress callbacks, skip-empty logic, and error resolution mapping. Provides * `execute()` and `getStatus()` as callbacks so BulkExecutionService can trigger * and monitor individual profiling requests without circular dependencies. * * @param definitions - Array of profiling definitions to execute * @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[], options?: BulkExecutionOptions, onProgress?: ProgressCallback): Promise>; }