gitflarePublicPartly agent-ready50
cf-d1-queues-pulse
Event analytics on Cloudflare D1 and Queues: ingestion API, batched consumer, rollups, live dashboard, load generator, dead-letter view.
- LicenseApache-2.0
- LanguageTypeScript
- Last landed
8a65841Oct 20, 2026
Build the full D1 + Queues pulse app: dashboard, load generator, dead letters, percentiles, docs
8a65841import { describe, it, expect } from "vitest";import { validateEvent, validateBatch } from "../src/lib/validate";import { aggregate } from "../src/lib/aggregate";import { UPSERT_ROLLUP, upsertParams } from "../src/lib/sql";import { fillMinutes } from "../src/lib/series"; describe("validate", () => { it("defaults", () => { expect(validateEvent({ type: "click" }, 5)).toEqual({ type: "click", path: "/", country: "XX", value: 0, ts: 5 }); }); it("rejects bad", () => { expect(validateEvent({ type: 1 }, 1)).toBeNull(); expect(validateEvent(null, 1)).toBeNull(); expect(validateEvent({ type: "a", value: "x" }, 1)).toBeNull(); }); it("batch", () => { const r = validateBatch([{ type: "a" }, {}], 1); expect(r).toMatchObject({ rejected: 1 }); expect(validateBatch(Array(101).fill({ type: "a" }), 1)).toHaveProperty("error"); });});describe("aggregate/sql/series", () => { it("groups by minute", () => { const e = (ts: number, value: number) => ({ type: "a", path: "/", country: "US", value, ts }); const rows = aggregate([e(1000, 1), e(2000, 2), e(61000, 5)]); expect(rows).toHaveLength(2); expect(rows[0]).toMatchObject({ count: 2, sum: 3 }); expect(upsertParams(rows[1])).toEqual([1, "a", "/", "US", 1, 5]); expect(UPSERT_ROLLUP).toContain("ON CONFLICT"); }); it("fills", () => { expect(fillMinutes([{ minute: 3, count: 4 }], 3, 3).map((r) => r.count)).toEqual([0, 0, 4]); });});