Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -3,9 +3,9 @@ import { describe, expect, it } from "vitest";
import { ExportTableValidationError } from "../types.js";
import { buildCsvExportArtifact, serializeExportTableToCsv } from "./index.js";
describe("@toolctrl/exports/csv public entrypoint", () => {
describe("@hivegrid/exports/csv public entrypoint", () => {
it("exposes CSV-only runtime helpers without loading unrelated exporters", async () => {
const exportsModule = await import("@toolctrl/exports/csv");
const exportsModule = await import("@hivegrid/exports/csv");
expect(Object.keys(exportsModule).sort()).toEqual([
"ExportTableValidationError",
@@ -0,0 +1,131 @@
import { Writable } from "node:stream";
import { describe, expect, it } from "vitest";
import { serializeExportTableToCsvStream } from "./index.js";
/**
* Writable that always reports back-pressure (highWaterMark 1) and defers its
* write callback to the next event-loop tick. Forces every `writeStream.write`
* to return `false`, driving the producer through the drain-wait branch of
* `writeChunk` that a fast PassThrough sink never exercises.
*/
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");
}
}
/** Writable whose deferred write callback fails, so writeChunk hits 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("serializeExportTableToCsvStream — back-pressure and error propagation", () => {
it("waits for drain on a back-pressured sink without corrupting output", async () => {
const sink = new BackpressureSink();
const result = await serializeExportTableToCsvStream(sink, {
columns: ["id", "name"],
rows: [
{ id: 1, name: "Ada" },
{ id: 2, name: "Grace" },
],
});
expect(result.rowCount).toBe(2);
expect(sink.text()).toBe(['"id","name"', '"1","Ada"', '"2","Grace"'].join("\n"));
});
it("rejects when the sink emits an error mid-write", async () => {
const sink = new ExplodingSink(new Error("sink exploded"));
await expect(
serializeExportTableToCsvStream(sink, {
columns: ["id"],
rows: [{ id: 1 }],
}),
).rejects.toThrow("sink exploded");
});
});
describe("serializeExportTableToCsvStream — input validation", () => {
it("throws when a row is not an object record", async () => {
const sink = new BackpressureSink();
await expect(
serializeExportTableToCsvStream(sink, {
columns: ["id"],
rows: [42 as never],
}),
).rejects.toThrow("Export table row must be an object record.");
});
it("treats arrays and null as non-record rows", async () => {
const sink = new BackpressureSink();
await expect(
serializeExportTableToCsvStream(sink, {
columns: ["id"],
rows: [[1, 2] as never],
}),
).rejects.toThrow("Export table row must be an object record.");
const nullSink = new BackpressureSink();
await expect(
serializeExportTableToCsvStream(nullSink, {
columns: ["id"],
rows: [null as never],
}),
).rejects.toThrow("Export table row must be an object record.");
});
it("throws when columns are omitted for an async row source", async () => {
const sink = new BackpressureSink();
await expect(
serializeExportTableToCsvStream(sink, {
rows: [{ id: 1 }],
} as never),
).rejects.toThrow("Streaming CSV writer requires explicit columns; cannot infer from an async row source.");
});
});
describe("serializeExportTableToCsvStream — value stringification", () => {
it("renders dates, bigints and null/undefined deterministically and labels default to the key", async () => {
const sink = new BackpressureSink();
const result = await serializeExportTableToCsvStream(sink, {
// object column without a label -> label falls back to the key
columns: [{ key: "createdAt" }, "big", "missing", "blank"],
rows: [
{
createdAt: new Date("2024-01-02T03:04:05.006Z"),
big: 9007199254740993n,
missing: undefined,
blank: null,
},
],
});
expect(result.rowCount).toBe(1);
expect(sink.text()).toBe(
[
'"createdAt","big","missing","blank"',
'"2024-01-02T03:04:05.006Z","9007199254740993","",""',
].join("\n"),
);
});
});