import { hasOwnErrorCode } from "./error-codes.js";
export function isRecord(value) {
    return typeof value === "object" && value !== null && !Array.isArray(value);
}
export function defineRecordEntry(record, key, value) {
    Object.defineProperty(record, key, {
        configurable: true,
        enumerable: true,
        value,
        writable: true
    });
}
export function isNotFound(error) {
    return hasOwnErrorCode(error, "ENOENT");
}
export async function readOptionalFile(fs, filePath) {
    try {
        return await fs.readFile(filePath, "utf8");
    }
    catch (error) {
        if (isNotFound(error)) {
            return null;
        }
        throw error;
    }
}
export function assertNotAborted(signal) {
    if (!signal?.aborted) {
        return;
    }
    throw createAbortError();
}
export function createAbortError() {
    const error = new Error("Pipeline run cancelled");
    error.name = "AbortError";
    return error;
}
