@pnpm/exe 11.0.0-rc.0 → 11.0.0-rc.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/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +10 -0
- package/dist/node_modules/lru-cache/dist/commonjs/index.js +227 -130
- package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
- package/dist/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
- package/dist/node_modules/lru-cache/dist/esm/browser/index.js +1688 -0
- package/dist/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
- package/dist/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
- package/dist/node_modules/lru-cache/dist/esm/index.js +227 -130
- package/dist/node_modules/lru-cache/dist/esm/index.min.js +1 -1
- package/dist/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +7 -0
- package/dist/node_modules/lru-cache/dist/esm/node/index.js +1688 -0
- package/dist/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
- package/dist/node_modules/lru-cache/package.json +42 -9
- package/dist/node_modules/minimatch/dist/commonjs/ast.js +9 -10
- package/dist/node_modules/minimatch/dist/commonjs/index.js +26 -20
- package/dist/node_modules/minimatch/dist/commonjs/unescape.js +6 -6
- package/dist/node_modules/minimatch/dist/esm/ast.js +9 -10
- package/dist/node_modules/minimatch/dist/esm/index.js +26 -20
- package/dist/node_modules/minimatch/dist/esm/unescape.js +6 -6
- package/dist/node_modules/minimatch/package.json +14 -8
- package/dist/node_modules/minipass-flush/package.json +6 -3
- package/dist/node_modules/tinyglobby/dist/index.cjs +132 -148
- package/dist/node_modules/tinyglobby/dist/index.d.cts +33 -32
- package/dist/node_modules/tinyglobby/dist/index.d.mts +33 -32
- package/dist/node_modules/tinyglobby/dist/index.mjs +134 -146
- package/dist/node_modules/tinyglobby/package.json +10 -10
- package/dist/pnpm.mjs +10126 -8751
- package/package.json +9 -9
- package/dist/node_modules/minipass-flush/LICENSE +0 -15
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var C={hasSubscribers:!1},S=C,W=C;var D=()=>S.hasSubscribers||W.hasSubscribers,I=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,U=new Set,L=typeof process=="object"&&process?process:{},G=(u,e,t,i)=>{typeof L.emitWarning=="function"?L.emitWarning(u,e,t,i):console.error(`[${t}] ${e}: ${u}`)},P=u=>!U.has(u),V=Symbol("type"),F=u=>!!u&&u===Math.floor(u)&&u>0&&isFinite(u),j=u=>F(u)?u<=Math.pow(2,8)?Uint8Array:u<=Math.pow(2,16)?Uint16Array:u<=Math.pow(2,32)?Uint32Array:u<=Number.MAX_SAFE_INTEGER?O:null:null,O=class extends Array{constructor(e){super(e),this.fill(0)}},R=class u{heap;length;static#o=!1;static create(e){let t=j(e);if(!t)return[];u.#o=!0;let i=new u(e,t);return u.#o=!1,i}constructor(e,t){if(!u.#o)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new t(e),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},M=class u{#o;#u;#w;#D;#S;#M;#U;#m;get perf(){return this.#m}ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#n;#b;#s;#i;#t;#a;#c;#l;#h;#y;#r;#_;#F;#d;#g;#T;#W;#f;#j;static unsafeExposeInternals(e){return{starts:e.#F,ttls:e.#d,autopurgeTimers:e.#g,sizes:e.#_,keyMap:e.#s,keyList:e.#i,valList:e.#t,next:e.#a,prev:e.#c,get head(){return e.#l},get tail(){return e.#h},free:e.#y,isBackgroundFetch:t=>e.#e(t),backgroundFetch:(t,i,s,n)=>e.#P(t,i,s,n),moveToTail:t=>e.#L(t),indexes:t=>e.#A(t),rindexes:t=>e.#z(t),isStale:t=>e.#p(t)}}get max(){return this.#o}get maxSize(){return this.#u}get calculatedSize(){return this.#b}get size(){return this.#n}get fetchMethod(){return this.#M}get memoMethod(){return this.#U}get dispose(){return this.#w}get onInsert(){return this.#D}get disposeAfter(){return this.#S}constructor(e){let{max:t=0,ttl:i,ttlResolution:s=1,ttlAutopurge:n,updateAgeOnGet:o,updateAgeOnHas:r,allowStale:h,dispose:l,onInsert:c,disposeAfter:f,noDisposeOnSet:g,noUpdateTTL:p,maxSize:T=0,maxEntrySize:w=0,sizeCalculation:y,fetchMethod:a,memoMethod:m,noDeleteOnFetchRejection:_,noDeleteOnStaleGet:b,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:A,ignoreFetchAbort:z,perf:x}=e;if(x!==void 0&&typeof x?.now!="function")throw new TypeError("perf option must have a now() method if specified");if(this.#m=x??I,t!==0&&!F(t))throw new TypeError("max option must be a nonnegative integer");let v=t?j(t):Array;if(!v)throw new Error("invalid max value: "+t);if(this.#o=t,this.#u=T,this.maxEntrySize=w||this.#u,this.sizeCalculation=y,this.sizeCalculation){if(!this.#u&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(m!==void 0&&typeof m!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#U=m,a!==void 0&&typeof a!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#M=a,this.#W=!!a,this.#s=new Map,this.#i=Array.from({length:t}).fill(void 0),this.#t=Array.from({length:t}).fill(void 0),this.#a=new v(t),this.#c=new v(t),this.#l=0,this.#h=0,this.#y=R.create(t),this.#n=0,this.#b=0,typeof l=="function"&&(this.#w=l),typeof c=="function"&&(this.#D=c),typeof f=="function"?(this.#S=f,this.#r=[]):(this.#S=void 0,this.#r=void 0),this.#T=!!this.#w,this.#j=!!this.#D,this.#f=!!this.#S,this.noDisposeOnSet=!!g,this.noUpdateTTL=!!p,this.noDeleteOnFetchRejection=!!_,this.allowStaleOnFetchRejection=!!d,this.allowStaleOnFetchAbort=!!A,this.ignoreFetchAbort=!!z,this.maxEntrySize!==0){if(this.#u!==0&&!F(this.#u))throw new TypeError("maxSize must be a positive integer if specified");if(!F(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#X()}if(this.allowStale=!!h,this.noDeleteOnStaleGet=!!b,this.updateAgeOnGet=!!o,this.updateAgeOnHas=!!r,this.ttlResolution=F(s)||s===0?s:1,this.ttlAutopurge=!!n,this.ttl=i||0,this.ttl){if(!F(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#H()}if(this.#o===0&&this.ttl===0&&this.#u===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#o&&!this.#u){let E="LRU_CACHE_UNBOUNDED";P(E)&&(U.add(E),G("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",E,u))}}getRemainingTTL(e){return this.#s.has(e)?1/0:0}#H(){let e=new O(this.#o),t=new O(this.#o);this.#d=e,this.#F=t;let i=this.ttlAutopurge?Array.from({length:this.#o}):void 0;this.#g=i,this.#N=(r,h,l=this.#m.now())=>{t[r]=h!==0?l:0,e[r]=h,s(r,h)},this.#x=r=>{t[r]=e[r]!==0?this.#m.now():0,s(r,e[r])};let s=this.ttlAutopurge?(r,h)=>{if(i?.[r]&&(clearTimeout(i[r]),i[r]=void 0),h&&h!==0&&i){let l=setTimeout(()=>{this.#p(r)&&this.#v(this.#i[r],"expire")},h+1);l.unref&&l.unref(),i[r]=l}}:()=>{};this.#E=(r,h)=>{if(e[h]){let l=e[h],c=t[h];if(!l||!c)return;r.ttl=l,r.start=c,r.now=n||o();let f=r.now-c;r.remainingTTL=l-f}};let n=0,o=()=>{let r=this.#m.now();if(this.ttlResolution>0){n=r;let h=setTimeout(()=>n=0,this.ttlResolution);h.unref&&h.unref()}return r};this.getRemainingTTL=r=>{let h=this.#s.get(r);if(h===void 0)return 0;let l=e[h],c=t[h];if(!l||!c)return 1/0;let f=(n||o())-c;return l-f},this.#p=r=>{let h=t[r],l=e[r];return!!l&&!!h&&(n||o())-h>l}}#x=()=>{};#E=()=>{};#N=()=>{};#p=()=>!1;#X(){let e=new O(this.#o);this.#b=0,this.#_=e,this.#R=t=>{this.#b-=e[t],e[t]=0},this.#k=(t,i,s,n)=>{if(this.#e(i))return 0;if(!F(s))if(n){if(typeof n!="function")throw new TypeError("sizeCalculation must be a function");if(s=n(i,t),!F(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return s},this.#I=(t,i,s)=>{if(e[t]=i,this.#u){let n=this.#u-e[t];for(;this.#b>n;)this.#G(!0)}this.#b+=e[t],s&&(s.entrySize=i,s.totalCalculatedSize=this.#b)}}#R=e=>{};#I=(e,t,i)=>{};#k=(e,t,i,s)=>{if(i||s)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#A({allowStale:e=this.allowStale}={}){if(this.#n)for(let t=this.#h;this.#V(t)&&((e||!this.#p(t))&&(yield t),t!==this.#l);)t=this.#c[t]}*#z({allowStale:e=this.allowStale}={}){if(this.#n)for(let t=this.#l;this.#V(t)&&((e||!this.#p(t))&&(yield t),t!==this.#h);)t=this.#a[t]}#V(e){return e!==void 0&&this.#s.get(this.#i[e])===e}*entries(){for(let e of this.#A())this.#t[e]!==void 0&&this.#i[e]!==void 0&&!this.#e(this.#t[e])&&(yield[this.#i[e],this.#t[e]])}*rentries(){for(let e of this.#z())this.#t[e]!==void 0&&this.#i[e]!==void 0&&!this.#e(this.#t[e])&&(yield[this.#i[e],this.#t[e]])}*keys(){for(let e of this.#A()){let t=this.#i[e];t!==void 0&&!this.#e(this.#t[e])&&(yield t)}}*rkeys(){for(let e of this.#z()){let t=this.#i[e];t!==void 0&&!this.#e(this.#t[e])&&(yield t)}}*values(){for(let e of this.#A())this.#t[e]!==void 0&&!this.#e(this.#t[e])&&(yield this.#t[e])}*rvalues(){for(let e of this.#z())this.#t[e]!==void 0&&!this.#e(this.#t[e])&&(yield this.#t[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(e,t={}){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;if(n!==void 0&&e(n,this.#i[i],this))return this.#C(this.#i[i],t)}}forEach(e,t=this){for(let i of this.#A()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&e.call(t,n,this.#i[i],this)}}rforEach(e,t=this){for(let i of this.#z()){let s=this.#t[i],n=this.#e(s)?s.__staleWhileFetching:s;n!==void 0&&e.call(t,n,this.#i[i],this)}}purgeStale(){let e=!1;for(let t of this.#z({allowStale:!0}))this.#p(t)&&(this.#v(this.#i[t],"expire"),e=!0);return e}info(e){let t=this.#s.get(e);if(t===void 0)return;let i=this.#t[t],s=this.#e(i)?i.__staleWhileFetching:i;if(s===void 0)return;let n={value:s};if(this.#d&&this.#F){let o=this.#d[t],r=this.#F[t];if(o&&r){let h=o-(this.#m.now()-r);n.ttl=h,n.start=Date.now()}}return this.#_&&(n.size=this.#_[t]),n}dump(){let e=[];for(let t of this.#A({allowStale:!0})){let i=this.#i[t],s=this.#t[t],n=this.#e(s)?s.__staleWhileFetching:s;if(n===void 0||i===void 0)continue;let o={value:n};if(this.#d&&this.#F){o.ttl=this.#d[t];let r=this.#m.now()-this.#F[t];o.start=Math.floor(Date.now()-r)}this.#_&&(o.size=this.#_[t]),e.unshift([i,o])}return e}load(e){this.clear();for(let[t,i]of e){if(i.start){let s=Date.now()-i.start;i.start=this.#m.now()-s}this.#O(t,i.value,i)}}set(e,t,i={}){let{status:s=S.hasSubscribers?{}:void 0}=i;i.status=s,s&&(s.op="set",s.key=e,t!==void 0&&(s.value=t));let n=this.#O(e,t,i);return s&&S.hasSubscribers&&S.publish(s),n}#O(e,t,i={}){let{ttl:s=this.ttl,start:n,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:r=this.sizeCalculation,status:h}=i;if(t===void 0)return h&&(h.set="deleted"),this.delete(e),this;let{noUpdateTTL:l=this.noUpdateTTL}=i;h&&!this.#e(t)&&(h.value=t);let c=this.#k(e,t,i.size||0,r,h);if(this.maxEntrySize&&c>this.maxEntrySize)return this.#v(e,"set"),h&&(h.set="miss",h.maxEntrySizeExceeded=!0),this;let f=this.#n===0?void 0:this.#s.get(e);if(f===void 0)f=this.#n===0?this.#h:this.#y.length!==0?this.#y.pop():this.#n===this.#o?this.#G(!1):this.#n,this.#i[f]=e,this.#t[f]=t,this.#s.set(e,f),this.#a[this.#h]=f,this.#c[f]=this.#h,this.#h=f,this.#n++,this.#I(f,c,h),h&&(h.set="add"),l=!1,this.#j&&this.#D?.(t,e,"add");else{this.#L(f);let g=this.#t[f];if(t!==g){if(this.#W&&this.#e(g)){g.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:p}=g;p!==void 0&&!o&&(this.#T&&this.#w?.(p,e,"set"),this.#f&&this.#r?.push([p,e,"set"]))}else o||(this.#T&&this.#w?.(g,e,"set"),this.#f&&this.#r?.push([g,e,"set"]));if(this.#R(f),this.#I(f,c,h),this.#t[f]=t,h){h.set="replace";let p=g&&this.#e(g)?g.__staleWhileFetching:g;p!==void 0&&(h.oldValue=p)}}else h&&(h.set="update");this.#j&&this.onInsert?.(t,e,t===g?"update":"replace")}if(s!==0&&!this.#d&&this.#H(),this.#d&&(l||this.#N(f,s,n),h&&this.#E(h,f)),!o&&this.#f&&this.#r){let g=this.#r,p;for(;p=g?.shift();)this.#S?.(...p)}return this}pop(){try{for(;this.#n;){let e=this.#t[this.#l];if(this.#G(!0),this.#e(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(e!==void 0)return e}}finally{if(this.#f&&this.#r){let e=this.#r,t;for(;t=e?.shift();)this.#S?.(...t)}}}#G(e){let t=this.#l,i=this.#i[t],s=this.#t[t];return this.#W&&this.#e(s)?s.__abortController.abort(new Error("evicted")):(this.#T||this.#f)&&(this.#T&&this.#w?.(s,i,"evict"),this.#f&&this.#r?.push([s,i,"evict"])),this.#R(t),this.#g?.[t]&&(clearTimeout(this.#g[t]),this.#g[t]=void 0),e&&(this.#i[t]=void 0,this.#t[t]=void 0,this.#y.push(t)),this.#n===1?(this.#l=this.#h=0,this.#y.length=0):this.#l=this.#a[t],this.#s.delete(i),this.#n--,t}has(e,t={}){let{status:i=S.hasSubscribers?{}:void 0}=t;t.status=i,i&&(i.op="has",i.key=e);let s=this.#Y(e,t);return S.hasSubscribers&&S.publish(i),s}#Y(e,t={}){let{updateAgeOnHas:i=this.updateAgeOnHas,status:s}=t,n=this.#s.get(e);if(n!==void 0){let o=this.#t[n];if(this.#e(o)&&o.__staleWhileFetching===void 0)return!1;if(this.#p(n))s&&(s.has="stale",this.#E(s,n));else return i&&this.#x(n),s&&(s.has="hit",this.#E(s,n)),!0}else s&&(s.has="miss");return!1}peek(e,t={}){let{status:i=D()?{}:void 0}=t;i&&(i.op="peek",i.key=e),t.status=i;let s=this.#J(e,t);return S.hasSubscribers&&S.publish(i),s}#J(e,t){let{status:i,allowStale:s=this.allowStale}=t,n=this.#s.get(e);if(n===void 0||!s&&this.#p(n)){i&&(i.peek=n===void 0?"miss":"stale");return}let o=this.#t[n],r=this.#e(o)?o.__staleWhileFetching:o;return i&&(r!==void 0?(i.peek="hit",i.value=r):i.peek="miss"),r}#P(e,t,i,s){let n=t===void 0?void 0:this.#t[t];if(this.#e(n))return n;let o=new AbortController,{signal:r}=i;r?.addEventListener("abort",()=>o.abort(r.reason),{signal:o.signal});let h={signal:o.signal,options:i,context:s},l=(w,y=!1)=>{let{aborted:a}=o.signal,m=i.ignoreFetchAbort&&w!==void 0,_=i.ignoreFetchAbort||!!(i.allowStaleOnFetchAbort&&w!==void 0);if(i.status&&(a&&!y?(i.status.fetchAborted=!0,i.status.fetchError=o.signal.reason,m&&(i.status.fetchAbortIgnored=!0)):i.status.fetchResolved=!0),a&&!m&&!y)return f(o.signal.reason,_);let b=p,d=this.#t[t];return(d===p||d===void 0&&m&&y)&&(w===void 0?b.__staleWhileFetching!==void 0?this.#t[t]=b.__staleWhileFetching:this.#v(e,"fetch"):(i.status&&(i.status.fetchUpdated=!0),this.#O(e,w,h.options))),w},c=w=>(i.status&&(i.status.fetchRejected=!0,i.status.fetchError=w),f(w,!1)),f=(w,y)=>{let{aborted:a}=o.signal,m=a&&i.allowStaleOnFetchAbort,_=m||i.allowStaleOnFetchRejection,b=_||i.noDeleteOnFetchRejection,d=p;if(this.#t[t]===p&&(!b||!y&&d.__staleWhileFetching===void 0?this.#v(e,"fetch"):m||(this.#t[t]=d.__staleWhileFetching)),_)return i.status&&d.__staleWhileFetching!==void 0&&(i.status.returnedStale=!0),d.__staleWhileFetching;if(d.__returned===d)throw w},g=(w,y)=>{let a=this.#M?.(e,n,h);a&&a instanceof Promise&&a.then(m=>w(m===void 0?void 0:m),y),o.signal.addEventListener("abort",()=>{(!i.ignoreFetchAbort||i.allowStaleOnFetchAbort)&&(w(void 0),i.allowStaleOnFetchAbort&&(w=m=>l(m,!0)))})};i.status&&(i.status.fetchDispatched=!0);let p=new Promise(g).then(l,c),T=Object.assign(p,{__abortController:o,__staleWhileFetching:n,__returned:void 0});return t===void 0?(this.#O(e,T,{...h.options,status:void 0}),t=this.#s.get(e)):this.#t[t]=T,T}#e(e){if(!this.#W)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof AbortController}fetch(e,t={}){let i=W.hasSubscribers,{status:s=D()?{}:void 0}=t;t.status=s,s&&t.context&&(s.context=t.context);let n=this.#B(e,t);return s&&D()&&i&&(s.trace=!0,W.tracePromise(()=>n,s).catch(()=>{})),n}async#B(e,t={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:r=this.noDisposeOnSet,size:h=0,sizeCalculation:l=this.sizeCalculation,noUpdateTTL:c=this.noUpdateTTL,noDeleteOnFetchRejection:f=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:g=this.allowStaleOnFetchRejection,ignoreFetchAbort:p=this.ignoreFetchAbort,allowStaleOnFetchAbort:T=this.allowStaleOnFetchAbort,context:w,forceRefresh:y=!1,status:a,signal:m}=t;if(a&&(a.op="fetch",a.key=e,y&&(a.forceRefresh=!0)),!this.#W)return a&&(a.fetch="get"),this.#C(e,{allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,status:a});let _={allowStale:i,updateAgeOnGet:s,noDeleteOnStaleGet:n,ttl:o,noDisposeOnSet:r,size:h,sizeCalculation:l,noUpdateTTL:c,noDeleteOnFetchRejection:f,allowStaleOnFetchRejection:g,allowStaleOnFetchAbort:T,ignoreFetchAbort:p,status:a,signal:m},b=this.#s.get(e);if(b===void 0){a&&(a.fetch="miss");let d=this.#P(e,b,_,w);return d.__returned=d}else{let d=this.#t[b];if(this.#e(d)){let E=i&&d.__staleWhileFetching!==void 0;return a&&(a.fetch="inflight",E&&(a.returnedStale=!0)),E?d.__staleWhileFetching:d.__returned=d}let A=this.#p(b);if(!y&&!A)return a&&(a.fetch="hit"),this.#L(b),s&&this.#x(b),a&&this.#E(a,b),d;let z=this.#P(e,b,_,w),v=z.__staleWhileFetching!==void 0&&i;return a&&(a.fetch=A?"stale":"refresh",v&&A&&(a.returnedStale=!0)),v?z.__staleWhileFetching:z.__returned=z}}forceFetch(e,t={}){let i=W.hasSubscribers,{status:s=D()?{}:void 0}=t;t.status=s,s&&t.context&&(s.context=t.context);let n=this.#K(e,t);return s&&D()&&i&&(s.trace=!0,W.tracePromise(()=>n,s).catch(()=>{})),n}async#K(e,t={}){let i=await this.#B(e,t);if(i===void 0)throw new Error("fetch() returned undefined");return i}memo(e,t={}){let{status:i=S.hasSubscribers?{}:void 0}=t;t.status=i,i&&(i.op="memo",i.key=e,t.context&&(i.context=t.context));let s=this.#Q(e,t);return i&&(i.value=s),S.hasSubscribers&&S.publish(i),s}#Q(e,t={}){let i=this.#U;if(!i)throw new Error("no memoMethod provided to constructor");let{context:s,status:n,forceRefresh:o,...r}=t;n&&o&&(n.forceRefresh=!0);let h=this.#C(e,r),l=o||h===void 0;if(n&&(n.memo=l?"miss":"hit",l||(n.value=h)),!l)return h;let c=i(e,h,{options:r,context:s});return n&&(n.value=c),this.#O(e,c,r),c}get(e,t={}){let{status:i=S.hasSubscribers?{}:void 0}=t;t.status=i,i&&(i.op="get",i.key=e);let s=this.#C(e,t);return i&&(s!==void 0&&(i.value=s),S.hasSubscribers&&S.publish(i)),s}#C(e,t={}){let{allowStale:i=this.allowStale,updateAgeOnGet:s=this.updateAgeOnGet,noDeleteOnStaleGet:n=this.noDeleteOnStaleGet,status:o}=t,r=this.#s.get(e);if(r===void 0){o&&(o.get="miss");return}let h=this.#t[r],l=this.#e(h);return o&&this.#E(o,r),this.#p(r)?l?(o&&(o.get="stale-fetching"),i&&h.__staleWhileFetching!==void 0?(o&&(o.returnedStale=!0),h.__staleWhileFetching):void 0):(n||this.#v(e,"expire"),o&&(o.get="stale"),i?(o&&(o.returnedStale=!0),h):void 0):(o&&(o.get=l?"fetching":"hit"),this.#L(r),s&&this.#x(r),l?h.__staleWhileFetching:h)}#$(e,t){this.#c[t]=e,this.#a[e]=t}#L(e){e!==this.#h&&(e===this.#l?this.#l=this.#a[e]:this.#$(this.#c[e],this.#a[e]),this.#$(this.#h,e),this.#h=e)}delete(e){return this.#v(e,"delete")}#v(e,t){S.hasSubscribers&&S.publish({op:"delete",delete:t,key:e});let i=!1;if(this.#n!==0){let s=this.#s.get(e);if(s!==void 0)if(this.#g?.[s]&&(clearTimeout(this.#g?.[s]),this.#g[s]=void 0),i=!0,this.#n===1)this.#q(t);else{this.#R(s);let n=this.#t[s];if(this.#e(n)?n.__abortController.abort(new Error("deleted")):(this.#T||this.#f)&&(this.#T&&this.#w?.(n,e,t),this.#f&&this.#r?.push([n,e,t])),this.#s.delete(e),this.#i[s]=void 0,this.#t[s]=void 0,s===this.#h)this.#h=this.#c[s];else if(s===this.#l)this.#l=this.#a[s];else{let o=this.#c[s];this.#a[o]=this.#a[s];let r=this.#a[s];this.#c[r]=this.#c[s]}this.#n--,this.#y.push(s)}}if(this.#f&&this.#r?.length){let s=this.#r,n;for(;n=s?.shift();)this.#S?.(...n)}return i}clear(){return this.#q("delete")}#q(e){for(let t of this.#z({allowStale:!0})){let i=this.#t[t];if(this.#e(i))i.__abortController.abort(new Error("deleted"));else{let s=this.#i[t];this.#T&&this.#w?.(i,s,e),this.#f&&this.#r?.push([i,s,e])}}if(this.#s.clear(),this.#t.fill(void 0),this.#i.fill(void 0),this.#d&&this.#F){this.#d.fill(0),this.#F.fill(0);for(let t of this.#g??[])t!==void 0&&clearTimeout(t);this.#g?.fill(void 0)}if(this.#_&&this.#_.fill(0),this.#l=0,this.#h=0,this.#y.length=0,this.#b=0,this.#n=0,this.#f&&this.#r){let t=this.#r,i;for(;i=t?.shift();)this.#S?.(...i)}}};export{M as LRUCache};
|
|
2
|
+
//# sourceMappingURL=index.min.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* no-op polyfills for non-node environments. tries to load the actual
|
|
3
|
+
* diagnostics_channel module on platforms that support it, but fails
|
|
4
|
+
* gracefully if not found. This means that the first tick of metrics
|
|
5
|
+
* and tracing will be missed, but that probably doesn't matter much.
|
|
6
|
+
*/
|
|
7
|
+
// conditionally import from diagnostic_channel, fall back to dummyfill
|
|
8
|
+
// all we actually have to mock is the hasSubscribers, since we always check
|
|
9
|
+
/* v8 ignore next */
|
|
10
|
+
const dummy = { hasSubscribers: false };
|
|
11
|
+
export let metrics = dummy;
|
|
12
|
+
export let tracing = dummy;
|
|
13
|
+
import('node:diagnostics_channel')
|
|
14
|
+
.then(dc => {
|
|
15
|
+
metrics = dc.channel('lru-cache:metrics');
|
|
16
|
+
tracing = dc.tracingChannel('lru-cache');
|
|
17
|
+
})
|
|
18
|
+
.catch(() => { });
|
|
19
|
+
//# sourceMappingURL=diagnostics-channel-esm.mjs.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module LRUCache
|
|
3
3
|
*/
|
|
4
|
+
import { metrics, tracing } from './diagnostics-channel.js';
|
|
5
|
+
const hasSubscribers = () => metrics.hasSubscribers || tracing.hasSubscribers;
|
|
4
6
|
const defaultPerf = (typeof performance === 'object' &&
|
|
5
7
|
performance &&
|
|
6
8
|
typeof performance.now === 'function') ?
|
|
@@ -11,65 +13,19 @@ const warned = new Set();
|
|
|
11
13
|
const PROCESS = (typeof process === 'object' && !!process ?
|
|
12
14
|
process
|
|
13
15
|
: {});
|
|
14
|
-
/* c8 ignore
|
|
16
|
+
/* c8 ignore stop */
|
|
15
17
|
const emitWarning = (msg, type, code, fn) => {
|
|
16
|
-
typeof PROCESS.emitWarning === 'function'
|
|
17
|
-
PROCESS.emitWarning(msg, type, code, fn)
|
|
18
|
-
|
|
18
|
+
if (typeof PROCESS.emitWarning === 'function') {
|
|
19
|
+
PROCESS.emitWarning(msg, type, code, fn);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
//oxlint-disable-next-line no-console
|
|
23
|
+
console.error(`[${code}] ${type}: ${msg}`);
|
|
24
|
+
}
|
|
19
25
|
};
|
|
20
|
-
let AC = globalThis.AbortController;
|
|
21
|
-
let AS = globalThis.AbortSignal;
|
|
22
|
-
/* c8 ignore start */
|
|
23
|
-
if (typeof AC === 'undefined') {
|
|
24
|
-
//@ts-ignore
|
|
25
|
-
AS = class AbortSignal {
|
|
26
|
-
onabort;
|
|
27
|
-
_onabort = [];
|
|
28
|
-
reason;
|
|
29
|
-
aborted = false;
|
|
30
|
-
addEventListener(_, fn) {
|
|
31
|
-
this._onabort.push(fn);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
//@ts-ignore
|
|
35
|
-
AC = class AbortController {
|
|
36
|
-
constructor() {
|
|
37
|
-
warnACPolyfill();
|
|
38
|
-
}
|
|
39
|
-
signal = new AS();
|
|
40
|
-
abort(reason) {
|
|
41
|
-
if (this.signal.aborted)
|
|
42
|
-
return;
|
|
43
|
-
//@ts-ignore
|
|
44
|
-
this.signal.reason = reason;
|
|
45
|
-
//@ts-ignore
|
|
46
|
-
this.signal.aborted = true;
|
|
47
|
-
//@ts-ignore
|
|
48
|
-
for (const fn of this.signal._onabort) {
|
|
49
|
-
fn(reason);
|
|
50
|
-
}
|
|
51
|
-
this.signal.onabort?.(reason);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== '1';
|
|
55
|
-
const warnACPolyfill = () => {
|
|
56
|
-
if (!printACPolyfillWarning)
|
|
57
|
-
return;
|
|
58
|
-
printACPolyfillWarning = false;
|
|
59
|
-
emitWarning('AbortController is not defined. If using lru-cache in ' +
|
|
60
|
-
'node 14, load an AbortController polyfill from the ' +
|
|
61
|
-
'`node-abort-controller` package. A minimal polyfill is ' +
|
|
62
|
-
'provided for use by LRUCache.fetch(), but it should not be ' +
|
|
63
|
-
'relied upon in other contexts (eg, passing it to other APIs that ' +
|
|
64
|
-
'use AbortController/AbortSignal might have undesirable effects). ' +
|
|
65
|
-
'You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.', 'NO_ABORT_CONTROLLER', 'ENOTSUP', warnACPolyfill);
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
/* c8 ignore stop */
|
|
69
26
|
const shouldWarn = (code) => !warned.has(code);
|
|
70
27
|
const TYPE = Symbol('type');
|
|
71
|
-
const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
|
|
72
|
-
/* c8 ignore start */
|
|
28
|
+
const isPosInt = (n) => !!n && n === Math.floor(n) && n > 0 && isFinite(n);
|
|
73
29
|
// This is a little bit ridiculous, tbh.
|
|
74
30
|
// The maximum array length is 2^32-1 or thereabouts on most JS impls.
|
|
75
31
|
// And well before that point, you're caching the entire world, I mean,
|
|
@@ -78,6 +34,7 @@ const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
|
|
|
78
34
|
// zeroes at init time is brutal when you get that big.
|
|
79
35
|
// But why not be complete?
|
|
80
36
|
// Maybe in the future, these limits will have expanded.
|
|
37
|
+
/* c8 ignore start */
|
|
81
38
|
const getUintArray = (max) => !isPosInt(max) ? null
|
|
82
39
|
: max <= Math.pow(2, 8) ? Uint8Array
|
|
83
40
|
: max <= Math.pow(2, 16) ? Uint16Array
|
|
@@ -358,8 +315,8 @@ export class LRUCache {
|
|
|
358
315
|
this.#fetchMethod = fetchMethod;
|
|
359
316
|
this.#hasFetchMethod = !!fetchMethod;
|
|
360
317
|
this.#keyMap = new Map();
|
|
361
|
-
this.#keyList =
|
|
362
|
-
this.#valList =
|
|
318
|
+
this.#keyList = Array.from({ length: max }).fill(undefined);
|
|
319
|
+
this.#valList = Array.from({ length: max }).fill(undefined);
|
|
363
320
|
this.#next = new UintArray(max);
|
|
364
321
|
this.#prev = new UintArray(max);
|
|
365
322
|
this.#head = 0;
|
|
@@ -443,7 +400,9 @@ export class LRUCache {
|
|
|
443
400
|
this.#ttls = ttls;
|
|
444
401
|
this.#starts = starts;
|
|
445
402
|
const purgeTimers = this.ttlAutopurge ?
|
|
446
|
-
|
|
403
|
+
Array.from({
|
|
404
|
+
length: this.#max,
|
|
405
|
+
})
|
|
447
406
|
: undefined;
|
|
448
407
|
this.#autopurgeTimers = purgeTimers;
|
|
449
408
|
this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
|
|
@@ -485,9 +444,11 @@ export class LRUCache {
|
|
|
485
444
|
if (ttls[index]) {
|
|
486
445
|
const ttl = ttls[index];
|
|
487
446
|
const start = starts[index];
|
|
488
|
-
/* c8 ignore
|
|
489
|
-
if (!ttl || !start)
|
|
447
|
+
/* c8 ignore start */
|
|
448
|
+
if (!ttl || !start) {
|
|
490
449
|
return;
|
|
450
|
+
}
|
|
451
|
+
/* c8 ignore stop */
|
|
491
452
|
status.ttl = ttl;
|
|
492
453
|
status.start = start;
|
|
493
454
|
status.now = cachedNow || getNow();
|
|
@@ -594,10 +555,7 @@ export class LRUCache {
|
|
|
594
555
|
};
|
|
595
556
|
*#indexes({ allowStale = this.allowStale } = {}) {
|
|
596
557
|
if (this.#size) {
|
|
597
|
-
for (let i = this.#tail;
|
|
598
|
-
if (!this.#isValidIndex(i)) {
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
558
|
+
for (let i = this.#tail; this.#isValidIndex(i);) {
|
|
601
559
|
if (allowStale || !this.#isStale(i)) {
|
|
602
560
|
yield i;
|
|
603
561
|
}
|
|
@@ -612,10 +570,7 @@ export class LRUCache {
|
|
|
612
570
|
}
|
|
613
571
|
*#rindexes({ allowStale = this.allowStale } = {}) {
|
|
614
572
|
if (this.#size) {
|
|
615
|
-
for (let i = this.#head;
|
|
616
|
-
if (!this.#isValidIndex(i)) {
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
573
|
+
for (let i = this.#head; this.#isValidIndex(i);) {
|
|
619
574
|
if (allowStale || !this.#isStale(i)) {
|
|
620
575
|
yield i;
|
|
621
576
|
}
|
|
@@ -736,7 +691,7 @@ export class LRUCache {
|
|
|
736
691
|
if (value === undefined)
|
|
737
692
|
continue;
|
|
738
693
|
if (fn(value, this.#keyList[i], this)) {
|
|
739
|
-
return this
|
|
694
|
+
return this.#get(this.#keyList[i], getOptions);
|
|
740
695
|
}
|
|
741
696
|
}
|
|
742
697
|
}
|
|
@@ -809,7 +764,7 @@ export class LRUCache {
|
|
|
809
764
|
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
810
765
|
if (value === undefined)
|
|
811
766
|
return undefined;
|
|
812
|
-
/* c8 ignore
|
|
767
|
+
/* c8 ignore stop */
|
|
813
768
|
const entry = { value };
|
|
814
769
|
if (this.#ttls && this.#starts) {
|
|
815
770
|
const ttl = this.#ttls[i];
|
|
@@ -883,7 +838,7 @@ export class LRUCache {
|
|
|
883
838
|
const age = Date.now() - entry.start;
|
|
884
839
|
entry.start = this.#perf.now() - age;
|
|
885
840
|
}
|
|
886
|
-
this
|
|
841
|
+
this.#set(key, entry.value, entry);
|
|
887
842
|
}
|
|
888
843
|
}
|
|
889
844
|
/**
|
|
@@ -917,22 +872,41 @@ export class LRUCache {
|
|
|
917
872
|
* `cache.delete(key)`. `undefined` is never stored in the cache.
|
|
918
873
|
*/
|
|
919
874
|
set(k, v, setOptions = {}) {
|
|
875
|
+
const { status = metrics.hasSubscribers ? {} : undefined } = setOptions;
|
|
876
|
+
setOptions.status = status;
|
|
877
|
+
if (status) {
|
|
878
|
+
status.op = 'set';
|
|
879
|
+
status.key = k;
|
|
880
|
+
if (v !== undefined)
|
|
881
|
+
status.value = v;
|
|
882
|
+
}
|
|
883
|
+
const result = this.#set(k, v, setOptions);
|
|
884
|
+
if (status && metrics.hasSubscribers) {
|
|
885
|
+
metrics.publish(status);
|
|
886
|
+
}
|
|
887
|
+
return result;
|
|
888
|
+
}
|
|
889
|
+
#set(k, v, setOptions = {}) {
|
|
890
|
+
const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
|
|
920
891
|
if (v === undefined) {
|
|
892
|
+
if (status)
|
|
893
|
+
status.set = 'deleted';
|
|
921
894
|
this.delete(k);
|
|
922
895
|
return this;
|
|
923
896
|
}
|
|
924
|
-
const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status, } = setOptions;
|
|
925
897
|
let { noUpdateTTL = this.noUpdateTTL } = setOptions;
|
|
926
|
-
|
|
898
|
+
if (status && !this.#isBackgroundFetch(v))
|
|
899
|
+
status.value = v;
|
|
900
|
+
const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation, status);
|
|
927
901
|
// if the item doesn't fit, don't do anything
|
|
928
902
|
// NB: maxEntrySize set to maxSize by default
|
|
929
903
|
if (this.maxEntrySize && size > this.maxEntrySize) {
|
|
904
|
+
// have to delete, in case something is there already.
|
|
905
|
+
this.#delete(k, 'set');
|
|
930
906
|
if (status) {
|
|
931
907
|
status.set = 'miss';
|
|
932
908
|
status.maxEntrySizeExceeded = true;
|
|
933
909
|
}
|
|
934
|
-
// have to delete, in case something is there already.
|
|
935
|
-
this.#delete(k, 'set');
|
|
936
910
|
return this;
|
|
937
911
|
}
|
|
938
912
|
let index = this.#size === 0 ? undefined : this.#keyMap.get(k);
|
|
@@ -1103,6 +1077,18 @@ export class LRUCache {
|
|
|
1103
1077
|
* {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
|
|
1104
1078
|
*/
|
|
1105
1079
|
has(k, hasOptions = {}) {
|
|
1080
|
+
const { status = metrics.hasSubscribers ? {} : undefined } = hasOptions;
|
|
1081
|
+
hasOptions.status = status;
|
|
1082
|
+
if (status) {
|
|
1083
|
+
status.op = 'has';
|
|
1084
|
+
status.key = k;
|
|
1085
|
+
}
|
|
1086
|
+
const result = this.#has(k, hasOptions);
|
|
1087
|
+
if (metrics.hasSubscribers)
|
|
1088
|
+
metrics.publish(status);
|
|
1089
|
+
return result;
|
|
1090
|
+
}
|
|
1091
|
+
#has(k, hasOptions = {}) {
|
|
1106
1092
|
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
1107
1093
|
const index = this.#keyMap.get(k);
|
|
1108
1094
|
if (index !== undefined) {
|
|
@@ -1139,21 +1125,45 @@ export class LRUCache {
|
|
|
1139
1125
|
* {@link LRUCache.OptionsBase.allowStale} is set.
|
|
1140
1126
|
*/
|
|
1141
1127
|
peek(k, peekOptions = {}) {
|
|
1142
|
-
const {
|
|
1128
|
+
const { status = hasSubscribers() ? {} : undefined } = peekOptions;
|
|
1129
|
+
if (status) {
|
|
1130
|
+
status.op = 'peek';
|
|
1131
|
+
status.key = k;
|
|
1132
|
+
}
|
|
1133
|
+
peekOptions.status = status;
|
|
1134
|
+
const result = this.#peek(k, peekOptions);
|
|
1135
|
+
if (metrics.hasSubscribers) {
|
|
1136
|
+
metrics.publish(status);
|
|
1137
|
+
}
|
|
1138
|
+
return result;
|
|
1139
|
+
}
|
|
1140
|
+
#peek(k, peekOptions) {
|
|
1141
|
+
const { status, allowStale = this.allowStale } = peekOptions;
|
|
1143
1142
|
const index = this.#keyMap.get(k);
|
|
1144
1143
|
if (index === undefined || (!allowStale && this.#isStale(index))) {
|
|
1145
|
-
|
|
1144
|
+
if (status)
|
|
1145
|
+
status.peek = index === undefined ? 'miss' : 'stale';
|
|
1146
|
+
return undefined;
|
|
1146
1147
|
}
|
|
1147
1148
|
const v = this.#valList[index];
|
|
1148
|
-
|
|
1149
|
-
|
|
1149
|
+
const val = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
1150
|
+
if (status) {
|
|
1151
|
+
if (val !== undefined) {
|
|
1152
|
+
status.peek = 'hit';
|
|
1153
|
+
status.value = val;
|
|
1154
|
+
}
|
|
1155
|
+
else {
|
|
1156
|
+
status.peek = 'miss';
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return val;
|
|
1150
1160
|
}
|
|
1151
1161
|
#backgroundFetch(k, index, options, context) {
|
|
1152
1162
|
const v = index === undefined ? undefined : this.#valList[index];
|
|
1153
1163
|
if (this.#isBackgroundFetch(v)) {
|
|
1154
1164
|
return v;
|
|
1155
1165
|
}
|
|
1156
|
-
const ac = new
|
|
1166
|
+
const ac = new AbortController();
|
|
1157
1167
|
const { signal } = options;
|
|
1158
1168
|
// when/if our AC signals, then stop listening to theirs.
|
|
1159
1169
|
signal?.addEventListener('abort', () => ac.abort(signal.reason), {
|
|
@@ -1189,7 +1199,7 @@ export class LRUCache {
|
|
|
1189
1199
|
// cache and ignore the abort, or if it's still pending on this specific
|
|
1190
1200
|
// background request, then write it to the cache.
|
|
1191
1201
|
const vl = this.#valList[index];
|
|
1192
|
-
if (vl === p || (
|
|
1202
|
+
if (vl === p || (vl === undefined && ignoreAbort && updateCache)) {
|
|
1193
1203
|
if (v === undefined) {
|
|
1194
1204
|
if (bf.__staleWhileFetching !== undefined) {
|
|
1195
1205
|
this.#valList[index] = bf.__staleWhileFetching;
|
|
@@ -1201,7 +1211,7 @@ export class LRUCache {
|
|
|
1201
1211
|
else {
|
|
1202
1212
|
if (options.status)
|
|
1203
1213
|
options.status.fetchUpdated = true;
|
|
1204
|
-
this
|
|
1214
|
+
this.#set(k, v, fetchOpts.options);
|
|
1205
1215
|
}
|
|
1206
1216
|
}
|
|
1207
1217
|
return v;
|
|
@@ -1273,7 +1283,7 @@ export class LRUCache {
|
|
|
1273
1283
|
});
|
|
1274
1284
|
if (index === undefined) {
|
|
1275
1285
|
// internal, don't expose status.
|
|
1276
|
-
this
|
|
1286
|
+
this.#set(k, bf, { ...fetchOpts.options, status: undefined });
|
|
1277
1287
|
index = this.#keyMap.get(k);
|
|
1278
1288
|
}
|
|
1279
1289
|
else {
|
|
@@ -1288,9 +1298,25 @@ export class LRUCache {
|
|
|
1288
1298
|
return (!!b &&
|
|
1289
1299
|
b instanceof Promise &&
|
|
1290
1300
|
b.hasOwnProperty('__staleWhileFetching') &&
|
|
1291
|
-
b.__abortController instanceof
|
|
1301
|
+
b.__abortController instanceof AbortController);
|
|
1302
|
+
}
|
|
1303
|
+
fetch(k, fetchOptions = {}) {
|
|
1304
|
+
const ths = tracing.hasSubscribers;
|
|
1305
|
+
const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
|
|
1306
|
+
fetchOptions.status = status;
|
|
1307
|
+
if (status && fetchOptions.context) {
|
|
1308
|
+
status.context = fetchOptions.context;
|
|
1309
|
+
}
|
|
1310
|
+
const p = this.#fetch(k, fetchOptions);
|
|
1311
|
+
if (status && hasSubscribers()) {
|
|
1312
|
+
if (ths) {
|
|
1313
|
+
status.trace = true;
|
|
1314
|
+
tracing.tracePromise(() => p, status).catch(() => { });
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
return p;
|
|
1292
1318
|
}
|
|
1293
|
-
async fetch(k, fetchOptions = {}) {
|
|
1319
|
+
async #fetch(k, fetchOptions = {}) {
|
|
1294
1320
|
const {
|
|
1295
1321
|
// get options
|
|
1296
1322
|
allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
|
@@ -1298,10 +1324,16 @@ export class LRUCache {
|
|
|
1298
1324
|
ttl = this.ttl, noDisposeOnSet = this.noDisposeOnSet, size = 0, sizeCalculation = this.sizeCalculation, noUpdateTTL = this.noUpdateTTL,
|
|
1299
1325
|
// fetch exclusive options
|
|
1300
1326
|
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection, allowStaleOnFetchRejection = this.allowStaleOnFetchRejection, ignoreFetchAbort = this.ignoreFetchAbort, allowStaleOnFetchAbort = this.allowStaleOnFetchAbort, context, forceRefresh = false, status, signal, } = fetchOptions;
|
|
1327
|
+
if (status) {
|
|
1328
|
+
status.op = 'fetch';
|
|
1329
|
+
status.key = k;
|
|
1330
|
+
if (forceRefresh)
|
|
1331
|
+
status.forceRefresh = true;
|
|
1332
|
+
}
|
|
1301
1333
|
if (!this.#hasFetchMethod) {
|
|
1302
1334
|
if (status)
|
|
1303
1335
|
status.fetch = 'get';
|
|
1304
|
-
return this
|
|
1336
|
+
return this.#get(k, {
|
|
1305
1337
|
allowStale,
|
|
1306
1338
|
updateAgeOnGet,
|
|
1307
1339
|
noDeleteOnStaleGet,
|
|
@@ -1370,26 +1402,69 @@ export class LRUCache {
|
|
|
1370
1402
|
return staleVal ? p.__staleWhileFetching : (p.__returned = p);
|
|
1371
1403
|
}
|
|
1372
1404
|
}
|
|
1373
|
-
|
|
1374
|
-
const
|
|
1405
|
+
forceFetch(k, fetchOptions = {}) {
|
|
1406
|
+
const ths = tracing.hasSubscribers;
|
|
1407
|
+
const { status = hasSubscribers() ? {} : undefined } = fetchOptions;
|
|
1408
|
+
fetchOptions.status = status;
|
|
1409
|
+
if (status && fetchOptions.context) {
|
|
1410
|
+
status.context = fetchOptions.context;
|
|
1411
|
+
}
|
|
1412
|
+
const p = this.#forceFetch(k, fetchOptions);
|
|
1413
|
+
if (status && hasSubscribers()) {
|
|
1414
|
+
if (ths) {
|
|
1415
|
+
status.trace = true;
|
|
1416
|
+
tracing.tracePromise(() => p, status).catch(() => { });
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
return p;
|
|
1420
|
+
}
|
|
1421
|
+
async #forceFetch(k, fetchOptions = {}) {
|
|
1422
|
+
const v = await this.#fetch(k, fetchOptions);
|
|
1375
1423
|
if (v === undefined)
|
|
1376
1424
|
throw new Error('fetch() returned undefined');
|
|
1377
1425
|
return v;
|
|
1378
1426
|
}
|
|
1379
1427
|
memo(k, memoOptions = {}) {
|
|
1428
|
+
const { status = metrics.hasSubscribers ? {} : undefined } = memoOptions;
|
|
1429
|
+
memoOptions.status = status;
|
|
1430
|
+
if (status) {
|
|
1431
|
+
status.op = 'memo';
|
|
1432
|
+
status.key = k;
|
|
1433
|
+
if (memoOptions.context) {
|
|
1434
|
+
status.context = memoOptions.context;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
const result = this.#memo(k, memoOptions);
|
|
1438
|
+
if (status)
|
|
1439
|
+
status.value = result;
|
|
1440
|
+
if (metrics.hasSubscribers)
|
|
1441
|
+
metrics.publish(status);
|
|
1442
|
+
return result;
|
|
1443
|
+
}
|
|
1444
|
+
#memo(k, memoOptions = {}) {
|
|
1380
1445
|
const memoMethod = this.#memoMethod;
|
|
1381
1446
|
if (!memoMethod) {
|
|
1382
1447
|
throw new Error('no memoMethod provided to constructor');
|
|
1383
1448
|
}
|
|
1384
|
-
const { context, forceRefresh, ...options } = memoOptions;
|
|
1385
|
-
|
|
1386
|
-
|
|
1449
|
+
const { context, status, forceRefresh, ...options } = memoOptions;
|
|
1450
|
+
if (status && forceRefresh)
|
|
1451
|
+
status.forceRefresh = true;
|
|
1452
|
+
const v = this.#get(k, options);
|
|
1453
|
+
const refresh = forceRefresh || v === undefined;
|
|
1454
|
+
if (status) {
|
|
1455
|
+
status.memo = refresh ? 'miss' : 'hit';
|
|
1456
|
+
if (!refresh)
|
|
1457
|
+
status.value = v;
|
|
1458
|
+
}
|
|
1459
|
+
if (!refresh)
|
|
1387
1460
|
return v;
|
|
1388
1461
|
const vv = memoMethod(k, v, {
|
|
1389
1462
|
options,
|
|
1390
1463
|
context,
|
|
1391
1464
|
});
|
|
1392
|
-
|
|
1465
|
+
if (status)
|
|
1466
|
+
status.value = vv;
|
|
1467
|
+
this.#set(k, vv, options);
|
|
1393
1468
|
return vv;
|
|
1394
1469
|
}
|
|
1395
1470
|
/**
|
|
@@ -1399,55 +1474,70 @@ export class LRUCache {
|
|
|
1399
1474
|
* If the key is not found, get() will return `undefined`.
|
|
1400
1475
|
*/
|
|
1401
1476
|
get(k, getOptions = {}) {
|
|
1477
|
+
const { status = metrics.hasSubscribers ? {} : undefined } = getOptions;
|
|
1478
|
+
getOptions.status = status;
|
|
1479
|
+
if (status) {
|
|
1480
|
+
status.op = 'get';
|
|
1481
|
+
status.key = k;
|
|
1482
|
+
}
|
|
1483
|
+
const result = this.#get(k, getOptions);
|
|
1484
|
+
if (status) {
|
|
1485
|
+
if (result !== undefined)
|
|
1486
|
+
status.value = result;
|
|
1487
|
+
if (metrics.hasSubscribers)
|
|
1488
|
+
metrics.publish(status);
|
|
1489
|
+
}
|
|
1490
|
+
return result;
|
|
1491
|
+
}
|
|
1492
|
+
#get(k, getOptions = {}) {
|
|
1402
1493
|
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status, } = getOptions;
|
|
1403
1494
|
const index = this.#keyMap.get(k);
|
|
1404
|
-
if (index
|
|
1405
|
-
const value = this.#valList[index];
|
|
1406
|
-
const fetching = this.#isBackgroundFetch(value);
|
|
1495
|
+
if (index === undefined) {
|
|
1407
1496
|
if (status)
|
|
1408
|
-
|
|
1409
|
-
|
|
1497
|
+
status.get = 'miss';
|
|
1498
|
+
return undefined;
|
|
1499
|
+
}
|
|
1500
|
+
const value = this.#valList[index];
|
|
1501
|
+
const fetching = this.#isBackgroundFetch(value);
|
|
1502
|
+
if (status)
|
|
1503
|
+
this.#statusTTL(status, index);
|
|
1504
|
+
if (this.#isStale(index)) {
|
|
1505
|
+
// delete only if not an in-flight background fetch
|
|
1506
|
+
if (!fetching) {
|
|
1507
|
+
if (!noDeleteOnStaleGet) {
|
|
1508
|
+
this.#delete(k, 'expire');
|
|
1509
|
+
}
|
|
1410
1510
|
if (status)
|
|
1411
1511
|
status.get = 'stale';
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
if (!noDeleteOnStaleGet) {
|
|
1415
|
-
this.#delete(k, 'expire');
|
|
1416
|
-
}
|
|
1417
|
-
if (status && allowStale)
|
|
1512
|
+
if (allowStale) {
|
|
1513
|
+
if (status)
|
|
1418
1514
|
status.returnedStale = true;
|
|
1419
|
-
return
|
|
1420
|
-
}
|
|
1421
|
-
else {
|
|
1422
|
-
if (status &&
|
|
1423
|
-
allowStale &&
|
|
1424
|
-
value.__staleWhileFetching !== undefined) {
|
|
1425
|
-
status.returnedStale = true;
|
|
1426
|
-
}
|
|
1427
|
-
return allowStale ? value.__staleWhileFetching : undefined;
|
|
1515
|
+
return value;
|
|
1428
1516
|
}
|
|
1517
|
+
return undefined;
|
|
1429
1518
|
}
|
|
1430
|
-
|
|
1519
|
+
if (status)
|
|
1520
|
+
status.get = 'stale-fetching';
|
|
1521
|
+
if (allowStale && value.__staleWhileFetching !== undefined) {
|
|
1431
1522
|
if (status)
|
|
1432
|
-
status.
|
|
1433
|
-
|
|
1434
|
-
// it's not stale, which means this isn't a staleWhileRefetching.
|
|
1435
|
-
// If it's not stale, and fetching, AND has a __staleWhileFetching
|
|
1436
|
-
// value, then that means the user fetched with {forceRefresh:true},
|
|
1437
|
-
// so it's safe to return that value.
|
|
1438
|
-
if (fetching) {
|
|
1439
|
-
return value.__staleWhileFetching;
|
|
1440
|
-
}
|
|
1441
|
-
this.#moveToTail(index);
|
|
1442
|
-
if (updateAgeOnGet) {
|
|
1443
|
-
this.#updateItemAge(index);
|
|
1444
|
-
}
|
|
1445
|
-
return value;
|
|
1523
|
+
status.returnedStale = true;
|
|
1524
|
+
return value.__staleWhileFetching;
|
|
1446
1525
|
}
|
|
1526
|
+
return undefined;
|
|
1447
1527
|
}
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1528
|
+
// not stale
|
|
1529
|
+
if (status)
|
|
1530
|
+
status.get = fetching ? 'fetching' : 'hit';
|
|
1531
|
+
// if we're currently fetching it, we don't actually have it yet
|
|
1532
|
+
// it's not stale, which means this isn't a staleWhileRefetching.
|
|
1533
|
+
// If it's not stale, and fetching, AND has a __staleWhileFetching
|
|
1534
|
+
// value, then that means the user fetched with {forceRefresh:true},
|
|
1535
|
+
// so it's safe to return that value.
|
|
1536
|
+
this.#moveToTail(index);
|
|
1537
|
+
if (updateAgeOnGet) {
|
|
1538
|
+
this.#updateItemAge(index);
|
|
1539
|
+
}
|
|
1540
|
+
return fetching ? value.__staleWhileFetching : value;
|
|
1451
1541
|
}
|
|
1452
1542
|
#connect(p, n) {
|
|
1453
1543
|
this.#prev[n] = p;
|
|
@@ -1482,6 +1572,13 @@ export class LRUCache {
|
|
|
1482
1572
|
return this.#delete(k, 'delete');
|
|
1483
1573
|
}
|
|
1484
1574
|
#delete(k, reason) {
|
|
1575
|
+
if (metrics.hasSubscribers) {
|
|
1576
|
+
metrics.publish({
|
|
1577
|
+
op: 'delete',
|
|
1578
|
+
delete: reason,
|
|
1579
|
+
key: k,
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1485
1582
|
let deleted = false;
|
|
1486
1583
|
if (this.#size !== 0) {
|
|
1487
1584
|
const index = this.#keyMap.get(k);
|