UNPKG

@xec-sh/core

Version:

Universal shell execution engine

59 lines 1.9 kB
import { CommandError } from './error.js'; export class ExecutionResultImpl { constructor(stdout, stderr, exitCode, signal, command, duration, startedAt, finishedAt, adapter, host, container) { this.stdout = stdout; this.stderr = stderr; this.exitCode = exitCode; this.signal = signal; this.command = command; this.duration = duration; this.startedAt = startedAt; this.finishedAt = finishedAt; this.adapter = adapter; this.host = host; this.container = container; this.ok = exitCode === 0; if (!this.ok) { this.cause = signal ? `signal: ${signal}` : `exitCode: ${exitCode}`; } } toMetadata() { return { stdout: this.stdout, stderr: this.stderr, exitCode: this.exitCode, signal: this.signal, command: this.command, duration: this.duration, startedAt: this.startedAt.toISOString(), finishedAt: this.finishedAt.toISOString(), adapter: this.adapter, host: this.host, container: this.container }; } throwIfFailed() { if (this.exitCode !== 0) { throw new CommandError(this.command, this.exitCode, this.signal, this.stdout, this.stderr, this.duration); } } text() { return this.stdout.trim(); } json() { const text = this.text(); try { return JSON.parse(text); } catch (error) { throw new Error(`Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}\nOutput: ${text}`); } } lines() { return this.stdout.split('\n').filter(line => line.length > 0); } buffer() { return Buffer.from(this.stdout); } } //# sourceMappingURL=result.js.map