Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mortice

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mortice - npm Package Compare versions

Comparing version 3.0.4 to 3.0.5

2

dist/index.min.js
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Mortice = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Mortice=(()=>{var H=Object.create;var b=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),te=(r,e)=>{for(var t in e)b(r,t,{get:e[t],enumerable:!0})},M=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of X(e))!j.call(r,i)&&i!==t&&b(r,i,{get:()=>e[i],enumerable:!(n=J(e,i))||n.enumerable});return r};var re=(r,e,t)=>(t=r!=null?H(Z(r)):{},M(e||!r||!r.__esModule?b(t,"default",{value:r,enumerable:!0}):t,r)),ne=r=>M(b({},"__esModule",{value:!0}),r);var Q=ee((fe,I)=>{"use strict";var ie=Object.prototype.hasOwnProperty,d="~";function w(){}Object.create&&(w.prototype=Object.create(null),new w().__proto__||(d=!1));function se(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function D(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var a=new se(t,n||r,i),o=d?d+e:e;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],a]:r._events[o].push(a):(r._events[o]=a,r._eventsCount++),r}function x(r,e){--r._eventsCount===0?r._events=new w:delete r._events[e]}function h(){this._events=new w,this._eventsCount=0}h.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)ie.call(t,n)&&e.push(d?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};h.prototype.listeners=function(e){var t=d?d+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,o=new Array(a);i<a;i++)o[i]=n[i].fn;return o};h.prototype.listenerCount=function(e){var t=d?d+e:e,n=this._events[t];return n?n.fn?1:n.length:0};h.prototype.emit=function(e,t,n,i,a,o){var c=d?d+e:e;if(!this._events[c])return!1;var s=this._events[c],f=arguments.length,l,u;if(s.fn){switch(s.once&&this.removeListener(e,s.fn,void 0,!0),f){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,t),!0;case 3:return s.fn.call(s.context,t,n),!0;case 4:return s.fn.call(s.context,t,n,i),!0;case 5:return s.fn.call(s.context,t,n,i,a),!0;case 6:return s.fn.call(s.context,t,n,i,a,o),!0}for(u=1,l=new Array(f-1);u<f;u++)l[u-1]=arguments[u];s.fn.apply(s.context,l)}else{var m=s.length,_;for(u=0;u<m;u++)switch(s[u].once&&this.removeListener(e,s[u].fn,void 0,!0),f){case 1:s[u].fn.call(s[u].context);break;case 2:s[u].fn.call(s[u].context,t);break;case 3:s[u].fn.call(s[u].context,t,n);break;case 4:s[u].fn.call(s[u].context,t,n,i);break;default:if(!l)for(_=1,l=new Array(f-1);_<f;_++)l[_-1]=arguments[_];s[u].fn.apply(s[u].context,l)}}return!0};h.prototype.on=function(e,t,n){return D(this,e,t,n,!1)};h.prototype.once=function(e,t,n){return D(this,e,t,n,!0)};h.prototype.removeListener=function(e,t,n,i){var a=d?d+e:e;if(!this._events[a])return this;if(!t)return x(this,a),this;var o=this._events[a];if(o.fn)o.fn===t&&(!i||o.once)&&(!n||o.context===n)&&x(this,a);else{for(var c=0,s=[],f=o.length;c<f;c++)(o[c].fn!==t||i&&!o[c].once||n&&o[c].context!==n)&&s.push(o[c]);s.length?this._events[a]=s.length===1?s[0]:s:x(this,a)}return this};h.prototype.removeAllListeners=function(e){var t;return e?(t=d?d+e:e,this._events[t]&&x(this,t)):(this._events=new w,this._eventsCount=0),this};h.prototype.off=h.prototype.removeListener;h.prototype.addListener=h.prototype.on;h.prefixed=d;h.EventEmitter=h;typeof I<"u"&&(I.exports=h)});var le={};te(le,{default:()=>Y});var O=re(Q(),1);var L=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},C=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},$=r=>globalThis.DOMException===void 0?new C(r):new DOMException(r),F=r=>{let e=r.reason===void 0?$("This operation was aborted."):r.reason;return e instanceof Error?e:$(e)};function T(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:a={setTimeout,clearTimeout}}=e,o,s=new Promise((f,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&l(F(m)),m.addEventListener("abort",()=>{l(F(m))})}if(t===Number.POSITIVE_INFINITY){r.then(f,l);return}let u=new L;o=a.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?f():i instanceof Error?l(i):(u.message=i??`Promise timed out after ${t} milliseconds`,l(u))},t),(async()=>{try{f(await r)}catch(m){l(m)}})()}).finally(()=>{s.clear()});return s.clear=()=>{a.clearTimeout.call(void 0,o),o=void 0},s}function k(r,e,t){let n=0,i=r.length;for(;i>0;){let a=Math.trunc(i/2),o=n+a;t(r[o],e)<=0?(n=++o,i-=a+1):i=a}return n}var R=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let i=k(this.#e,n,(a,o)=>o.priority-a.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var v=class extends O.default{#e;#a;#s=0;#d;#o;#m=0;#r;#u;#t;#p;#n=0;#l;#i;#E;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:R,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#a=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#o=e.interval,this.#t=new e.queueClass,this.#p=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#E=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#g(){return this.#a||this.#s<this.#d}get#_(){return this.#n<this.#l}#w(){this.#n--,this.#c(),this.emit("next")}#L(){this.#v(),this.#y(),this.#u=void 0}get#T(){let e=Date.now();if(this.#r===void 0){let t=this.#m-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#L()},t)),!0}return!1}#c(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#T;if(this.#g&&this.#_){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#a||this.#r!==void 0||(this.#r=setInterval(()=>{this.#v()},this.#o),this.#m=Date.now()+this.#o)}#v(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#f()}#f(){for(;this.#c(););}get concurrency(){return this.#l}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#l=e,this.#f()}async#R(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#E,...t},new Promise((n,i)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let a=e({signal:t.signal});t.timeout&&(a=T(Promise.resolve(a),{milliseconds:t.timeout})),t.signal&&(a=Promise.race([a,this.#R(t.signal)]));let o=await a;n(o),this.emit("completed",o)}catch(a){if(a instanceof L&&!t.throwOnTimeout){n();return}i(a),this.emit("error",a)}finally{this.#w()}},t),this.emit("add"),this.#c()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#i?(this.#i=!1,this.#f(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#p}async onEmpty(){this.#t.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#h("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};var p={},g=r=>{r.addEventListener("message",e=>{g.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{g.dispatchEvent("message",r,e)})};g.addEventListener=(r,e)=>{p[r]==null&&(p[r]=[]),p[r].push(e)};g.removeEventListener=(r,e)=>{p[r]!=null&&(p[r]=p[r].filter(t=>t===e))};g.dispatchEvent=function(r,e,t){p[r]!=null&&p[r].forEach(n=>n(e,t))};var A=g;var P="lock:worker:request-read",S="lock:worker:release-read",W="lock:master:grant-read",K="lock:worker:request-write",N="lock:worker:release-write",q="lock:master:grant-write";var B=(r=21)=>Math.random().toString().substring(2);var G=(r,e,t,n,i)=>(a,o)=>{if(o.data.type!==t)return;let c={type:o.data.type,name:o.data.name,identifier:o.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{a.postMessage({type:i,name:c.name,identifier:c.identifier}),await new Promise(s=>{let f=l=>{if(l==null||l.data==null)return;let u={type:l.data.type,name:l.data.name,identifier:l.data.identifier};u.type===n&&u.identifier===c.identifier&&(a.removeEventListener("message",f),s())};a.addEventListener("message",f)})}}}))},U=(r,e,t,n)=>async()=>{let i=B();return globalThis.postMessage({type:e,identifier:i,name:r}),new Promise(a=>{let o=c=>{if(c==null||c.data==null)return;let s={type:c.data.type,identifier:c.data.identifier};s.type===t&&s.identifier===i&&(globalThis.removeEventListener("message",o),a(()=>{globalThis.postMessage({type:n,identifier:i,name:r})}))};globalThis.addEventListener("message",o)})},ae={singleProcess:!1},V=r=>{if(r=Object.assign({},ae,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return A.addEventListener("message",G(t,"requestReadLock",P,S,W)),A.addEventListener("message",G(t,"requestWriteLock",K,N,q)),t}return{isWorker:!0,readLock:t=>U(t,P,W,S),writeLock:t=>U(t,K,q,N)}};var y={},E;async function z(r,e){let t,n=new Promise(i=>{t=i});return r.add(async()=>T((async()=>{await new Promise(i=>{t(()=>{i()})})})(),{milliseconds:e.timeout})),n}var oe=(r,e)=>{if(E.isWorker===!0)return{readLock:E.readLock(r,e),writeLock:E.writeLock(r,e)};let t=new v({concurrency:1}),n;return{async readLock(){if(n!=null)return z(n,e);n=new v({concurrency:e.concurrency,autoStart:!1});let i=n,a=z(n,e);return t.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),a},async writeLock(){return n=null,z(t,e)}}},ue={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Y(r){let e=Object.assign({},ue,r);return E==null&&(E=V(e),E.isWorker!==!0&&(E.addEventListener("requestReadLock",t=>{y[t.data.name]!=null&&y[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),E.addEventListener("requestWriteLock",async t=>{y[t.data.name]!=null&&y[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),y[e.name]==null&&(y[e.name]=oe(e.name,e)),y[e.name]}return ne(le);})();
"use strict";var Mortice=(()=>{var H=Object.create;var R=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),te=(r,e)=>{for(var t in e)R(r,t,{get:e[t],enumerable:!0})},M=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of X(e))!j.call(r,i)&&i!==t&&R(r,i,{get:()=>e[i],enumerable:!(n=J(e,i))||n.enumerable});return r};var re=(r,e,t)=>(t=r!=null?H(Z(r)):{},M(e||!r||!r.__esModule?R(t,"default",{value:r,enumerable:!0}):t,r)),ne=r=>M(R({},"__esModule",{value:!0}),r);var Q=ee((fe,I)=>{"use strict";var ie=Object.prototype.hasOwnProperty,d="~";function w(){}Object.create&&(w.prototype=Object.create(null),new w().__proto__||(d=!1));function se(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function D(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var a=new se(t,n||r,i),o=d?d+e:e;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],a]:r._events[o].push(a):(r._events[o]=a,r._eventsCount++),r}function x(r,e){--r._eventsCount===0?r._events=new w:delete r._events[e]}function h(){this._events=new w,this._eventsCount=0}h.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)ie.call(t,n)&&e.push(d?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};h.prototype.listeners=function(e){var t=d?d+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,o=new Array(a);i<a;i++)o[i]=n[i].fn;return o};h.prototype.listenerCount=function(e){var t=d?d+e:e,n=this._events[t];return n?n.fn?1:n.length:0};h.prototype.emit=function(e,t,n,i,a,o){var c=d?d+e:e;if(!this._events[c])return!1;var s=this._events[c],f=arguments.length,l,u;if(s.fn){switch(s.once&&this.removeListener(e,s.fn,void 0,!0),f){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,t),!0;case 3:return s.fn.call(s.context,t,n),!0;case 4:return s.fn.call(s.context,t,n,i),!0;case 5:return s.fn.call(s.context,t,n,i,a),!0;case 6:return s.fn.call(s.context,t,n,i,a,o),!0}for(u=1,l=new Array(f-1);u<f;u++)l[u-1]=arguments[u];s.fn.apply(s.context,l)}else{var m=s.length,p;for(u=0;u<m;u++)switch(s[u].once&&this.removeListener(e,s[u].fn,void 0,!0),f){case 1:s[u].fn.call(s[u].context);break;case 2:s[u].fn.call(s[u].context,t);break;case 3:s[u].fn.call(s[u].context,t,n);break;case 4:s[u].fn.call(s[u].context,t,n,i);break;default:if(!l)for(p=1,l=new Array(f-1);p<f;p++)l[p-1]=arguments[p];s[u].fn.apply(s[u].context,l)}}return!0};h.prototype.on=function(e,t,n){return D(this,e,t,n,!1)};h.prototype.once=function(e,t,n){return D(this,e,t,n,!0)};h.prototype.removeListener=function(e,t,n,i){var a=d?d+e:e;if(!this._events[a])return this;if(!t)return x(this,a),this;var o=this._events[a];if(o.fn)o.fn===t&&(!i||o.once)&&(!n||o.context===n)&&x(this,a);else{for(var c=0,s=[],f=o.length;c<f;c++)(o[c].fn!==t||i&&!o[c].once||n&&o[c].context!==n)&&s.push(o[c]);s.length?this._events[a]=s.length===1?s[0]:s:x(this,a)}return this};h.prototype.removeAllListeners=function(e){var t;return e?(t=d?d+e:e,this._events[t]&&x(this,t)):(this._events=new w,this._eventsCount=0),this};h.prototype.off=h.prototype.removeListener;h.prototype.addListener=h.prototype.on;h.prefixed=d;h.EventEmitter=h;typeof I<"u"&&(I.exports=h)});var le={};te(le,{default:()=>Y});var O=re(Q(),1);var L=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},C=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},$=r=>globalThis.DOMException===void 0?new C(r):new DOMException(r),F=r=>{let e=r.reason===void 0?$("This operation was aborted."):r.reason;return e instanceof Error?e:$(e)};function T(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:a={setTimeout,clearTimeout}}=e,o,s=new Promise((f,l)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&l(F(m));let p=()=>{l(F(m))};m.addEventListener("abort",p,{once:!0}),r.finally(()=>{m.removeEventListener("abort",p)})}if(t===Number.POSITIVE_INFINITY){r.then(f,l);return}let u=new L;o=a.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){l(m)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?f():i instanceof Error?l(i):(u.message=i??`Promise timed out after ${t} milliseconds`,l(u))},t),(async()=>{try{f(await r)}catch(m){l(m)}})()}).finally(()=>{s.clear()});return s.clear=()=>{a.clearTimeout.call(void 0,o),o=void 0},s}function k(r,e,t){let n=0,i=r.length;for(;i>0;){let a=Math.trunc(i/2),o=n+a;t(r[o],e)<=0?(n=++o,i-=a+1):i=a}return n}var b=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let i=k(this.#e,n,(a,o)=>o.priority-a.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var g=class extends O.default{#e;#a;#s=0;#d;#o;#m=0;#r;#u;#t;#p;#n=0;#l;#i;#E;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:b,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#a=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#o=e.interval,this.#t=new e.queueClass,this.#p=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#E=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#g(){return this.#a||this.#s<this.#d}get#_(){return this.#n<this.#l}#w(){this.#n--,this.#c(),this.emit("next")}#L(){this.#y(),this.#v(),this.#u=void 0}get#T(){let e=Date.now();if(this.#r===void 0){let t=this.#m-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#L()},t)),!0}return!1}#c(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#T;if(this.#g&&this.#_){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#v(),!0):!1}}return!1}#v(){this.#a||this.#r!==void 0||(this.#r=setInterval(()=>{this.#y()},this.#o),this.#m=Date.now()+this.#o)}#y(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#f()}#f(){for(;this.#c(););}get concurrency(){return this.#l}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#l=e,this.#f()}async#b(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#E,...t},new Promise((n,i)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let a=e({signal:t.signal});t.timeout&&(a=T(Promise.resolve(a),{milliseconds:t.timeout})),t.signal&&(a=Promise.race([a,this.#b(t.signal)]));let o=await a;n(o),this.emit("completed",o)}catch(a){if(a instanceof L&&!t.throwOnTimeout){n();return}i(a),this.emit("error",a)}finally{this.#w()}},t),this.emit("add"),this.#c()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#i?(this.#i=!1,this.#f(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#p}async onEmpty(){this.#t.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#h("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};var E={},_=r=>{r.addEventListener("message",e=>{_.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{_.dispatchEvent("message",r,e)})};_.addEventListener=(r,e)=>{E[r]==null&&(E[r]=[]),E[r].push(e)};_.removeEventListener=(r,e)=>{E[r]!=null&&(E[r]=E[r].filter(t=>t===e))};_.dispatchEvent=function(r,e,t){E[r]!=null&&E[r].forEach(n=>n(e,t))};var A=_;var P="lock:worker:request-read",S="lock:worker:release-read",W="lock:master:grant-read",K="lock:worker:request-write",N="lock:worker:release-write",q="lock:master:grant-write";var B=(r=21)=>Math.random().toString().substring(2);var G=(r,e,t,n,i)=>(a,o)=>{if(o.data.type!==t)return;let c={type:o.data.type,name:o.data.name,identifier:o.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:c.name,handler:async()=>{a.postMessage({type:i,name:c.name,identifier:c.identifier}),await new Promise(s=>{let f=l=>{if(l?.data==null)return;let u={type:l.data.type,name:l.data.name,identifier:l.data.identifier};u.type===n&&u.identifier===c.identifier&&(a.removeEventListener("message",f),s())};a.addEventListener("message",f)})}}}))},U=(r,e,t,n)=>async()=>{let i=B();return globalThis.postMessage({type:e,identifier:i,name:r}),new Promise(a=>{let o=c=>{if(c?.data==null)return;let s={type:c.data.type,identifier:c.data.identifier};s.type===t&&s.identifier===i&&(globalThis.removeEventListener("message",o),a(()=>{globalThis.postMessage({type:n,identifier:i,name:r})}))};globalThis.addEventListener("message",o)})},ae={singleProcess:!1},V=r=>{if(r=Object.assign({},ae,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return A.addEventListener("message",G(t,"requestReadLock",P,S,W)),A.addEventListener("message",G(t,"requestWriteLock",K,N,q)),t}return{isWorker:!0,readLock:t=>U(t,P,W,S),writeLock:t=>U(t,K,q,N)}};var y={},v;async function z(r,e){let t,n=new Promise(i=>{t=i});return r.add(async()=>T((async()=>{await new Promise(i=>{t(()=>{i()})})})(),{milliseconds:e.timeout})),n}var oe=(r,e)=>{if(v.isWorker===!0)return{readLock:v.readLock(r,e),writeLock:v.writeLock(r,e)};let t=new g({concurrency:1}),n;return{async readLock(){if(n!=null)return z(n,e);n=new g({concurrency:e.concurrency,autoStart:!1});let i=n,a=z(n,e);return t.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),a},async writeLock(){return n=null,z(t,e)}}},ue={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Y(r){let e=Object.assign({},ue,r);return v==null&&(v=V(e),v.isWorker!==!0&&(v.addEventListener("requestReadLock",t=>{y[t.data.name]!=null&&y[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),v.addEventListener("requestWriteLock",async t=>{y[t.data.name]!=null&&y[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),y[e.name]==null&&(y[e.name]=oe(e.name,e)),y[e.name]}return ne(le);})();
return Mortice}));

@@ -27,3 +27,3 @@ import observer from 'observable-webworkers';

const releaseEventListener = (event) => {
if (event == null || event.data == null) {
if (event?.data == null) {
return;

@@ -58,3 +58,3 @@ }

const listener = (event) => {
if (event == null || event.data == null) {
if (event?.data == null) {
return;

@@ -61,0 +61,0 @@ }

@@ -250,4 +250,8 @@ "use strict";

}
signal.addEventListener("abort", () => {
const abortHandler = () => {
reject(getAbortedReason(signal));
};
signal.addEventListener("abort", abortHandler, { once: true });
promise.finally(() => {
signal.removeEventListener("abort", abortHandler);
});

@@ -707,3 +711,3 @@ }

const releaseEventListener = (event2) => {
if (event2 == null || event2.data == null) {
if (event2?.data == null) {
return;

@@ -738,3 +742,3 @@ }

const listener = (event) => {
if (event == null || event.data == null) {
if (event?.data == null) {
return;

@@ -741,0 +745,0 @@ }

@@ -250,4 +250,8 @@ "use strict";

}
signal.addEventListener("abort", () => {
const abortHandler = () => {
reject(getAbortedReason(signal));
};
signal.addEventListener("abort", abortHandler, { once: true });
promise.finally(() => {
signal.removeEventListener("abort", abortHandler);
});

@@ -707,3 +711,3 @@ }

const releaseEventListener = (event2) => {
if (event2 == null || event2.data == null) {
if (event2?.data == null) {
return;

@@ -738,3 +742,3 @@ }

const listener = (event) => {
if (event == null || event.data == null) {
if (event?.data == null) {
return;

@@ -741,0 +745,0 @@ }

{
"name": "mortice",
"version": "3.0.4",
"version": "3.0.5",
"description": "Isomorphic read/write lock that works in single processes, node clusters and web workers",

@@ -143,3 +143,5 @@ "author": "Alex Potsides <alex@achingbrain.net>",

"release": "aegir release",
"docs": "aegir docs"
"docs": "aegir docs",
"dep-check": "aegir dep-check -i esbuild",
"doc-check": "aegir doc-check"
},

@@ -152,3 +154,3 @@ "dependencies": {

"devDependencies": {
"aegir": "^41.1.14",
"aegir": "^44.1.4",
"delay": "^6.0.0",

@@ -155,0 +157,0 @@ "esbuild": "^0.19.8",

@@ -1,2 +0,2 @@

# mortice <!-- omit in toc -->
# mortice

@@ -10,2 +10,17 @@ [![codecov](https://img.shields.io/codecov/c/github/achingbrain/mortice.svg?style=flat-square)](https://codecov.io/gh/achingbrain/mortice)

<!--
!IMPORTANT!
Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.
To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts
To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.
-->
- Reads occur concurrently

@@ -128,3 +143,3 @@ - Writes occur one at a time

Loading this module through a script tag will make it's exports available as `Mortice` in the global namespace.
Loading this module through a script tag will make its exports available as `Mortice` in the global namespace.

@@ -143,4 +158,4 @@ ```html

- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
- Apache 2.0, ([LICENSE-APACHE](https://github.com/achingbrain/mortice/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/achingbrain/mortice/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

@@ -147,0 +162,0 @@ # Contribution

@@ -39,3 +39,3 @@ import observer from 'observable-webworkers'

const releaseEventListener = (event: MessageEvent): void => {
if (event == null || event.data == null) {
if (event?.data == null) {
return

@@ -76,3 +76,3 @@ }

const listener = (event: MessageEvent): void => {
if (event == null || event.data == null) {
if (event?.data == null) {
return

@@ -79,0 +79,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc