@adapt-arch/utiliti-es 0.2.0 → 0.3.2

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
  /**
@@ -222,6 +239,7 @@ class v {
222
239
  case o.Critical:
223
240
  e = this._console.error || this._console.log;
224
241
  break;
242
+ // case LogLevel.None: // Do not log.
225
243
  default:
226
244
  e = null;
227
245
  break;
@@ -235,37 +253,37 @@ class v {
235
253
  return Promise.resolve();
236
254
  }
237
255
  }
238
- class w {
256
+ class x {
239
257
  constructor() {
240
258
  /**
241
259
  * Endpoint that receives the logs.
242
260
  */
243
- i(this, "endpoint", "");
261
+ r(this, "endpoint", "");
244
262
  /**
245
263
  * HTTP verb used when calling the endpoint.
246
264
  */
247
- i(this, "verb", "POST");
265
+ r(this, "verb", "POST");
248
266
  /**
249
267
  * The number of items to send in a batch.
250
268
  */
251
- i(this, "batchSize", 20);
269
+ r(this, "batchSize", 20);
252
270
  /**
253
271
  * The maximum interval, in milliseconds, to wait for the batch size to be achieved before reporting.
254
272
  */
255
- i(this, "interval", 2e3);
273
+ r(this, "interval", 2e3);
256
274
  /**
257
275
  * A function that can be used to transform the request before sending it.
258
276
  */
259
- i(this, "requestTransform");
277
+ r(this, "requestTransform");
260
278
  }
261
279
  }
262
- class y {
280
+ class R {
263
281
  constructor(s) {
264
- i(this, "_messageQueue");
265
- i(this, "_options");
266
- i(this, "_reportActionTimeoutRef");
267
- i(this, "_reportActionPromise");
268
- i(this, "_disposed");
282
+ r(this, "_messageQueue");
283
+ r(this, "_options");
284
+ r(this, "_reportActionTimeoutRef");
285
+ r(this, "_reportActionPromise");
286
+ r(this, "_disposed");
269
287
  if (!s)
270
288
  throw new Error('Argument "options" is required');
271
289
  this._messageQueue = [], this._options = s, this._reportActionTimeoutRef = void 0, this._reportActionPromise = null, this._disposed = !1;
@@ -314,9 +332,9 @@ class y {
314
332
  });
315
333
  }
316
334
  }
317
- class P {
335
+ class k {
318
336
  constructor() {
319
- i(this, "_messages", []);
337
+ r(this, "_messages", []);
320
338
  }
321
339
  get messages() {
322
340
  return this._messages.slice();
@@ -334,9 +352,9 @@ class P {
334
352
  return Promise.resolve();
335
353
  }
336
354
  }
337
- class E {
355
+ class A {
338
356
  constructor(s) {
339
- i(this, "_reporters");
357
+ r(this, "_reporters");
340
358
  this._reporters = s || [];
341
359
  }
342
360
  /**
@@ -356,14 +374,14 @@ class E {
356
374
  s.length && await Promise.all(s);
357
375
  }
358
376
  }
359
- class T {
377
+ class C {
360
378
  /**
361
379
  * Constructor.
362
380
  *
363
381
  * @param {LoggerOptions} options The logger options.
364
382
  */
365
383
  constructor(s) {
366
- i(this, "_options");
384
+ r(this, "_options");
367
385
  this._options = s;
368
386
  }
369
387
  /**
@@ -386,83 +404,62 @@ class T {
386
404
  await ((s = this._options.reporter) == null ? void 0 : s[Symbol.asyncDispose]());
387
405
  }
388
406
  /**
389
- * Indicates if the specified level will be logged.
390
- *
391
- * @param {LogLevel} level The log level.
407
+ * @inheritdoc
392
408
  */
393
409
  isEnabled(s) {
394
410
  return s !== o.None && s >= this._options.minimumLevel;
395
411
  }
396
412
  /**
397
- * Log trace.
398
- *
399
- * @param msg The message to log.
413
+ * @inheritdoc
400
414
  */
401
415
  trace(s) {
402
416
  const e = new c();
403
417
  e.level = o.Trace, e.message = s, this.logMessage(e);
404
418
  }
405
419
  /**
406
- * Log debug.
407
- *
408
- * @param msg The message to log.
420
+ * @inheritdoc
409
421
  */
410
422
  debug(s) {
411
423
  const e = new c();
412
424
  e.level = o.Debug, e.message = s, this.logMessage(e);
413
425
  }
414
426
  /**
415
- * Log information.
416
- *
417
- * @param msg The message to log.
427
+ * @inheritdoc
418
428
  */
419
429
  info(s) {
420
430
  const e = new c();
421
431
  e.level = o.Information, e.message = s, this.logMessage(e);
422
432
  }
423
433
  /**
424
- * Log warning.
425
- *
426
- * @param msg The message to log.
434
+ * @inheritdoc
427
435
  */
428
436
  warn(s) {
429
437
  const e = new c();
430
438
  e.level = o.Warning, e.message = s, this.logMessage(e);
431
439
  }
432
440
  /**
433
- * Log error.
434
- *
435
- * @param msg The message to log.
441
+ * @inheritdoc
436
442
  */
437
443
  error(s) {
438
444
  const e = new c();
439
445
  e.level = o.Error, e.message = s, this.logMessage(e);
440
446
  }
441
447
  /**
442
- * Log error.
443
- *
444
- * @param msg The message to log.
448
+ * @inheritdoc
445
449
  */
446
450
  crit(s) {
447
451
  const e = new c();
448
452
  e.level = o.Critical, e.message = s, this.logMessage(e);
449
453
  }
450
454
  /**
451
- * Log an event.
452
- *
453
- * @param {LogLevel} level The level to log the event.
454
- * @param {String} message Custom message.
455
- * @param {Error} e The error associated with the event.
456
- * @param {ExtraParams} params Extra parameters.
455
+ * @inheritdoc
457
456
  */
458
457
  log(s, e, t, n) {
459
458
  const a = new c();
460
459
  a.level = s, a.message = e, a.errorMessage = t == null ? void 0 : t.message, a.stackTrace = t == null ? void 0 : t.stack, a.extraParams = n, this.logMessage(a);
461
460
  }
462
461
  /**
463
- * Log a message.
464
- *
465
- * @param {LogMessage} message The message to log.
462
+ * @inheritdoc
466
463
  */
467
464
  logMessage(s) {
468
465
  this.isEnabled(s.level) && setTimeout(() => {
@@ -470,24 +467,24 @@ class T {
470
467
  }, 1);
471
468
  }
472
469
  }
473
- class M {
470
+ class I {
474
471
  constructor() {
475
472
  /**
476
473
  * The name of the logger.
477
474
  */
478
- i(this, "name", "");
475
+ r(this, "name", "");
479
476
  /**
480
477
  * The reporter for the messages.
481
478
  */
482
- i(this, "reporter", null);
479
+ r(this, "reporter", null);
483
480
  /**
484
481
  * The minimum log level.
485
482
  */
486
- i(this, "minimumLevel", o.Warning);
483
+ r(this, "minimumLevel", o.Warning);
487
484
  /**
488
485
  * Log enrichers.
489
486
  */
490
- i(this, "enrichers", []);
487
+ r(this, "enrichers", []);
491
488
  }
492
489
  /**
493
490
  * Get the LogLevel from a string value.
@@ -515,7 +512,7 @@ class M {
515
512
  }
516
513
  }
517
514
  }
518
- class R {
515
+ class N {
519
516
  /**
520
517
  * Constructor.
521
518
  *
@@ -523,8 +520,8 @@ class R {
523
520
  * @param {LogLevel} logLevel The log level.
524
521
  */
525
522
  constructor(s, e = o.Information) {
526
- i(this, "_logger");
527
- i(this, "_logLevel");
523
+ r(this, "_logger");
524
+ r(this, "_logLevel");
528
525
  this._logger = s, this._logLevel = e;
529
526
  }
530
527
  /** @inheritdoc */
@@ -535,27 +532,31 @@ class R {
535
532
  });
536
533
  }
537
534
  }
538
- function x(r = 1, s) {
535
+ function b(i = 1, s) {
539
536
  return new Promise((e, t) => {
540
537
  setTimeout(() => {
541
538
  s ? t(s) : e();
542
- }, r);
539
+ }, i);
543
540
  });
544
541
  }
542
+ function v(i = 1) {
543
+ return i <= 0 ? Promise.resolve() : b(0).then(() => v(i - 1));
544
+ }
545
545
  export {
546
- f as BroadcastChannelPlugin,
547
- v as ConsoleReporter,
548
- b as DynamicValuesEnricher,
549
- P as InMemoryReporter,
546
+ P as BroadcastChannelPlugin,
547
+ M as ConsoleReporter,
548
+ E as DynamicValuesEnricher,
549
+ k as InMemoryReporter,
550
550
  o as LogLevel,
551
551
  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
552
+ C as Logger,
553
+ I as LoggerOptions,
554
+ N as LoggerPlugin,
555
+ A as MultipleReporter,
556
+ y as PubSubHub,
557
+ T as ValuesEnricher,
558
+ R as XhrReporter,
559
+ x as XhrReporterOptions,
560
+ b as delay,
561
+ v as nextTicks
561
562
  };
@@ -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"})});
@@ -1 +1 @@
1
- export { type SerializableValues } from "./contracts";
1
+ export type { SerializableValues } from "./contracts";
@@ -93,3 +93,47 @@ export interface ILogMessageEnricher {
93
93
  */
94
94
  enrich(message: LogMessage): void;
95
95
  }
96
+ /**
97
+ * Logging service.
98
+ */
99
+ /**
100
+ * Interface for logging operations.
101
+ */
102
+ export interface ILogger extends AsyncDisposable {
103
+ /**
104
+ * Indicates if the specified level will be logged.
105
+ */
106
+ isEnabled(level: LogLevel): boolean;
107
+ /**
108
+ * Log trace.
109
+ */
110
+ trace(msg: string): void;
111
+ /**
112
+ * Log debug.
113
+ */
114
+ debug(msg: string): void;
115
+ /**
116
+ * Log information.
117
+ */
118
+ info(msg: string): void;
119
+ /**
120
+ * Log warning.
121
+ */
122
+ warn(msg: string): void;
123
+ /**
124
+ * Log error.
125
+ */
126
+ error(msg: string): void;
127
+ /**
128
+ * Log critical.
129
+ */
130
+ crit(msg: string): void;
131
+ /**
132
+ * Log an event.
133
+ */
134
+ log(level: LogLevel, message: string, e?: Error, params?: ExtraParams): void;
135
+ /**
136
+ * Log a message.
137
+ */
138
+ logMessage(message: LogMessage): void;
139
+ }
@@ -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
  *
@@ -1,10 +1,10 @@
1
- import { type ExtraParams, LogLevel, LogMessage } from "./contracts";
1
+ import { type ExtraParams, type ILogger, LogLevel, LogMessage } from "./contracts";
2
2
  import type { LoggerOptions } from "./loggerOptions";
3
3
  /**
4
4
  * Logging service.
5
5
  */
6
- export declare class Logger implements AsyncDisposable {
7
- private _options;
6
+ export declare class Logger implements ILogger {
7
+ private readonly _options;
8
8
  /**
9
9
  * Constructor.
10
10
  *
@@ -22,60 +22,39 @@ export declare class Logger implements AsyncDisposable {
22
22
  */
23
23
  [Symbol.asyncDispose](): Promise<void>;
24
24
  /**
25
- * Indicates if the specified level will be logged.
26
- *
27
- * @param {LogLevel} level The log level.
25
+ * @inheritdoc
28
26
  */
29
27
  isEnabled(level: LogLevel): boolean;
30
28
  /**
31
- * Log trace.
32
- *
33
- * @param msg The message to log.
29
+ * @inheritdoc
34
30
  */
35
31
  trace(msg: string): void;
36
32
  /**
37
- * Log debug.
38
- *
39
- * @param msg The message to log.
33
+ * @inheritdoc
40
34
  */
41
35
  debug(msg: string): void;
42
36
  /**
43
- * Log information.
44
- *
45
- * @param msg The message to log.
37
+ * @inheritdoc
46
38
  */
47
39
  info(msg: string): void;
48
40
  /**
49
- * Log warning.
50
- *
51
- * @param msg The message to log.
41
+ * @inheritdoc
52
42
  */
53
43
  warn(msg: string): void;
54
44
  /**
55
- * Log error.
56
- *
57
- * @param msg The message to log.
45
+ * @inheritdoc
58
46
  */
59
47
  error(msg: string): void;
60
48
  /**
61
- * Log error.
62
- *
63
- * @param msg The message to log.
49
+ * @inheritdoc
64
50
  */
65
51
  crit(msg: string): void;
66
52
  /**
67
- * Log an event.
68
- *
69
- * @param {LogLevel} level The level to log the event.
70
- * @param {String} message Custom message.
71
- * @param {Error} e The error associated with the event.
72
- * @param {ExtraParams} params Extra parameters.
53
+ * @inheritdoc
73
54
  */
74
55
  log(level: LogLevel, message: string, e?: Error, params?: ExtraParams): void;
75
56
  /**
76
- * Log a message.
77
- *
78
- * @param {LogMessage} message The message to log.
57
+ * @inheritdoc
79
58
  */
80
59
  logMessage(message: LogMessage): void;
81
60
  }
@@ -31,17 +31,13 @@ export class Logger {
31
31
  await this._options.reporter?.[Symbol.asyncDispose]();
32
32
  }
33
33
  /**
34
- * Indicates if the specified level will be logged.
35
- *
36
- * @param {LogLevel} level The log level.
34
+ * @inheritdoc
37
35
  */
38
36
  isEnabled(level) {
39
37
  return level !== LogLevel.None && level >= this._options.minimumLevel;
40
38
  }
41
39
  /**
42
- * Log trace.
43
- *
44
- * @param msg The message to log.
40
+ * @inheritdoc
45
41
  */
46
42
  trace(msg) {
47
43
  const message = new LogMessage();
@@ -50,9 +46,7 @@ export class Logger {
50
46
  this.logMessage(message);
51
47
  }
52
48
  /**
53
- * Log debug.
54
- *
55
- * @param msg The message to log.
49
+ * @inheritdoc
56
50
  */
57
51
  debug(msg) {
58
52
  const message = new LogMessage();
@@ -61,9 +55,7 @@ export class Logger {
61
55
  this.logMessage(message);
62
56
  }
63
57
  /**
64
- * Log information.
65
- *
66
- * @param msg The message to log.
58
+ * @inheritdoc
67
59
  */
68
60
  info(msg) {
69
61
  const message = new LogMessage();
@@ -72,9 +64,7 @@ export class Logger {
72
64
  this.logMessage(message);
73
65
  }
74
66
  /**
75
- * Log warning.
76
- *
77
- * @param msg The message to log.
67
+ * @inheritdoc
78
68
  */
79
69
  warn(msg) {
80
70
  const message = new LogMessage();
@@ -83,9 +73,7 @@ export class Logger {
83
73
  this.logMessage(message);
84
74
  }
85
75
  /**
86
- * Log error.
87
- *
88
- * @param msg The message to log.
76
+ * @inheritdoc
89
77
  */
90
78
  error(msg) {
91
79
  const message = new LogMessage();
@@ -94,9 +82,7 @@ export class Logger {
94
82
  this.logMessage(message);
95
83
  }
96
84
  /**
97
- * Log error.
98
- *
99
- * @param msg The message to log.
85
+ * @inheritdoc
100
86
  */
101
87
  crit(msg) {
102
88
  const message = new LogMessage();
@@ -105,12 +91,7 @@ export class Logger {
105
91
  this.logMessage(message);
106
92
  }
107
93
  /**
108
- * Log an event.
109
- *
110
- * @param {LogLevel} level The level to log the event.
111
- * @param {String} message Custom message.
112
- * @param {Error} e The error associated with the event.
113
- * @param {ExtraParams} params Extra parameters.
94
+ * @inheritdoc
114
95
  */
115
96
  log(level, message, e, params) {
116
97
  const msg = new LogMessage();
@@ -122,9 +103,7 @@ export class Logger {
122
103
  this.logMessage(msg);
123
104
  }
124
105
  /**
125
- * Log a message.
126
- *
127
- * @param {LogMessage} message The message to log.
106
+ * @inheritdoc
128
107
  */
129
108
  logMessage(message) {
130
109
  if (!this.isEnabled(message.level))
@@ -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
  /**
@@ -1,18 +1,18 @@
1
- import { LogLevel, type Logger } from "../../logger";
1
+ import { type ILogger, LogLevel } from "../../logger";
2
2
  import type { PubSubPlugin, PubSubPluginContext } from "../pubsub";
3
3
  /**
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
  *
12
12
  * @param {Logger} logger The logger.
13
13
  * @param {LogLevel} logLevel The log level.
14
14
  */
15
- constructor(logger: Logger, logLevel?: LogLevel);
15
+ constructor(logger: ILogger, logLevel?: LogLevel);
16
16
  /** @inheritdoc */
17
17
  onPublish(context: PubSubPluginContext): void;
18
18
  }
@@ -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.2",
4
4
  "license": "MIT",
5
5
  "description": "ECMAScript common utilities library",
6
6
  "keywords": [
@@ -23,15 +23,15 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "types": "./dist/index.d.ts",
26
- "import": "./dist/bundle/utiliti-es.js",
27
- "require": "./dist/bundle/utiliti-es.cjs",
28
26
  "node": {
29
27
  "import": {
30
28
  "production": "./dist/bundle/utiliti-es.js",
31
29
  "development": "./dist/index.js",
32
30
  "default": "./dist/index.js"
33
31
  }
34
- }
32
+ },
33
+ "require": "./dist/bundle/utiliti-es.cjs",
34
+ "import": "./dist/bundle/utiliti-es.js"
35
35
  }
36
36
  },
37
37
  "repository": {
@@ -45,28 +45,29 @@
45
45
  "name": "Adaptive Architecture"
46
46
  },
47
47
  "scripts": {
48
+ "clean": "rm -rf ./node_modules/ && rm -rf ./package-lock.json",
48
49
  "dev": "vite",
49
50
  "empty-output": "node ./ci-cd/empty-output.js",
50
51
  "build": "tsc && vite build",
51
52
  "preview": "vite preview",
52
53
  "prelint": "node ./ci-cd/empty-output.js",
53
- "lint": "npx @biomejs/biome check --apply ./",
54
+ "lint": "npx @biomejs/biome check --write ./",
54
55
  "test": "vitest run --coverage",
55
56
  "docs:dev": "typedoc && vitepress dev docs",
56
57
  "docs:build": "typedoc && vitepress build docs",
57
58
  "docs:preview": "vitepress preview docs"
58
59
  },
59
60
  "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"
61
+ "@biomejs/biome": "1.9.4",
62
+ "@types/node": "22.13.10",
63
+ "@vitest/coverage-v8": "3.0.9",
64
+ "jsdom": "26.0.0",
65
+ "msw": "2.7.3",
66
+ "typedoc": "0.28.0",
67
+ "typescript": "5.8.2",
68
+ "vite": "6.2.2",
69
+ "vitepress": "1.6.3",
70
+ "vitest": "3.0.9"
70
71
  },
71
72
  "msw": {
72
73
  "workerDirectory": [