import { type ServiceResult } from '../models/service-result.js'; import { ProfilingDefinitionService, type DefinitionType, type ProfilingStatus, type DeleteSkipReason, type DeleteFailure, type DeleteProgressEvent } from '../services/ProfilingDefinitionService.js'; /** * Options for the definition purge operation. * * Selection modes: * - `keys` — delete specific definitions by key (exclusive, all other flags ignored) * - `all` — fetch all definitions (optionally narrowed by filters) * - Filters alone — fetch matching definitions via inclusive AND logic * * Filters that map to SOQL (server-side): objectNames, pattern, category, status, isActive, method (as type) * Filters applied client-side after fetch: filter (standard/custom — derived from __c suffix), namespace (string-prefix on objectName) */ /** Canonical message returned when the user declines the purge confirmation prompt. */ export declare const PURGE_CANCELLED_MESSAGE = "Purge cancelled by user."; export type PurgeOptions = { /** Target org username or alias */ targetOrg: string; /** Definition keys to delete (e.g., PD-0001) — exclusive mode, all other flags ignored */ keys?: string[]; /** Purge all definitions (can be combined with filter flags to narrow) */ all?: boolean; /** Filter by target object API names (comma-delimited from CLI) */ objectNames?: string[]; /** Filter by object type: standard or custom (client-side) */ filter?: 'standard' | 'custom'; /** Filter by definition name pattern with SOQL LIKE (e.g., Account%) */ pattern?: string; /** Filter by definition method/type: metadata, historical, or comparative (client-side) */ method?: DefinitionType; /** Filter by category */ category?: string; /** Filter by profiling status */ status?: ProfilingStatus; /** Filter by object namespace prefix (client-side) */ namespace?: string; /** Maximum number of definitions to process */ limit?: number; /** Filter by active status */ isActive?: boolean; /** Preview mode — categorize without deleting */ dryRun?: boolean; /** Skip interactive confirmation prompt */ noPrompt?: boolean; /** Progress callback for per-definition status updates */ onProgress?: (event: DeleteProgressEvent) => void; /** Callback invoked after definitions are retrieved, reporting count and max label length */ onDefinitionsFound?: (count: number, maxLabelLength: number) => void; /** * Callback invoked after categorization but before deletion. * Receives the categorized preview data and returns whether to proceed with deletion. * If not provided or returns true, deletion proceeds. If returns false, operation aborts. */ onPreviewReady?: (preview: PreviewData) => Promise; /** Optional logger for debug output */ logger?: Console; }; /** * Preview entry for a single definition in dry-run mode. */ export type PurgePreviewEntry = { id: string; key: string; name: string; objectName: string; status: string; action: 'delete' | 'skip'; reason?: string; }; /** * Dry-run preview summary. */ export type PurgePreview = { deletable: number; blockedBySummaries: number; definitions: PurgePreviewEntry[]; }; /** * Data passed to the onPreviewReady callback for user confirmation. */ export type PreviewData = { /** Definitions eligible for deletion */ deletable: BlockedDefinition[]; /** Definitions blocked by related summaries */ blockedBySummaries: BlockedDefinition[]; /** Total definitions matched by filters */ total: number; }; /** * Blocked definition info for display. */ export type BlockedDefinition = { id: string; key: string; name: string; objectName: string; objectLabel?: string; category?: string; timeCategory?: string; segmentCategory?: string; status: string; }; /** * Result of a definition purge operation. */ export type PurgeResult = { /** Number of definitions successfully deleted */ deleted: number; /** Number of definitions skipped (has summaries or other reasons) */ skipped: number; /** Number of definitions that failed to delete */ failed: number; /** Total number of definitions processed (including blocked) */ total: number; /** Details about why each definition was skipped */ skipReasons: DeleteSkipReason[]; /** Details about each deletion failure */ failures: DeleteFailure[]; /** Definitions blocked by related summaries (pre-categorized) */ blockedBySummaries: BlockedDefinition[]; /** Whether this was a dry-run (no deletions performed) */ dryRun?: boolean; /** Dry-run preview (only present when dryRun is true) */ preview?: PurgePreview; }; /** * Error codes specific to purge operations. */ export declare const PurgeErrorCodes: { /** No selection criteria provided (no --all, --keys, or filters) */ readonly NO_SELECTION_CRITERIA: "PURGE_NO_SELECTION_CRITERIA"; /** Query for definitions failed */ readonly QUERY_FAILED: "PURGE_QUERY_FAILED"; /** No eligible definitions found */ readonly NO_ELIGIBLE_DEFINITIONS: "PURGE_NO_ELIGIBLE_DEFINITIONS"; /** Delete operation failed */ readonly DELETE_FAILED: "PURGE_DELETE_FAILED"; /** User cancelled the operation */ readonly USER_CANCELLED: "PURGE_USER_CANCELLED"; /** Operation failed unexpectedly */ readonly OPERATION_FAILED: "PURGE_OPERATION_FAILED"; }; /** * Orchestrates purging of profiling definitions. * * Follows the 4-layer architecture: Command → Operation → Service → API * This operation layer handles: * 1. Validates selection mode (IDs, --all, or filters) * 2. Fetches definitions using getAllDefinitions() with inclusive AND filters * 3. Pre-categorizes into deletable vs blocked (by summaries) * 4. Applies client-side filters (object type, method) * 5. Optionally previews (dry-run) or executes deletion * 6. Reports per-definition progress and statistics */ export declare class DefinitionPurgeOperation { private readonly definitionService; private readonly logger?; constructor(definitionService: ProfilingDefinitionService, logger?: Console | undefined); /** * Checks if any filter flags are specified. */ private static hasFilterFlags; /** * Builds GetDefinitionsOptions from purge options (server-side filters only). */ private static buildQueryOptions; /** * Applies client-side filters that can't be expressed in SOQL. */ private static applyClientFilters; /** * Categorizes definitions into deletable and blocked-by-summaries. * * Definitions can be deleted regardless of profiling status as long as * they have no associated summaries. */ private static categorize; /** * Maps a definition to a BlockedDefinition for display. */ private static toBlockedDefinition; /** * Creates the empty result structure. */ private static emptyResult; /** * Executes the definition purge operation. */ execute(options: PurgeOptions): Promise>; /** * Executes purge in key-list mode. * Fetches all definitions, matches by key, ignores all other flags. */ private executeKeyMode; /** * Executes purge in filter mode (--all or filter flags). */ private executeFilterMode; }