Type Definitions
Implementation Referenceβ
Source Files:
packages/core/src/types/index.ts
- Main type exportspackages/core/src/types/target.ts
- Target type definitionspackages/core/src/types/result.ts
- Result type definitionspackages/core/src/types/options.ts
- Options type definitionspackages/core/src/types/config.ts
- Configuration types
Core Typesβ
Target Typesβ
Targetβ
Base target interface for all execution targets.
interface Target {
type: 'local' | 'ssh' | 'docker' | 'kubernetes';
name?: string;
description?: string;
}
LocalTargetβ
Local execution target.
interface LocalTarget extends Target {
type: 'local';
shell?: string;
cwd?: string;
env?: Record<string, string>;
}
SSHTargetβ
SSH remote execution target.
interface SSHTarget extends Target {
type: 'ssh';
host: string;
port?: number;
user?: string;
password?: string;
privateKey?: string | Buffer;
passphrase?: string;
agentForward?: boolean;
strictHostKeyChecking?: boolean;
knownHosts?: string;
timeout?: number;
keepaliveInterval?: number;
keepaliveCountMax?: number;
readyTimeout?: number;
compress?: boolean;
algorithms?: {
kex?: string[];
cipher?: string[];
serverHostKey?: string[];
hmac?: string[];
};
}
DockerTargetβ
Docker container execution target.
interface DockerTarget extends Target {
type: 'docker';
container: string;
image?: string;
user?: string;
workingDir?: string;
env?: Record<string, string>;
privileged?: boolean;
network?: string;
volumes?: string[];
ports?: string[];
detach?: boolean;
remove?: boolean;
tty?: boolean;
interactive?: boolean;
}
KubernetesTargetβ
Kubernetes pod execution target.
interface KubernetesTarget extends Target {
type: 'kubernetes';
pod: string;
container?: string;
namespace?: string;
context?: string;
kubeconfig?: string;
labels?: Record<string, string>;
annotations?: Record<string, string>;
serviceAccount?: string;
}
Execution Typesβ
ExecutionOptionsβ
Options for command execution.
interface ExecutionOptions {
// Working directory
cwd?: string;
// Environment variables
env?: Record<string, string | undefined>;
// Shell configuration
shell?: string | boolean;
// Timeout in milliseconds
timeout?: number;
// Maximum buffer size for stdout/stderr
maxBuffer?: number;
// Encoding for output
encoding?: BufferEncoding;
// Abort signal for cancellation
signal?: AbortSignal;
// Input stream or data
stdin?: string | Buffer | Readable;
// Output streams
stdout?: Writable;
stderr?: Writable;
// Behavior flags
quiet?: boolean;
verbose?: boolean;
nothrow?: boolean;
// Process options
uid?: number;
gid?: number;
windowsHide?: boolean;
killSignal?: string | number;
}
ExecutionResultβ
Result of command execution.
interface ExecutionResult {
// Output
stdout: string;
stderr: string;
// Exit status
exitCode: number;
signal?: string;
// Success indicator
ok: boolean;
// Metadata
command: string;
duration: number;
target?: Target;
// Original options
options?: ExecutionOptions;
}
ProcessOutputβ
Extended output with additional properties.
interface ProcessOutput extends ExecutionResult {
// Additional stream data
combined?: string;
// Parsed data
lines?: string[];
json?: any;
// Process info
pid?: number;
killed?: boolean;
}
Configuration Typesβ
Configβ
Main configuration interface.
interface Config {
// Project metadata
name?: string;
description?: string;
version?: string;
// Targets
targets?: {
hosts?: Record<string, SSHTarget>;
containers?: Record<string, DockerTarget>;
pods?: Record<string, KubernetesTarget>;
groups?: Record<string, string[]>;
};
// Tasks
tasks?: Record<string, Task>;
// Variables
variables?: Record<string, any>;
// Defaults
defaults?: {
shell?: string;
timeout?: number;
cwd?: string;
env?: Record<string, string>;
ssh?: Partial<SSHTarget>;
docker?: Partial<DockerTarget>;
kubernetes?: Partial<KubernetesTarget>;
};
// Commands configuration
commands?: Record<string, CommandConfig>;
// Aliases
aliases?: Record<string, string>;
// Scripts configuration
scripts?: {
env?: Record<string, string>;
globals?: string[];
runtime?: 'auto' | 'node' | 'bun' | 'deno';
};
}
Taskβ
Task definition.
interface Task {
// Basic info
name?: string;
description?: string;
// Execution
command?: string;
script?: string;
steps?: TaskStep[];
// Parameters
params?: TaskParameter[];
// Target selection
targets?: string | string[];
parallel?: boolean;
// Options
timeout?: number;
cwd?: string;
env?: Record<string, string>;
// Conditions
condition?: string;
continueOnError?: boolean;
// Dependencies
depends?: string[];
// Hooks
before?: string | string[];
after?: string | string[];
onError?: string | string[];
}
TaskStepβ
Individual step in a multi-step task.
interface TaskStep {
name: string;
command?: string;
script?: string;
targets?: string | string[];
condition?: string;
continueOnError?: boolean;
timeout?: number;
env?: Record<string, string>;
}
TaskParameterβ
Task parameter definition.
interface TaskParameter {
name: string;
description?: string;
type?: 'string' | 'number' | 'boolean' | 'array' | 'object';
required?: boolean;
default?: any;
values?: any[];
pattern?: string;
min?: number;
max?: number;
}
Connection Typesβ
ConnectionPoolβ
SSH connection pool configuration.
interface ConnectionPoolConfig {
// Pool size
max?: number;
min?: number;
// Timeouts
acquireTimeoutMillis?: number;
createTimeoutMillis?: number;
destroyTimeoutMillis?: number;
idleTimeoutMillis?: number;
reapIntervalMillis?: number;
// Behavior
createRetryIntervalMillis?: number;
propagateCreateError?: boolean;
// Validation
testOnBorrow?: boolean;
testOnReturn?: boolean;
testWhileIdle?: boolean;
// Eviction
evictionRunIntervalMillis?: number;
numTestsPerEvictionRun?: number;
softIdleTimeoutMillis?: number;
}
SSHConnectionβ
Active SSH connection.
interface SSHConnection {
// Connection state
connected: boolean;
ready: boolean;
// Execute command
exec(command: string, options?: ExecOptions): Promise<ExecutionResult>;
// File operations
uploadFile(localPath: string, remotePath: string): Promise<void>;
downloadFile(remotePath: string, localPath: string): Promise<void>;
// Port forwarding
forwardPort(localPort: number, remoteHost: string, remotePort: number): Promise<void>;
reverseForward(remotePort: number, localHost: string, localPort: number): Promise<void>;
// Connection management
close(): Promise<void>;
destroy(): void;
}
Error Typesβ
XecErrorβ
Base error class for all Xec errors.
class XecError extends Error {
readonly code: string;
readonly details?: any;
readonly cause?: Error;
}
ExecutionErrorβ
Error thrown when command execution fails.
class ExecutionError extends XecError {
readonly exitCode: number;
readonly signal?: string;
readonly stdout: string;
readonly stderr: string;
readonly command: string;
readonly duration: number;
readonly target?: Target;
}
ValidationErrorβ
Error thrown for validation failures.
class ValidationError extends XecError {
readonly field?: string;
readonly value?: any;
readonly constraint?: string;
}
ConnectionErrorβ
Error thrown for connection failures.
class ConnectionError extends XecError {
readonly host?: string;
readonly port?: number;
readonly protocol?: string;
readonly attempt?: number;
}
TimeoutErrorβ
Error thrown when operation times out.
class TimeoutError extends XecError {
readonly timeout: number;
readonly operation?: string;
}
ConfigurationErrorβ
Error thrown for configuration issues.
class ConfigurationError extends XecError {
readonly configPath?: string;
readonly key?: string;
}
Event Typesβ
ExecutionEventβ
Events emitted during execution.
interface ExecutionEvent {
type: 'start' | 'stdout' | 'stderr' | 'end' | 'error';
timestamp: Date;
command?: string;
target?: Target;
data?: any;
}
ConnectionEventβ
Events for connection lifecycle.
interface ConnectionEvent {
type: 'connecting' | 'connected' | 'disconnecting' | 'disconnected' | 'error';
timestamp: Date;
target: Target;
error?: Error;
}
Utility Typesβ
DeepPartialβ
Make all properties optional recursively.
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
ValueOfβ
Get union of all values in object.
type ValueOf<T> = T[keyof T];
Promisableβ
Value or Promise of value.
type Promisable<T> = T | Promise<T>;
Nullableβ
Value or null/undefined.
type Nullable<T> = T | null | undefined;
Type Guardsβ
Target Guardsβ
function isSSHTarget(target: Target): target is SSHTarget {
return target.type === 'ssh';
}
function isDockerTarget(target: Target): target is DockerTarget {
return target.type === 'docker';
}
function isKubernetesTarget(target: Target): target is KubernetesTarget {
return target.type === 'kubernetes';
}
function isLocalTarget(target: Target): target is LocalTarget {
return target.type === 'local';
}
Error Guardsβ
function isExecutionError(error: unknown): error is ExecutionError {
return error instanceof ExecutionError;
}
function isTimeoutError(error: unknown): error is TimeoutError {
return error instanceof TimeoutError;
}
function isConnectionError(error: unknown): error is ConnectionError {
return error instanceof ConnectionError;
}
Generic Typesβ
Result Typeβ
Result pattern for error handling.
type Result<T, E = Error> =
| { ok: true; value: T }
| { ok: false; error: E };
function isOk<T, E>(result: Result<T, E>): result is { ok: true; value: T } {
return result.ok === true;
}
function isErr<T, E>(result: Result<T, E>): result is { ok: false; error: E } {
return result.ok === false;
}
AsyncResultβ
Async version of Result.
type AsyncResult<T, E = Error> = Promise<Result<T, E>>;
Constantsβ
Exit Codesβ
enum ExitCode {
Success = 0,
GeneralError = 1,
MisuseOfShellBuiltin = 2,
PermissionDenied = 126,
CommandNotFound = 127,
InvalidExitArgument = 128,
// Signal-based codes
SIGHUP = 129,
SIGINT = 130,
SIGQUIT = 131,
SIGTERM = 143,
}
Signalsβ
enum Signal {
SIGHUP = 'SIGHUP',
SIGINT = 'SIGINT',
SIGQUIT = 'SIGQUIT',
SIGILL = 'SIGILL',
SIGTRAP = 'SIGTRAP',
SIGABRT = 'SIGABRT',
SIGBUS = 'SIGBUS',
SIGFPE = 'SIGFPE',
SIGKILL = 'SIGKILL',
SIGUSR1 = 'SIGUSR1',
SIGSEGV = 'SIGSEGV',
SIGUSR2 = 'SIGUSR2',
SIGPIPE = 'SIGPIPE',
SIGALRM = 'SIGALRM',
SIGTERM = 'SIGTERM',
}
Usage Examplesβ
Using Target Typesβ
import { SSHTarget, DockerTarget } from '@xec-sh/core';
const sshTarget: SSHTarget = {
type: 'ssh',
host: 'server.example.com',
user: 'deploy',
privateKey: '/home/user/.ssh/id_rsa'
};
const dockerTarget: DockerTarget = {
type: 'docker',
container: 'my-app',
user: 'node',
workingDir: '/app'
};
Using Result Typeβ
import { Result } from '@xec-sh/core';
async function tryOperation(): Promise<Result<string>> {
try {
const data = await riskyOperation();
return { ok: true, value: data };
} catch (error) {
return { ok: false, error };
}
}
const result = await tryOperation();
if (result.ok) {
console.log('Success:', result.value);
} else {
console.log('Error:', result.error.message);
}
Type Guardsβ
import { isSSHTarget, isExecutionError } from '@xec-sh/core';
function handleTarget(target: Target) {
if (isSSHTarget(target)) {
console.log('SSH host:', target.host);
}
}
try {
await $`command`;
} catch (error) {
if (isExecutionError(error)) {
console.log('Exit code:', error.exitCode);
}
}
Related Documentationβ
- API Index - API overview
- Execution Engine - Engine types
- Process Promise - Promise types
- Configuration - Config structure