import { appendFile, readFile } from "node:fs/promises";
import path from "node:path";
import { ensureDir, withFileLock } from "./fs.js";
export async function appendJsonl(file, value) {
    await ensureDir(path.dirname(file));
    await withFileLock(file, async () => {
        await appendFile(file, `${JSON.stringify(value)}\n`, "utf8");
    });
}
export async function readJsonl(file) {
    try {
        const text = await readFile(file, "utf8");
        return text
            .split("\n")
            .filter((line) => line.trim().length > 0)
            .map((line) => JSON.parse(line));
    }
    catch (error) {
        if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
            return [];
        throw error;
    }
}
//# sourceMappingURL=jsonl.js.map