"use strict";var c=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var h=(t,s)=>{for(var i in s)c(t,i,{get:s[i],enumerable:!0})},l=(t,s,i,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of m(s))!g.call(t,r)&&r!==i&&c(t,r,{get:()=>s[r],enumerable:!(e=b(s,r))||e.enumerable});return t};var v=t=>l(c({},"__esModule",{value:!0}),t);var y={};h(y,{MemoryMessageProvider:()=>n,Qified:()=>a,QifiedEvents:()=>d});module.exports=v(y);var p=require("hookified");var P="@qified/memory",n=class{_subscriptions;_id;constructor(s){this._subscriptions=new Map,this._id=s?.id??P}get id(){return this._id}set id(s){this._id=s}get subscriptions(){return this._subscriptions}set subscriptions(s){this._subscriptions=s}async publish(s,i){let e={...i,providerId:this._id},r=this._subscriptions.get(s)??[];for(let u of r)await u.handler(e)}async subscribe(s,i){this._subscriptions.has(s)||this._subscriptions.set(s,[]),this._subscriptions.get(s)?.push(i)}async unsubscribe(s,i){if(i){let e=this._subscriptions.get(s);e&&this._subscriptions.set(s,e.filter(r=>r.id!==i))}else this._subscriptions.delete(s)}async disconnect(){this._subscriptions.clear()}};var d=(o=>(o.error="error",o.info="info",o.warn="warn",o.publish="publish",o.subscribe="subscribe",o.unsubscribe="unsubscribe",o.disconnect="disconnect",o))(d||{}),a=class extends p.Hookified{_messageProviders=[];constructor(s){super(s),s?.messageProviders&&(this._messageProviders=s.messageProviders)}get messageProviders(){return this._messageProviders}set messageProviders(s){this._messageProviders=s}async subscribe(s,i){try{let e=this._messageProviders.map(async r=>r.subscribe(s,i));await Promise.all(e),this.emit("subscribe",{topic:s,handler:i})}catch(e){this.emit("error",e)}}async publish(s,i){try{let e=this._messageProviders.map(async r=>r.publish(s,i));await Promise.all(e),this.emit("publish",{topic:s,message:i})}catch(e){this.emit("error",e)}}async unsubscribe(s,i){try{let e=this._messageProviders.map(async r=>r.unsubscribe(s,i));await Promise.all(e),this.emit("unsubscribe",{topic:s,id:i})}catch(e){this.emit("error",e)}}async disconnect(){try{let s=this._messageProviders.map(async i=>i.disconnect());await Promise.all(s),this._messageProviders=[],this.emit("disconnect")}catch(s){this.emit("error",s)}}};0&&(module.exports={MemoryMessageProvider,Qified,QifiedEvents});
