UNPKG

@xec-sh/core

Version:

Universal shell execution engine

61 lines (60 loc) 3.09 kB
import { Command } from '../core/command.js'; import { StreamHandler } from '../utils/stream.js'; import { ProgressReporter } from '../utils/progress.js'; import { EnhancedEventEmitter } from '../utils/event-emitter.js'; import { ExecutionResult } from '../core/result.js'; import type { UshEventMap } from '../types/events.js'; import type { Disposable } from '../types/disposable.js'; export interface SensitiveDataMaskingConfig { enabled: boolean; patterns: RegExp[]; replacement: string; } export interface BaseAdapterConfig { defaultTimeout?: number; defaultCwd?: string; defaultEnv?: Record<string, string>; defaultShell?: string | boolean; encoding?: BufferEncoding; maxBuffer?: number; throwOnNonZeroExit?: boolean; sensitiveDataMasking?: Partial<SensitiveDataMaskingConfig>; } interface ResolvedBaseAdapterConfig extends Omit<Required<BaseAdapterConfig>, 'sensitiveDataMasking'> { sensitiveDataMasking: SensitiveDataMaskingConfig; } export declare abstract class BaseAdapter extends EnhancedEventEmitter implements Disposable { protected config: ResolvedBaseAdapterConfig; protected abstract readonly adapterName: string; name: string; constructor(config?: BaseAdapterConfig); protected emitAdapterEvent<K extends keyof UshEventMap>(event: K, data: Omit<UshEventMap[K], 'timestamp' | 'adapter'>): void; abstract execute(command: Command): Promise<ExecutionResult>; abstract isAvailable(): Promise<boolean>; executeSync?(command: Command): ExecutionResult; protected mergeCommand(command: Command): Command; protected createStreamHandler(options?: { onData?: (chunk: string) => void; }): StreamHandler; protected createProgressReporter(command: Command): ProgressReporter | null; protected handleTimeout(promise: Promise<any>, timeout: number, command: string, cleanup?: () => void): Promise<any>; protected maskSensitiveData(text: string): string; protected createResultSync(stdout: string, stderr: string, exitCode: number, signal: string | undefined, command: string, startTime: number, endTime: number, context?: { host?: string; container?: string; originalCommand?: Command; }): ExecutionResult; protected createResult(stdout: string, stderr: string, exitCode: number, signal: string | undefined, command: string, startTime: number, endTime: number, context?: { host?: string; container?: string; originalCommand?: Command; }): Promise<ExecutionResult>; protected shouldThrowOnNonZeroExit(command: Command | string, exitCode: number): boolean; protected buildCommandString(command: Command): string; protected handleAbortSignal(signal: AbortSignal | undefined, cleanup: () => void): Promise<void>; protected createCombinedEnv(baseEnv: Record<string, string>, commandEnv?: Record<string, string>): Record<string, string>; updateConfig(config: Partial<BaseAdapterConfig>): void; getConfig(): Readonly<ResolvedBaseAdapterConfig>; abstract dispose(): Promise<void>; } export {};