@adapt-arch/utiliti-es 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var 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
+ "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 +1 @@
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
+ 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})({});