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
8a65841export function fmt(n){return n==null||isNaN(n)?"–":Number(n).toLocaleString("en-US",{maximumFractionDigits:1});}export function fmtLag(ms){if(ms==null||isNaN(ms))return "–";if(ms<1000)return Math.round(ms)+" ms";if(ms<60000)return (ms/1000).toFixed(1)+" s";return Math.round(ms/60000)+" min";}export function lagLevel(ms){if(ms==null)return "idle";return ms<5000?"ok":ms<30000?"warn":"bad";}export function delta(cur,prev){if(!prev)return cur?null:0;return Math.round((cur-prev)/prev*100);}export function linePath(vals,w,h,pad=4){const n=vals.length;if(!n)return "";const max=Math.max(1,...vals); return vals.map((v,i)=>`${i?"L":"M"}${(n===1?w/2:pad+i*(w-2*pad)/(n-1)).toFixed(1)},${(h-pad-v/max*(h-2*pad)).toFixed(1)}`).join("");}export function barList(items,limit=6){const a=(items||[]).slice(0,limit);const max=Math.max(1,...a.map(i=>i.count??i.n??0)); return a.map(i=>{const c=i.count??i.n??0;return {label:i.type??i.path??i.country??i.label??"?",count:c,pct:Math.round(c/max*100)};});}export function planBatch(rate,elapsedMs,sent){const target=Math.floor(rate*elapsedMs/1000);return Math.max(0,Math.min(100,target-sent));}export function makeEvents(n,mix,poisonPct,rnd=Math.random){const out=[];const types=mix.length?mix:["click"]; for(let i=0;i<n;i++){if(rnd()*100<poisonPct){out.push({type:"",value:"poison"});continue;} out.push({type:types[Math.floor(rnd()*types.length)],path:"/"+["home","pricing","docs","blog"][Math.floor(rnd()*4)],country:["US","DE","JP","BR","IN"][Math.floor(rnd()*5)],value:Math.round(rnd()*500)});} return out;}export function esc(s){return String(s??"").replace(/[&<>"']/g,c=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));}