Function: parseJsonlFile()
Makaio Framework / ai-adapters-core/node / parseJsonlFile
Function: parseJsonlFile()
Section titled “Function: parseJsonlFile()”parseJsonlFile<
T>(options):Promise<JsonlParseResult<T>>
Defined in: ../../../adapters/core/src/log-importer/jsonl-parser.ts:145
Parse a JSONL file starting from a byte offset.
Type Parameters
Section titled “Type Parameters”T
The expected type of each parsed JSON record
Parameters
Section titled “Parameters”options
Section titled “options”Parser configuration including file path and start offset
Returns
Section titled “Returns”Promise<JsonlParseResult<T>>
Parse result with records, new byte offset, and any errors
Throws
Section titled “Throws”Error if the file cannot be opened or read
Remarks
Section titled “Remarks”Partial Line Handling
Section titled “Partial Line Handling”JSONL files may be actively written to, leaving incomplete lines at the end.
This parser only processes complete lines (lines ending with \n). Incomplete
trailing content is left for the next read cycle.
Error Handling
Section titled “Error Handling”Malformed JSON lines don’t stop parsing. The parser logs the error and
continues to the next line. Callers should check the errors array and
log/alert as appropriate.
Type Safety
Section titled “Type Safety”The generic type T is not validated at runtime. Callers should either:
- Use Zod or similar to validate each record
- Use type guards before accessing properties
- Trust the source format (e.g., known tool log format)
Example
Section titled “Example”interface LogRecord { type: string; timestamp: string; data: unknown;}
// First read (from beginning)const result = await parseJsonlFile<LogRecord>({ filePath: '/path/to/logs.jsonl',});
// Process recordsfor (const record of result.records) { console.log(record.type);}
// Store cursor for next readawait saveCursor(result.bytesRead);
// Later: resume from cursorconst cursor = await loadCursor();const nextResult = await parseJsonlFile<LogRecord>({ filePath: '/path/to/logs.jsonl', startOffset: cursor,});