Comparing version 6.0.0-canary.1 to 6.0.0-canary.3
@@ -0,0 +0,0 @@ { |
@@ -1,1 +0,1 @@ | ||
var x=Object.create;var f=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var M=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var P=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of w(e))!L.call(s,a)&&a!==t&&f(s,a,{get:()=>e[a],enumerable:!(n=A(e,a))||n.enumerable});return s};var v=(s,e,t)=>(t=s!=null?x(g(s)):{},P(e||!s||!s.__esModule?f(t,"default",{value:s,enumerable:!0}):t,s));var m=M((F,b)=>{var i=1e3,o=i*60,u=o*60,r=u*24,k=r*7,D=r*365.25;b.exports=function(s,e){e=e||{};var t=typeof s;if(t==="string"&&s.length>0)return z(s);if(t==="number"&&isFinite(s))return e.long?O(s):E(s);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(s))};function z(s){if(s=String(s),!(s.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(!!e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*D;case"weeks":case"week":case"w":return t*k;case"days":case"day":case"d":return t*r;case"hours":case"hour":case"hrs":case"hr":case"h":return t*u;case"minutes":case"minute":case"mins":case"min":case"m":return t*o;case"seconds":case"second":case"secs":case"sec":case"s":return t*i;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function E(s){var e=Math.abs(s);return e>=r?Math.round(s/r)+"d":e>=u?Math.round(s/u)+"h":e>=o?Math.round(s/o)+"m":e>=i?Math.round(s/i)+"s":s+"ms"}function O(s){var e=Math.abs(s);return e>=r?_(s,e,r,"day"):e>=u?_(s,e,u,"hour"):e>=o?_(s,e,o,"minute"):e>=i?_(s,e,i,"second"):s+" ms"}function _(s,e,t,n){var a=e>=t*1.5;return Math.round(s/t)+" "+n+(a?"s":"")}});var c=v(m(),1);var y=v(m(),1),d=class{__eventListeners;__recentEntry;__maxAge;__maxAmount;__webhook;__autoclear;constructor(e){e=e??{},this.__eventListeners={},this.__maxAge=typeof e.maxAge=="number"?e.maxAge*1e3:typeof e.maxAge=="string"?(0,y.default)(e.maxAge):(0,y.default)("10m"),this.__maxAmount=e.maxAmount??1e4,this.__autoclear=e.autoclear??!1,typeof e.webhook=="string"&&(this.__webhook=e.webhook)}},p=d;var l=class extends p{store;consumedMemory;constructor(e){super(e),this.store=new Map,this.consumedMemory=0}async deleteOutdated(e){}async set(e,t,n){if(this.__eventListeners.set&&await this.__eventListeners.set(e,t,n),this.store.has(e))return;this.__autoclear&&this.__maxAge!==1/0&&await this.deleteOutdated(),this.__autoclear&&this.store.size+1>this.__maxAmount&&await this.deleteOutdated(1);let a={value:t,...typeof n=="string"?{expiresAt:Date.now()+(0,c.default)(n)}:typeof n=="number"?{expiresAt:Date.now()+n*1e3}:this.__maxAge!==1/0&&{expiresAt:Date.now()+this.__maxAge}};this.store.set(e,a),this.__recentEntry={key:e,...a}}async setMany(e){this.__eventListeners.setMany&&await this.__eventListeners.setMany(e),this.__autoclear&&this.__maxAge!==1/0&&await this.deleteOutdated(),this.__autoclear&&this.store.size+e.length>this.__maxAmount&&await this.deleteOutdated(this.store.size+e.length-this.__maxAmount);for(let t of e){if(this.store.has(t[0]))continue;let n={value:t[1],...typeof t[2]=="string"?{expiresAt:Date.now()+(0,c.default)(t[2])}:typeof t[2]=="number"?{expiresAt:Date.now()+t[2]*1e3}:this.__maxAge!==1/0&&{expiresAt:Date.now()+this.__maxAge}};this.store.set(t[0],n),this.__recentEntry={key:t[0],...n}}}async get(e,t){t=t??{},this.__eventListeners.get&&await this.__eventListeners.get(e,t);let n=this.store.get(e);if(!!n){if(t.validate&&n.expiresAt&&Date.now()>=n.expiresAt){this.store.delete(e);return}return t.delete&&this.store.delete(e),n.value}}async getMany(e,t){t=t??{},this.__eventListeners.getMany&&await this.__eventListeners.getMany(e,t);let n=[];for(let a of e){let h=this.store.get(a);if(!h){n=[...n,void 0];continue}if(t.validate&&h.expiresAt&&Date.now()>=h.expiresAt){this.store.delete(a),n=[...n,void 0];continue}t.delete&&this.store.delete(a),n=[...n,h.value]}return n}async update(e,t){this.__eventListeners.update&&await this.__eventListeners.update(e,t);let n=this.store.get(e);if(!n)return;let a={value:t,...n.expiresAt&&{expiresAt:n.expiresAt}};this.store.set(e,a),this.__recentEntry={key:e,...a}}async updateMany(e){this.__eventListeners.updateMany&&await this.__eventListeners.updateMany(e);for(let t of e){let n=this.store.get(t[0]);if(!n)continue;let a={value:t[1],...n.expiresAt&&{expiresAt:n.expiresAt}};this.store.set(t[0],a),this.__recentEntry={key:t[0],...a}}}async delete(e){this.__eventListeners.delete&&await this.__eventListeners.delete(e),this.store.delete(e)}async deleteMany(e){this.__eventListeners.deleteMany&&await this.__eventListeners.deleteMany(e),e.length===0&&this.store.clear();for(let t of e)this.store.delete(t)}async has(e){return this.__eventListeners.has&&await this.__eventListeners.has(e),this.store.has(e)}async size(){return this.__eventListeners.size&&await this.__eventListeners.size(),this.store.size}async keys(){return this.__eventListeners.keys&&await this.__eventListeners.keys(),[...this.store.keys()]}async values(){this.__eventListeners.values&&await this.__eventListeners.values();let e=[];for(let[t,n]of this.store)e=[...e,n.value];return e}async clear(){this.__eventListeners.clear&&await this.__eventListeners.clear();for(let[e,t]of this.store)t.expiresAt&&Date.now()>=t.expiresAt&&this.store.delete(e)}async memory(){this.__eventListeners.memory&&await this.__eventListeners.memory();let e=[...this.store.keys()].toString()+[...this.store.values()].toString(),t=Buffer.from(e);return Buffer.byteLength(t)}async recent(){return this.__eventListeners.recent&&await this.__eventListeners.recent(),this.__recentEntry}async maxAge(e){return this.__eventListeners.maxAge&&await this.__eventListeners.maxAge(),e?(this.__maxAge=typeof e=="number"?e*1e3:(0,c.default)(e),this.__maxAge):this.__maxAge}async maxAmount(e){return this.__eventListeners.maxAmount&&await this.__eventListeners.maxAmount(),e?(this.__maxAmount=e,e):this.__maxAmount}async each(e){this.__eventListeners.each&&await this.__eventListeners.each();for(let[t,n]of this.store)await e(t,n)}async on(){this.__eventListeners.on&&await this.__eventListeners.on()}},S=l;export{S as MemoryCache}; | ||
var x=Object.create;var f=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var M=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports);var k=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of w(e))!L.call(s,a)&&a!==t&&f(s,a,{get:()=>e[a],enumerable:!(n=A(e,a))||n.enumerable});return s};var v=(s,e,t)=>(t=s!=null?x(g(s)):{},k(e||!s||!s.__esModule?f(t,"default",{value:s,enumerable:!0}):t,s));var y=M((S,b)=>{var i=1e3,o=i*60,u=o*60,r=u*24,P=r*7,D=r*365.25;b.exports=function(s,e){e=e||{};var t=typeof s;if(t==="string"&&s.length>0)return E(s);if(t==="number"&&isFinite(s))return e.long?O(s):z(s);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(s))};function E(s){if(s=String(s),!(s.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(s);if(!!e){var t=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return t*D;case"weeks":case"week":case"w":return t*P;case"days":case"day":case"d":return t*r;case"hours":case"hour":case"hrs":case"hr":case"h":return t*u;case"minutes":case"minute":case"mins":case"min":case"m":return t*o;case"seconds":case"second":case"secs":case"sec":case"s":return t*i;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function z(s){var e=Math.abs(s);return e>=r?Math.round(s/r)+"d":e>=u?Math.round(s/u)+"h":e>=o?Math.round(s/o)+"m":e>=i?Math.round(s/i)+"s":s+"ms"}function O(s){var e=Math.abs(s);return e>=r?h(s,e,r,"day"):e>=u?h(s,e,u,"hour"):e>=o?h(s,e,o,"minute"):e>=i?h(s,e,i,"second"):s+" ms"}function h(s,e,t,n){var a=e>=t*1.5;return Math.round(s/t)+" "+n+(a?"s":"")}});var m=v(y(),1);var c=v(y(),1),d=class{__eventListeners;__recentEntry;__maxAge;__maxAmount;__webhook;__autoclear;constructor(e){e=e??{},this.__eventListeners={},this.__maxAge=typeof e.maxAge=="number"?e.maxAge*1e3:typeof e.maxAge=="string"?(0,c.default)(e.maxAge):(0,c.default)("10m"),this.__maxAmount=e.maxAmount??1e4,this.__autoclear=e.autoclear??!1,typeof e.webhook=="string"&&(this.__webhook=e.webhook)}},p=d;var l=class extends p{store;consumedMemory;constructor(e){super(e),this.store=new Map,this.consumedMemory=0}async deleteOutdated(e){}async set(e,t,n){this.__eventListeners.set&&await this.__eventListeners.set(e,t,n),this.__autoclear&&this.__maxAge!==1/0&&await this.deleteOutdated(),this.__autoclear&&this.store.size+1>this.__maxAmount&&await this.deleteOutdated(1);let a={value:t,...typeof n=="string"?{expiresAt:Date.now()+(0,m.default)(n)}:typeof n=="number"?{expiresAt:Date.now()+n*1e3}:this.__maxAge!==1/0&&{expiresAt:Date.now()+this.__maxAge}};this.store.set(e,a),this.__recentEntry={key:e,...a}}async setMany(e){this.__eventListeners.setMany&&await this.__eventListeners.setMany(e),this.__autoclear&&this.__maxAge!==1/0&&await this.deleteOutdated(),this.__autoclear&&this.store.size+e.length>this.__maxAmount&&await this.deleteOutdated(this.store.size+e.length-this.__maxAmount);for(let t of e){if(this.store.has(t[0]))continue;let n={value:t[1],...typeof t[2]=="string"?{expiresAt:Date.now()+(0,m.default)(t[2])}:typeof t[2]=="number"?{expiresAt:Date.now()+t[2]*1e3}:this.__maxAge!==1/0&&{expiresAt:Date.now()+this.__maxAge}};this.store.set(t[0],n),this.__recentEntry={key:t[0],...n}}}async get(e,t){t=t??{},this.__eventListeners.get&&await this.__eventListeners.get(e,t);let n=this.store.get(e);if(!!n){if(t.validate&&n.expiresAt&&Date.now()>=n.expiresAt){this.store.delete(e);return}return t.delete&&this.store.delete(e),n.value}}async getMany(e,t){t=t??{},this.__eventListeners.getMany&&await this.__eventListeners.getMany(e,t);let n=[];for(let a of e){let _=this.store.get(a);if(!_){n=[...n,void 0];continue}if(t.validate&&_.expiresAt&&Date.now()>=_.expiresAt){this.store.delete(a),n=[...n,void 0];continue}t.delete&&this.store.delete(a),n=[...n,_.value]}return n}async update(e,t){this.__eventListeners.update&&await this.__eventListeners.update(e,t),this.__autoclear&&this.__maxAge!==1/0&&await this.deleteOutdated();let n=this.store.get(e);if(!n)return;let a={value:t,...n.expiresAt&&{expiresAt:n.expiresAt}};this.store.set(e,a),this.__recentEntry={key:e,...a}}async updateMany(e){this.__eventListeners.updateMany&&await this.__eventListeners.updateMany(e);for(let t of e){let n=this.store.get(t[0]);if(!n)continue;let a={value:t[1],...n.expiresAt&&{expiresAt:n.expiresAt}};this.store.set(t[0],a),this.__recentEntry={key:t[0],...a}}}async delete(e){this.__eventListeners.delete&&await this.__eventListeners.delete(e),this.store.delete(e)}async deleteMany(e){this.__eventListeners.deleteMany&&await this.__eventListeners.deleteMany(e),e.length===0&&this.store.clear();for(let t of e)this.store.delete(t)}async has(e){return this.__eventListeners.has&&await this.__eventListeners.has(e),this.store.has(e)}async size(){return this.__eventListeners.size&&await this.__eventListeners.size(),this.store.size}async keys(){return this.__eventListeners.keys&&await this.__eventListeners.keys(),[...this.store.keys()]}async values(){this.__eventListeners.values&&await this.__eventListeners.values();let e=[];for(let[t,n]of this.store)e=[...e,n.value];return e}async clear(){this.__eventListeners.clear&&await this.__eventListeners.clear();for(let[e,t]of this.store)t.expiresAt&&Date.now()>=t.expiresAt&&this.store.delete(e)}async memory(){this.__eventListeners.memory&&await this.__eventListeners.memory();let e=[...this.store.keys()].toString()+[...this.store.values()].toString(),t=Buffer.from(e);return Buffer.byteLength(t)}async recent(){return this.__eventListeners.recent&&await this.__eventListeners.recent(),this.__recentEntry}async maxAge(e){return this.__eventListeners.maxAge&&await this.__eventListeners.maxAge(),e?(this.__maxAge=typeof e=="number"?e*1e3:(0,m.default)(e),this.__maxAge):this.__maxAge}async maxAmount(e){return this.__eventListeners.maxAmount&&await this.__eventListeners.maxAmount(),e?(this.__maxAmount=e,e):this.__maxAmount}async on(e,t){this.__eventListeners[e]=t}},F=l;export{F as MemoryCache}; |
{ | ||
"name": "cachu", | ||
"version": "6.0.0-canary.1", | ||
"version": "6.0.0-canary.3", | ||
"description": "A modern and simple key-value cache for Node.js.", | ||
@@ -34,15 +34,15 @@ "types": "types/index.d.ts", | ||
"devDependencies": { | ||
"@types/jest": "^27.5.1", | ||
"@types/jest": "^28.1.1", | ||
"@types/ms": "^0.7.31", | ||
"@types/node": "^17.0.40", | ||
"@typescript-eslint/eslint-plugin": "^5.27.0", | ||
"@typescript-eslint/parser": "^5.27.0", | ||
"esbuild": "^0.14.42", | ||
"@types/node": "^17.0.44", | ||
"@typescript-eslint/eslint-plugin": "^5.28.0", | ||
"@typescript-eslint/parser": "^5.28.0", | ||
"esbuild": "^0.14.43", | ||
"eslint": "^8.17.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-unused-imports": "^2.0.0", | ||
"jest": "^28.1.0", | ||
"jest": "^28.1.1", | ||
"ms": "^2.1.3", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^28.0.3", | ||
"ts-jest": "^28.0.5", | ||
"typescript": "^4.7.2" | ||
@@ -49,0 +49,0 @@ }, |
@@ -1,13 +0,10 @@ | ||
# cachu | ||
## cachu | ||
**Simple, minimalistic key-value cache, created by [Azury](https://azury.dev).** | ||
> **Warning** | ||
> cachu v6 is **not yet production-ready** and may contain bugs causing memory leaks. Check out the docs for our stable version [here](https://github.com/azurydev/cachu/tree/v5.x). | ||
- `fully asynchronous` | ||
- `small n' easy` | ||
- `zero dependencies` | ||
### Setup | ||
## Setup | ||
#### Installation | ||
### Installation | ||
```bash | ||
@@ -17,7 +14,7 @@ # Install the latest (stable) release. | ||
# Try out new feature before they hit our stable release. | ||
# Try out new features before they hit our stable release. | ||
npm i cachu@canary | ||
``` | ||
### Usage | ||
#### Usage | ||
@@ -37,11 +34,11 @@ ```js | ||
## Caches | ||
### Caches | ||
- [`BigCache`](/guide/caches/BigCache.md) | ||
- [`BigCache`](/guide/caches/BigCache.md) *(coming soon)* | ||
- [`MemoryCache`](/guide/caches/MemoryCache.md) | ||
- [`DiskCache`](/guide/caches/DiskCache.md) | ||
- [`DiskCache`](/guide/caches/DiskCache.md) *(coming soon)* | ||
## API | ||
### API | ||
- ### Configuration | ||
- #### Configuration | ||
@@ -51,3 +48,3 @@ - [`maxAge`](/guide/config/maxAge.md) to set the **maximum age** for each record in the cache | ||
- ### Features | ||
- #### Features | ||
@@ -58,4 +55,4 @@ - [`set(key, value, maxAge)`](/guide/features/set.md) | ||
- [`getMany([keys], config)`](/guide/features/getMany.md) | ||
- [`update(key, value, config)`](/guide/features/update.md) | ||
- [`updateMany([[key, value]], config)`](/guide/features/updateMany.md) | ||
- [`update(key, value)`](/guide/features/update.md) | ||
- [`updateMany([[key, value]])`](/guide/features/updateMany.md) | ||
- [`delete(key)`](/guide/features/delete.md) | ||
@@ -69,9 +66,4 @@ - [`deleteMany([keys])`](/guide/features/deleteMany.md) | ||
- [`recent()`](/guide/features/recent.md) | ||
- [`maxAge(age)`](/guide/features/maxAge.md) | ||
- [`maxAmount(amount)`](/guide/features/maxAmount.md) | ||
- [`oldest()`](/guide/features/oldest.md) | ||
- [`newest()`](/guide/features/newest.md) | ||
- [`maxAge(maxAge)`](/guide/features/maxAge.md) | ||
- [`maxAmount(maxAmount)`](/guide/features/maxAmount.md) | ||
- [`on(event, action)`](/guide/features/on.md) | ||
- [`dump()`](/guide/features/newest.md) | ||
- [`import(path, key)`](/guide/features/import.md) | ||
- [`export(path, key)`](/guide/features/export.md) |
@@ -1,2 +0,1 @@ | ||
import { Action } from '../types'; | ||
declare abstract class Cache { | ||
@@ -47,5 +46,4 @@ protected __eventListeners: { | ||
abstract maxAmount(maxAmount?: number): Promise<number>; | ||
abstract each(action: Action): Promise<void>; | ||
abstract on(): Promise<void>; | ||
abstract on(event: string, action: Function): Promise<void>; | ||
} | ||
export default Cache; |
@@ -1,2 +0,2 @@ | ||
import { Action } from '../types'; | ||
import { Event } from '../types'; | ||
import Cache from './Cache'; | ||
@@ -41,5 +41,4 @@ declare class MemoryCache extends Cache { | ||
maxAmount(maxAmount?: number): Promise<number>; | ||
each(action: Action): Promise<void>; | ||
on(): Promise<void>; | ||
on(event: Event | 'memory', action: Function): Promise<void>; | ||
} | ||
export default MemoryCache; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31229
10
190
65