"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLogsFromReadable = void 0;
const split2_1 = __importDefault(require("split2"));
const promises_1 = require("node:stream/promises");
const MAX_LOGS = 1000;
const getLogsFromReadable = async (readable, log) => {
    const result = [];
    await (0, promises_1.pipeline)(readable, (0, split2_1.default)(), async function* (source) {
        for await (const line of source) {
            try {
                const parsedObject = JSON.parse(line);
                if (result.length >= MAX_LOGS) {
                    result.shift();
                }
                result.push(parsedObject);
            }
            catch (err) {
                log?.warn({ line }, 'Invalid JSON line found:');
            }
        }
    });
    return result;
};
exports.getLogsFromReadable = getLogsFromReadable;
//# sourceMappingURL=log.js.map