@adapt-arch/utiliti-es 0.4.2 → 0.4.3

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";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});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 n{timestamp=Date.now();level=exports.LogLevel.None;name="";message="";errorMessage;stackTrace;extraParams}class m{_valuesFn;_overrideExisting;constructor(e,s){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 o in s)t.indexOf(o)!==-1&&!this._overrideExisting||(e.extraParams[o]=s[o])}}class f{_values;_overrideExisting;constructor(e,s){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 d{_options;constructor(e){this._options=e}logMessageCore(e){e.name=this._options.name;for(const s of this._options.enrichers)s.enrich(e);this._options.reporter?.register(e)}async[Symbol.asyncDispose](){await this._options.reporter?.[Symbol.asyncDispose]()}isEnabled(e){return e!==exports.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new n;s.level=exports.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new n;s.level=exports.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new n;s.level=exports.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new n;s.level=exports.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new n;s.level=exports.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new n;s.level=exports.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,t,o){const r=new n,a=this._extractErrorDetails(t);r.level=e,r.message=s,r.errorMessage=a?.message,r.stackTrace=a?.stack,r.extraParams=o,this.logMessage(r)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}_extractErrorDetails(e){if(e instanceof Error)return{message:e.message,stack:e.stack};switch(typeof e){case"string":return{message:e};case"object":{const s=e;if(s===null)break;const t={message:s.message??s.Message,stack:s.stack??s.Stack??s.stackTrace??s.StackTrace};return t.message===void 0&&(t.message=JSON.stringify(e)),t}default:{const s=e;if(typeof s?.toString=="function")return{message:s.toString()};break}}}}class b{name="";reporter=null;minimumLevel=exports.LogLevel.Warning;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 v{_console;constructor(e){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 L{_messages=[];get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class y{_reporters;constructor(e){this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=[];for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class P{endpoint="";verb="POST";batchSize=20;interval=2e3;requestTransform}class T{_messageQueue;_options;_reportActionTimeoutRef;_reportActionPromise;_disposed;constructor(e){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)},o=new XMLHttpRequest;o.open(this._options.verb,this._options.endpoint),o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(o),o.onload=function(){s(this.status>=200&&this.status<300)},o.onerror=t,o.onabort=t,o.send(JSON.stringify(e))})}}class w{_options;_channel;_eventListeners=null;_broadcastEnabled=!0;constructor(e){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 E{_logger;_logLevel;constructor(e,s=exports.LogLevel.Information){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})}}const c=(i,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=i.timeouts.indexOf(e);i.timeouts.splice(s,1)};class k{_subscriptions=new Map;_options;constructor(e){if(this._options=e,this._options?.plugins)for(const s of this._options.plugins)s.init&&s.init(this)}publish(e,s){const t={topic:e,message:s};if(this._options?.plugins)for(const r of this._options.plugins)r.onPublish&&r.onPublish(t);if(!t.topic)throw new Error("Invalid topic.");if(!t.message)throw new Error("Invalid message.");const o=this._subscriptions.get(t.topic);if(o)for(const r of o.values()){const a={};r.timeouts.push(a),a.ref=setTimeout((h,g,p,_)=>{h.handler(p,_),c(r,g)},0,r,a,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 o=`sub-${Date.now()}`;return t.set(o,{handler:s,timeouts:[]}),o}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const t of s.values())for(;;){const o=t.timeouts.pop();if(!o)break;c(t,o)}if(s.delete(e))return}}[Symbol.dispose](){for(const e of this._subscriptions.values())for(const s of e.keys())this.unsubscribe(s);if(this._subscriptions.clear(),this._options?.plugins)for(const e of this._options.plugins){const s=e[Symbol.dispose];s&&s.call(e)}return Promise.resolve()}}function l(i=1,e){return new Promise((s,t)=>{setTimeout(()=>{e?t(e):s()},i)})}function u(i=1){return i<=0?Promise.resolve():l(0).then(()=>u(i-1))}exports.BroadcastChannelPlugin=w;exports.ConsoleReporter=v;exports.DynamicValuesEnricher=m;exports.InMemoryReporter=L;exports.LogMessage=n;exports.Logger=d;exports.LoggerOptions=b;exports.LoggerPlugin=E;exports.MultipleReporter=y;exports.PubSubHub=k;exports.ValuesEnricher=f;exports.XhrReporter=T;exports.XhrReporterOptions=P;exports.delay=l;exports.nextTicks=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});exports.LogLevel=void 0;(function(t){t[t.Trace=0]="Trace",t[t.Debug=1]="Debug",t[t.Information=2]="Information",t[t.Warning=3]="Warning",t[t.Error=4]="Error",t[t.Critical=5]="Critical",t[t.None=6]="None"})(exports.LogLevel||(exports.LogLevel={}));class n{timestamp=Date.now();level=exports.LogLevel.None;name="";message="";errorMessage;stackTrace;extraParams}class m{_valuesFn;_overrideExisting;constructor(e,s){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 o in s)i.includes(o)&&!this._overrideExisting||(e.extraParams[o]=s[o])}}class f{_values;_overrideExisting;constructor(e,s){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.includes(i)&&!this._overrideExisting||(e.extraParams[i]=this._values[i])}}class d{_options;constructor(e){this._options=e}logMessageCore(e){e.name=this._options.name;for(const s of this._options.enrichers)s.enrich(e);this._options.reporter?.register(e)}async[Symbol.asyncDispose](){await this._options.reporter?.[Symbol.asyncDispose]()}isEnabled(e){return e!==exports.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new n;s.level=exports.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new n;s.level=exports.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new n;s.level=exports.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new n;s.level=exports.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new n;s.level=exports.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new n;s.level=exports.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,o){const r=new n,a=this._extractErrorDetails(i);r.level=e,r.message=s,r.errorMessage=a?.message,r.stackTrace=a?.stack,r.extraParams=o,this.logMessage(r)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}_extractErrorDetails(e){if(e instanceof Error)return{message:e.message,stack:e.stack};switch(typeof e){case"string":return{message:e};case"object":{const s=e;if(s===null)break;const i={message:s.message??s.Message,stack:s.stack??s.Stack??s.stackTrace??s.StackTrace};return i.message??=JSON.stringify(e),i}default:{const s=e;if(typeof s?.toString=="function")return{message:s.toString()};break}}}}class b{name="";reporter=null;minimumLevel=exports.LogLevel.Warning;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 v{_console;constructor(e){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 L{_messages=[];get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class y{_reporters;constructor(e){this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=[];for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class P{endpoint="";verb="POST";batchSize=20;interval=2e3;requestTransform}class T{_messageQueue;_options;_reportActionTimeoutRef;_reportActionPromise;_disposed;constructor(e){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](){this._disposed||(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)},o=new XMLHttpRequest;o.open(this._options.verb,this._options.endpoint),o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(o),o.onload=function(){s(this.status>=200&&this.status<300)},o.onerror=i,o.onabort=i,o.send(JSON.stringify(e))})}}class w{_options;_channel;_eventListeners=null;_broadcastEnabled=!0;constructor(e){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 E{_logger;_logLevel;constructor(e,s=exports.LogLevel.Information){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})}}const c=(t,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=t.timeouts.indexOf(e);t.timeouts.splice(s,1)};class M{_subscriptions=new Map;_options;constructor(e){if(this._options=e,this._options?.plugins)for(const s of this._options.plugins)s.init&&s.init(this)}publish(e,s){const i={topic:e,message:s};if(this._options?.plugins)for(const r of this._options.plugins)r.onPublish&&r.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const o=this._subscriptions.get(i.topic);if(o)for(const r of o.values()){const a={};r.timeouts.push(a),a.ref=setTimeout((h,g,p,_)=>{h.handler(p,_),c(r,g)},0,r,a,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 o=`sub-${Date.now()}-${Math.random().toString(16).slice(2)}`;return i.set(o,{handler:s,timeouts:[]}),o}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const i of s.values())for(;;){const o=i.timeouts.pop();if(!o)break;c(i,o)}if(s.delete(e))return}}[Symbol.dispose](){for(const e of this._subscriptions.values())for(const s of e.keys())this.unsubscribe(s);if(this._subscriptions.clear(),this._options?.plugins)for(const e of this._options.plugins){const s=e[Symbol.dispose];s&&s.call(e)}return Promise.resolve()}}function l(t=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},t)})}function u(t=1){return t<=0?Promise.resolve():l(0).then(()=>u(t-1))}exports.BroadcastChannelPlugin=w;exports.ConsoleReporter=v;exports.DynamicValuesEnricher=m;exports.InMemoryReporter=L;exports.LogMessage=n;exports.Logger=d;exports.LoggerOptions=b;exports.LoggerPlugin=E;exports.MultipleReporter=y;exports.PubSubHub=M;exports.ValuesEnricher=f;exports.XhrReporter=T;exports.XhrReporterOptions=P;exports.delay=l;exports.nextTicks=u;
@@ -1 +1 @@
1
- var adaptArch_utilitiEs=(function(t){"use strict";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 a{timestamp=Date.now();level=t.LogLevel.None;name="";message="";errorMessage;stackTrace;extraParams}class g{_valuesFn;_overrideExisting;constructor(e,s){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 o in s)i.indexOf(o)!==-1&&!this._overrideExisting||(e.extraParams[o]=s[o])}}class _{_values;_overrideExisting;constructor(e,s){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 m{_options;constructor(e){this._options=e}logMessageCore(e){e.name=this._options.name;for(const s of this._options.enrichers)s.enrich(e);this._options.reporter?.register(e)}async[Symbol.asyncDispose](){await this._options.reporter?.[Symbol.asyncDispose]()}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new a;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new a;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new a;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new a;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new a;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new a;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,o){const r=new a,c=this._extractErrorDetails(i);r.level=e,r.message=s,r.errorMessage=c?.message,r.stackTrace=c?.stack,r.extraParams=o,this.logMessage(r)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}_extractErrorDetails(e){if(e instanceof Error)return{message:e.message,stack:e.stack};switch(typeof e){case"string":return{message:e};case"object":{const s=e;if(s===null)break;const i={message:s.message??s.Message,stack:s.stack??s.Stack??s.stackTrace??s.StackTrace};return i.message===void 0&&(i.message=JSON.stringify(e)),i}default:{const s=e;if(typeof s?.toString=="function")return{message:s.toString()};break}}}}class f{name="";reporter=null;minimumLevel=t.LogLevel.Warning;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 p{_console;constructor(e){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 d{_messages=[];get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class b{_reporters;constructor(e){this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=[];for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class v{endpoint="";verb="POST";batchSize=20;interval=2e3;requestTransform}class L{_messageQueue;_options;_reportActionTimeoutRef;_reportActionPromise;_disposed;constructor(e){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)},o=new XMLHttpRequest;o.open(this._options.verb,this._options.endpoint),o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(o),o.onload=function(){s(this.status>=200&&this.status<300)},o.onerror=i,o.onabort=i,o.send(JSON.stringify(e))})}}class y{_options;_channel;_eventListeners=null;_broadcastEnabled=!0;constructor(e){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{_logger;_logLevel;constructor(e,s=t.LogLevel.Information){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})}}const l=(n,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=n.timeouts.indexOf(e);n.timeouts.splice(s,1)};class T{_subscriptions=new Map;_options;constructor(e){if(this._options=e,this._options?.plugins)for(const s of this._options.plugins)s.init&&s.init(this)}publish(e,s){const i={topic:e,message:s};if(this._options?.plugins)for(const r of this._options.plugins)r.onPublish&&r.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const o=this._subscriptions.get(i.topic);if(o)for(const r of o.values()){const c={};r.timeouts.push(c),c.ref=setTimeout((w,E,k,M)=>{w.handler(k,M),l(r,E)},0,r,c,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 o=`sub-${Date.now()}`;return i.set(o,{handler:s,timeouts:[]}),o}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const i of s.values())for(;;){const o=i.timeouts.pop();if(!o)break;l(i,o)}if(s.delete(e))return}}[Symbol.dispose](){for(const e of this._subscriptions.values())for(const s of e.keys())this.unsubscribe(s);if(this._subscriptions.clear(),this._options?.plugins)for(const e of this._options.plugins){const s=e[Symbol.dispose];s&&s.call(e)}return Promise.resolve()}}function u(n=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},n)})}function h(n=1){return n<=0?Promise.resolve():u(0).then(()=>h(n-1))}return t.BroadcastChannelPlugin=y,t.ConsoleReporter=p,t.DynamicValuesEnricher=g,t.InMemoryReporter=d,t.LogMessage=a,t.Logger=m,t.LoggerOptions=f,t.LoggerPlugin=P,t.MultipleReporter=b,t.PubSubHub=T,t.ValuesEnricher=_,t.XhrReporter=L,t.XhrReporterOptions=v,t.delay=u,t.nextTicks=h,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t})({});
1
+ var adaptArch_utilitiEs=(function(t){"use strict";t.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"})(t.LogLevel||(t.LogLevel={}));class a{timestamp=Date.now();level=t.LogLevel.None;name="";message="";errorMessage;stackTrace;extraParams}class g{_valuesFn;_overrideExisting;constructor(e,s){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 n=Object.keys(e.extraParams);for(const o in s)n.includes(o)&&!this._overrideExisting||(e.extraParams[o]=s[o])}}class _{_values;_overrideExisting;constructor(e,s){this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const n in this._values)s.includes(n)&&!this._overrideExisting||(e.extraParams[n]=this._values[n])}}class m{_options;constructor(e){this._options=e}logMessageCore(e){e.name=this._options.name;for(const s of this._options.enrichers)s.enrich(e);this._options.reporter?.register(e)}async[Symbol.asyncDispose](){await this._options.reporter?.[Symbol.asyncDispose]()}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new a;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new a;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new a;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new a;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new a;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new a;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,n,o){const r=new a,c=this._extractErrorDetails(n);r.level=e,r.message=s,r.errorMessage=c?.message,r.stackTrace=c?.stack,r.extraParams=o,this.logMessage(r)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}_extractErrorDetails(e){if(e instanceof Error)return{message:e.message,stack:e.stack};switch(typeof e){case"string":return{message:e};case"object":{const s=e;if(s===null)break;const n={message:s.message??s.Message,stack:s.stack??s.Stack??s.stackTrace??s.StackTrace};return n.message??=JSON.stringify(e),n}default:{const s=e;if(typeof s?.toString=="function")return{message:s.toString()};break}}}}class f{name="";reporter=null;minimumLevel=t.LogLevel.Warning;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 p{_console;constructor(e){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 d{_messages=[];get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class b{_reporters;constructor(e){this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=[];for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class v{endpoint="";verb="POST";batchSize=20;interval=2e3;requestTransform}class L{_messageQueue;_options;_reportActionTimeoutRef;_reportActionPromise;_disposed;constructor(e){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](){this._disposed||(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 n=()=>{s(!1)},o=new XMLHttpRequest;o.open(this._options.verb,this._options.endpoint),o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(o),o.onload=function(){s(this.status>=200&&this.status<300)},o.onerror=n,o.onabort=n,o.send(JSON.stringify(e))})}}class y{_options;_channel;_eventListeners=null;_broadcastEnabled=!0;constructor(e){this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const n=s.data;if(!(!n.topic||!n.message))try{this._broadcastEnabled=!1,e.publish(n.topic,n.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{_logger;_logLevel;constructor(e,s=t.LogLevel.Information){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})}}const l=(i,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=i.timeouts.indexOf(e);i.timeouts.splice(s,1)};class T{_subscriptions=new Map;_options;constructor(e){if(this._options=e,this._options?.plugins)for(const s of this._options.plugins)s.init&&s.init(this)}publish(e,s){const n={topic:e,message:s};if(this._options?.plugins)for(const r of this._options.plugins)r.onPublish&&r.onPublish(n);if(!n.topic)throw new Error("Invalid topic.");if(!n.message)throw new Error("Invalid message.");const o=this._subscriptions.get(n.topic);if(o)for(const r of o.values()){const c={};r.timeouts.push(c),c.ref=setTimeout((w,E,M,k)=>{w.handler(M,k),l(r,E)},0,r,c,structuredClone(n.topic),structuredClone(n.message))}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let n=this._subscriptions.get(e);n||(n=new Map,this._subscriptions.set(structuredClone(e),n));const o=`sub-${Date.now()}-${Math.random().toString(16).slice(2)}`;return n.set(o,{handler:s,timeouts:[]}),o}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const n of s.values())for(;;){const o=n.timeouts.pop();if(!o)break;l(n,o)}if(s.delete(e))return}}[Symbol.dispose](){for(const e of this._subscriptions.values())for(const s of e.keys())this.unsubscribe(s);if(this._subscriptions.clear(),this._options?.plugins)for(const e of this._options.plugins){const s=e[Symbol.dispose];s&&s.call(e)}return Promise.resolve()}}function u(i=1,e){return new Promise((s,n)=>{setTimeout(()=>{e?n(e):s()},i)})}function h(i=1){return i<=0?Promise.resolve():u(0).then(()=>h(i-1))}return t.BroadcastChannelPlugin=y,t.ConsoleReporter=p,t.DynamicValuesEnricher=g,t.InMemoryReporter=d,t.LogMessage=a,t.Logger=m,t.LoggerOptions=f,t.LoggerPlugin=P,t.MultipleReporter=b,t.PubSubHub=T,t.ValuesEnricher=_,t.XhrReporter=L,t.XhrReporterOptions=v,t.delay=u,t.nextTicks=h,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t})({});
@@ -1,6 +1,6 @@
1
1
  var r;
2
- (function(i) {
3
- 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";
2
+ (function(t) {
3
+ t[t.Trace = 0] = "Trace", t[t.Debug = 1] = "Debug", t[t.Information = 2] = "Information", t[t.Warning = 3] = "Warning", t[t.Error = 4] = "Error", t[t.Critical = 5] = "Critical", t[t.None = 6] = "None";
4
4
  })(r || (r = {}));
5
5
  class a {
6
6
  /**
@@ -52,9 +52,9 @@ class f {
52
52
  if (!e)
53
53
  return;
54
54
  s.extraParams = s.extraParams || {};
55
- const t = Object.keys(s.extraParams);
55
+ const i = Object.keys(s.extraParams);
56
56
  for (const o in e)
57
- t.indexOf(o) !== -1 && !this._overrideExisting || (s.extraParams[o] = e[o]);
57
+ i.includes(o) && !this._overrideExisting || (s.extraParams[o] = e[o]);
58
58
  }
59
59
  }
60
60
  class d {
@@ -77,8 +77,8 @@ class d {
77
77
  return;
78
78
  s.extraParams = s.extraParams || {};
79
79
  const e = Object.keys(s.extraParams);
80
- for (const t in this._values)
81
- e.indexOf(t) !== -1 && !this._overrideExisting || (s.extraParams[t] = this._values[t]);
80
+ for (const i in this._values)
81
+ e.includes(i) && !this._overrideExisting || (s.extraParams[i] = this._values[i]);
82
82
  }
83
83
  }
84
84
  class b {
@@ -159,8 +159,8 @@ class b {
159
159
  /**
160
160
  * @inheritdoc
161
161
  */
162
- log(s, e, t, o) {
163
- const n = new a(), c = this._extractErrorDetails(t);
162
+ log(s, e, i, o) {
163
+ const n = new a(), c = this._extractErrorDetails(i);
164
164
  n.level = s, n.message = e, n.errorMessage = c?.message, n.stackTrace = c?.stack, n.extraParams = o, this.logMessage(n);
165
165
  }
166
166
  /**
@@ -181,11 +181,11 @@ class b {
181
181
  const e = s;
182
182
  if (e === null)
183
183
  break;
184
- const t = {
184
+ const i = {
185
185
  message: e.message ?? e.Message,
186
186
  stack: e.stack ?? e.Stack ?? e.stackTrace ?? e.StackTrace
187
187
  };
188
- return t.message === void 0 && (t.message = JSON.stringify(s)), t;
188
+ return i.message ??= JSON.stringify(s), i;
189
189
  }
190
190
  default: {
191
191
  const e = s;
@@ -371,9 +371,7 @@ class E {
371
371
  * @inheritdoc
372
372
  */
373
373
  async [Symbol.asyncDispose]() {
374
- if (this._disposed)
375
- return Promise.resolve();
376
- await (this._reportActionPromise ?? this._processMessages()), this._disposed = !0;
374
+ this._disposed || (await (this._reportActionPromise ?? this._processMessages()), this._disposed = !0);
377
375
  }
378
376
  _scheduleNextProcessAction() {
379
377
  if (this._reportActionTimeoutRef)
@@ -396,12 +394,12 @@ class E {
396
394
  }
397
395
  _sendMessagesBatch(s) {
398
396
  return new Promise((e) => {
399
- const t = () => {
397
+ const i = () => {
400
398
  e(!1);
401
399
  }, o = new XMLHttpRequest();
402
400
  o.open(this._options.verb, this._options.endpoint), o.setRequestHeader("Content-Type", "application/json;charset=UTF-8"), this._options.requestTransform && this._options.requestTransform(o), o.onload = function() {
403
401
  e(this.status >= 200 && this.status < 300);
404
- }, o.onerror = t, o.onabort = t, o.send(JSON.stringify(s));
402
+ }, o.onerror = i, o.onabort = i, o.send(JSON.stringify(s));
405
403
  });
406
404
  }
407
405
  }
@@ -421,10 +419,10 @@ class k {
421
419
  /** @inheritdoc */
422
420
  init(s) {
423
421
  this._eventListeners || (this._eventListeners = (e) => {
424
- const t = e.data;
425
- if (!(!t.topic || !t.message))
422
+ const i = e.data;
423
+ if (!(!i.topic || !i.message))
426
424
  try {
427
- this._broadcastEnabled = !1, s.publish(t.topic, t.message);
425
+ this._broadcastEnabled = !1, s.publish(i.topic, i.message);
428
426
  } finally {
429
427
  this._broadcastEnabled = !0;
430
428
  }
@@ -464,10 +462,10 @@ class M {
464
462
  });
465
463
  }
466
464
  }
467
- const l = (i, s) => {
465
+ const l = (t, s) => {
468
466
  clearTimeout(s.ref), s.ref = void 0;
469
- const e = i.timeouts.indexOf(s);
470
- i.timeouts.splice(e, 1);
467
+ const e = t.timeouts.indexOf(s);
468
+ t.timeouts.splice(e, 1);
471
469
  };
472
470
  class x {
473
471
  _subscriptions = /* @__PURE__ */ new Map();
@@ -482,24 +480,24 @@ class x {
482
480
  }
483
481
  /** @inheritdoc */
484
482
  publish(s, e) {
485
- const t = {
483
+ const i = {
486
484
  topic: s,
487
485
  message: e
488
486
  };
489
487
  if (this._options?.plugins)
490
488
  for (const n of this._options.plugins)
491
- n.onPublish && n.onPublish(t);
492
- if (!t.topic)
489
+ n.onPublish && n.onPublish(i);
490
+ if (!i.topic)
493
491
  throw new Error("Invalid topic.");
494
- if (!t.message)
492
+ if (!i.message)
495
493
  throw new Error("Invalid message.");
496
- const o = this._subscriptions.get(t.topic);
494
+ const o = this._subscriptions.get(i.topic);
497
495
  if (o)
498
496
  for (const n of o.values()) {
499
497
  const c = {};
500
498
  n.timeouts.push(c), c.ref = setTimeout((u, h, g, p) => {
501
499
  u.handler(g, p), l(n, h);
502
- }, 0, n, c, structuredClone(t.topic), structuredClone(t.message));
500
+ }, 0, n, c, structuredClone(i.topic), structuredClone(i.message));
503
501
  }
504
502
  }
505
503
  /** @inheritdoc */
@@ -508,21 +506,21 @@ class x {
508
506
  throw new Error("Invalid topic.");
509
507
  if (!e)
510
508
  throw new Error("Invalid handler.");
511
- let t = this._subscriptions.get(s);
512
- t || (t = /* @__PURE__ */ new Map(), this._subscriptions.set(structuredClone(s), t));
513
- const o = `sub-${Date.now()}`;
514
- return t.set(o, { handler: e, timeouts: [] }), o;
509
+ let i = this._subscriptions.get(s);
510
+ i || (i = /* @__PURE__ */ new Map(), this._subscriptions.set(structuredClone(s), i));
511
+ const o = `sub-${Date.now()}-${Math.random().toString(16).slice(2)}`;
512
+ return i.set(o, { handler: e, timeouts: [] }), o;
515
513
  }
516
514
  /** @inheritdoc */
517
515
  unsubscribe(s) {
518
516
  if (s)
519
517
  for (const e of this._subscriptions.values()) {
520
- for (const t of e.values())
518
+ for (const i of e.values())
521
519
  for (; ; ) {
522
- const o = t.timeouts.pop();
520
+ const o = i.timeouts.pop();
523
521
  if (!o)
524
522
  break;
525
- l(t, o);
523
+ l(i, o);
526
524
  }
527
525
  if (e.delete(s))
528
526
  return;
@@ -540,15 +538,15 @@ class x {
540
538
  return Promise.resolve();
541
539
  }
542
540
  }
543
- function _(i = 1, s) {
544
- return new Promise((e, t) => {
541
+ function _(t = 1, s) {
542
+ return new Promise((e, i) => {
545
543
  setTimeout(() => {
546
- s ? t(s) : e();
547
- }, i);
544
+ s ? i(s) : e();
545
+ }, t);
548
546
  });
549
547
  }
550
- function m(i = 1) {
551
- return i <= 0 ? Promise.resolve() : _(0).then(() => m(i - 1));
548
+ function m(t = 1) {
549
+ return t <= 0 ? Promise.resolve() : _(0).then(() => m(t - 1));
552
550
  }
553
551
  export {
554
552
  k as BroadcastChannelPlugin,
@@ -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";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 a{timestamp=Date.now();level=t.LogLevel.None;name="";message="";errorMessage;stackTrace;extraParams}class g{_valuesFn;_overrideExisting;constructor(e,s){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 o in s)i.indexOf(o)!==-1&&!this._overrideExisting||(e.extraParams[o]=s[o])}}class f{_values;_overrideExisting;constructor(e,s){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 _{_options;constructor(e){this._options=e}logMessageCore(e){e.name=this._options.name;for(const s of this._options.enrichers)s.enrich(e);this._options.reporter?.register(e)}async[Symbol.asyncDispose](){await this._options.reporter?.[Symbol.asyncDispose]()}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new a;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new a;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new a;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new a;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new a;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new a;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,o){const r=new a,c=this._extractErrorDetails(i);r.level=e,r.message=s,r.errorMessage=c?.message,r.stackTrace=c?.stack,r.extraParams=o,this.logMessage(r)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}_extractErrorDetails(e){if(e instanceof Error)return{message:e.message,stack:e.stack};switch(typeof e){case"string":return{message:e};case"object":{const s=e;if(s===null)break;const i={message:s.message??s.Message,stack:s.stack??s.Stack??s.stackTrace??s.StackTrace};return i.message===void 0&&(i.message=JSON.stringify(e)),i}default:{const s=e;if(typeof s?.toString=="function")return{message:s.toString()};break}}}}class m{name="";reporter=null;minimumLevel=t.LogLevel.Warning;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 p{_console;constructor(e){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 d{_messages=[];get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class b{_reporters;constructor(e){this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=[];for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class v{endpoint="";verb="POST";batchSize=20;interval=2e3;requestTransform}class L{_messageQueue;_options;_reportActionTimeoutRef;_reportActionPromise;_disposed;constructor(e){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)},o=new XMLHttpRequest;o.open(this._options.verb,this._options.endpoint),o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(o),o.onload=function(){s(this.status>=200&&this.status<300)},o.onerror=i,o.onabort=i,o.send(JSON.stringify(e))})}}class y{_options;_channel;_eventListeners=null;_broadcastEnabled=!0;constructor(e){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 T{_logger;_logLevel;constructor(e,s=t.LogLevel.Information){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})}}const l=(n,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=n.timeouts.indexOf(e);n.timeouts.splice(s,1)};class P{_subscriptions=new Map;_options;constructor(e){if(this._options=e,this._options?.plugins)for(const s of this._options.plugins)s.init&&s.init(this)}publish(e,s){const i={topic:e,message:s};if(this._options?.plugins)for(const r of this._options.plugins)r.onPublish&&r.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const o=this._subscriptions.get(i.topic);if(o)for(const r of o.values()){const c={};r.timeouts.push(c),c.ref=setTimeout((w,E,k,M)=>{w.handler(k,M),l(r,E)},0,r,c,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 o=`sub-${Date.now()}`;return i.set(o,{handler:s,timeouts:[]}),o}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const i of s.values())for(;;){const o=i.timeouts.pop();if(!o)break;l(i,o)}if(s.delete(e))return}}[Symbol.dispose](){for(const e of this._subscriptions.values())for(const s of e.keys())this.unsubscribe(s);if(this._subscriptions.clear(),this._options?.plugins)for(const e of this._options.plugins){const s=e[Symbol.dispose];s&&s.call(e)}return Promise.resolve()}}function u(n=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},n)})}function h(n=1){return n<=0?Promise.resolve():u(0).then(()=>h(n-1))}t.BroadcastChannelPlugin=y,t.ConsoleReporter=p,t.DynamicValuesEnricher=g,t.InMemoryReporter=d,t.LogMessage=a,t.Logger=_,t.LoggerOptions=m,t.LoggerPlugin=T,t.MultipleReporter=b,t.PubSubHub=P,t.ValuesEnricher=f,t.XhrReporter=L,t.XhrReporterOptions=v,t.delay=u,t.nextTicks=h,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";t.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"})(t.LogLevel||(t.LogLevel={}));class a{timestamp=Date.now();level=t.LogLevel.None;name="";message="";errorMessage;stackTrace;extraParams}class g{_valuesFn;_overrideExisting;constructor(e,s){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 n=Object.keys(e.extraParams);for(const o in s)n.includes(o)&&!this._overrideExisting||(e.extraParams[o]=s[o])}}class _{_values;_overrideExisting;constructor(e,s){this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const n in this._values)s.includes(n)&&!this._overrideExisting||(e.extraParams[n]=this._values[n])}}class m{_options;constructor(e){this._options=e}logMessageCore(e){e.name=this._options.name;for(const s of this._options.enrichers)s.enrich(e);this._options.reporter?.register(e)}async[Symbol.asyncDispose](){await this._options.reporter?.[Symbol.asyncDispose]()}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new a;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new a;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new a;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new a;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new a;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new a;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,n,o){const r=new a,c=this._extractErrorDetails(n);r.level=e,r.message=s,r.errorMessage=c?.message,r.stackTrace=c?.stack,r.extraParams=o,this.logMessage(r)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}_extractErrorDetails(e){if(e instanceof Error)return{message:e.message,stack:e.stack};switch(typeof e){case"string":return{message:e};case"object":{const s=e;if(s===null)break;const n={message:s.message??s.Message,stack:s.stack??s.Stack??s.stackTrace??s.StackTrace};return n.message??=JSON.stringify(e),n}default:{const s=e;if(typeof s?.toString=="function")return{message:s.toString()};break}}}}class f{name="";reporter=null;minimumLevel=t.LogLevel.Warning;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 p{_console;constructor(e){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 d{_messages=[];get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class b{_reporters;constructor(e){this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=[];for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class v{endpoint="";verb="POST";batchSize=20;interval=2e3;requestTransform}class L{_messageQueue;_options;_reportActionTimeoutRef;_reportActionPromise;_disposed;constructor(e){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](){this._disposed||(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 n=()=>{s(!1)},o=new XMLHttpRequest;o.open(this._options.verb,this._options.endpoint),o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(o),o.onload=function(){s(this.status>=200&&this.status<300)},o.onerror=n,o.onabort=n,o.send(JSON.stringify(e))})}}class y{_options;_channel;_eventListeners=null;_broadcastEnabled=!0;constructor(e){this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const n=s.data;if(!(!n.topic||!n.message))try{this._broadcastEnabled=!1,e.publish(n.topic,n.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 T{_logger;_logLevel;constructor(e,s=t.LogLevel.Information){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})}}const l=(i,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=i.timeouts.indexOf(e);i.timeouts.splice(s,1)};class P{_subscriptions=new Map;_options;constructor(e){if(this._options=e,this._options?.plugins)for(const s of this._options.plugins)s.init&&s.init(this)}publish(e,s){const n={topic:e,message:s};if(this._options?.plugins)for(const r of this._options.plugins)r.onPublish&&r.onPublish(n);if(!n.topic)throw new Error("Invalid topic.");if(!n.message)throw new Error("Invalid message.");const o=this._subscriptions.get(n.topic);if(o)for(const r of o.values()){const c={};r.timeouts.push(c),c.ref=setTimeout((w,E,M,k)=>{w.handler(M,k),l(r,E)},0,r,c,structuredClone(n.topic),structuredClone(n.message))}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let n=this._subscriptions.get(e);n||(n=new Map,this._subscriptions.set(structuredClone(e),n));const o=`sub-${Date.now()}-${Math.random().toString(16).slice(2)}`;return n.set(o,{handler:s,timeouts:[]}),o}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const n of s.values())for(;;){const o=n.timeouts.pop();if(!o)break;l(n,o)}if(s.delete(e))return}}[Symbol.dispose](){for(const e of this._subscriptions.values())for(const s of e.keys())this.unsubscribe(s);if(this._subscriptions.clear(),this._options?.plugins)for(const e of this._options.plugins){const s=e[Symbol.dispose];s&&s.call(e)}return Promise.resolve()}}function u(i=1,e){return new Promise((s,n)=>{setTimeout(()=>{e?n(e):s()},i)})}function h(i=1){return i<=0?Promise.resolve():u(0).then(()=>h(i-1))}t.BroadcastChannelPlugin=y,t.ConsoleReporter=p,t.DynamicValuesEnricher=g,t.InMemoryReporter=d,t.LogMessage=a,t.Logger=m,t.LoggerOptions=f,t.LoggerPlugin=T,t.MultipleReporter=b,t.PubSubHub=P,t.ValuesEnricher=_,t.XhrReporter=L,t.XhrReporterOptions=v,t.delay=u,t.nextTicks=h,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
@@ -22,7 +22,7 @@ export class DynamicValuesEnricher {
22
22
  message.extraParams = message.extraParams || {};
23
23
  const existingKeys = Object.keys(message.extraParams);
24
24
  for (const name in values) {
25
- if (existingKeys.indexOf(name) !== -1 && !this._overrideExisting) {
25
+ if (existingKeys.includes(name) && !this._overrideExisting) {
26
26
  continue;
27
27
  }
28
28
  message.extraParams[name] = values[name];
@@ -21,7 +21,7 @@ export class ValuesEnricher {
21
21
  message.extraParams = message.extraParams || {};
22
22
  const existingKeys = Object.keys(message.extraParams);
23
23
  for (const name in this._values) {
24
- if (existingKeys.indexOf(name) !== -1 && !this._overrideExisting) {
24
+ if (existingKeys.includes(name) && !this._overrideExisting) {
25
25
  continue;
26
26
  }
27
27
  message.extraParams[name] = this._values[name];
@@ -129,9 +129,7 @@ export class Logger {
129
129
  message: (record.message ?? record.Message),
130
130
  stack: (record.stack ?? record.Stack ?? record.stackTrace ?? record.StackTrace),
131
131
  };
132
- if (r.message === undefined) {
133
- r.message = JSON.stringify(error);
134
- }
132
+ r.message ??= JSON.stringify(error);
135
133
  return r;
136
134
  }
137
135
  default: {
@@ -54,7 +54,7 @@ export class XhrReporter {
54
54
  */
55
55
  async [Symbol.asyncDispose]() {
56
56
  if (this._disposed) {
57
- return Promise.resolve();
57
+ return;
58
58
  }
59
59
  await (this._reportActionPromise ?? this._processMessages());
60
60
  this._disposed = true;
@@ -64,13 +64,13 @@ export class PubSubHub {
64
64
  if (!handler) {
65
65
  throw new Error("Invalid handler.");
66
66
  }
67
- let subTrackers = this._subscriptions.get(topic);
68
- if (!subTrackers) {
69
- subTrackers = new Map();
70
- this._subscriptions.set(structuredClone(topic), subTrackers);
67
+ let subscriptionTrackers = this._subscriptions.get(topic);
68
+ if (!subscriptionTrackers) {
69
+ subscriptionTrackers = new Map();
70
+ this._subscriptions.set(structuredClone(topic), subscriptionTrackers);
71
71
  }
72
- const subscriptionId = `sub-${Date.now()}`;
73
- subTrackers.set(subscriptionId, { handler: handler, timeouts: [] });
72
+ const subscriptionId = `sub-${Date.now()}-${Math.random().toString(16).slice(2)}`; // NOSONAR S2245 Non-cryptographic randomness is acceptable here
73
+ subscriptionTrackers.set(subscriptionId, { handler: handler, timeouts: [] });
74
74
  return subscriptionId;
75
75
  }
76
76
  /** @inheritdoc */
@@ -78,8 +78,8 @@ export class PubSubHub {
78
78
  if (!subscriptionId) {
79
79
  return;
80
80
  }
81
- for (const subTrackers of this._subscriptions.values()) {
82
- for (const tracker of subTrackers.values()) {
81
+ for (const subscriptionTrackers of this._subscriptions.values()) {
82
+ for (const tracker of subscriptionTrackers.values()) {
83
83
  while (true) {
84
84
  const timeout = tracker.timeouts.pop();
85
85
  if (!timeout) {
@@ -88,7 +88,7 @@ export class PubSubHub {
88
88
  clearTimeoutRef(tracker, timeout);
89
89
  }
90
90
  }
91
- if (subTrackers.delete(subscriptionId)) {
91
+ if (subscriptionTrackers.delete(subscriptionId)) {
92
92
  return;
93
93
  }
94
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adapt-arch/utiliti-es",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "license": "MIT",
5
5
  "description": "ECMAScript common utilities library",
6
6
  "keywords": [
@@ -51,16 +51,16 @@
51
51
  "docs:preview": "vitepress preview docs"
52
52
  },
53
53
  "devDependencies": {
54
- "@biomejs/biome": "2.2.6",
55
- "@types/node": "24.7.2",
56
- "@vitest/coverage-v8": "3.2.4",
57
- "jsdom": "27.0.0",
58
- "msw": "2.11.5",
54
+ "@biomejs/biome": "2.3.4",
55
+ "@types/node": "24.10.0",
56
+ "@vitest/coverage-v8": "4.0.8",
57
+ "jsdom": "27.1.0",
58
+ "msw": "2.12.0",
59
59
  "typedoc": "0.28.14",
60
60
  "typescript": "5.9.3",
61
- "vite": "7.1.9",
61
+ "vite": "7.2.2",
62
62
  "vitepress": "1.6.4",
63
- "vitest": "3.2.4"
63
+ "vitest": "4.0.8"
64
64
  },
65
65
  "msw": {
66
66
  "workerDirectory": [