@adapt-arch/utiliti-es 0.2.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/utiliti-es.cjs +1 -1
- package/dist/bundle/utiliti-es.iife.js +1 -1
- package/dist/bundle/utiliti-es.js +106 -105
- package/dist/bundle/utiliti-es.umd.cjs +1 -1
- package/dist/common/index.d.ts +1 -1
- package/dist/logger/contracts.d.ts +44 -0
- package/dist/logger/enrichers/dynamicValuesEnricher.d.ts +2 -2
- package/dist/logger/enrichers/valuesEnricher.d.ts +2 -2
- package/dist/logger/logger.d.ts +12 -33
- package/dist/logger/logger.js +9 -30
- package/dist/logger/reporters/consoleReporter.d.ts +1 -1
- package/dist/logger/reporters/inMemoryReporter.d.ts +1 -1
- package/dist/logger/reporters/multipleReporter.d.ts +1 -1
- package/dist/logger/reporters/xhrReporter.d.ts +2 -2
- package/dist/pubsub/plugins/broadcastChannelPlugin.d.ts +2 -2
- package/dist/pubsub/plugins/loggerPlugin.d.ts +4 -4
- package/dist/pubsub/pubsub.d.ts +1 -1
- package/dist/pubsub/pubsub.js +36 -13
- package/dist/utils/delay.d.ts +7 -0
- package/dist/utils/delay.js +12 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +16 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var b=(o,e,s)=>e in o?d(o,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[e]=s;var i=(o,e,s)=>b(o,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=(o,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=o.timeouts.indexOf(e);o.timeouts.splice(s,1)};class v{constructor(e){i(this,"_subscriptions",new Map);i(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const t of this._options.plugins)t.init&&t.init(this)}publish(e,s){var n;const t={topic:e,message:s};if((n=this._options)!=null&&n.plugins)for(const c of this._options.plugins)c.onPublish&&c.onPublish(t);if(!t.topic)throw new Error("Invalid topic.");if(!t.message)throw new Error("Invalid message.");const r=this._subscriptions.get(t.topic);if(r)for(const c of r.values()){const l={};c.timeouts.push(l),l.ref=setTimeout((p,_,m,f)=>{p.handler(m,f),u(c,_)},0,c,l,structuredClone(t.topic),structuredClone(t.message))}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let t=this._subscriptions.get(e);t||(t=new Map,this._subscriptions.set(structuredClone(e),t));const r=`sub-${Date.now()}`;return t.set(r,{handler:s,timeouts:[]}),r}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const t of s.values())for(;;){const r=t.timeouts.pop();if(!r)break;u(t,r)}if(s.delete(e))return}}[Symbol.dispose](){var e;for(const s of this._subscriptions.values())for(const t of s.keys())this.unsubscribe(t);if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const t=s[Symbol.dispose];t&&t.call(s)}return Promise.resolve()}}class L{constructor(e){i(this,"_options");i(this,"_channel");i(this,"_eventListeners",null);i(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const t=s.data;if(!(!t.topic||!t.message))try{this._broadcastEnabled=!1,e.publish(t.topic,t.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class y{constructor(e,s){i(this,"_values");i(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const t in this._values)s.indexOf(t)!==-1&&!this._overrideExisting||(e.extraParams[t]=this._values[t])}}class P{constructor(e,s){i(this,"_valuesFn");i(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const t=Object.keys(e.extraParams);for(const r in s)t.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}exports.LogLevel=void 0;(function(o){o[o.Trace=0]="Trace",o[o.Debug=1]="Debug",o[o.Information=2]="Information",o[o.Warning=3]="Warning",o[o.Error=4]="Error",o[o.Critical=5]="Critical",o[o.None=6]="None"})(exports.LogLevel||(exports.LogLevel={}));class a{constructor(){i(this,"timestamp",new Date().getTime());i(this,"level",exports.LogLevel.None);i(this,"name","");i(this,"message","");i(this,"errorMessage");i(this,"stackTrace");i(this,"extraParams")}}class T{constructor(e){i(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case exports.LogLevel.Trace:s=this._console.trace||this._console.log;break;case exports.LogLevel.Debug:s=this._console.debug||this._console.log;break;case exports.LogLevel.Information:s=this._console.info||this._console.log;break;case exports.LogLevel.Warning:s=this._console.warn||this._console.log;break;case exports.LogLevel.Error:s=this._console.error||this._console.log;break;case exports.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class w{constructor(){i(this,"endpoint","");i(this,"verb","POST");i(this,"batchSize",20);i(this,"interval",2e3);i(this,"requestTransform")}}class E{constructor(e){i(this,"_messageQueue");i(this,"_options");i(this,"_reportActionTimeoutRef");i(this,"_reportActionPromise");i(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const t=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=t,r.onabort=t,r.send(JSON.stringify(e))})}}class M{constructor(){i(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class R{constructor(e){i(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class x{constructor(e){i(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const t of this._options.enrichers)t.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==exports.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new a;s.level=exports.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new a;s.level=exports.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new a;s.level=exports.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new a;s.level=exports.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new a;s.level=exports.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new a;s.level=exports.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,t,r){const n=new a;n.level=e,n.message=s,n.errorMessage=t==null?void 0:t.message,n.stackTrace=t==null?void 0:t.stack,n.extraParams=r,this.logMessage(n)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class k{constructor(){i(this,"name","");i(this,"reporter",null);i(this,"minimumLevel",exports.LogLevel.Warning);i(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return exports.LogLevel.Trace;case"DEBUG":return exports.LogLevel.Debug;case"INFORMATION":return exports.LogLevel.Information;case"WARNING":return exports.LogLevel.Warning;case"ERROR":return exports.LogLevel.Error;case"CRITICAL":return exports.LogLevel.Critical;case"NONE":return exports.LogLevel.None;default:return exports.LogLevel.None}}}class A{constructor(e,s=exports.LogLevel.Information){i(this,"_logger");i(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function h(o=1,e){return new Promise((s,t)=>{setTimeout(()=>{e?t(e):s()},o)})}function g(o=1){return o<=0?Promise.resolve():h(0).then(()=>g(o-1))}exports.BroadcastChannelPlugin=L;exports.ConsoleReporter=T;exports.DynamicValuesEnricher=P;exports.InMemoryReporter=M;exports.LogMessage=a;exports.Logger=x;exports.LoggerOptions=k;exports.LoggerPlugin=A;exports.MultipleReporter=R;exports.PubSubHub=v;exports.ValuesEnricher=y;exports.XhrReporter=E;exports.XhrReporterOptions=w;exports.delay=h;exports.nextTicks=g;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var adaptArch_utilitiEs=function(t){"use strict";var
|
|
1
|
+
var adaptArch_utilitiEs=function(t){"use strict";var C=Object.defineProperty;var S=(t,a,u)=>a in t?C(t,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[a]=u;var o=(t,a,u)=>S(t,typeof a!="symbol"?a+"":a,u);const a=(n,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=n.timeouts.indexOf(e);n.timeouts.splice(s,1)};class u{constructor(e){o(this,"_subscriptions",new Map);o(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const i of this._options.plugins)i.init&&i.init(this)}publish(e,s){var c;const i={topic:e,message:s};if((c=this._options)!=null&&c.plugins)for(const h of this._options.plugins)h.onPublish&&h.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const r=this._subscriptions.get(i.topic);if(r)for(const h of r.values()){const g={};h.timeouts.push(g),g.ref=setTimeout((M,R,k,A)=>{M.handler(k,A),a(h,R)},0,h,g,structuredClone(i.topic),structuredClone(i.message))}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let i=this._subscriptions.get(e);i||(i=new Map,this._subscriptions.set(structuredClone(e),i));const r=`sub-${Date.now()}`;return i.set(r,{handler:s,timeouts:[]}),r}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const i of s.values())for(;;){const r=i.timeouts.pop();if(!r)break;a(i,r)}if(s.delete(e))return}}[Symbol.dispose](){var e;for(const s of this._subscriptions.values())for(const i of s.keys())this.unsubscribe(i);if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const i=s[Symbol.dispose];i&&i.call(s)}return Promise.resolve()}}class f{constructor(e){o(this,"_options");o(this,"_channel");o(this,"_eventListeners",null);o(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const i=s.data;if(!(!i.topic||!i.message))try{this._broadcastEnabled=!1,e.publish(i.topic,i.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class p{constructor(e,s){o(this,"_values");o(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const i in this._values)s.indexOf(i)!==-1&&!this._overrideExisting||(e.extraParams[i]=this._values[i])}}class d{constructor(e,s){o(this,"_valuesFn");o(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const i=Object.keys(e.extraParams);for(const r in s)i.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}t.LogLevel=void 0,function(n){n[n.Trace=0]="Trace",n[n.Debug=1]="Debug",n[n.Information=2]="Information",n[n.Warning=3]="Warning",n[n.Error=4]="Error",n[n.Critical=5]="Critical",n[n.None=6]="None"}(t.LogLevel||(t.LogLevel={}));class l{constructor(){o(this,"timestamp",new Date().getTime());o(this,"level",t.LogLevel.None);o(this,"name","");o(this,"message","");o(this,"errorMessage");o(this,"stackTrace");o(this,"extraParams")}}class b{constructor(e){o(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case t.LogLevel.Trace:s=this._console.trace||this._console.log;break;case t.LogLevel.Debug:s=this._console.debug||this._console.log;break;case t.LogLevel.Information:s=this._console.info||this._console.log;break;case t.LogLevel.Warning:s=this._console.warn||this._console.log;break;case t.LogLevel.Error:s=this._console.error||this._console.log;break;case t.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class v{constructor(){o(this,"endpoint","");o(this,"verb","POST");o(this,"batchSize",20);o(this,"interval",2e3);o(this,"requestTransform")}}class L{constructor(e){o(this,"_messageQueue");o(this,"_options");o(this,"_reportActionTimeoutRef");o(this,"_reportActionPromise");o(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const i=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=i,r.onabort=i,r.send(JSON.stringify(e))})}}class y{constructor(){o(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class P{constructor(e){o(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class T{constructor(e){o(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const i of this._options.enrichers)i.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new l;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new l;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new l;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new l;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new l;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new l;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,r){const c=new l;c.level=e,c.message=s,c.errorMessage=i==null?void 0:i.message,c.stackTrace=i==null?void 0:i.stack,c.extraParams=r,this.logMessage(c)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class w{constructor(){o(this,"name","");o(this,"reporter",null);o(this,"minimumLevel",t.LogLevel.Warning);o(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return t.LogLevel.Trace;case"DEBUG":return t.LogLevel.Debug;case"INFORMATION":return t.LogLevel.Information;case"WARNING":return t.LogLevel.Warning;case"ERROR":return t.LogLevel.Error;case"CRITICAL":return t.LogLevel.Critical;case"NONE":return t.LogLevel.None;default:return t.LogLevel.None}}}class E{constructor(e,s=t.LogLevel.Information){o(this,"_logger");o(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function _(n=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},n)})}function m(n=1){return n<=0?Promise.resolve():_(0).then(()=>m(n-1))}return t.BroadcastChannelPlugin=f,t.ConsoleReporter=b,t.DynamicValuesEnricher=d,t.InMemoryReporter=y,t.LogMessage=l,t.Logger=T,t.LoggerOptions=w,t.LoggerPlugin=E,t.MultipleReporter=P,t.PubSubHub=u,t.ValuesEnricher=p,t.XhrReporter=L,t.XhrReporterOptions=v,t.delay=_,t.nextTicks=m,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({});
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
var f = Object.defineProperty;
|
|
2
|
+
var d = (i, s, e) => s in i ? f(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
|
|
3
|
+
var r = (i, s, e) => d(i, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
const h = (i, s) => {
|
|
5
|
+
clearTimeout(s.ref), s.ref = void 0;
|
|
6
|
+
const e = i.timeouts.indexOf(s);
|
|
7
|
+
i.timeouts.splice(e, 1);
|
|
8
|
+
};
|
|
9
|
+
class y {
|
|
5
10
|
/**
|
|
6
11
|
*
|
|
7
12
|
*/
|
|
8
13
|
constructor(s) {
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
r(this, "_subscriptions", /* @__PURE__ */ new Map());
|
|
15
|
+
r(this, "_options");
|
|
11
16
|
var e;
|
|
12
17
|
if (this._options = s, (e = this._options) != null && e.plugins)
|
|
13
18
|
for (const t of this._options.plugins)
|
|
@@ -30,8 +35,10 @@ class m {
|
|
|
30
35
|
const n = this._subscriptions.get(t.topic);
|
|
31
36
|
if (n)
|
|
32
37
|
for (const l of n.values()) {
|
|
33
|
-
const
|
|
34
|
-
|
|
38
|
+
const u = {};
|
|
39
|
+
l.timeouts.push(u), u.ref = setTimeout((p, _, g, m) => {
|
|
40
|
+
p.handler(g, m), h(l, _);
|
|
41
|
+
}, 0, l, u, structuredClone(t.topic), structuredClone(t.message));
|
|
35
42
|
}
|
|
36
43
|
}
|
|
37
44
|
/** @inheritdoc */
|
|
@@ -43,18 +50,28 @@ class m {
|
|
|
43
50
|
let t = this._subscriptions.get(s);
|
|
44
51
|
t || (t = /* @__PURE__ */ new Map(), this._subscriptions.set(structuredClone(s), t));
|
|
45
52
|
const n = `sub-${Date.now()}`;
|
|
46
|
-
return t.set(n, e), n;
|
|
53
|
+
return t.set(n, { handler: e, timeouts: [] }), n;
|
|
47
54
|
}
|
|
48
55
|
/** @inheritdoc */
|
|
49
56
|
unsubscribe(s) {
|
|
50
|
-
if (s)
|
|
51
|
-
for (const e of this._subscriptions.values())
|
|
57
|
+
if (s)
|
|
58
|
+
for (const e of this._subscriptions.values()) {
|
|
59
|
+
for (const t of e.values())
|
|
60
|
+
for (; ; ) {
|
|
61
|
+
const n = t.timeouts.pop();
|
|
62
|
+
if (!n)
|
|
63
|
+
break;
|
|
64
|
+
h(t, n);
|
|
65
|
+
}
|
|
52
66
|
if (e.delete(s))
|
|
53
67
|
return;
|
|
54
|
-
|
|
68
|
+
}
|
|
55
69
|
}
|
|
56
70
|
[Symbol.dispose]() {
|
|
57
71
|
var s;
|
|
72
|
+
for (const e of this._subscriptions.values())
|
|
73
|
+
for (const t of e.keys())
|
|
74
|
+
this.unsubscribe(t);
|
|
58
75
|
if (this._subscriptions.clear(), (s = this._options) != null && s.plugins)
|
|
59
76
|
for (const e of this._options.plugins) {
|
|
60
77
|
const t = e[Symbol.dispose];
|
|
@@ -63,17 +80,17 @@ class m {
|
|
|
63
80
|
return Promise.resolve();
|
|
64
81
|
}
|
|
65
82
|
}
|
|
66
|
-
class
|
|
83
|
+
class P {
|
|
67
84
|
/**
|
|
68
85
|
* Constructor.
|
|
69
86
|
*
|
|
70
87
|
* @param {Options} options The options.
|
|
71
88
|
*/
|
|
72
89
|
constructor(s) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
r(this, "_options");
|
|
91
|
+
r(this, "_channel");
|
|
92
|
+
r(this, "_eventListeners", null);
|
|
93
|
+
r(this, "_broadcastEnabled", !0);
|
|
77
94
|
this._options = s, this._channel = new BroadcastChannel(this._options.channelName);
|
|
78
95
|
}
|
|
79
96
|
/** @inheritdoc */
|
|
@@ -102,7 +119,7 @@ class f {
|
|
|
102
119
|
this._eventListeners && this._channel.removeEventListener("message", this._eventListeners), this._channel.close();
|
|
103
120
|
}
|
|
104
121
|
}
|
|
105
|
-
class
|
|
122
|
+
class T {
|
|
106
123
|
/**
|
|
107
124
|
* Constructor.
|
|
108
125
|
*
|
|
@@ -110,8 +127,8 @@ class d {
|
|
|
110
127
|
* @param {boolean} overrideExisting Override a value if it already exists.
|
|
111
128
|
*/
|
|
112
129
|
constructor(s, e) {
|
|
113
|
-
|
|
114
|
-
|
|
130
|
+
r(this, "_values");
|
|
131
|
+
r(this, "_overrideExisting");
|
|
115
132
|
this._values = s, this._overrideExisting = e;
|
|
116
133
|
}
|
|
117
134
|
/**
|
|
@@ -126,7 +143,7 @@ class d {
|
|
|
126
143
|
e.indexOf(t) !== -1 && !this._overrideExisting || (s.extraParams[t] = this._values[t]);
|
|
127
144
|
}
|
|
128
145
|
}
|
|
129
|
-
class
|
|
146
|
+
class E {
|
|
130
147
|
/**
|
|
131
148
|
* Constructor.
|
|
132
149
|
*
|
|
@@ -134,8 +151,8 @@ class b {
|
|
|
134
151
|
* @param {boolean} overrideExisting Override a value if it already exists.
|
|
135
152
|
*/
|
|
136
153
|
constructor(s, e) {
|
|
137
|
-
|
|
138
|
-
|
|
154
|
+
r(this, "_valuesFn");
|
|
155
|
+
r(this, "_overrideExisting");
|
|
139
156
|
this._valuesFn = s, this._overrideExisting = e;
|
|
140
157
|
}
|
|
141
158
|
/**
|
|
@@ -152,49 +169,49 @@ class b {
|
|
|
152
169
|
}
|
|
153
170
|
}
|
|
154
171
|
var o;
|
|
155
|
-
(function(
|
|
156
|
-
|
|
172
|
+
(function(i) {
|
|
173
|
+
i[i.Trace = 0] = "Trace", i[i.Debug = 1] = "Debug", i[i.Information = 2] = "Information", i[i.Warning = 3] = "Warning", i[i.Error = 4] = "Error", i[i.Critical = 5] = "Critical", i[i.None = 6] = "None";
|
|
157
174
|
})(o || (o = {}));
|
|
158
175
|
class c {
|
|
159
176
|
constructor() {
|
|
160
177
|
/**
|
|
161
178
|
* The timestamp of the log message.
|
|
162
179
|
*/
|
|
163
|
-
|
|
180
|
+
r(this, "timestamp", (/* @__PURE__ */ new Date()).getTime());
|
|
164
181
|
/**
|
|
165
182
|
* The level of the log message.
|
|
166
183
|
*/
|
|
167
|
-
|
|
184
|
+
r(this, "level", o.None);
|
|
168
185
|
/**
|
|
169
186
|
* The name of the logger.
|
|
170
187
|
*/
|
|
171
|
-
|
|
188
|
+
r(this, "name", "");
|
|
172
189
|
/**
|
|
173
190
|
* The message to log.
|
|
174
191
|
*/
|
|
175
|
-
|
|
192
|
+
r(this, "message", "");
|
|
176
193
|
/**
|
|
177
194
|
* The error message.
|
|
178
195
|
*/
|
|
179
|
-
|
|
196
|
+
r(this, "errorMessage");
|
|
180
197
|
/**
|
|
181
198
|
* The stack trace of the error.
|
|
182
199
|
*/
|
|
183
|
-
|
|
200
|
+
r(this, "stackTrace");
|
|
184
201
|
/**
|
|
185
202
|
* Any extra parameters to log.
|
|
186
203
|
*/
|
|
187
|
-
|
|
204
|
+
r(this, "extraParams");
|
|
188
205
|
}
|
|
189
206
|
}
|
|
190
|
-
class
|
|
207
|
+
class M {
|
|
191
208
|
/**
|
|
192
209
|
* Constructor.
|
|
193
210
|
*
|
|
194
211
|
* @param {Console} console The current console reference.
|
|
195
212
|
*/
|
|
196
213
|
constructor(s) {
|
|
197
|
-
|
|
214
|
+
r(this, "_console");
|
|
198
215
|
this._console = s;
|
|
199
216
|
}
|
|
200
217
|
/**
|
|
@@ -222,6 +239,7 @@ class v {
|
|
|
222
239
|
case o.Critical:
|
|
223
240
|
e = this._console.error || this._console.log;
|
|
224
241
|
break;
|
|
242
|
+
// case LogLevel.None: // Do not log.
|
|
225
243
|
default:
|
|
226
244
|
e = null;
|
|
227
245
|
break;
|
|
@@ -235,37 +253,37 @@ class v {
|
|
|
235
253
|
return Promise.resolve();
|
|
236
254
|
}
|
|
237
255
|
}
|
|
238
|
-
class
|
|
256
|
+
class x {
|
|
239
257
|
constructor() {
|
|
240
258
|
/**
|
|
241
259
|
* Endpoint that receives the logs.
|
|
242
260
|
*/
|
|
243
|
-
|
|
261
|
+
r(this, "endpoint", "");
|
|
244
262
|
/**
|
|
245
263
|
* HTTP verb used when calling the endpoint.
|
|
246
264
|
*/
|
|
247
|
-
|
|
265
|
+
r(this, "verb", "POST");
|
|
248
266
|
/**
|
|
249
267
|
* The number of items to send in a batch.
|
|
250
268
|
*/
|
|
251
|
-
|
|
269
|
+
r(this, "batchSize", 20);
|
|
252
270
|
/**
|
|
253
271
|
* The maximum interval, in milliseconds, to wait for the batch size to be achieved before reporting.
|
|
254
272
|
*/
|
|
255
|
-
|
|
273
|
+
r(this, "interval", 2e3);
|
|
256
274
|
/**
|
|
257
275
|
* A function that can be used to transform the request before sending it.
|
|
258
276
|
*/
|
|
259
|
-
|
|
277
|
+
r(this, "requestTransform");
|
|
260
278
|
}
|
|
261
279
|
}
|
|
262
|
-
class
|
|
280
|
+
class R {
|
|
263
281
|
constructor(s) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
282
|
+
r(this, "_messageQueue");
|
|
283
|
+
r(this, "_options");
|
|
284
|
+
r(this, "_reportActionTimeoutRef");
|
|
285
|
+
r(this, "_reportActionPromise");
|
|
286
|
+
r(this, "_disposed");
|
|
269
287
|
if (!s)
|
|
270
288
|
throw new Error('Argument "options" is required');
|
|
271
289
|
this._messageQueue = [], this._options = s, this._reportActionTimeoutRef = void 0, this._reportActionPromise = null, this._disposed = !1;
|
|
@@ -314,9 +332,9 @@ class y {
|
|
|
314
332
|
});
|
|
315
333
|
}
|
|
316
334
|
}
|
|
317
|
-
class
|
|
335
|
+
class k {
|
|
318
336
|
constructor() {
|
|
319
|
-
|
|
337
|
+
r(this, "_messages", []);
|
|
320
338
|
}
|
|
321
339
|
get messages() {
|
|
322
340
|
return this._messages.slice();
|
|
@@ -334,9 +352,9 @@ class P {
|
|
|
334
352
|
return Promise.resolve();
|
|
335
353
|
}
|
|
336
354
|
}
|
|
337
|
-
class
|
|
355
|
+
class A {
|
|
338
356
|
constructor(s) {
|
|
339
|
-
|
|
357
|
+
r(this, "_reporters");
|
|
340
358
|
this._reporters = s || [];
|
|
341
359
|
}
|
|
342
360
|
/**
|
|
@@ -356,14 +374,14 @@ class E {
|
|
|
356
374
|
s.length && await Promise.all(s);
|
|
357
375
|
}
|
|
358
376
|
}
|
|
359
|
-
class
|
|
377
|
+
class C {
|
|
360
378
|
/**
|
|
361
379
|
* Constructor.
|
|
362
380
|
*
|
|
363
381
|
* @param {LoggerOptions} options The logger options.
|
|
364
382
|
*/
|
|
365
383
|
constructor(s) {
|
|
366
|
-
|
|
384
|
+
r(this, "_options");
|
|
367
385
|
this._options = s;
|
|
368
386
|
}
|
|
369
387
|
/**
|
|
@@ -386,83 +404,62 @@ class T {
|
|
|
386
404
|
await ((s = this._options.reporter) == null ? void 0 : s[Symbol.asyncDispose]());
|
|
387
405
|
}
|
|
388
406
|
/**
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* @param {LogLevel} level The log level.
|
|
407
|
+
* @inheritdoc
|
|
392
408
|
*/
|
|
393
409
|
isEnabled(s) {
|
|
394
410
|
return s !== o.None && s >= this._options.minimumLevel;
|
|
395
411
|
}
|
|
396
412
|
/**
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
* @param msg The message to log.
|
|
413
|
+
* @inheritdoc
|
|
400
414
|
*/
|
|
401
415
|
trace(s) {
|
|
402
416
|
const e = new c();
|
|
403
417
|
e.level = o.Trace, e.message = s, this.logMessage(e);
|
|
404
418
|
}
|
|
405
419
|
/**
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
* @param msg The message to log.
|
|
420
|
+
* @inheritdoc
|
|
409
421
|
*/
|
|
410
422
|
debug(s) {
|
|
411
423
|
const e = new c();
|
|
412
424
|
e.level = o.Debug, e.message = s, this.logMessage(e);
|
|
413
425
|
}
|
|
414
426
|
/**
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
* @param msg The message to log.
|
|
427
|
+
* @inheritdoc
|
|
418
428
|
*/
|
|
419
429
|
info(s) {
|
|
420
430
|
const e = new c();
|
|
421
431
|
e.level = o.Information, e.message = s, this.logMessage(e);
|
|
422
432
|
}
|
|
423
433
|
/**
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
* @param msg The message to log.
|
|
434
|
+
* @inheritdoc
|
|
427
435
|
*/
|
|
428
436
|
warn(s) {
|
|
429
437
|
const e = new c();
|
|
430
438
|
e.level = o.Warning, e.message = s, this.logMessage(e);
|
|
431
439
|
}
|
|
432
440
|
/**
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* @param msg The message to log.
|
|
441
|
+
* @inheritdoc
|
|
436
442
|
*/
|
|
437
443
|
error(s) {
|
|
438
444
|
const e = new c();
|
|
439
445
|
e.level = o.Error, e.message = s, this.logMessage(e);
|
|
440
446
|
}
|
|
441
447
|
/**
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* @param msg The message to log.
|
|
448
|
+
* @inheritdoc
|
|
445
449
|
*/
|
|
446
450
|
crit(s) {
|
|
447
451
|
const e = new c();
|
|
448
452
|
e.level = o.Critical, e.message = s, this.logMessage(e);
|
|
449
453
|
}
|
|
450
454
|
/**
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
* @param {LogLevel} level The level to log the event.
|
|
454
|
-
* @param {String} message Custom message.
|
|
455
|
-
* @param {Error} e The error associated with the event.
|
|
456
|
-
* @param {ExtraParams} params Extra parameters.
|
|
455
|
+
* @inheritdoc
|
|
457
456
|
*/
|
|
458
457
|
log(s, e, t, n) {
|
|
459
458
|
const a = new c();
|
|
460
459
|
a.level = s, a.message = e, a.errorMessage = t == null ? void 0 : t.message, a.stackTrace = t == null ? void 0 : t.stack, a.extraParams = n, this.logMessage(a);
|
|
461
460
|
}
|
|
462
461
|
/**
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
* @param {LogMessage} message The message to log.
|
|
462
|
+
* @inheritdoc
|
|
466
463
|
*/
|
|
467
464
|
logMessage(s) {
|
|
468
465
|
this.isEnabled(s.level) && setTimeout(() => {
|
|
@@ -470,24 +467,24 @@ class T {
|
|
|
470
467
|
}, 1);
|
|
471
468
|
}
|
|
472
469
|
}
|
|
473
|
-
class
|
|
470
|
+
class I {
|
|
474
471
|
constructor() {
|
|
475
472
|
/**
|
|
476
473
|
* The name of the logger.
|
|
477
474
|
*/
|
|
478
|
-
|
|
475
|
+
r(this, "name", "");
|
|
479
476
|
/**
|
|
480
477
|
* The reporter for the messages.
|
|
481
478
|
*/
|
|
482
|
-
|
|
479
|
+
r(this, "reporter", null);
|
|
483
480
|
/**
|
|
484
481
|
* The minimum log level.
|
|
485
482
|
*/
|
|
486
|
-
|
|
483
|
+
r(this, "minimumLevel", o.Warning);
|
|
487
484
|
/**
|
|
488
485
|
* Log enrichers.
|
|
489
486
|
*/
|
|
490
|
-
|
|
487
|
+
r(this, "enrichers", []);
|
|
491
488
|
}
|
|
492
489
|
/**
|
|
493
490
|
* Get the LogLevel from a string value.
|
|
@@ -515,7 +512,7 @@ class M {
|
|
|
515
512
|
}
|
|
516
513
|
}
|
|
517
514
|
}
|
|
518
|
-
class
|
|
515
|
+
class N {
|
|
519
516
|
/**
|
|
520
517
|
* Constructor.
|
|
521
518
|
*
|
|
@@ -523,8 +520,8 @@ class R {
|
|
|
523
520
|
* @param {LogLevel} logLevel The log level.
|
|
524
521
|
*/
|
|
525
522
|
constructor(s, e = o.Information) {
|
|
526
|
-
|
|
527
|
-
|
|
523
|
+
r(this, "_logger");
|
|
524
|
+
r(this, "_logLevel");
|
|
528
525
|
this._logger = s, this._logLevel = e;
|
|
529
526
|
}
|
|
530
527
|
/** @inheritdoc */
|
|
@@ -535,27 +532,31 @@ class R {
|
|
|
535
532
|
});
|
|
536
533
|
}
|
|
537
534
|
}
|
|
538
|
-
function
|
|
535
|
+
function b(i = 1, s) {
|
|
539
536
|
return new Promise((e, t) => {
|
|
540
537
|
setTimeout(() => {
|
|
541
538
|
s ? t(s) : e();
|
|
542
|
-
},
|
|
539
|
+
}, i);
|
|
543
540
|
});
|
|
544
541
|
}
|
|
542
|
+
function v(i = 1) {
|
|
543
|
+
return i <= 0 ? Promise.resolve() : b(0).then(() => v(i - 1));
|
|
544
|
+
}
|
|
545
545
|
export {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
546
|
+
P as BroadcastChannelPlugin,
|
|
547
|
+
M as ConsoleReporter,
|
|
548
|
+
E as DynamicValuesEnricher,
|
|
549
|
+
k as InMemoryReporter,
|
|
550
550
|
o as LogLevel,
|
|
551
551
|
c as LogMessage,
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
552
|
+
C as Logger,
|
|
553
|
+
I as LoggerOptions,
|
|
554
|
+
N as LoggerPlugin,
|
|
555
|
+
A as MultipleReporter,
|
|
556
|
+
y as PubSubHub,
|
|
557
|
+
T as ValuesEnricher,
|
|
558
|
+
R as XhrReporter,
|
|
559
|
+
x as XhrReporterOptions,
|
|
560
|
+
b as delay,
|
|
561
|
+
v as nextTicks
|
|
561
562
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(t,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(t=typeof globalThis<"u"?globalThis:t||self,a(t.adaptArch_utilitiEs={}))})(this,function(t){"use strict";var
|
|
1
|
+
(function(t,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(t=typeof globalThis<"u"?globalThis:t||self,a(t.adaptArch_utilitiEs={}))})(this,function(t){"use strict";var C=Object.defineProperty;var S=(t,a,u)=>a in t?C(t,a,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[a]=u;var o=(t,a,u)=>S(t,typeof a!="symbol"?a+"":a,u);const a=(n,e)=>{clearTimeout(e.ref),e.ref=void 0;const s=n.timeouts.indexOf(e);n.timeouts.splice(s,1)};class u{constructor(e){o(this,"_subscriptions",new Map);o(this,"_options");var s;if(this._options=e,(s=this._options)!=null&&s.plugins)for(const i of this._options.plugins)i.init&&i.init(this)}publish(e,s){var c;const i={topic:e,message:s};if((c=this._options)!=null&&c.plugins)for(const h of this._options.plugins)h.onPublish&&h.onPublish(i);if(!i.topic)throw new Error("Invalid topic.");if(!i.message)throw new Error("Invalid message.");const r=this._subscriptions.get(i.topic);if(r)for(const h of r.values()){const g={};h.timeouts.push(g),g.ref=setTimeout((M,R,k,A)=>{M.handler(k,A),a(h,R)},0,h,g,structuredClone(i.topic),structuredClone(i.message))}}subscribe(e,s){if(!e)throw new Error("Invalid topic.");if(!s)throw new Error("Invalid handler.");let i=this._subscriptions.get(e);i||(i=new Map,this._subscriptions.set(structuredClone(e),i));const r=`sub-${Date.now()}`;return i.set(r,{handler:s,timeouts:[]}),r}unsubscribe(e){if(e)for(const s of this._subscriptions.values()){for(const i of s.values())for(;;){const r=i.timeouts.pop();if(!r)break;a(i,r)}if(s.delete(e))return}}[Symbol.dispose](){var e;for(const s of this._subscriptions.values())for(const i of s.keys())this.unsubscribe(i);if(this._subscriptions.clear(),(e=this._options)!=null&&e.plugins)for(const s of this._options.plugins){const i=s[Symbol.dispose];i&&i.call(s)}return Promise.resolve()}}class f{constructor(e){o(this,"_options");o(this,"_channel");o(this,"_eventListeners",null);o(this,"_broadcastEnabled",!0);this._options=e,this._channel=new BroadcastChannel(this._options.channelName)}init(e){this._eventListeners||(this._eventListeners=s=>{const i=s.data;if(!(!i.topic||!i.message))try{this._broadcastEnabled=!1,e.publish(i.topic,i.message)}finally{this._broadcastEnabled=!0}},this._channel.addEventListener("message",this._eventListeners))}onPublish(e){if(!this._broadcastEnabled||!e.topic||!e.message)return;const s={topic:e.topic,message:e.message};this._channel.postMessage(s)}[Symbol.dispose](){this._eventListeners&&this._channel.removeEventListener("message",this._eventListeners),this._channel.close()}}class p{constructor(e,s){o(this,"_values");o(this,"_overrideExisting");this._values=e,this._overrideExisting=s}enrich(e){if(!this._values)return;e.extraParams=e.extraParams||{};const s=Object.keys(e.extraParams);for(const i in this._values)s.indexOf(i)!==-1&&!this._overrideExisting||(e.extraParams[i]=this._values[i])}}class d{constructor(e,s){o(this,"_valuesFn");o(this,"_overrideExisting");this._valuesFn=e,this._overrideExisting=s}enrich(e){const s=typeof this._valuesFn=="function"?this._valuesFn():void 0;if(!s)return;e.extraParams=e.extraParams||{};const i=Object.keys(e.extraParams);for(const r in s)i.indexOf(r)!==-1&&!this._overrideExisting||(e.extraParams[r]=s[r])}}t.LogLevel=void 0,function(n){n[n.Trace=0]="Trace",n[n.Debug=1]="Debug",n[n.Information=2]="Information",n[n.Warning=3]="Warning",n[n.Error=4]="Error",n[n.Critical=5]="Critical",n[n.None=6]="None"}(t.LogLevel||(t.LogLevel={}));class l{constructor(){o(this,"timestamp",new Date().getTime());o(this,"level",t.LogLevel.None);o(this,"name","");o(this,"message","");o(this,"errorMessage");o(this,"stackTrace");o(this,"extraParams")}}class b{constructor(e){o(this,"_console");this._console=e}register(e){let s;if(this._console)switch(e.level){case t.LogLevel.Trace:s=this._console.trace||this._console.log;break;case t.LogLevel.Debug:s=this._console.debug||this._console.log;break;case t.LogLevel.Information:s=this._console.info||this._console.log;break;case t.LogLevel.Warning:s=this._console.warn||this._console.log;break;case t.LogLevel.Error:s=this._console.error||this._console.log;break;case t.LogLevel.Critical:s=this._console.error||this._console.log;break;default:s=null;break}typeof s=="function"&&s.call(this._console,e.message,e)}[Symbol.asyncDispose](){return Promise.resolve()}}class v{constructor(){o(this,"endpoint","");o(this,"verb","POST");o(this,"batchSize",20);o(this,"interval",2e3);o(this,"requestTransform")}}class L{constructor(e){o(this,"_messageQueue");o(this,"_options");o(this,"_reportActionTimeoutRef");o(this,"_reportActionPromise");o(this,"_disposed");if(!e)throw new Error('Argument "options" is required');this._messageQueue=[],this._options=e,this._reportActionTimeoutRef=void 0,this._reportActionPromise=null,this._disposed=!1}register(e){this._disposed||(this._messageQueue.push(e),this._scheduleNextProcessAction())}async[Symbol.asyncDispose](){if(this._disposed)return Promise.resolve();await(this._reportActionPromise??this._processMessages()),this._disposed=!0}_scheduleNextProcessAction(){if(this._reportActionTimeoutRef)return;const e=this._messageQueue.length>=this._options.batchSize?0:this._options.interval;this._reportActionTimeoutRef=setTimeout(()=>{this._reportActionPromise=this._processMessages().then(()=>{const s=this._reportActionTimeoutRef;this._reportActionTimeoutRef=void 0,clearTimeout(s),this._reportActionPromise=null,this._scheduleNextProcessAction()})},e)}async _processMessages(){let e,s;for(;this._messageQueue.length>0;)if(e=this._messageQueue.splice(0,Math.min(this._messageQueue.length,this._options.batchSize)),s=await this._sendMessagesBatch(e),!s){this._messageQueue.unshift(...e);return}}_sendMessagesBatch(e){return new Promise(s=>{const i=()=>{s(!1)},r=new XMLHttpRequest;r.open(this._options.verb,this._options.endpoint),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),this._options.requestTransform&&this._options.requestTransform(r),r.onload=function(){s(this.status>=200&&this.status<300)},r.onerror=i,r.onabort=i,r.send(JSON.stringify(e))})}}class y{constructor(){o(this,"_messages",[])}get messages(){return this._messages.slice()}register(e){this._messages.push(e)}[Symbol.asyncDispose](){return Promise.resolve()}}class P{constructor(e){o(this,"_reporters");this._reporters=e||[]}register(e){for(const s of this._reporters)s.register(e)}async[Symbol.asyncDispose](){const e=new Array;for(const s of this._reporters)e.push(s[Symbol.asyncDispose]());e.length&&await Promise.all(e)}}class T{constructor(e){o(this,"_options");this._options=e}logMessageCore(e){var s;e.name=this._options.name;for(const i of this._options.enrichers)i.enrich(e);(s=this._options.reporter)==null||s.register(e)}async[Symbol.asyncDispose](){var e;await((e=this._options.reporter)==null?void 0:e[Symbol.asyncDispose]())}isEnabled(e){return e!==t.LogLevel.None&&e>=this._options.minimumLevel}trace(e){const s=new l;s.level=t.LogLevel.Trace,s.message=e,this.logMessage(s)}debug(e){const s=new l;s.level=t.LogLevel.Debug,s.message=e,this.logMessage(s)}info(e){const s=new l;s.level=t.LogLevel.Information,s.message=e,this.logMessage(s)}warn(e){const s=new l;s.level=t.LogLevel.Warning,s.message=e,this.logMessage(s)}error(e){const s=new l;s.level=t.LogLevel.Error,s.message=e,this.logMessage(s)}crit(e){const s=new l;s.level=t.LogLevel.Critical,s.message=e,this.logMessage(s)}log(e,s,i,r){const c=new l;c.level=e,c.message=s,c.errorMessage=i==null?void 0:i.message,c.stackTrace=i==null?void 0:i.stack,c.extraParams=r,this.logMessage(c)}logMessage(e){this.isEnabled(e.level)&&setTimeout(()=>{this.logMessageCore(e)},1)}}class w{constructor(){o(this,"name","");o(this,"reporter",null);o(this,"minimumLevel",t.LogLevel.Warning);o(this,"enrichers",[])}static getLevel(e){switch((e||"").toUpperCase()){case"TRACE":return t.LogLevel.Trace;case"DEBUG":return t.LogLevel.Debug;case"INFORMATION":return t.LogLevel.Information;case"WARNING":return t.LogLevel.Warning;case"ERROR":return t.LogLevel.Error;case"CRITICAL":return t.LogLevel.Critical;case"NONE":return t.LogLevel.None;default:return t.LogLevel.None}}}class E{constructor(e,s=t.LogLevel.Information){o(this,"_logger");o(this,"_logLevel");this._logger=e,this._logLevel=s}onPublish(e){this._logger.log(this._logLevel,`Publishing message to topic: ${e.topic}`,void 0,{topic:e.topic??null,message:e.message??null})}}function _(n=1,e){return new Promise((s,i)=>{setTimeout(()=>{e?i(e):s()},n)})}function m(n=1){return n<=0?Promise.resolve():_(0).then(()=>m(n-1))}t.BroadcastChannelPlugin=f,t.ConsoleReporter=b,t.DynamicValuesEnricher=d,t.InMemoryReporter=y,t.LogMessage=l,t.Logger=T,t.LoggerOptions=w,t.LoggerPlugin=E,t.MultipleReporter=P,t.PubSubHub=u,t.ValuesEnricher=p,t.XhrReporter=L,t.XhrReporterOptions=v,t.delay=_,t.nextTicks=m,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export type { SerializableValues } from "./contracts";
|
|
@@ -93,3 +93,47 @@ export interface ILogMessageEnricher {
|
|
|
93
93
|
*/
|
|
94
94
|
enrich(message: LogMessage): void;
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Logging service.
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* Interface for logging operations.
|
|
101
|
+
*/
|
|
102
|
+
export interface ILogger extends AsyncDisposable {
|
|
103
|
+
/**
|
|
104
|
+
* Indicates if the specified level will be logged.
|
|
105
|
+
*/
|
|
106
|
+
isEnabled(level: LogLevel): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Log trace.
|
|
109
|
+
*/
|
|
110
|
+
trace(msg: string): void;
|
|
111
|
+
/**
|
|
112
|
+
* Log debug.
|
|
113
|
+
*/
|
|
114
|
+
debug(msg: string): void;
|
|
115
|
+
/**
|
|
116
|
+
* Log information.
|
|
117
|
+
*/
|
|
118
|
+
info(msg: string): void;
|
|
119
|
+
/**
|
|
120
|
+
* Log warning.
|
|
121
|
+
*/
|
|
122
|
+
warn(msg: string): void;
|
|
123
|
+
/**
|
|
124
|
+
* Log error.
|
|
125
|
+
*/
|
|
126
|
+
error(msg: string): void;
|
|
127
|
+
/**
|
|
128
|
+
* Log critical.
|
|
129
|
+
*/
|
|
130
|
+
crit(msg: string): void;
|
|
131
|
+
/**
|
|
132
|
+
* Log an event.
|
|
133
|
+
*/
|
|
134
|
+
log(level: LogLevel, message: string, e?: Error, params?: ExtraParams): void;
|
|
135
|
+
/**
|
|
136
|
+
* Log a message.
|
|
137
|
+
*/
|
|
138
|
+
logMessage(message: LogMessage): void;
|
|
139
|
+
}
|
|
@@ -4,8 +4,8 @@ import type { ExtraParams, ILogMessageEnricher, LogMessage } from "../contracts"
|
|
|
4
4
|
*/
|
|
5
5
|
export type DynamicValuesFunction = () => ExtraParams;
|
|
6
6
|
export declare class DynamicValuesEnricher implements ILogMessageEnricher {
|
|
7
|
-
private _valuesFn;
|
|
8
|
-
private _overrideExisting;
|
|
7
|
+
private readonly _valuesFn;
|
|
8
|
+
private readonly _overrideExisting;
|
|
9
9
|
/**
|
|
10
10
|
* Constructor.
|
|
11
11
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtraParams, ILogMessageEnricher, LogMessage } from "../contracts";
|
|
2
2
|
export declare class ValuesEnricher implements ILogMessageEnricher {
|
|
3
|
-
private _values;
|
|
4
|
-
private _overrideExisting;
|
|
3
|
+
private readonly _values;
|
|
4
|
+
private readonly _overrideExisting;
|
|
5
5
|
/**
|
|
6
6
|
* Constructor.
|
|
7
7
|
*
|
package/dist/logger/logger.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type ExtraParams, LogLevel, LogMessage } from "./contracts";
|
|
1
|
+
import { type ExtraParams, type ILogger, LogLevel, LogMessage } from "./contracts";
|
|
2
2
|
import type { LoggerOptions } from "./loggerOptions";
|
|
3
3
|
/**
|
|
4
4
|
* Logging service.
|
|
5
5
|
*/
|
|
6
|
-
export declare class Logger implements
|
|
7
|
-
private _options;
|
|
6
|
+
export declare class Logger implements ILogger {
|
|
7
|
+
private readonly _options;
|
|
8
8
|
/**
|
|
9
9
|
* Constructor.
|
|
10
10
|
*
|
|
@@ -22,60 +22,39 @@ export declare class Logger implements AsyncDisposable {
|
|
|
22
22
|
*/
|
|
23
23
|
[Symbol.asyncDispose](): Promise<void>;
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param {LogLevel} level The log level.
|
|
25
|
+
* @inheritdoc
|
|
28
26
|
*/
|
|
29
27
|
isEnabled(level: LogLevel): boolean;
|
|
30
28
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* @param msg The message to log.
|
|
29
|
+
* @inheritdoc
|
|
34
30
|
*/
|
|
35
31
|
trace(msg: string): void;
|
|
36
32
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param msg The message to log.
|
|
33
|
+
* @inheritdoc
|
|
40
34
|
*/
|
|
41
35
|
debug(msg: string): void;
|
|
42
36
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @param msg The message to log.
|
|
37
|
+
* @inheritdoc
|
|
46
38
|
*/
|
|
47
39
|
info(msg: string): void;
|
|
48
40
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @param msg The message to log.
|
|
41
|
+
* @inheritdoc
|
|
52
42
|
*/
|
|
53
43
|
warn(msg: string): void;
|
|
54
44
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @param msg The message to log.
|
|
45
|
+
* @inheritdoc
|
|
58
46
|
*/
|
|
59
47
|
error(msg: string): void;
|
|
60
48
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* @param msg The message to log.
|
|
49
|
+
* @inheritdoc
|
|
64
50
|
*/
|
|
65
51
|
crit(msg: string): void;
|
|
66
52
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @param {LogLevel} level The level to log the event.
|
|
70
|
-
* @param {String} message Custom message.
|
|
71
|
-
* @param {Error} e The error associated with the event.
|
|
72
|
-
* @param {ExtraParams} params Extra parameters.
|
|
53
|
+
* @inheritdoc
|
|
73
54
|
*/
|
|
74
55
|
log(level: LogLevel, message: string, e?: Error, params?: ExtraParams): void;
|
|
75
56
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* @param {LogMessage} message The message to log.
|
|
57
|
+
* @inheritdoc
|
|
79
58
|
*/
|
|
80
59
|
logMessage(message: LogMessage): void;
|
|
81
60
|
}
|
package/dist/logger/logger.js
CHANGED
|
@@ -31,17 +31,13 @@ export class Logger {
|
|
|
31
31
|
await this._options.reporter?.[Symbol.asyncDispose]();
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @param {LogLevel} level The log level.
|
|
34
|
+
* @inheritdoc
|
|
37
35
|
*/
|
|
38
36
|
isEnabled(level) {
|
|
39
37
|
return level !== LogLevel.None && level >= this._options.minimumLevel;
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* @param msg The message to log.
|
|
40
|
+
* @inheritdoc
|
|
45
41
|
*/
|
|
46
42
|
trace(msg) {
|
|
47
43
|
const message = new LogMessage();
|
|
@@ -50,9 +46,7 @@ export class Logger {
|
|
|
50
46
|
this.logMessage(message);
|
|
51
47
|
}
|
|
52
48
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @param msg The message to log.
|
|
49
|
+
* @inheritdoc
|
|
56
50
|
*/
|
|
57
51
|
debug(msg) {
|
|
58
52
|
const message = new LogMessage();
|
|
@@ -61,9 +55,7 @@ export class Logger {
|
|
|
61
55
|
this.logMessage(message);
|
|
62
56
|
}
|
|
63
57
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @param msg The message to log.
|
|
58
|
+
* @inheritdoc
|
|
67
59
|
*/
|
|
68
60
|
info(msg) {
|
|
69
61
|
const message = new LogMessage();
|
|
@@ -72,9 +64,7 @@ export class Logger {
|
|
|
72
64
|
this.logMessage(message);
|
|
73
65
|
}
|
|
74
66
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @param msg The message to log.
|
|
67
|
+
* @inheritdoc
|
|
78
68
|
*/
|
|
79
69
|
warn(msg) {
|
|
80
70
|
const message = new LogMessage();
|
|
@@ -83,9 +73,7 @@ export class Logger {
|
|
|
83
73
|
this.logMessage(message);
|
|
84
74
|
}
|
|
85
75
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @param msg The message to log.
|
|
76
|
+
* @inheritdoc
|
|
89
77
|
*/
|
|
90
78
|
error(msg) {
|
|
91
79
|
const message = new LogMessage();
|
|
@@ -94,9 +82,7 @@ export class Logger {
|
|
|
94
82
|
this.logMessage(message);
|
|
95
83
|
}
|
|
96
84
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @param msg The message to log.
|
|
85
|
+
* @inheritdoc
|
|
100
86
|
*/
|
|
101
87
|
crit(msg) {
|
|
102
88
|
const message = new LogMessage();
|
|
@@ -105,12 +91,7 @@ export class Logger {
|
|
|
105
91
|
this.logMessage(message);
|
|
106
92
|
}
|
|
107
93
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* @param {LogLevel} level The level to log the event.
|
|
111
|
-
* @param {String} message Custom message.
|
|
112
|
-
* @param {Error} e The error associated with the event.
|
|
113
|
-
* @param {ExtraParams} params Extra parameters.
|
|
94
|
+
* @inheritdoc
|
|
114
95
|
*/
|
|
115
96
|
log(level, message, e, params) {
|
|
116
97
|
const msg = new LogMessage();
|
|
@@ -122,9 +103,7 @@ export class Logger {
|
|
|
122
103
|
this.logMessage(msg);
|
|
123
104
|
}
|
|
124
105
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @param {LogMessage} message The message to log.
|
|
106
|
+
* @inheritdoc
|
|
128
107
|
*/
|
|
129
108
|
logMessage(message) {
|
|
130
109
|
if (!this.isEnabled(message.level))
|
|
@@ -16,7 +16,7 @@ export interface IReporterConsole {
|
|
|
16
16
|
* Depending on the browser settings some messages might noy be output to the console.
|
|
17
17
|
*/
|
|
18
18
|
export declare class ConsoleReporter implements ILogsReporter {
|
|
19
|
-
private _console;
|
|
19
|
+
private readonly _console;
|
|
20
20
|
/**
|
|
21
21
|
* Constructor.
|
|
22
22
|
*
|
|
@@ -4,7 +4,7 @@ import type { ILogsReporter, LogMessage } from "../contracts";
|
|
|
4
4
|
* DO NOT user this in production. This is meant for unit tests.
|
|
5
5
|
*/
|
|
6
6
|
export declare class InMemoryReporter implements ILogsReporter {
|
|
7
|
-
private _messages;
|
|
7
|
+
private readonly _messages;
|
|
8
8
|
get messages(): LogMessage[];
|
|
9
9
|
/**
|
|
10
10
|
* @inheritdoc
|
|
@@ -3,7 +3,7 @@ import type { ILogsReporter, LogMessage } from "../contracts";
|
|
|
3
3
|
* An implementations that can report to multiple implementations of `ILogsReporter`.
|
|
4
4
|
*/
|
|
5
5
|
export declare class MultipleReporter implements ILogsReporter {
|
|
6
|
-
private _reporters;
|
|
6
|
+
private readonly _reporters;
|
|
7
7
|
constructor(reporters: ILogsReporter[]);
|
|
8
8
|
/**
|
|
9
9
|
* @inheritdoc
|
|
@@ -25,8 +25,8 @@ export declare class XhrReporterOptions {
|
|
|
25
25
|
requestTransform?: (request: XMLHttpRequest) => void;
|
|
26
26
|
}
|
|
27
27
|
export declare class XhrReporter implements ILogsReporter {
|
|
28
|
-
private _messageQueue;
|
|
29
|
-
private _options;
|
|
28
|
+
private readonly _messageQueue;
|
|
29
|
+
private readonly _options;
|
|
30
30
|
private _reportActionTimeoutRef;
|
|
31
31
|
private _reportActionPromise;
|
|
32
32
|
private _disposed;
|
|
@@ -11,8 +11,8 @@ export type Options = {
|
|
|
11
11
|
* A plugin to log messages.
|
|
12
12
|
*/
|
|
13
13
|
export declare class BroadcastChannelPlugin implements PubSubPlugin {
|
|
14
|
-
private _options;
|
|
15
|
-
private _channel;
|
|
14
|
+
private readonly _options;
|
|
15
|
+
private readonly _channel;
|
|
16
16
|
private _eventListeners;
|
|
17
17
|
private _broadcastEnabled;
|
|
18
18
|
/**
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ILogger, LogLevel } from "../../logger";
|
|
2
2
|
import type { PubSubPlugin, PubSubPluginContext } from "../pubsub";
|
|
3
3
|
/**
|
|
4
4
|
* A plugin to log messages.
|
|
5
5
|
*/
|
|
6
6
|
export declare class LoggerPlugin implements PubSubPlugin {
|
|
7
|
-
private _logger;
|
|
8
|
-
private _logLevel;
|
|
7
|
+
private readonly _logger;
|
|
8
|
+
private readonly _logLevel;
|
|
9
9
|
/**
|
|
10
10
|
* Constructor.
|
|
11
11
|
*
|
|
12
12
|
* @param {Logger} logger The logger.
|
|
13
13
|
* @param {LogLevel} logLevel The log level.
|
|
14
14
|
*/
|
|
15
|
-
constructor(logger:
|
|
15
|
+
constructor(logger: ILogger, logLevel?: LogLevel);
|
|
16
16
|
/** @inheritdoc */
|
|
17
17
|
onPublish(context: PubSubPluginContext): void;
|
|
18
18
|
}
|
package/dist/pubsub/pubsub.d.ts
CHANGED
package/dist/pubsub/pubsub.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
const clearTimeoutRef = (tracker, timeout) => {
|
|
2
|
+
clearTimeout(timeout.ref);
|
|
3
|
+
timeout.ref = undefined;
|
|
4
|
+
const ix = tracker.timeouts.indexOf(timeout);
|
|
5
|
+
tracker.timeouts.splice(ix, 1);
|
|
6
|
+
};
|
|
1
7
|
/**
|
|
2
8
|
* A PubSub implementation.
|
|
3
9
|
*/
|
|
@@ -38,12 +44,15 @@ export class PubSubHub {
|
|
|
38
44
|
if (!context.message) {
|
|
39
45
|
throw new Error("Invalid message.");
|
|
40
46
|
}
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
for (const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
setTimeout((
|
|
47
|
+
const subTrackers = this._subscriptions.get(context.topic);
|
|
48
|
+
if (subTrackers) {
|
|
49
|
+
for (const tracker of subTrackers.values()) {
|
|
50
|
+
const timeout = {};
|
|
51
|
+
tracker.timeouts.push(timeout);
|
|
52
|
+
timeout.ref = setTimeout((ctx, timeout, topic, message) => {
|
|
53
|
+
ctx.handler(topic, message);
|
|
54
|
+
clearTimeoutRef(tracker, timeout);
|
|
55
|
+
}, 0, tracker, timeout, structuredClone(context.topic), structuredClone(context.message));
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
58
|
}
|
|
@@ -55,13 +64,13 @@ export class PubSubHub {
|
|
|
55
64
|
if (!handler) {
|
|
56
65
|
throw new Error("Invalid handler.");
|
|
57
66
|
}
|
|
58
|
-
let
|
|
59
|
-
if (!
|
|
60
|
-
|
|
61
|
-
this._subscriptions.set(structuredClone(topic),
|
|
67
|
+
let subTrackers = this._subscriptions.get(topic);
|
|
68
|
+
if (!subTrackers) {
|
|
69
|
+
subTrackers = new Map();
|
|
70
|
+
this._subscriptions.set(structuredClone(topic), subTrackers);
|
|
62
71
|
}
|
|
63
72
|
const subscriptionId = `sub-${Date.now()}`;
|
|
64
|
-
|
|
73
|
+
subTrackers.set(subscriptionId, { handler: handler, timeouts: [] });
|
|
65
74
|
return subscriptionId;
|
|
66
75
|
}
|
|
67
76
|
/** @inheritdoc */
|
|
@@ -69,13 +78,27 @@ export class PubSubHub {
|
|
|
69
78
|
if (!subscriptionId) {
|
|
70
79
|
return;
|
|
71
80
|
}
|
|
72
|
-
for (const
|
|
73
|
-
|
|
81
|
+
for (const subTrackers of this._subscriptions.values()) {
|
|
82
|
+
for (const tracker of subTrackers.values()) {
|
|
83
|
+
while (true) {
|
|
84
|
+
const timeout = tracker.timeouts.pop();
|
|
85
|
+
if (!timeout) {
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
clearTimeoutRef(tracker, timeout);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (subTrackers.delete(subscriptionId)) {
|
|
74
92
|
return;
|
|
75
93
|
}
|
|
76
94
|
}
|
|
77
95
|
}
|
|
78
96
|
[Symbol.dispose]() {
|
|
97
|
+
for (const subTrackers of this._subscriptions.values()) {
|
|
98
|
+
for (const trackerId of subTrackers.keys()) {
|
|
99
|
+
this.unsubscribe(trackerId);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
79
102
|
this._subscriptions.clear();
|
|
80
103
|
if (this._options?.plugins) {
|
|
81
104
|
for (const plugin of this._options.plugins) {
|
package/dist/utils/delay.d.ts
CHANGED
|
@@ -6,3 +6,10 @@
|
|
|
6
6
|
* @returns {Promise<void>} A promise that resolves after a certain duration.
|
|
7
7
|
*/
|
|
8
8
|
export declare function delay(duration?: number, error?: Error): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Await the next {count} ticks.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} count The number of ticks to wait for.
|
|
13
|
+
* @returns {Promise<void>} A promise that resolves after a certain number of ticks.
|
|
14
|
+
*/
|
|
15
|
+
export declare function nextTicks(count?: number): Promise<void>;
|
package/dist/utils/delay.js
CHANGED
|
@@ -12,3 +12,15 @@ export function delay(duration = 1, error) {
|
|
|
12
12
|
}, duration);
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Await the next {count} ticks.
|
|
17
|
+
*
|
|
18
|
+
* @param {number} count The number of ticks to wait for.
|
|
19
|
+
* @returns {Promise<void>} A promise that resolves after a certain number of ticks.
|
|
20
|
+
*/
|
|
21
|
+
export function nextTicks(count = 1) {
|
|
22
|
+
if (count <= 0) {
|
|
23
|
+
return Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
return delay(0).then(() => nextTicks(count - 1));
|
|
26
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./delay";
|
package/dist/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./delay";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adapt-arch/utiliti-es",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ECMAScript common utilities library",
|
|
6
6
|
"keywords": [
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
|
-
"import": "./dist/bundle/utiliti-es.js",
|
|
27
|
-
"require": "./dist/bundle/utiliti-es.cjs",
|
|
28
26
|
"node": {
|
|
29
27
|
"import": {
|
|
30
28
|
"production": "./dist/bundle/utiliti-es.js",
|
|
31
29
|
"development": "./dist/index.js",
|
|
32
30
|
"default": "./dist/index.js"
|
|
33
31
|
}
|
|
34
|
-
}
|
|
32
|
+
},
|
|
33
|
+
"require": "./dist/bundle/utiliti-es.cjs",
|
|
34
|
+
"import": "./dist/bundle/utiliti-es.js"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|
|
@@ -45,28 +45,29 @@
|
|
|
45
45
|
"name": "Adaptive Architecture"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
|
+
"clean": "rm -rf ./node_modules/ && rm -rf ./package-lock.json",
|
|
48
49
|
"dev": "vite",
|
|
49
50
|
"empty-output": "node ./ci-cd/empty-output.js",
|
|
50
51
|
"build": "tsc && vite build",
|
|
51
52
|
"preview": "vite preview",
|
|
52
53
|
"prelint": "node ./ci-cd/empty-output.js",
|
|
53
|
-
"lint": "npx @biomejs/biome check --
|
|
54
|
+
"lint": "npx @biomejs/biome check --write ./",
|
|
54
55
|
"test": "vitest run --coverage",
|
|
55
56
|
"docs:dev": "typedoc && vitepress dev docs",
|
|
56
57
|
"docs:build": "typedoc && vitepress build docs",
|
|
57
58
|
"docs:preview": "vitepress preview docs"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@biomejs/biome": "1.
|
|
61
|
-
"@types/node": "
|
|
62
|
-
"@vitest/coverage-v8": "
|
|
63
|
-
"jsdom": "
|
|
64
|
-
"msw": "2.3
|
|
65
|
-
"typedoc": "0.
|
|
66
|
-
"typescript": "5.
|
|
67
|
-
"vite": "
|
|
68
|
-
"vitepress": "1.
|
|
69
|
-
"vitest": "
|
|
61
|
+
"@biomejs/biome": "1.9.4",
|
|
62
|
+
"@types/node": "22.13.10",
|
|
63
|
+
"@vitest/coverage-v8": "3.0.9",
|
|
64
|
+
"jsdom": "26.0.0",
|
|
65
|
+
"msw": "2.7.3",
|
|
66
|
+
"typedoc": "0.28.0",
|
|
67
|
+
"typescript": "5.8.2",
|
|
68
|
+
"vite": "6.2.2",
|
|
69
|
+
"vitepress": "1.6.3",
|
|
70
|
+
"vitest": "3.0.9"
|
|
70
71
|
},
|
|
71
72
|
"msw": {
|
|
72
73
|
"workerDirectory": [
|