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

cachu

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cachu - npm Package Compare versions

Comparing version 5.4.4 to 6.0.0-canary.0

2

dist/index.js

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

var U=Object.create;var x=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var N=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),E=(r,e)=>{for(var a in e)x(r,a,{get:e[a],enumerable:!0})},b=(r,e,a,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of F(e))!I.call(r,d)&&d!==a&&x(r,d,{get:()=>e[d],enumerable:!(c=k(e,d))||c.enumerable});return r};var G=(r,e,a)=>(a=r!=null?U(_(r)):{},b(e||!r||!r.__esModule?x(a,"default",{value:r,enumerable:!0}):a,r)),K=r=>b(x({},"__esModule",{value:!0}),r);var C=N((xe,S)=>{var h=1e3,M=h*60,p=M*60,l=p*24,V=l*7,J=l*365.25;S.exports=function(r,e){e=e||{};var a=typeof r;if(a==="string"&&r.length>0)return L(r);if(a==="number"&&isFinite(r))return e.long?P(r):H(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function L(r){if(r=String(r),!(r.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(r);if(!!e){var a=parseFloat(e[1]),c=(e[2]||"ms").toLowerCase();switch(c){case"years":case"year":case"yrs":case"yr":case"y":return a*J;case"weeks":case"week":case"w":return a*V;case"days":case"day":case"d":return a*l;case"hours":case"hour":case"hrs":case"hr":case"h":return a*p;case"minutes":case"minute":case"mins":case"min":case"m":return a*M;case"seconds":case"second":case"secs":case"sec":case"s":return a*h;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}function H(r){var e=Math.abs(r);return e>=l?Math.round(r/l)+"d":e>=p?Math.round(r/p)+"h":e>=M?Math.round(r/M)+"m":e>=h?Math.round(r/h)+"s":r+"ms"}function P(r){var e=Math.abs(r);return e>=l?w(r,e,l,"day"):e>=p?w(r,e,p,"hour"):e>=M?w(r,e,M,"minute"):e>=h?w(r,e,h,"second"):r+" ms"}function w(r,e,a,c){var d=e>=a*1.5;return Math.round(r/a)+" "+c+(d?"s":"")}});var Y={};E(Y,{MemoryCache:()=>$});module.exports=K(Y);var g=G(C()),v=require("fs/promises");var A=require("crypto"),R=async(r,e)=>{let a=(0,A.randomBytes)(16),c=(0,A.createCipheriv)("aes-256-cbc",Buffer.from(e),a),d=Buffer.concat([c.update(r),c.final()]);return`${a.toString("hex")}:${d.toString("hex")}`};var z=require("crypto"),O=async(r,e)=>{let a=r.split(":"),c=Buffer.from(a.shift(),"hex"),d=Buffer.from(a.join(":"),"hex"),f=(0,z.createDecipheriv)("aes-256-cbc",Buffer.from(e),c);return Buffer.concat([f.update(d),f.final()]).toString()};var j=(r={})=>{let e=new Map,a={},c,d=typeof r.maxAge=="number"?r.maxAge*1e3:typeof r.maxAge=="string"?(0,g.default)(r.maxAge):6e5,f=r.maxAmount??1e4,m=async()=>{for(let[t,o]of e)Date.now()-o.age>d&&e.delete(t)},D=async()=>{let t=0,o;for(let[n,s]of e)s.age>t&&(t=s.age,o=n);o&&e.delete(o)};return{set:async(t,o,n)=>{if(a.set&&await a.set(t,o,n),e.has(t))return;d!==1/0&&await m(),e.size>f&&await D();let s={value:o,age:Date.now(),...typeof n=="string"?{maxAge:(0,g.default)(n)}:typeof n=="number"&&{maxAge:n*1e3}};return e.set(t,s),c={key:t,...s},{key:t,...s}},setMany:async t=>{a.setMany&&await a.setMany(t),d!==1/0&&await m();let o=[];for(let n of t){let s=n[0],i=n[1],u=n[2];if(e.has(s)){o.push(void 0);continue}let y={value:i,age:Date.now(),...typeof u=="string"?{maxAge:(0,g.default)(u)}:typeof u=="number"&&{maxAge:u*1e3}};e.size>f&&await D(),e.set(s,y),c={key:s,...y},o.push({key:s,...y})}return o},get:async(t,o={})=>{a.get&&await a.get(t,o);let n=e.get(t);if(!!n){if(o.validate!==!1&&(n.maxAge?Date.now()-n.age>n.maxAge:Date.now()-n.age>d)){e.delete(t);return}return o.delete&&e.delete(t),{key:t,...n}}},getMany:async(t,o={})=>{a.getMany&&await a.getMany(t,o);let n=[];for(let s of t){let i=e.get(s);if(!i){n=[...n,void 0];continue}if(o.validate!==!1&&(i.maxAge?Date.now()-i.age>i.maxAge:Date.now()-i.age>d)){e.delete(s),n=[...n,void 0];continue}o.delete&&e.delete(s),n=[...n,{key:s,...i}]}return o.reverse?n.reverse():n},update:async(t,o,n)=>{a.update&&await a.update(t,o,n??{});let s=e.get(t);if(!s)return;let i={value:o,age:n&&n.updateAge?Date.now():s.age,...s.maxAge&&{maxAge:s.maxAge}};e.set(t,i),c={key:t,...i}},updateMany:async(t,o)=>{a.updateMany&&await a.updateMany(t,o??{});for(let n of t){let s=e.get(n[0]);if(!s)continue;let i={value:n[1],age:o&&o.updateAge?Date.now():s.age,...s.maxAge&&{maxAge:s.maxAge}};e.set(n[0],i),c={key:n[0],...i}}},delete:async t=>{a.delete&&await a.delete(t),e.delete(t)},deleteMany:async t=>{a.deleteMany&&await a.deleteMany(t),t.length===0&&e.clear();for(let o of t)e.delete(o)},has:async t=>(a.has&&await a.has(t),e.has(t)),size:async()=>(a.size&&await a.size(),e.size),keys:async()=>(a.keys&&await a.keys(),[...e.keys()]),values:async()=>{a.values&&await a.values();let t=[];for(let[o,n]of e)t=[...t,n.value];return t},clear:async()=>(a.clear&&await a.clear(),await m()),memory:async()=>{a.memory&&await a.memory();let t=[...e.keys()].toString()+[...e.values()].toString(),o=Buffer.from(t);return Buffer.byteLength(o)},recent:async()=>(a.recent&&await a.recent(),c),maxAge:async t=>(a.maxAge&&await a.maxAge(t),t&&(d=typeof t=="number"?t*1e3:typeof t=="string"?(0,g.default)(t):6e5,await m()),d),maxAmount:async t=>(a.maxAmount&&await a.maxAmount(t),t&&(f=t??1e4,await m()),f),newest:async()=>{if(a.newest&&await a.newest(),e.size===0)return;let t=0,o;for(let[n,s]of e)s.age>t&&(t=s.age,o={key:n,...s});return o},oldest:async()=>{if(a.oldest&&await a.oldest(),e.size===0)return;let t=0,o;for(let[n,s]of e)(t===0||s.age<t)&&(t=s.age,o={key:n,...s});return o},on:async(t,o)=>{a[t]=o},dump:async()=>{if(a.dump&&await a.dump(),e.size===0)return[];let t=[];for(let[o,n]of e)t=[...t,{key:o,...n}];return t},import:async(t,o)=>{try{let n=await(0,v.readFile)(t,{encoding:"utf-8"}),s=await O(n,o),i=JSON.parse(s);for(let u of i.records)e.set(u.key,{value:u.value,age:u.age,...u.maxAge&&{maxAge:u.maxAge}});return!0}catch(n){return console.log(n),!1}},export:async(t,o)=>{try{let n=[];for(let[B,T]of e)n=[...n,{key:B,...T}];let s=new Date,i={records:n,metadata:{exportedAt:s,version:5}},u=Math.floor(Math.random()*1e8),y=`${t}/${s.getUTCMonth()<10?"0":""}${s.getUTCMonth()+1}-${s.getUTCDate()<10?"0":""}${s.getUTCDate()}-${s.getUTCFullYear()} #${u}.cachu`;return await(0,v.writeFile)(y,await R(JSON.stringify(i),o),{encoding:"utf-8"}),{path:y,success:!0,exportedAt:s,version:5}}catch{return{path:void 0,success:!1,exportedAt:void 0,version:5}}}}},$=j;0&&(module.exports={MemoryCache});
var k=Object.create;var w=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var E=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),G=(r,e)=>{for(var a in e)w(r,a,{get:e[a],enumerable:!0})},S=(r,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of _(e))!N.call(r,c)&&c!==a&&w(r,c,{get:()=>e[c],enumerable:!(i=F(e,c))||i.enumerable});return r};var K=(r,e,a)=>(a=r!=null?k(I(r)):{},S(e||!r||!r.__esModule?w(a,"default",{value:r,enumerable:!0}):a,r)),V=r=>S(w({},"__esModule",{value:!0}),r);var R=E((we,C)=>{var h=1e3,M=h*60,p=M*60,m=p*24,J=m*7,L=m*365.25;C.exports=function(r,e){e=e||{};var a=typeof r;if(a==="string"&&r.length>0)return H(r);if(a==="number"&&isFinite(r))return e.long?j(r):P(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))};function H(r){if(r=String(r),!(r.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(r);if(!!e){var a=parseFloat(e[1]),i=(e[2]||"ms").toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return a*L;case"weeks":case"week":case"w":return a*J;case"days":case"day":case"d":return a*m;case"hours":case"hour":case"hrs":case"hr":case"h":return a*p;case"minutes":case"minute":case"mins":case"min":case"m":return a*M;case"seconds":case"second":case"secs":case"sec":case"s":return a*h;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}function P(r){var e=Math.abs(r);return e>=m?Math.round(r/m)+"d":e>=p?Math.round(r/p)+"h":e>=M?Math.round(r/M)+"m":e>=h?Math.round(r/h)+"s":r+"ms"}function j(r){var e=Math.abs(r);return e>=m?A(r,e,m,"day"):e>=p?A(r,e,p,"hour"):e>=M?A(r,e,M,"minute"):e>=h?A(r,e,h,"second"):r+" ms"}function A(r,e,a,i){var c=e>=a*1.5;return Math.round(r/a)+" "+i+(c?"s":"")}});var q={};G(q,{MemoryCache:()=>B});module.exports=V(q);var x=K(R()),D=require("fs/promises");var v=require("crypto"),z=async(r,e)=>{let a=(0,v.randomBytes)(16),i=(0,v.createCipheriv)("aes-256-cbc",Buffer.from(e),a),c=Buffer.concat([i.update(r),i.final()]);return`${a.toString("hex")}:${c.toString("hex")}`};var O=require("crypto"),$=async(r,e)=>{let a=r.split(":"),i=Buffer.from(a.shift(),"hex"),c=Buffer.from(a.join(":"),"hex"),f=(0,O.createDecipheriv)("aes-256-cbc",Buffer.from(e),i);return Buffer.concat([f.update(c),f.final()]).toString()};var Y=(r={})=>{let e=new Map,a={},i,c=0,f=typeof r.maxAge=="number"?r.maxAge*1e3:typeof r.maxAge=="string"?(0,x.default)(r.maxAge):6e5,l=r.maxAmount??1e4,g=async()=>{for(let[t,o]of e)Date.now()-o.age>f&&e.delete(t)},b=async()=>{let t=0,o;for(let[n,s]of e)s.age>t&&(t=s.age,o=n);o&&e.delete(o)};return{set:async(t,o,n)=>{if(a.set&&await a.set(t,o,n),e.has(t))return;f!==1/0&&await g(),e.size>l&&await b();let s={value:o,age:Date.now(),...typeof n=="string"?{maxAge:(0,x.default)(n)}:typeof n=="number"&&{maxAge:n*1e3}};return e.set(t,s),i={key:t,...s},{key:t,...s}},setMany:async t=>{a.setMany&&await a.setMany(t),f!==1/0&&await g();let o=[];for(let n of t){let s=n[0],d=n[1],u=n[2];if(e.has(s)){o.push(void 0);continue}let y={value:d,age:Date.now(),...typeof u=="string"?{maxAge:(0,x.default)(u)}:typeof u=="number"&&{maxAge:u*1e3}};e.size>l&&await b(),e.set(s,y),i={key:s,...y},o.push({key:s,...y})}return o},get:async(t,o={})=>{a.get&&await a.get(t,o);let n=e.get(t);if(!!n){if(o.validate!==!1&&(n.maxAge?Date.now()-n.age>n.maxAge:Date.now()-n.age>f)){e.delete(t);return}return o.delete&&e.delete(t),{key:t,...n}}},getMany:async(t,o={})=>{a.getMany&&await a.getMany(t,o);let n=[];for(let s of t){let d=e.get(s);if(!d){n=[...n,void 0];continue}if(o.validate!==!1&&(d.maxAge?Date.now()-d.age>d.maxAge:Date.now()-d.age>f)){e.delete(s),n=[...n,void 0];continue}o.delete&&e.delete(s),n=[...n,{key:s,...d}]}return o.reverse?n.reverse():n},update:async(t,o,n)=>{a.update&&await a.update(t,o,n??{});let s=e.get(t);if(!s)return;let d={value:o,age:n&&n.updateAge?Date.now():s.age,...s.maxAge&&{maxAge:s.maxAge}};e.set(t,d),i={key:t,...d}},updateMany:async(t,o)=>{a.updateMany&&await a.updateMany(t,o??{});for(let n of t){let s=e.get(n[0]);if(!s)continue;let d={value:n[1],age:o&&o.updateAge?Date.now():s.age,...s.maxAge&&{maxAge:s.maxAge}};e.set(n[0],d),i={key:n[0],...d}}},delete:async t=>{a.delete&&await a.delete(t),e.delete(t)},deleteMany:async t=>{a.deleteMany&&await a.deleteMany(t),t.length===0&&e.clear();for(let o of t)e.delete(o)},has:async t=>(a.has&&await a.has(t),e.has(t)),size:async()=>(a.size&&await a.size(),e.size),keys:async()=>(a.keys&&await a.keys(),[...e.keys()]),values:async()=>{a.values&&await a.values();let t=[];for(let[o,n]of e)t=[...t,n.value];return t},clear:async()=>(a.clear&&await a.clear(),await g()),memory:async()=>{a.memory&&await a.memory();let t=[...e.keys()].toString()+[...e.values()].toString(),o=Buffer.from(t);return Buffer.byteLength(o)},recent:async()=>(a.recent&&await a.recent(),i),maxAge:async t=>(a.maxAge&&await a.maxAge(t),t&&(f=typeof t=="number"?t*1e3:typeof t=="string"?(0,x.default)(t):6e5,await g()),f),maxAmount:async t=>(a.maxAmount&&await a.maxAmount(t),t&&(l=t??1e4,await g()),l),newest:async()=>{if(a.newest&&await a.newest(),e.size===0)return;let t=0,o;for(let[n,s]of e)s.age>t&&(t=s.age,o={key:n,...s});return o},oldest:async()=>{if(a.oldest&&await a.oldest(),e.size===0)return;let t=0,o;for(let[n,s]of e)(t===0||s.age<t)&&(t=s.age,o={key:n,...s});return o},on:async(t,o)=>{a[t]=o},dump:async()=>{if(a.dump&&await a.dump(),e.size===0)return[];let t=[];for(let[o,n]of e)t=[...t,{key:o,...n}];return t},import:async(t,o)=>{try{let n=await(0,D.readFile)(t,{encoding:"utf-8"}),s=await $(n,o),d=JSON.parse(s);for(let u of d.records)e.set(u.key,{value:u.value,age:u.age,...u.maxAge&&{maxAge:u.maxAge}});return!0}catch(n){return console.log(n),!1}},export:async(t,o)=>{try{let n=[];for(let[T,U]of e)n=[...n,{key:T,...U}];let s=new Date,d={records:n,metadata:{exportedAt:s,version:5}},u=Math.floor(Math.random()*1e8),y=`${t}/${s.getUTCMonth()<10?"0":""}${s.getUTCMonth()+1}-${s.getUTCDate()<10?"0":""}${s.getUTCDate()}-${s.getUTCFullYear()} #${u}.cachu`;return await(0,D.writeFile)(y,await z(JSON.stringify(d),o),{encoding:"utf-8"}),{path:y,success:!0,exportedAt:s,version:5}}catch{return{path:void 0,success:!1,exportedAt:void 0,version:5}}}}},B=Y;0&&(module.exports={MemoryCache});
{
"name": "cachu",
"version": "5.4.4",
"version": "6.0.0-canary.0",
"description": "🦝 Simple, Minimalistic KV Cache",

@@ -36,7 +36,7 @@ "types": "./types/index.d.ts",

"devDependencies": {
"@types/jest": "^27.5.0",
"@types/jest": "^27.5.1",
"@types/ms": "^0.7.31",
"esbuild": "^0.14.38",
"esbuild": "^0.14.39",
"ms": "^2.1.3",
"ts-jest": "^28.0.1",
"ts-jest": "^28.0.2",
"typescript": "^4.6.4"

@@ -43,0 +43,0 @@ },

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