@gjsify/diagnostics_channel 0.3.19 → 0.3.21
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/lib/esm/index.js +1 -1
- package/package.json +3 -3
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new Map;var
|
|
1
|
+
const e=new Map;var Channel=class{name;_subscribers=[];constructor(e){this.name=e}get hasSubscribers(){return this._subscribers.length>0}publish(e){if(this._subscribers.length===0)return;let t=this._subscribers;for(let n=0;n<t.length;n++)try{t[n](e,this.name)}catch(e){Promise.resolve().then(()=>{throw e})}}subscribe(e){if(typeof e!=`function`)throw TypeError(`The "subscription" argument must be of type function`);this._subscribers=[...this._subscribers,e]}unsubscribe(e){let t=this._subscribers.indexOf(e);return t===-1?!1:(this._subscribers=[...this._subscribers.slice(0,t),...this._subscribers.slice(t+1)],!0)}runStores(e,t,n,...r){return this.publish(e),t.apply(n,r)}bindStore(e,t){}unbindStore(e){}};function channel(t){if(typeof t!=`string`&&typeof t!=`symbol`)throw TypeError(`The "channel" argument must be of type string or symbol`);let n=e.get(t);return n||(n=new Channel(t),e.set(t,n)),n}function hasSubscribers(t){let n=e.get(t);return n?n.hasSubscribers:!1}function subscribe(e,t){channel(e).subscribe(t)}function unsubscribe(e,t){return channel(e).unsubscribe(t)}var TracingChannel=class{start;end;asyncStart;asyncEnd;error;constructor(e){if(typeof e==`string`){let t=e;this.start=channel(`tracing:${t}:start`),this.end=channel(`tracing:${t}:end`),this.asyncStart=channel(`tracing:${t}:asyncStart`),this.asyncEnd=channel(`tracing:${t}:asyncEnd`),this.error=channel(`tracing:${t}:error`)}else if(typeof e==`object`&&e){for(let t of[`start`,`end`,`asyncStart`,`asyncEnd`,`error`])if(!(e[t]instanceof Channel))throw TypeError(`The "nameOrChannels.${t}" property must be an instance of Channel`);this.start=e.start,this.end=e.end,this.asyncStart=e.asyncStart,this.asyncEnd=e.asyncEnd,this.error=e.error}else throw TypeError(`The "nameOrChannels" argument must be of type string or an instance of TracingChannel or Object`)}get hasSubscribers(){return this.start.hasSubscribers||this.end.hasSubscribers||this.asyncStart.hasSubscribers||this.asyncEnd.hasSubscribers||this.error.hasSubscribers}subscribe(e){e.start&&this.start.subscribe(e.start),e.end&&this.end.subscribe(e.end),e.asyncStart&&this.asyncStart.subscribe(e.asyncStart),e.asyncEnd&&this.asyncEnd.subscribe(e.asyncEnd),e.error&&this.error.subscribe(e.error)}unsubscribe(e){let t=!0;return e.start&&!this.start.unsubscribe(e.start)&&(t=!1),e.end&&!this.end.unsubscribe(e.end)&&(t=!1),e.asyncStart&&!this.asyncStart.unsubscribe(e.asyncStart)&&(t=!1),e.asyncEnd&&!this.asyncEnd.unsubscribe(e.asyncEnd)&&(t=!1),e.error&&!this.error.unsubscribe(e.error)&&(t=!1),t}traceSync(e,t={},n,...r){if(!this.hasSubscribers)return e.apply(n,r);let{start:i,end:a,error:o}=this;i.publish(t);try{let i=e.apply(n,r);return t.result=i,i}catch(e){throw t.error=e,o.publish(t),e}finally{a.publish(t)}}tracePromise(e,t={},n,...r){if(!this.hasSubscribers)return e.apply(n,r);let{start:i,end:a,asyncStart:o,asyncEnd:s,error:c}=this;function resolve(e){return t.result=e,o.publish(t),s.publish(t),e}function reject(e){throw t.error=e,c.publish(t),o.publish(t),s.publish(t),e}i.publish(t);try{let i=e.apply(n,r);return typeof i?.then==`function`?i.then(resolve,reject):(t.result=i,i)}catch(e){throw t.error=e,c.publish(t),e}finally{a.publish(t)}}traceCallback(e,t=-1,n={},r,...i){if(!this.hasSubscribers)return e.apply(r,i);let{start:a,end:o,asyncStart:s,asyncEnd:c,error:l}=this,u=t<0?i.length+t:t,d=i[u];if(typeof d!=`function`)throw TypeError(`The "callback" argument must be of type function`);function wrappedCallback(e,t){e?(n.error=e,l.publish(n)):n.result=t,s.publish(n);try{return d.apply(this,arguments)}finally{c.publish(n)}}let f=[...i];f[u]=wrappedCallback,a.publish(n);try{return e.apply(r,f)}catch(e){throw n.error=e,l.publish(n),e}finally{o.publish(n)}}};function tracingChannel(e){return new TracingChannel(e)}var t={Channel,channel,hasSubscribers,subscribe,unsubscribe,TracingChannel,tracingChannel};export{Channel,TracingChannel,channel,t as default,hasSubscribers,subscribe,tracingChannel,unsubscribe};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/diagnostics_channel",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.21",
|
|
4
4
|
"description": "Node.js diagnostics_channel module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"diagnostics_channel"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@gjsify/cli": "^0.3.
|
|
34
|
-
"@gjsify/unit": "^0.3.
|
|
33
|
+
"@gjsify/cli": "^0.3.21",
|
|
34
|
+
"@gjsify/unit": "^0.3.21",
|
|
35
35
|
"@types/node": "^25.6.2",
|
|
36
36
|
"typescript": "^6.0.3"
|
|
37
37
|
}
|