@adapt-arch/utiliti-es 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var h=Object.defineProperty;var g=(i,e,s)=>e in i?h(i,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[e]=s;var o=(i,e,s)=>(g(i,typeof e!="symbol"?e+"":e,s),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class p{constructor(e){o(this,"_subscriptions",new Map);o(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const t of this._options.plugins)t.init&&t.init(this)}publish(e,s){var n;const t={topic:e,message:s};if((n=this._options)!=null&&n.plugins)for(const l of this._options.plugins)l.onPublish&&l.onPublish(t);if(!t.topic)throw new Error("Invalid topic.");if(!t.message)throw new Error("Invalid message.");const r=this._subscriptions.get(t.topic);if(r)for(const l of r.values()){const c=structuredClone(t.topic),u=structuredClone(t.message);setTimeout(()=>l(c,u),0)}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let t=this._subscriptions.get(e);t||(t=new Map,this._subscriptions.set(structuredClone(e),t));const r=`sub-${Date.now()}`;return t.set(r,s),r}unsubscribe(e){if(e){for(const s of this._subscriptions.values())if(s.delete(e))return}}[Symbol.dispose](){var e;if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const t=s[Symbol.dispose];t&&t.call(s)}return Promise.resolve()}}class _{constructor(e){o(this,"_options");o(this,"_channel");o(this,"_eventListeners",null);o(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const t=s.data;if(!(!t.topic||!t.message))try{this._broadcastEnabled=!1,e.publish(t.topic,t.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class m{constructor(e,s){o(this,"_values");o(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const t in this._values)s.indexOf(t)!==-1&&!this._overrideExisting||(e.extraParams[t]=this._values[t])}}class f{constructor(e,s){o(this,"_valuesFn");o(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const t=Object.keys(e.extraParams);for(const r in s)t.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}exports.LogLevel=void 0;(function(i){i[i.Trace=0]="Trace",i[i.Debug=1]="Debug",i[i.Information=2]="Information",i[i.Warning=3]="Warning",i[i.Error=4]="Error",i[i.Critical=5]="Critical",i[i.None=6]="None"})(exports.LogLevel||(exports.LogLevel={}));class a{constructor(){o(this,"timestamp",new Date().getTime());o(this,"level",exports.LogLevel.None);o(this,"name","");o(this,"message","");o(this,"errorMessage");o(this,"stackTrace");o(this,"extraParams")}}class d{constructor(e){o(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case exports.LogLevel.Trace:s=this._console.trace||this._console.log;break;case exports.LogLevel.Debug:s=this._console.debug||this._console.log;break;case exports.LogLevel.Information:s=this._console.info||this._console.log;break;case exports.LogLevel.Warning:s=this._console.warn||this._console.log;break;case exports.LogLevel.Error:s=this._console.error||this._console.log;break;case exports.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class v{constructor(){o(this,"endpoint","");o(this,"verb","POST");o(this,"batchSize",20);o(this,"interval",2e3);o(this,"requestTransform")}}class b{constructor(e){o(this,"_messageQueue");o(this,"_options");o(this,"_reportActionTimeoutRef");o(this,"_reportActionPromise");o(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const t=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=t,r.onabort=t,r.send(JSON.stringify(e))})}}class L{constructor(){o(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class y{constructor(e){o(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class P{constructor(e){o(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const t of this._options.enrichers)t.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==exports.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new a;s.level=exports.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new a;s.level=exports.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new a;s.level=exports.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new a;s.level=exports.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new a;s.level=exports.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new a;s.level=exports.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,t,r){const n=new a;n.level=e,n.message=s,n.errorMessage=t==null?void 0:t.message,n.stackTrace=t==null?void 0:t.stack,n.extraParams=r,this.logMessage(n)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class w{constructor(){o(this,"name","");o(this,"reporter",null);o(this,"minimumLevel",exports.LogLevel.Warning);o(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return exports.LogLevel.Trace;case"DEBUG":return exports.LogLevel.Debug;case"INFORMATION":return exports.LogLevel.Information;case"WARNING":return exports.LogLevel.Warning;case"ERROR":return exports.LogLevel.Error;case"CRITICAL":return exports.LogLevel.Critical;case"NONE":return exports.LogLevel.None;default:return exports.LogLevel.None}}}class E{constructor(e,s=exports.LogLevel.Information){o(this,"_logger");o(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function M(i=1,e){return new Promise((s,t)=>{setTimeout(()=>{e?t(e):s()},i)})}exports.BroadcastChannelPlugin=_;exports.ConsoleReporter=d;exports.DynamicValuesEnricher=f;exports.InMemoryReporter=L;exports.LogMessage=a;exports.Logger=P;exports.LoggerOptions=w;exports.LoggerPlugin=E;exports.MultipleReporter=y;exports.PubSubHub=p;exports.ValuesEnricher=m;exports.XhrReporter=b;exports.XhrReporterOptions=v;exports.delay=M;
1
+ "use strict";var d=Object.defineProperty;var b=(o,e,s)=>e in o?d(o,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[e]=s;var i=(o,e,s)=>b(o,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=(o,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=o.timeouts.indexOf(e);o.timeouts.splice(s,1)};class v{constructor(e){i(this,"_subscriptions",new Map);i(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const t of this._options.plugins)t.init&&t.init(this)}publish(e,s){var n;const t={topic:e,message:s};if((n=this._options)!=null&&n.plugins)for(const c of this._options.plugins)c.onPublish&&c.onPublish(t);if(!t.topic)throw new Error("Invalid topic.");if(!t.message)throw new Error("Invalid message.");const r=this._subscriptions.get(t.topic);if(r)for(const c of r.values()){const l={};c.timeouts.push(l),l.ref=setTimeout((p,_,m,f)=>{p.handler(m,f),u(c,_)},0,c,l,structuredClone(t.topic),structuredClone(t.message))}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let t=this._subscriptions.get(e);t||(t=new Map,this._subscriptions.set(structuredClone(e),t));const r=`sub-${Date.now()}`;return t.set(r,{handler:s,timeouts:[]}),r}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const t of s.values())for(;;){const r=t.timeouts.pop();if(!r)break;u(t,r)}if(s.delete(e))return}}[Symbol.dispose](){var e;for(const s of this._subscriptions.values())for(const t of s.keys())this.unsubscribe(t);if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const t=s[Symbol.dispose];t&&t.call(s)}return Promise.resolve()}}class L{constructor(e){i(this,"_options");i(this,"_channel");i(this,"_eventListeners",null);i(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const t=s.data;if(!(!t.topic||!t.message))try{this._broadcastEnabled=!1,e.publish(t.topic,t.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class y{constructor(e,s){i(this,"_values");i(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const t in this._values)s.indexOf(t)!==-1&&!this._overrideExisting||(e.extraParams[t]=this._values[t])}}class P{constructor(e,s){i(this,"_valuesFn");i(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const t=Object.keys(e.extraParams);for(const r in s)t.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}exports.LogLevel=void 0;(function(o){o[o.Trace=0]="Trace",o[o.Debug=1]="Debug",o[o.Information=2]="Information",o[o.Warning=3]="Warning",o[o.Error=4]="Error",o[o.Critical=5]="Critical",o[o.None=6]="None"})(exports.LogLevel||(exports.LogLevel={}));class a{constructor(){i(this,"timestamp",new Date().getTime());i(this,"level",exports.LogLevel.None);i(this,"name","");i(this,"message","");i(this,"errorMessage");i(this,"stackTrace");i(this,"extraParams")}}class T{constructor(e){i(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case exports.LogLevel.Trace:s=this._console.trace||this._console.log;break;case exports.LogLevel.Debug:s=this._console.debug||this._console.log;break;case exports.LogLevel.Information:s=this._console.info||this._console.log;break;case exports.LogLevel.Warning:s=this._console.warn||this._console.log;break;case exports.LogLevel.Error:s=this._console.error||this._console.log;break;case exports.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class w{constructor(){i(this,"endpoint","");i(this,"verb","POST");i(this,"batchSize",20);i(this,"interval",2e3);i(this,"requestTransform")}}class E{constructor(e){i(this,"_messageQueue");i(this,"_options");i(this,"_reportActionTimeoutRef");i(this,"_reportActionPromise");i(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const t=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=t,r.onabort=t,r.send(JSON.stringify(e))})}}class M{constructor(){i(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class R{constructor(e){i(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class x{constructor(e){i(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const t of this._options.enrichers)t.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==exports.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new a;s.level=exports.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new a;s.level=exports.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new a;s.level=exports.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new a;s.level=exports.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new a;s.level=exports.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new a;s.level=exports.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,t,r){const n=new a;n.level=e,n.message=s,n.errorMessage=t==null?void 0:t.message,n.stackTrace=t==null?void 0:t.stack,n.extraParams=r,this.logMessage(n)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class k{constructor(){i(this,"name","");i(this,"reporter",null);i(this,"minimumLevel",exports.LogLevel.Warning);i(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return exports.LogLevel.Trace;case"DEBUG":return exports.LogLevel.Debug;case"INFORMATION":return exports.LogLevel.Information;case"WARNING":return exports.LogLevel.Warning;case"ERROR":return exports.LogLevel.Error;case"CRITICAL":return exports.LogLevel.Critical;case"NONE":return exports.LogLevel.None;default:return exports.LogLevel.None}}}class A{constructor(e,s=exports.LogLevel.Information){i(this,"_logger");i(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function h(o=1,e){return new Promise((s,t)=>{setTimeout(()=>{e?t(e):s()},o)})}function g(o=1){return o<=0?Promise.resolve():h(0).then(()=>g(o-1))}exports.BroadcastChannelPlugin=L;exports.ConsoleReporter=T;exports.DynamicValuesEnricher=P;exports.InMemoryReporter=M;exports.LogMessage=a;exports.Logger=x;exports.LoggerOptions=k;exports.LoggerPlugin=A;exports.MultipleReporter=R;exports.PubSubHub=v;exports.ValuesEnricher=y;exports.XhrReporter=E;exports.XhrReporterOptions=w;exports.delay=h;exports.nextTicks=g;
@@ -1 +1 @@
1
- var adaptArch_utilitiEs=function(t){"use strict";var M=Object.defineProperty;var T=(t,a,u)=>a in t?M(t,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[a]=u;var n=(t,a,u)=>(T(t,typeof a!="symbol"?a+"":a,u),u);class a{constructor(e){n(this,"_subscriptions",new Map);n(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const i of this._options.plugins)i.init&&i.init(this)}publish(e,s){var l;const i={topic:e,message:s};if((l=this._options)!=null&&l.plugins)for(const h of this._options.plugins)h.onPublish&&h.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const r=this._subscriptions.get(i.topic);if(r)for(const h of r.values()){const w=structuredClone(i.topic),E=structuredClone(i.message);setTimeout(()=>h(w,E),0)}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let i=this._subscriptions.get(e);i||(i=new Map,this._subscriptions.set(structuredClone(e),i));const r=`sub-${Date.now()}`;return i.set(r,s),r}unsubscribe(e){if(e){for(const s of this._subscriptions.values())if(s.delete(e))return}}[Symbol.dispose](){var e;if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const i=s[Symbol.dispose];i&&i.call(s)}return Promise.resolve()}}class u{constructor(e){n(this,"_options");n(this,"_channel");n(this,"_eventListeners",null);n(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const i=s.data;if(!(!i.topic||!i.message))try{this._broadcastEnabled=!1,e.publish(i.topic,i.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class g{constructor(e,s){n(this,"_values");n(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const i in this._values)s.indexOf(i)!==-1&&!this._overrideExisting||(e.extraParams[i]=this._values[i])}}class _{constructor(e,s){n(this,"_valuesFn");n(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const i=Object.keys(e.extraParams);for(const r in s)i.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}t.LogLevel=void 0,function(o){o[o.Trace=0]="Trace",o[o.Debug=1]="Debug",o[o.Information=2]="Information",o[o.Warning=3]="Warning",o[o.Error=4]="Error",o[o.Critical=5]="Critical",o[o.None=6]="None"}(t.LogLevel||(t.LogLevel={}));class c{constructor(){n(this,"timestamp",new Date().getTime());n(this,"level",t.LogLevel.None);n(this,"name","");n(this,"message","");n(this,"errorMessage");n(this,"stackTrace");n(this,"extraParams")}}class m{constructor(e){n(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case t.LogLevel.Trace:s=this._console.trace||this._console.log;break;case t.LogLevel.Debug:s=this._console.debug||this._console.log;break;case t.LogLevel.Information:s=this._console.info||this._console.log;break;case t.LogLevel.Warning:s=this._console.warn||this._console.log;break;case t.LogLevel.Error:s=this._console.error||this._console.log;break;case t.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class f{constructor(){n(this,"endpoint","");n(this,"verb","POST");n(this,"batchSize",20);n(this,"interval",2e3);n(this,"requestTransform")}}class p{constructor(e){n(this,"_messageQueue");n(this,"_options");n(this,"_reportActionTimeoutRef");n(this,"_reportActionPromise");n(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const i=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=i,r.onabort=i,r.send(JSON.stringify(e))})}}class d{constructor(){n(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class v{constructor(e){n(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class b{constructor(e){n(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const i of this._options.enrichers)i.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new c;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new c;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new c;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new c;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new c;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new c;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,r){const l=new c;l.level=e,l.message=s,l.errorMessage=i==null?void 0:i.message,l.stackTrace=i==null?void 0:i.stack,l.extraParams=r,this.logMessage(l)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class L{constructor(){n(this,"name","");n(this,"reporter",null);n(this,"minimumLevel",t.LogLevel.Warning);n(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return t.LogLevel.Trace;case"DEBUG":return t.LogLevel.Debug;case"INFORMATION":return t.LogLevel.Information;case"WARNING":return t.LogLevel.Warning;case"ERROR":return t.LogLevel.Error;case"CRITICAL":return t.LogLevel.Critical;case"NONE":return t.LogLevel.None;default:return t.LogLevel.None}}}class y{constructor(e,s=t.LogLevel.Information){n(this,"_logger");n(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function P(o=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},o)})}return t.BroadcastChannelPlugin=u,t.ConsoleReporter=m,t.DynamicValuesEnricher=_,t.InMemoryReporter=d,t.LogMessage=c,t.Logger=b,t.LoggerOptions=L,t.LoggerPlugin=y,t.MultipleReporter=v,t.PubSubHub=a,t.ValuesEnricher=g,t.XhrReporter=p,t.XhrReporterOptions=f,t.delay=P,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({});
1
+ var adaptArch_utilitiEs=function(t){"use strict";var C=Object.defineProperty;var S=(t,a,u)=>a in t?C(t,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[a]=u;var o=(t,a,u)=>S(t,typeof a!="symbol"?a+"":a,u);const a=(n,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=n.timeouts.indexOf(e);n.timeouts.splice(s,1)};class u{constructor(e){o(this,"_subscriptions",new Map);o(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const i of this._options.plugins)i.init&&i.init(this)}publish(e,s){var c;const i={topic:e,message:s};if((c=this._options)!=null&&c.plugins)for(const h of this._options.plugins)h.onPublish&&h.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const r=this._subscriptions.get(i.topic);if(r)for(const h of r.values()){const g={};h.timeouts.push(g),g.ref=setTimeout((M,R,k,A)=>{M.handler(k,A),a(h,R)},0,h,g,structuredClone(i.topic),structuredClone(i.message))}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let i=this._subscriptions.get(e);i||(i=new Map,this._subscriptions.set(structuredClone(e),i));const r=`sub-${Date.now()}`;return i.set(r,{handler:s,timeouts:[]}),r}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const i of s.values())for(;;){const r=i.timeouts.pop();if(!r)break;a(i,r)}if(s.delete(e))return}}[Symbol.dispose](){var e;for(const s of this._subscriptions.values())for(const i of s.keys())this.unsubscribe(i);if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const i=s[Symbol.dispose];i&&i.call(s)}return Promise.resolve()}}class f{constructor(e){o(this,"_options");o(this,"_channel");o(this,"_eventListeners",null);o(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const i=s.data;if(!(!i.topic||!i.message))try{this._broadcastEnabled=!1,e.publish(i.topic,i.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class p{constructor(e,s){o(this,"_values");o(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const i in this._values)s.indexOf(i)!==-1&&!this._overrideExisting||(e.extraParams[i]=this._values[i])}}class d{constructor(e,s){o(this,"_valuesFn");o(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const i=Object.keys(e.extraParams);for(const r in s)i.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}t.LogLevel=void 0,function(n){n[n.Trace=0]="Trace",n[n.Debug=1]="Debug",n[n.Information=2]="Information",n[n.Warning=3]="Warning",n[n.Error=4]="Error",n[n.Critical=5]="Critical",n[n.None=6]="None"}(t.LogLevel||(t.LogLevel={}));class l{constructor(){o(this,"timestamp",new Date().getTime());o(this,"level",t.LogLevel.None);o(this,"name","");o(this,"message","");o(this,"errorMessage");o(this,"stackTrace");o(this,"extraParams")}}class b{constructor(e){o(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case t.LogLevel.Trace:s=this._console.trace||this._console.log;break;case t.LogLevel.Debug:s=this._console.debug||this._console.log;break;case t.LogLevel.Information:s=this._console.info||this._console.log;break;case t.LogLevel.Warning:s=this._console.warn||this._console.log;break;case t.LogLevel.Error:s=this._console.error||this._console.log;break;case t.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class v{constructor(){o(this,"endpoint","");o(this,"verb","POST");o(this,"batchSize",20);o(this,"interval",2e3);o(this,"requestTransform")}}class L{constructor(e){o(this,"_messageQueue");o(this,"_options");o(this,"_reportActionTimeoutRef");o(this,"_reportActionPromise");o(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const i=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=i,r.onabort=i,r.send(JSON.stringify(e))})}}class y{constructor(){o(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class P{constructor(e){o(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class T{constructor(e){o(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const i of this._options.enrichers)i.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new l;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new l;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new l;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new l;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new l;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new l;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,r){const c=new l;c.level=e,c.message=s,c.errorMessage=i==null?void 0:i.message,c.stackTrace=i==null?void 0:i.stack,c.extraParams=r,this.logMessage(c)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class w{constructor(){o(this,"name","");o(this,"reporter",null);o(this,"minimumLevel",t.LogLevel.Warning);o(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return t.LogLevel.Trace;case"DEBUG":return t.LogLevel.Debug;case"INFORMATION":return t.LogLevel.Information;case"WARNING":return t.LogLevel.Warning;case"ERROR":return t.LogLevel.Error;case"CRITICAL":return t.LogLevel.Critical;case"NONE":return t.LogLevel.None;default:return t.LogLevel.None}}}class E{constructor(e,s=t.LogLevel.Information){o(this,"_logger");o(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function _(n=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},n)})}function m(n=1){return n<=0?Promise.resolve():_(0).then(()=>m(n-1))}return t.BroadcastChannelPlugin=f,t.ConsoleReporter=b,t.DynamicValuesEnricher=d,t.InMemoryReporter=y,t.LogMessage=l,t.Logger=T,t.LoggerOptions=w,t.LoggerPlugin=E,t.MultipleReporter=P,t.PubSubHub=u,t.ValuesEnricher=p,t.XhrReporter=L,t.XhrReporterOptions=v,t.delay=_,t.nextTicks=m,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({});
@@ -1,13 +1,18 @@
1
- var g = Object.defineProperty;
2
- var p = (r, s, e) => s in r ? g(r, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[s] = e;
3
- var i = (r, s, e) => (p(r, typeof s != "symbol" ? s + "" : s, e), e);
4
- class m {
1
+ var f = Object.defineProperty;
2
+ var d = (i, s, e) => s in i ? f(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
3
+ var r = (i, s, e) => d(i, typeof s != "symbol" ? s + "" : s, e);
4
+ const h = (i, s) => {
5
+ clearTimeout(s.ref), s.ref = void 0;
6
+ const e = i.timeouts.indexOf(s);
7
+ i.timeouts.splice(e, 1);
8
+ };
9
+ class y {
5
10
  /**
6
11
  *
7
12
  */
8
13
  constructor(s) {
9
- i(this, "_subscriptions", /* @__PURE__ */ new Map());
10
- i(this, "_options");
14
+ r(this, "_subscriptions", /* @__PURE__ */ new Map());
15
+ r(this, "_options");
11
16
  var e;
12
17
  if (this._options = s, (e = this._options) != null && e.plugins)
13
18
  for (const t of this._options.plugins)
@@ -30,8 +35,10 @@ class m {
30
35
  const n = this._subscriptions.get(t.topic);
31
36
  if (n)
32
37
  for (const l of n.values()) {
33
- const h = structuredClone(t.topic), u = structuredClone(t.message);
34
- setTimeout(() => l(h, u), 0);
38
+ const u = {};
39
+ l.timeouts.push(u), u.ref = setTimeout((p, _, g, m) => {
40
+ p.handler(g, m), h(l, _);
41
+ }, 0, l, u, structuredClone(t.topic), structuredClone(t.message));
35
42
  }
36
43
  }
37
44
  /** @inheritdoc */
@@ -43,18 +50,28 @@ class m {
43
50
  let t = this._subscriptions.get(s);
44
51
  t || (t = /* @__PURE__ */ new Map(), this._subscriptions.set(structuredClone(s), t));
45
52
  const n = `sub-${Date.now()}`;
46
- return t.set(n, e), n;
53
+ return t.set(n, { handler: e, timeouts: [] }), n;
47
54
  }
48
55
  /** @inheritdoc */
49
56
  unsubscribe(s) {
50
- if (s) {
51
- for (const e of this._subscriptions.values())
57
+ if (s)
58
+ for (const e of this._subscriptions.values()) {
59
+ for (const t of e.values())
60
+ for (; ; ) {
61
+ const n = t.timeouts.pop();
62
+ if (!n)
63
+ break;
64
+ h(t, n);
65
+ }
52
66
  if (e.delete(s))
53
67
  return;
54
- }
68
+ }
55
69
  }
56
70
  [Symbol.dispose]() {
57
71
  var s;
72
+ for (const e of this._subscriptions.values())
73
+ for (const t of e.keys())
74
+ this.unsubscribe(t);
58
75
  if (this._subscriptions.clear(), (s = this._options) != null && s.plugins)
59
76
  for (const e of this._options.plugins) {
60
77
  const t = e[Symbol.dispose];
@@ -63,17 +80,17 @@ class m {
63
80
  return Promise.resolve();
64
81
  }
65
82
  }
66
- class f {
83
+ class P {
67
84
  /**
68
85
  * Constructor.
69
86
  *
70
87
  * @param {Options} options The options.
71
88
  */
72
89
  constructor(s) {
73
- i(this, "_options");
74
- i(this, "_channel");
75
- i(this, "_eventListeners", null);
76
- i(this, "_broadcastEnabled", !0);
90
+ r(this, "_options");
91
+ r(this, "_channel");
92
+ r(this, "_eventListeners", null);
93
+ r(this, "_broadcastEnabled", !0);
77
94
  this._options = s, this._channel = new BroadcastChannel(this._options.channelName);
78
95
  }
79
96
  /** @inheritdoc */
@@ -102,7 +119,7 @@ class f {
102
119
  this._eventListeners && this._channel.removeEventListener("message", this._eventListeners), this._channel.close();
103
120
  }
104
121
  }
105
- class d {
122
+ class T {
106
123
  /**
107
124
  * Constructor.
108
125
  *
@@ -110,8 +127,8 @@ class d {
110
127
  * @param {boolean} overrideExisting Override a value if it already exists.
111
128
  */
112
129
  constructor(s, e) {
113
- i(this, "_values");
114
- i(this, "_overrideExisting");
130
+ r(this, "_values");
131
+ r(this, "_overrideExisting");
115
132
  this._values = s, this._overrideExisting = e;
116
133
  }
117
134
  /**
@@ -126,7 +143,7 @@ class d {
126
143
  e.indexOf(t) !== -1 && !this._overrideExisting || (s.extraParams[t] = this._values[t]);
127
144
  }
128
145
  }
129
- class b {
146
+ class E {
130
147
  /**
131
148
  * Constructor.
132
149
  *
@@ -134,8 +151,8 @@ class b {
134
151
  * @param {boolean} overrideExisting Override a value if it already exists.
135
152
  */
136
153
  constructor(s, e) {
137
- i(this, "_valuesFn");
138
- i(this, "_overrideExisting");
154
+ r(this, "_valuesFn");
155
+ r(this, "_overrideExisting");
139
156
  this._valuesFn = s, this._overrideExisting = e;
140
157
  }
141
158
  /**
@@ -152,49 +169,49 @@ class b {
152
169
  }
153
170
  }
154
171
  var o;
155
- (function(r) {
156
- r[r.Trace = 0] = "Trace", r[r.Debug = 1] = "Debug", r[r.Information = 2] = "Information", r[r.Warning = 3] = "Warning", r[r.Error = 4] = "Error", r[r.Critical = 5] = "Critical", r[r.None = 6] = "None";
172
+ (function(i) {
173
+ i[i.Trace = 0] = "Trace", i[i.Debug = 1] = "Debug", i[i.Information = 2] = "Information", i[i.Warning = 3] = "Warning", i[i.Error = 4] = "Error", i[i.Critical = 5] = "Critical", i[i.None = 6] = "None";
157
174
  })(o || (o = {}));
158
175
  class c {
159
176
  constructor() {
160
177
  /**
161
178
  * The timestamp of the log message.
162
179
  */
163
- i(this, "timestamp", (/* @__PURE__ */ new Date()).getTime());
180
+ r(this, "timestamp", (/* @__PURE__ */ new Date()).getTime());
164
181
  /**
165
182
  * The level of the log message.
166
183
  */
167
- i(this, "level", o.None);
184
+ r(this, "level", o.None);
168
185
  /**
169
186
  * The name of the logger.
170
187
  */
171
- i(this, "name", "");
188
+ r(this, "name", "");
172
189
  /**
173
190
  * The message to log.
174
191
  */
175
- i(this, "message", "");
192
+ r(this, "message", "");
176
193
  /**
177
194
  * The error message.
178
195
  */
179
- i(this, "errorMessage");
196
+ r(this, "errorMessage");
180
197
  /**
181
198
  * The stack trace of the error.
182
199
  */
183
- i(this, "stackTrace");
200
+ r(this, "stackTrace");
184
201
  /**
185
202
  * Any extra parameters to log.
186
203
  */
187
- i(this, "extraParams");
204
+ r(this, "extraParams");
188
205
  }
189
206
  }
190
- class v {
207
+ class M {
191
208
  /**
192
209
  * Constructor.
193
210
  *
194
211
  * @param {Console} console The current console reference.
195
212
  */
196
213
  constructor(s) {
197
- i(this, "_console");
214
+ r(this, "_console");
198
215
  this._console = s;
199
216
  }
200
217
  /**
@@ -235,37 +252,37 @@ class v {
235
252
  return Promise.resolve();
236
253
  }
237
254
  }
238
- class w {
255
+ class x {
239
256
  constructor() {
240
257
  /**
241
258
  * Endpoint that receives the logs.
242
259
  */
243
- i(this, "endpoint", "");
260
+ r(this, "endpoint", "");
244
261
  /**
245
262
  * HTTP verb used when calling the endpoint.
246
263
  */
247
- i(this, "verb", "POST");
264
+ r(this, "verb", "POST");
248
265
  /**
249
266
  * The number of items to send in a batch.
250
267
  */
251
- i(this, "batchSize", 20);
268
+ r(this, "batchSize", 20);
252
269
  /**
253
270
  * The maximum interval, in milliseconds, to wait for the batch size to be achieved before reporting.
254
271
  */
255
- i(this, "interval", 2e3);
272
+ r(this, "interval", 2e3);
256
273
  /**
257
274
  * A function that can be used to transform the request before sending it.
258
275
  */
259
- i(this, "requestTransform");
276
+ r(this, "requestTransform");
260
277
  }
261
278
  }
262
- class y {
279
+ class R {
263
280
  constructor(s) {
264
- i(this, "_messageQueue");
265
- i(this, "_options");
266
- i(this, "_reportActionTimeoutRef");
267
- i(this, "_reportActionPromise");
268
- i(this, "_disposed");
281
+ r(this, "_messageQueue");
282
+ r(this, "_options");
283
+ r(this, "_reportActionTimeoutRef");
284
+ r(this, "_reportActionPromise");
285
+ r(this, "_disposed");
269
286
  if (!s)
270
287
  throw new Error('Argument "options" is required');
271
288
  this._messageQueue = [], this._options = s, this._reportActionTimeoutRef = void 0, this._reportActionPromise = null, this._disposed = !1;
@@ -314,9 +331,9 @@ class y {
314
331
  });
315
332
  }
316
333
  }
317
- class P {
334
+ class k {
318
335
  constructor() {
319
- i(this, "_messages", []);
336
+ r(this, "_messages", []);
320
337
  }
321
338
  get messages() {
322
339
  return this._messages.slice();
@@ -334,9 +351,9 @@ class P {
334
351
  return Promise.resolve();
335
352
  }
336
353
  }
337
- class E {
354
+ class A {
338
355
  constructor(s) {
339
- i(this, "_reporters");
356
+ r(this, "_reporters");
340
357
  this._reporters = s || [];
341
358
  }
342
359
  /**
@@ -356,14 +373,14 @@ class E {
356
373
  s.length && await Promise.all(s);
357
374
  }
358
375
  }
359
- class T {
376
+ class C {
360
377
  /**
361
378
  * Constructor.
362
379
  *
363
380
  * @param {LoggerOptions} options The logger options.
364
381
  */
365
382
  constructor(s) {
366
- i(this, "_options");
383
+ r(this, "_options");
367
384
  this._options = s;
368
385
  }
369
386
  /**
@@ -470,24 +487,24 @@ class T {
470
487
  }, 1);
471
488
  }
472
489
  }
473
- class M {
490
+ class I {
474
491
  constructor() {
475
492
  /**
476
493
  * The name of the logger.
477
494
  */
478
- i(this, "name", "");
495
+ r(this, "name", "");
479
496
  /**
480
497
  * The reporter for the messages.
481
498
  */
482
- i(this, "reporter", null);
499
+ r(this, "reporter", null);
483
500
  /**
484
501
  * The minimum log level.
485
502
  */
486
- i(this, "minimumLevel", o.Warning);
503
+ r(this, "minimumLevel", o.Warning);
487
504
  /**
488
505
  * Log enrichers.
489
506
  */
490
- i(this, "enrichers", []);
507
+ r(this, "enrichers", []);
491
508
  }
492
509
  /**
493
510
  * Get the LogLevel from a string value.
@@ -515,7 +532,7 @@ class M {
515
532
  }
516
533
  }
517
534
  }
518
- class R {
535
+ class N {
519
536
  /**
520
537
  * Constructor.
521
538
  *
@@ -523,8 +540,8 @@ class R {
523
540
  * @param {LogLevel} logLevel The log level.
524
541
  */
525
542
  constructor(s, e = o.Information) {
526
- i(this, "_logger");
527
- i(this, "_logLevel");
543
+ r(this, "_logger");
544
+ r(this, "_logLevel");
528
545
  this._logger = s, this._logLevel = e;
529
546
  }
530
547
  /** @inheritdoc */
@@ -535,27 +552,31 @@ class R {
535
552
  });
536
553
  }
537
554
  }
538
- function x(r = 1, s) {
555
+ function b(i = 1, s) {
539
556
  return new Promise((e, t) => {
540
557
  setTimeout(() => {
541
558
  s ? t(s) : e();
542
- }, r);
559
+ }, i);
543
560
  });
544
561
  }
562
+ function v(i = 1) {
563
+ return i <= 0 ? Promise.resolve() : b(0).then(() => v(i - 1));
564
+ }
545
565
  export {
546
- f as BroadcastChannelPlugin,
547
- v as ConsoleReporter,
548
- b as DynamicValuesEnricher,
549
- P as InMemoryReporter,
566
+ P as BroadcastChannelPlugin,
567
+ M as ConsoleReporter,
568
+ E as DynamicValuesEnricher,
569
+ k as InMemoryReporter,
550
570
  o as LogLevel,
551
571
  c as LogMessage,
552
- T as Logger,
553
- M as LoggerOptions,
554
- R as LoggerPlugin,
555
- E as MultipleReporter,
556
- m as PubSubHub,
557
- d as ValuesEnricher,
558
- y as XhrReporter,
559
- w as XhrReporterOptions,
560
- x as delay
572
+ C as Logger,
573
+ I as LoggerOptions,
574
+ N as LoggerPlugin,
575
+ A as MultipleReporter,
576
+ y as PubSubHub,
577
+ T as ValuesEnricher,
578
+ R as XhrReporter,
579
+ x as XhrReporterOptions,
580
+ b as delay,
581
+ v as nextTicks
561
582
  };
@@ -1 +1 @@
1
- (function(t,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(t=typeof globalThis<"u"?globalThis:t||self,a(t.adaptArch_utilitiEs={}))})(this,function(t){"use strict";var T=Object.defineProperty;var M=(t,a,u)=>a in t?T(t,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[a]=u;var n=(t,a,u)=>(M(t,typeof a!="symbol"?a+"":a,u),u);class a{constructor(e){n(this,"_subscriptions",new Map);n(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const i of this._options.plugins)i.init&&i.init(this)}publish(e,s){var l;const i={topic:e,message:s};if((l=this._options)!=null&&l.plugins)for(const h of this._options.plugins)h.onPublish&&h.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const r=this._subscriptions.get(i.topic);if(r)for(const h of r.values()){const w=structuredClone(i.topic),E=structuredClone(i.message);setTimeout(()=>h(w,E),0)}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let i=this._subscriptions.get(e);i||(i=new Map,this._subscriptions.set(structuredClone(e),i));const r=`sub-${Date.now()}`;return i.set(r,s),r}unsubscribe(e){if(e){for(const s of this._subscriptions.values())if(s.delete(e))return}}[Symbol.dispose](){var e;if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const i=s[Symbol.dispose];i&&i.call(s)}return Promise.resolve()}}class u{constructor(e){n(this,"_options");n(this,"_channel");n(this,"_eventListeners",null);n(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const i=s.data;if(!(!i.topic||!i.message))try{this._broadcastEnabled=!1,e.publish(i.topic,i.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class g{constructor(e,s){n(this,"_values");n(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const i in this._values)s.indexOf(i)!==-1&&!this._overrideExisting||(e.extraParams[i]=this._values[i])}}class _{constructor(e,s){n(this,"_valuesFn");n(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const i=Object.keys(e.extraParams);for(const r in s)i.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}t.LogLevel=void 0,function(o){o[o.Trace=0]="Trace",o[o.Debug=1]="Debug",o[o.Information=2]="Information",o[o.Warning=3]="Warning",o[o.Error=4]="Error",o[o.Critical=5]="Critical",o[o.None=6]="None"}(t.LogLevel||(t.LogLevel={}));class c{constructor(){n(this,"timestamp",new Date().getTime());n(this,"level",t.LogLevel.None);n(this,"name","");n(this,"message","");n(this,"errorMessage");n(this,"stackTrace");n(this,"extraParams")}}class m{constructor(e){n(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case t.LogLevel.Trace:s=this._console.trace||this._console.log;break;case t.LogLevel.Debug:s=this._console.debug||this._console.log;break;case t.LogLevel.Information:s=this._console.info||this._console.log;break;case t.LogLevel.Warning:s=this._console.warn||this._console.log;break;case t.LogLevel.Error:s=this._console.error||this._console.log;break;case t.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class f{constructor(){n(this,"endpoint","");n(this,"verb","POST");n(this,"batchSize",20);n(this,"interval",2e3);n(this,"requestTransform")}}class p{constructor(e){n(this,"_messageQueue");n(this,"_options");n(this,"_reportActionTimeoutRef");n(this,"_reportActionPromise");n(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const i=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=i,r.onabort=i,r.send(JSON.stringify(e))})}}class d{constructor(){n(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class v{constructor(e){n(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class b{constructor(e){n(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const i of this._options.enrichers)i.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new c;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new c;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new c;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new c;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new c;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new c;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,r){const l=new c;l.level=e,l.message=s,l.errorMessage=i==null?void 0:i.message,l.stackTrace=i==null?void 0:i.stack,l.extraParams=r,this.logMessage(l)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class L{constructor(){n(this,"name","");n(this,"reporter",null);n(this,"minimumLevel",t.LogLevel.Warning);n(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return t.LogLevel.Trace;case"DEBUG":return t.LogLevel.Debug;case"INFORMATION":return t.LogLevel.Information;case"WARNING":return t.LogLevel.Warning;case"ERROR":return t.LogLevel.Error;case"CRITICAL":return t.LogLevel.Critical;case"NONE":return t.LogLevel.None;default:return t.LogLevel.None}}}class y{constructor(e,s=t.LogLevel.Information){n(this,"_logger");n(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function P(o=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},o)})}t.BroadcastChannelPlugin=u,t.ConsoleReporter=m,t.DynamicValuesEnricher=_,t.InMemoryReporter=d,t.LogMessage=c,t.Logger=b,t.LoggerOptions=L,t.LoggerPlugin=y,t.MultipleReporter=v,t.PubSubHub=a,t.ValuesEnricher=g,t.XhrReporter=p,t.XhrReporterOptions=f,t.delay=P,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
1
+ (function(t,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(t=typeof globalThis<"u"?globalThis:t||self,a(t.adaptArch_utilitiEs={}))})(this,function(t){"use strict";var C=Object.defineProperty;var S=(t,a,u)=>a in t?C(t,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[a]=u;var o=(t,a,u)=>S(t,typeof a!="symbol"?a+"":a,u);const a=(n,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=n.timeouts.indexOf(e);n.timeouts.splice(s,1)};class u{constructor(e){o(this,"_subscriptions",new Map);o(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const i of this._options.plugins)i.init&&i.init(this)}publish(e,s){var c;const i={topic:e,message:s};if((c=this._options)!=null&&c.plugins)for(const h of this._options.plugins)h.onPublish&&h.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const r=this._subscriptions.get(i.topic);if(r)for(const h of r.values()){const g={};h.timeouts.push(g),g.ref=setTimeout((M,R,k,A)=>{M.handler(k,A),a(h,R)},0,h,g,structuredClone(i.topic),structuredClone(i.message))}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let i=this._subscriptions.get(e);i||(i=new Map,this._subscriptions.set(structuredClone(e),i));const r=`sub-${Date.now()}`;return i.set(r,{handler:s,timeouts:[]}),r}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const i of s.values())for(;;){const r=i.timeouts.pop();if(!r)break;a(i,r)}if(s.delete(e))return}}[Symbol.dispose](){var e;for(const s of this._subscriptions.values())for(const i of s.keys())this.unsubscribe(i);if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const i=s[Symbol.dispose];i&&i.call(s)}return Promise.resolve()}}class f{constructor(e){o(this,"_options");o(this,"_channel");o(this,"_eventListeners",null);o(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const i=s.data;if(!(!i.topic||!i.message))try{this._broadcastEnabled=!1,e.publish(i.topic,i.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class p{constructor(e,s){o(this,"_values");o(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const i in this._values)s.indexOf(i)!==-1&&!this._overrideExisting||(e.extraParams[i]=this._values[i])}}class d{constructor(e,s){o(this,"_valuesFn");o(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const i=Object.keys(e.extraParams);for(const r in s)i.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}t.LogLevel=void 0,function(n){n[n.Trace=0]="Trace",n[n.Debug=1]="Debug",n[n.Information=2]="Information",n[n.Warning=3]="Warning",n[n.Error=4]="Error",n[n.Critical=5]="Critical",n[n.None=6]="None"}(t.LogLevel||(t.LogLevel={}));class l{constructor(){o(this,"timestamp",new Date().getTime());o(this,"level",t.LogLevel.None);o(this,"name","");o(this,"message","");o(this,"errorMessage");o(this,"stackTrace");o(this,"extraParams")}}class b{constructor(e){o(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case t.LogLevel.Trace:s=this._console.trace||this._console.log;break;case t.LogLevel.Debug:s=this._console.debug||this._console.log;break;case t.LogLevel.Information:s=this._console.info||this._console.log;break;case t.LogLevel.Warning:s=this._console.warn||this._console.log;break;case t.LogLevel.Error:s=this._console.error||this._console.log;break;case t.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class v{constructor(){o(this,"endpoint","");o(this,"verb","POST");o(this,"batchSize",20);o(this,"interval",2e3);o(this,"requestTransform")}}class L{constructor(e){o(this,"_messageQueue");o(this,"_options");o(this,"_reportActionTimeoutRef");o(this,"_reportActionPromise");o(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const i=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=i,r.onabort=i,r.send(JSON.stringify(e))})}}class y{constructor(){o(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class P{constructor(e){o(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class T{constructor(e){o(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const i of this._options.enrichers)i.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new l;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new l;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new l;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new l;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new l;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new l;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,r){const c=new l;c.level=e,c.message=s,c.errorMessage=i==null?void 0:i.message,c.stackTrace=i==null?void 0:i.stack,c.extraParams=r,this.logMessage(c)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class w{constructor(){o(this,"name","");o(this,"reporter",null);o(this,"minimumLevel",t.LogLevel.Warning);o(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return t.LogLevel.Trace;case"DEBUG":return t.LogLevel.Debug;case"INFORMATION":return t.LogLevel.Information;case"WARNING":return t.LogLevel.Warning;case"ERROR":return t.LogLevel.Error;case"CRITICAL":return t.LogLevel.Critical;case"NONE":return t.LogLevel.None;default:return t.LogLevel.None}}}class E{constructor(e,s=t.LogLevel.Information){o(this,"_logger");o(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function _(n=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},n)})}function m(n=1){return n<=0?Promise.resolve():_(0).then(()=>m(n-1))}t.BroadcastChannelPlugin=f,t.ConsoleReporter=b,t.DynamicValuesEnricher=d,t.InMemoryReporter=y,t.LogMessage=l,t.Logger=T,t.LoggerOptions=w,t.LoggerPlugin=E,t.MultipleReporter=P,t.PubSubHub=u,t.ValuesEnricher=p,t.XhrReporter=L,t.XhrReporterOptions=v,t.delay=_,t.nextTicks=m,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
@@ -4,8 +4,8 @@ import type { ExtraParams, ILogMessageEnricher, LogMessage } from "../contracts"
4
4
  */
5
5
  export type DynamicValuesFunction = () => ExtraParams;
6
6
  export declare class DynamicValuesEnricher implements ILogMessageEnricher {
7
- private _valuesFn;
8
- private _overrideExisting;
7
+ private readonly _valuesFn;
8
+ private readonly _overrideExisting;
9
9
  /**
10
10
  * Constructor.
11
11
  *
@@ -1,7 +1,7 @@
1
1
  import type { ExtraParams, ILogMessageEnricher, LogMessage } from "../contracts";
2
2
  export declare class ValuesEnricher implements ILogMessageEnricher {
3
- private _values;
4
- private _overrideExisting;
3
+ private readonly _values;
4
+ private readonly _overrideExisting;
5
5
  /**
6
6
  * Constructor.
7
7
  *
@@ -4,7 +4,7 @@ import type { LoggerOptions } from "./loggerOptions";
4
4
  * Logging service.
5
5
  */
6
6
  export declare class Logger implements AsyncDisposable {
7
- private _options;
7
+ private readonly _options;
8
8
  /**
9
9
  * Constructor.
10
10
  *
@@ -16,7 +16,7 @@ export interface IReporterConsole {
16
16
  * Depending on the browser settings some messages might noy be output to the console.
17
17
  */
18
18
  export declare class ConsoleReporter implements ILogsReporter {
19
- private _console;
19
+ private readonly _console;
20
20
  /**
21
21
  * Constructor.
22
22
  *
@@ -4,7 +4,7 @@ import type { ILogsReporter, LogMessage } from "../contracts";
4
4
  * DO NOT user this in production. This is meant for unit tests.
5
5
  */
6
6
  export declare class InMemoryReporter implements ILogsReporter {
7
- private _messages;
7
+ private readonly _messages;
8
8
  get messages(): LogMessage[];
9
9
  /**
10
10
  * @inheritdoc
@@ -3,7 +3,7 @@ import type { ILogsReporter, LogMessage } from "../contracts";
3
3
  * An implementations that can report to multiple implementations of `ILogsReporter`.
4
4
  */
5
5
  export declare class MultipleReporter implements ILogsReporter {
6
- private _reporters;
6
+ private readonly _reporters;
7
7
  constructor(reporters: ILogsReporter[]);
8
8
  /**
9
9
  * @inheritdoc
@@ -25,8 +25,8 @@ export declare class XhrReporterOptions {
25
25
  requestTransform?: (request: XMLHttpRequest) => void;
26
26
  }
27
27
  export declare class XhrReporter implements ILogsReporter {
28
- private _messageQueue;
29
- private _options;
28
+ private readonly _messageQueue;
29
+ private readonly _options;
30
30
  private _reportActionTimeoutRef;
31
31
  private _reportActionPromise;
32
32
  private _disposed;
@@ -11,8 +11,8 @@ export type Options = {
11
11
  * A plugin to log messages.
12
12
  */
13
13
  export declare class BroadcastChannelPlugin implements PubSubPlugin {
14
- private _options;
15
- private _channel;
14
+ private readonly _options;
15
+ private readonly _channel;
16
16
  private _eventListeners;
17
17
  private _broadcastEnabled;
18
18
  /**
@@ -4,8 +4,8 @@ import type { PubSubPlugin, PubSubPluginContext } from "../pubsub";
4
4
  * A plugin to log messages.
5
5
  */
6
6
  export declare class LoggerPlugin implements PubSubPlugin {
7
- private _logger;
8
- private _logLevel;
7
+ private readonly _logger;
8
+ private readonly _logLevel;
9
9
  /**
10
10
  * Constructor.
11
11
  *
@@ -42,7 +42,7 @@ export type PubSubHubOptions = {
42
42
  * A PubSub implementation.
43
43
  */
44
44
  export declare class PubSubHub implements IPubSubHub {
45
- private _subscriptions;
45
+ private readonly _subscriptions;
46
46
  private readonly _options;
47
47
  /**
48
48
  *
@@ -1,3 +1,9 @@
1
+ const clearTimeoutRef = (tracker, timeout) => {
2
+ clearTimeout(timeout.ref);
3
+ timeout.ref = undefined;
4
+ const ix = tracker.timeouts.indexOf(timeout);
5
+ tracker.timeouts.splice(ix, 1);
6
+ };
1
7
  /**
2
8
  * A PubSub implementation.
3
9
  */
@@ -38,12 +44,15 @@ export class PubSubHub {
38
44
  if (!context.message) {
39
45
  throw new Error("Invalid message.");
40
46
  }
41
- const handlers = this._subscriptions.get(context.topic);
42
- if (handlers) {
43
- for (const handler of handlers.values()) {
44
- const newTopic = structuredClone(context.topic);
45
- const newMessage = structuredClone(context.message);
46
- setTimeout(() => handler(newTopic, newMessage), 0);
47
+ const subTrackers = this._subscriptions.get(context.topic);
48
+ if (subTrackers) {
49
+ for (const tracker of subTrackers.values()) {
50
+ const timeout = {};
51
+ tracker.timeouts.push(timeout);
52
+ timeout.ref = setTimeout((ctx, timeout, topic, message) => {
53
+ ctx.handler(topic, message);
54
+ clearTimeoutRef(tracker, timeout);
55
+ }, 0, tracker, timeout, structuredClone(context.topic), structuredClone(context.message));
47
56
  }
48
57
  }
49
58
  }
@@ -55,13 +64,13 @@ export class PubSubHub {
55
64
  if (!handler) {
56
65
  throw new Error("Invalid handler.");
57
66
  }
58
- let handlers = this._subscriptions.get(topic);
59
- if (!handlers) {
60
- handlers = new Map();
61
- this._subscriptions.set(structuredClone(topic), handlers);
67
+ let subTrackers = this._subscriptions.get(topic);
68
+ if (!subTrackers) {
69
+ subTrackers = new Map();
70
+ this._subscriptions.set(structuredClone(topic), subTrackers);
62
71
  }
63
72
  const subscriptionId = `sub-${Date.now()}`;
64
- handlers.set(subscriptionId, handler);
73
+ subTrackers.set(subscriptionId, { handler: handler, timeouts: [] });
65
74
  return subscriptionId;
66
75
  }
67
76
  /** @inheritdoc */
@@ -69,13 +78,27 @@ export class PubSubHub {
69
78
  if (!subscriptionId) {
70
79
  return;
71
80
  }
72
- for (const handlers of this._subscriptions.values()) {
73
- if (handlers.delete(subscriptionId)) {
81
+ for (const subTrackers of this._subscriptions.values()) {
82
+ for (const tracker of subTrackers.values()) {
83
+ while (true) {
84
+ const timeout = tracker.timeouts.pop();
85
+ if (!timeout) {
86
+ break;
87
+ }
88
+ clearTimeoutRef(tracker, timeout);
89
+ }
90
+ }
91
+ if (subTrackers.delete(subscriptionId)) {
74
92
  return;
75
93
  }
76
94
  }
77
95
  }
78
96
  [Symbol.dispose]() {
97
+ for (const subTrackers of this._subscriptions.values()) {
98
+ for (const trackerId of subTrackers.keys()) {
99
+ this.unsubscribe(trackerId);
100
+ }
101
+ }
79
102
  this._subscriptions.clear();
80
103
  if (this._options?.plugins) {
81
104
  for (const plugin of this._options.plugins) {
@@ -6,3 +6,10 @@
6
6
  * @returns {Promise<void>} A promise that resolves after a certain duration.
7
7
  */
8
8
  export declare function delay(duration?: number, error?: Error): Promise<void>;
9
+ /**
10
+ * Await the next {count} ticks.
11
+ *
12
+ * @param {number} count The number of ticks to wait for.
13
+ * @returns {Promise<void>} A promise that resolves after a certain number of ticks.
14
+ */
15
+ export declare function nextTicks(count?: number): Promise<void>;
@@ -12,3 +12,15 @@ export function delay(duration = 1, error) {
12
12
  }, duration);
13
13
  });
14
14
  }
15
+ /**
16
+ * Await the next {count} ticks.
17
+ *
18
+ * @param {number} count The number of ticks to wait for.
19
+ * @returns {Promise<void>} A promise that resolves after a certain number of ticks.
20
+ */
21
+ export function nextTicks(count = 1) {
22
+ if (count <= 0) {
23
+ return Promise.resolve();
24
+ }
25
+ return delay(0).then(() => nextTicks(count - 1));
26
+ }
@@ -1 +1 @@
1
- export { delay } from "./delay";
1
+ export * from "./delay";
@@ -1 +1 @@
1
- export { delay } from "./delay";
1
+ export * from "./delay";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adapt-arch/utiliti-es",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "MIT",
5
5
  "description": "ECMAScript common utilities library",
6
6
  "keywords": [
@@ -57,16 +57,16 @@
57
57
  "docs:preview": "vitepress preview docs"
58
58
  },
59
59
  "devDependencies": {
60
- "@biomejs/biome": "1.7.3",
61
- "@types/node": "20.14.0",
62
- "@vitest/coverage-v8": "1.6.0",
63
- "jsdom": "24.1.0",
64
- "msw": "2.3.1",
65
- "typedoc": "0.25.13",
66
- "typescript": "5.4.5",
67
- "vite": "5.2.12",
68
- "vitepress": "1.2.2",
69
- "vitest": "1.6.0"
60
+ "@biomejs/biome": "1.9.4",
61
+ "@types/node": "22.7.7",
62
+ "@vitest/coverage-v8": "2.1.3",
63
+ "jsdom": "25.0.1",
64
+ "msw": "2.4.12",
65
+ "typedoc": "0.26.10",
66
+ "typescript": "5.6.3",
67
+ "vite": "5.4.9",
68
+ "vitepress": "1.4.1",
69
+ "vitest": "2.1.3"
70
70
  },
71
71
  "msw": {
72
72
  "workerDirectory": [