Skip to content

Commit 5a1266d

Browse files
committed
rename
1 parent 5ca7181 commit 5a1266d

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,68 @@
11
import * as assert from "node:assert";
22

3-
import { JsonlStream } from "../utils/jsonl-stream.js";
3+
import { JsonLinesStream } from "../utils/json-lines-stream.js";
44

55
const setup = () => {
6-
const jsonlStream = new JsonlStream();
6+
const stream = new JsonLinesStream();
77

88
const callbackCalls: unknown[] = [];
9-
jsonlStream.onJson((data: unknown) => {
9+
stream.onJson((data: unknown) => {
1010
callbackCalls.push(data);
1111
});
1212

1313
return {
14-
jsonlStream,
14+
stream,
1515
callbackCalls,
1616
};
1717
};
1818

19-
suite("JSONL Streams", () => {
20-
test("should parse and emit complete JSONL messages", () => {
21-
const { jsonlStream, callbackCalls } = setup();
19+
suite("JsonLinesStream Test Suite", () => {
20+
test("should parse and emit complete JsonLines messages", () => {
21+
const { stream, callbackCalls } = setup();
2222

2323
// Test with multiple JSON objects in a single write
2424
const testData = Buffer.from('{"key1":"value1"}\n{"key2":"value2"}\n');
2525

26-
jsonlStream.write(testData);
26+
stream.write(testData);
2727

2828
assert.strictEqual(callbackCalls.length, 2);
2929
assert.deepStrictEqual(callbackCalls[0], { key1: "value1" });
3030
assert.deepStrictEqual(callbackCalls[1], { key2: "value2" });
3131
});
3232

33-
test("should handle incomplete JSONL messages across multiple writes", () => {
34-
const { jsonlStream, callbackCalls } = setup();
33+
test("should handle incomplete JsonLines messages across multiple writes", () => {
34+
const { stream, callbackCalls } = setup();
3535

3636
// First write with partial message
3737
const firstChunk = Buffer.from('{"key":"value');
38-
jsonlStream.write(firstChunk);
38+
stream.write(firstChunk);
3939

4040
// Shouldn't emit anything yet
4141
assert.strictEqual(callbackCalls.length, 0);
4242

4343
// Complete the message in second write
4444
const secondChunk = Buffer.from('1"}\n');
45-
jsonlStream.write(secondChunk);
45+
stream.write(secondChunk);
4646

4747
// Now it should emit the complete message
4848
assert.strictEqual(callbackCalls.length, 1);
4949
assert.deepStrictEqual(callbackCalls[0], { key: "value1" });
5050
});
5151

5252
test("should handle multiple messages in chunks", () => {
53-
const { jsonlStream, callbackCalls } = setup();
53+
const { stream, callbackCalls } = setup();
5454

5555
// Write first message and part of second
5656
const firstChunk = Buffer.from('{"first":1}\n{"second":');
57-
jsonlStream.write(firstChunk);
57+
stream.write(firstChunk);
5858

5959
// First message should be emitted
6060
assert.strictEqual(callbackCalls.length, 1);
6161
assert.deepStrictEqual(callbackCalls[0], { first: 1 });
6262

6363
// Complete second message and add third
6464
const secondChunk = Buffer.from('2}\n{"third":3}\n');
65-
jsonlStream.write(secondChunk);
65+
stream.write(secondChunk);
6666

6767
// Should have all three messages now
6868
assert.strictEqual(callbackCalls.length, 3);
@@ -71,23 +71,23 @@ suite("JSONL Streams", () => {
7171
});
7272

7373
test("should ignore invalid JSON lines", () => {
74-
const { jsonlStream, callbackCalls } = setup();
74+
const { stream, callbackCalls } = setup();
7575

7676
const testData = Buffer.from('not json\n{"valid":true}\n{invalid}\n');
7777

78-
jsonlStream.write(testData);
78+
stream.write(testData);
7979

8080
// Should only emit the valid JSON object
8181
assert.strictEqual(callbackCalls.length, 1);
8282
assert.deepStrictEqual(callbackCalls[0], { valid: true });
8383
});
8484

8585
test("should handle empty lines", () => {
86-
const { jsonlStream, callbackCalls } = setup();
86+
const { stream, callbackCalls } = setup();
8787

8888
const testData = Buffer.from('\n\n{"key":"value"}\n\n');
8989

90-
jsonlStream.write(testData);
90+
stream.write(testData);
9191

9292
// Should only emit the valid JSON object
9393
assert.strictEqual(callbackCalls.length, 1);

src/utils/container-status.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Disposable, LogOutputChannel } from "vscode";
44
import * as z from "zod/v4-mini";
55

66
import { createEmitter } from "./emitter.ts";
7-
import { JsonlStream } from "./jsonl-stream.ts";
7+
import { JsonLinesStream } from "./json-lines-stream.ts";
88

99
export type ContainerStatus = "running" | "stopping" | "stopped";
1010

@@ -123,7 +123,7 @@ function listenToContainerStatus(
123123
throw new Error("Failed to get stdout from docker events process");
124124
}
125125

126-
const jsonlStream = new JsonlStream();
126+
const jsonlStream = new JsonLinesStream();
127127
jsonlStream.onJson((json) => {
128128
const parsed = DockerEventsSchema.safeParse(json);
129129
if (!parsed.success) {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Writable } from "node:stream";
22

33
/**
4-
* Safely parses a JSON string, returning null if parsing fails.
4+
* Safely parses a JSON string, returning undefined if parsing fails.
55
* @param str - The JSON string to parse.
6-
* @returns The parsed object or null if invalid.
6+
* @returns The parsed object or undefined if invalid.
77
*/
88
export function safeJsonParse(str: string): unknown {
99
try {
@@ -17,7 +17,7 @@ export function safeJsonParse(str: string): unknown {
1717
* Writable stream that buffers data until a newline,
1818
* parses each line as JSON, and emits the parsed object.
1919
*/
20-
export class JsonlStream extends Writable {
20+
export class JsonLinesStream extends Writable {
2121
constructor() {
2222
let buffer = "";
2323
super({

0 commit comments

Comments
 (0)