import{logger as e}from"../logger/index.mjs";import{ErrorHandler as t}from"../utils/errors/ErrorHandler.mjs";let n=[];const r=e=>{let t=e.flatMap(e=>e.dictionary.projectIds),r=n.filter(e=>t.map(e=>String(e)).includes(String(e.projectId))),i=e.map(e=>({object:`DICTIONARY`,status:e.status,data:e.dictionary}));process.nextTick(()=>{for(let e of r)e.res.raw.write(`data: ${JSON.stringify(i)}\n\n`)})},i=async(r,i)=>{let{project:a}=r.locals||{};if(n.length>=10)return t.handleGenericErrorResponse(i,`TOO_MANY_CONNECTIONS`);i.raw.setHeader(`Content-Type`,`text/event-stream;charset=utf-8`),i.raw.setHeader(`Cache-Control`,`no-cache, no-transform`),i.raw.setHeader(`Connection`,`keep-alive`),i.raw.setHeader(`X-Accel-Buffering`,`no`),i.raw.write(`:

`),i.raw.flushHeaders?.();let o=Date.now(),s={id:o,projectId:String(a?.id),res:{raw:i.raw}};n.push(s),e.info(`New client connected to SSE. Total clients: ${n.length??0}`),r.raw.on(`close`,()=>{n=n.filter(e=>e.id!==o)})};export{i as listenChangeSSE,r as sendDictionaryUpdate};
//# sourceMappingURL=eventListener.controller.mjs.map