var e=new Map,t=new Map,n=new Map;function r(e){return e.map(e=>{let t=[];e.kinds&&t.push(`kinds:${e.kinds.join(`,`)}`),e.authors&&t.push(`authors:${e.authors.length}`),e.ids&&t.push(`ids:${e.ids.length}`),e.limit&&t.push(`limit:${e.limit}`),e.since&&t.push(`since:${e.since}`),e.until&&t.push(`until:${e.until}`),e.search&&t.push(`search:${e.search}`);for(let[n,r]of Object.entries(e))n.startsWith(`#`)&&Array.isArray(r)&&t.push(`${n}:${r.length}`);return t.join(` `)||`empty-filter`}).join(` | `)}function i(e){return JSON.stringify(e)}function a(t){return e.get(t)}function o(e){return t.get(e)}function s(e){if(e.kind<3e4||e.kind>=4e4)return;let t=e.tags.find(([e])=>e===`d`)?.[1];if(t)return`${e.kind}:${e.pubkey}:${t}`}function c(n,r){e.has(n.id)||e.set(n.id,r);let i=s(n);i&&!t.has(i)&&t.set(i,r)}var l=class{url;relay;constructor(e,t){this.url=e,this.relay=t}async*req(e,t){let a=performance.now(),o=r(e),s=i(e),l=0,u=!1;console.debug(`[nostr relay req:start]`,{relay:this.url,filters:o});for await(let r of this.relay.req(e,t)){let e=Math.round(performance.now()-a);if(r[0]===`EVENT`){let t=r[2];l+=1,c(t,this.url),u||(u=!0,console.info(`[nostr relay race:first-event]`,{relay:this.url,elapsedMs:e,kind:t.kind,id:t.id,filters:o}))}r[0]===`EOSE`&&(n.has(s)?console.debug(`[nostr relay req:eose]`,{relay:this.url,elapsedMs:e,eventCount:l,winner:n.get(s),filters:o}):(n.set(s,this.url),console.info(`[nostr relay race:first-eose]`,{relay:this.url,elapsedMs:e,eventCount:l,filters:o}))),r[0]===`CLOSED`&&console.debug(`[nostr relay req:closed]`,{relay:this.url,elapsedMs:e,eventCount:l,filters:o,message:r[2]}),yield r}}async query(e,t){let n=performance.now(),i=await this.relay.query(e,t);for(let e of i)c(e,this.url);return console.info(`[nostr relay query]`,{relay:this.url,elapsedMs:Math.round(performance.now()-n),eventCount:i.length,filters:r(e)}),i}event(e,t){return console.info(`[nostr relay publish]`,{relay:this.url,kind:e.kind,id:e.id}),this.relay.event(e,t)}close(){return this.relay.close()}};function u(e){let t=e.tags.filter(([e])=>e===`e`);return t.length!==0&&t.filter(([,,,e])=>e!==`mention`).length>0}function d(e){return p(e)?.[1]}function f(e){let t=p(e);if(!t)return;let n=t[4]||e.tags.find(([e])=>e===`p`)?.[1]||void 0;return{id:t[1],relayHint:t[2]||void 0,authorHint:n}}function p(e){if(e.kind===7)return e.tags.findLast(([e])=>e===`e`);let t=e.tags.filter(([e,,,t])=>e===`e`&&t!==`mention`);return t.length===0?void 0:t.find(([,,,e])=>e===`reply`)||t.find(([,,,e])=>e===`root`)||t[t.length-1]}function m(e){let t=e.split(`:`);if(t.length<3)return;let n=parseInt(t[0],10);if(isNaN(n)||n<0)return;let r=t[1];if(r)return{kind:n,pubkey:r,identifier:t.slice(2).join(`:`)}}export{l as a,m as i,d as n,o,u as r,a as s,f as t};