Skip to content

Commit f8e8252

Browse files
Add typing to readJsonlFile
We're still not verifying the actual object returned by JSON.parse so this isn't any safer at runtime than using 'any', but it helps add more static typing to the code calling readJsonlFile.
1 parent d7e9606 commit f8e8252

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

extensions/ql-vscode/src/common/jsonl-reader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import { readFile } from "fs-extra";
1010
* @param path The path to the file.
1111
* @param handler Callback to be invoked for each top-level JSON object in order.
1212
*/
13-
export async function readJsonlFile(
13+
export async function readJsonlFile<T>(
1414
path: string,
15-
handler: (value: any) => Promise<void>,
15+
handler: (value: T) => Promise<void>,
1616
): Promise<void> {
1717
const logSummary = await readFile(path, "utf-8");
1818

1919
// Remove newline delimiters because summary is in .jsonl format.
2020
const jsonSummaryObjects: string[] = logSummary.split(/\r?\n\r?\n/g);
2121

2222
for (const obj of jsonSummaryObjects) {
23-
const jsonObj = JSON.parse(obj);
23+
const jsonObj = JSON.parse(obj) as T;
2424
await handler(jsonObj);
2525
}
2626
}

extensions/ql-vscode/src/log-insights/log-scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class EvaluationLogScannerSet {
103103
p.createScanner(problemReporter),
104104
);
105105

106-
await readJsonlFile(jsonSummaryLocation, async (obj) => {
106+
await readJsonlFile<SummaryEvent>(jsonSummaryLocation, async (obj) => {
107107
scanners.forEach((scanner) => {
108108
scanner.onEvent(obj);
109109
});

extensions/ql-vscode/src/log-insights/log-summary-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function parseViewerData(
1919
): Promise<EvalLogData[]> {
2020
const viewerData: EvalLogData[] = [];
2121

22-
await readJsonlFile(jsonSummaryPath, async (jsonObj) => {
22+
await readJsonlFile<EvalLogData>(jsonSummaryPath, async (jsonObj) => {
2323
// Only convert log items that have an RA and millis field
2424
if (jsonObj.ra !== undefined && jsonObj.millis !== undefined) {
2525
const newLogData: EvalLogData = {

0 commit comments

Comments
 (0)