Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
@@ -7,7 +7,7 @@ import {
|
||||
serializeExportTableToJsonLines,
|
||||
} from "./index.js";
|
||||
|
||||
describe("@toolctrl/exports/json public entrypoint", () => {
|
||||
describe("@hivegrid/exports/json public entrypoint", () => {
|
||||
it("exposes JSON-only runtime helpers", async () => {
|
||||
const exportsModule = await import("./index.js");
|
||||
|
||||
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
import { Writable } from "node:stream";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { PRETTY_JSON_STREAM_ROW_LIMIT, serializeExportTableToJsonStream } from "./index.js";
|
||||
|
||||
/** Back-pressured sink (highWaterMark 1, deferred callback) for the drain branch. */
|
||||
class BackpressureSink extends Writable {
|
||||
public readonly chunks: Buffer[] = [];
|
||||
constructor() {
|
||||
super({ highWaterMark: 1 });
|
||||
}
|
||||
_write(chunk: Buffer | string, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
||||
this.chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
||||
setImmediate(callback);
|
||||
}
|
||||
text(): string {
|
||||
return Buffer.concat(this.chunks).toString("utf8");
|
||||
}
|
||||
}
|
||||
|
||||
/** Sink whose deferred callback fails, so writeChunk takes the error branch. */
|
||||
class ExplodingSink extends Writable {
|
||||
constructor(private readonly failure: Error) {
|
||||
super({ highWaterMark: 1 });
|
||||
}
|
||||
_write(_chunk: Buffer | string, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void {
|
||||
setImmediate(() => callback(this.failure));
|
||||
}
|
||||
}
|
||||
|
||||
describe("serializeExportTableToJsonStream — back-pressure and error propagation", () => {
|
||||
it("drains a back-pressured sink and still emits well-formed ndjson", async () => {
|
||||
const sink = new BackpressureSink();
|
||||
|
||||
const result = await serializeExportTableToJsonStream(sink, {
|
||||
// object columns drive the non-string branch of resolveJsonColumnKeys
|
||||
columns: [{ key: "id" }, { key: "name" }],
|
||||
rows: [
|
||||
{ id: 1, name: "Ada" },
|
||||
{ id: 2, name: "Grace" },
|
||||
],
|
||||
});
|
||||
|
||||
expect(result).toEqual({ rowCount: 2, mode: "ndjson" });
|
||||
expect(sink.text()).toBe('{"id":1,"name":"Ada"}\n{"id":2,"name":"Grace"}');
|
||||
});
|
||||
|
||||
it("rejects when the sink errors mid-write", async () => {
|
||||
const sink = new ExplodingSink(new Error("json sink down"));
|
||||
|
||||
await expect(
|
||||
serializeExportTableToJsonStream(sink, {
|
||||
columns: ["id"],
|
||||
rows: [{ id: 1 }],
|
||||
}),
|
||||
).rejects.toThrow("json sink down");
|
||||
});
|
||||
});
|
||||
|
||||
describe("serializeExportTableToJsonStream — column resolution", () => {
|
||||
it("throws when columns are omitted for an async row source", async () => {
|
||||
const sink = new BackpressureSink();
|
||||
|
||||
await expect(
|
||||
serializeExportTableToJsonStream(sink, { rows: [{ id: 1 }] } as never),
|
||||
).rejects.toThrow("Streaming JSON writer requires explicit columns; cannot infer from an async row source.");
|
||||
});
|
||||
|
||||
it("rejects duplicate column keys eagerly", async () => {
|
||||
const sink = new BackpressureSink();
|
||||
|
||||
await expect(
|
||||
serializeExportTableToJsonStream(sink, {
|
||||
columns: ["id", { key: "id", label: "Identifier" }],
|
||||
rows: [{ id: 1 }],
|
||||
}),
|
||||
).rejects.toThrow('Export table columns contain duplicate key "id".');
|
||||
});
|
||||
});
|
||||
|
||||
describe("serializeExportTableToJsonStream — pretty mode boundary", () => {
|
||||
it("accepts exactly the row limit without throwing", async () => {
|
||||
const sink = new BackpressureSink();
|
||||
|
||||
async function* rows() {
|
||||
for (let i = 0; i < PRETTY_JSON_STREAM_ROW_LIMIT; i += 1) {
|
||||
yield { id: i };
|
||||
}
|
||||
}
|
||||
|
||||
const result = await serializeExportTableToJsonStream(
|
||||
sink,
|
||||
{ columns: ["id"], rows: rows() },
|
||||
{ mode: "pretty" },
|
||||
);
|
||||
|
||||
expect(result).toEqual({ rowCount: PRETTY_JSON_STREAM_ROW_LIMIT, mode: "pretty" });
|
||||
const parsed = JSON.parse(sink.text()) as { id: number }[];
|
||||
expect(parsed).toHaveLength(PRETTY_JSON_STREAM_ROW_LIMIT);
|
||||
expect(parsed[0]).toEqual({ id: 0 });
|
||||
expect(parsed.at(-1)).toEqual({ id: PRETTY_JSON_STREAM_ROW_LIMIT - 1 });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user