Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,50 @@ describe("TinybirdApi", () => {
).rejects.toThrow("Date values are not supported in ingest payloads");
});

it.each([
{
name: "bigint entries",
payload: new Map([["total", 9007199254740993n], ["pending", 0n]]),
expected: { total: "9007199254740993", pending: "0" },
},
{
name: "nested maps",
payload: new Map([["current", new Map([["count", 42]])]]),
expected: { current: { count: 42 } },
},
])("serializes $name in ingested maps", async ({ payload, expected }) => {
let event: unknown;
server.use(
http.post(`${BASE_URL}/v0/events`, async ({ request }) => {
event = JSON.parse(await request.text());
return HttpResponse.json({ successful_rows: 1, quarantined_rows: 0 });
})
);

const api = createTinybirdApi({ baseUrl: BASE_URL, token: "p.default-token" });
await api.ingest("events", { payload });

expect(event).toEqual({ payload: expected });
});

it("rejects Date values inside ingest maps before making a request", async () => {
let requests = 0;
server.use(
http.post(`${BASE_URL}/v0/events`, () => {
requests += 1;
return HttpResponse.json({ successful_rows: 1, quarantined_rows: 0 });
})
);

const api = createTinybirdApi({ baseUrl: BASE_URL, token: "p.default-token" });
await expect(
api.ingest("events", {
payload: new Map([["when", new Date("2024-01-01T00:00:00.000Z")]]),
})
).rejects.toThrow("Date values are not supported in ingest payloads");
expect(requests).toBe(0);
});

it("does not retry ingest on 503 when retry is disabled", async () => {
let attempts = 0;

Expand Down
4 changes: 3 additions & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ export class TinybirdApi {
}

if (value instanceof Map) {
return Object.fromEntries(value);
return Object.fromEntries(
Array.from(value, ([key, entry]) => [key, this.serializeValue(entry)])
);
}

if (typeof value === "bigint") {
Expand Down