Comparing version 5.3.0 to 5.4.0
@@ -1,1 +0,1 @@ | ||
var S=Object.create;var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var G=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),U=(n,e)=>{for(var a in e)p(n,a,{get:e[a],enumerable:!0})},v=(n,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of O(e))!E.call(n,d)&&d!==a&&p(n,d,{get:()=>e[d],enumerable:!(i=R(e,d))||i.enumerable});return n};var k=(n,e,a)=>(a=n!=null?S(C(n)):{},v(e||!n||!n.__esModule?p(a,"default",{value:n,enumerable:!0}):a,n)),L=n=>v(p({},"__esModule",{value:!0}),n);var b=G((ue,D)=>{var f=1e3,y=f*60,m=y*60,u=m*24,N=u*7,B=u*365.25;D.exports=function(n,e){e=e||{};var a=typeof n;if(a==="string"&&n.length>0)return F(n);if(a==="number"&&isFinite(n))return e.long?I(n):H(n);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(n))};function F(n){if(n=String(n),!(n.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(n);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*B;case"weeks":case"week":case"w":return a*N;case"days":case"day":case"d":return a*u;case"hours":case"hour":case"hrs":case"hr":case"h":return a*m;case"minutes":case"minute":case"mins":case"min":case"m":return a*y;case"seconds":case"second":case"secs":case"sec":case"s":return a*f;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}function H(n){var e=Math.abs(n);return e>=u?Math.round(n/u)+"d":e>=m?Math.round(n/m)+"h":e>=y?Math.round(n/y)+"m":e>=f?Math.round(n/f)+"s":n+"ms"}function I(n){var e=Math.abs(n);return e>=u?w(n,e,u,"day"):e>=m?w(n,e,m,"hour"):e>=y?w(n,e,y,"minute"):e>=f?w(n,e,f,"second"):n+" ms"}function w(n,e,a,i){var d=e>=a*1.5;return Math.round(n/a)+" "+i+(d?"s":"")}});var V={};U(V,{MemoryCache:()=>z});module.exports=L(V);var M=k(b()),K=(n={})=>{let e=new Map,a={},i,d=typeof n.maxAge=="number"?n.maxAge*1e3:typeof n.maxAge=="string"?(0,M.default)(n.maxAge):6e5,l=n.maxAmount??1e4,h=async()=>{e.forEach(async(t,r)=>{Date.now()-t.age>d&&e.delete(r)})},A=async()=>{let t=0,r=0;e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r=o)}),e.delete(r)};return{set:async(t,r,s)=>{if(a.set&&await a.set(t,r,s),e.has(t))return;d!==1/0&&await h(),e.size>l&&await A();let o={value:r,age:Date.now(),...typeof s=="string"?{maxAge:(0,M.default)(s)}:typeof s=="number"&&{maxAge:s*1e3}};return e.set(t,o),i={key:t,...o},{key:t,...o}},setMany:async t=>{a.setMany&&await a.setMany(t),d!==1/0&&await h();let r=[];for(let s of t){let o=s[0],c=s[1],g=s[2];if(e.has(o)){r.push(void 0);continue}let x={value:c,age:Date.now(),...typeof g=="string"?{maxAge:(0,M.default)(g)}:typeof g=="number"&&{maxAge:g*1e3}};e.size>l&&await A(),e.set(o,x),i={key:o,...x},r.push({key:o,...x})}return r},get:async(t,r={})=>{a.get&&await a.get(t,r);let s=e.get(t);if(!!s){if(r.validate!==!1&&(s.maxAge?Date.now()-s.age>s.maxAge:Date.now()-s.age>d)){e.delete(t);return}return r.delete&&e.delete(t),{key:t,...s}}},getMany:async(t,r={})=>{a.getMany&&await a.getMany(t,r);let s=[];for(let o of t){let c=e.get(o);if(!c){s.push(void 0);continue}if(r.validate!==!1&&(c.maxAge?Date.now()-c.age>c.maxAge:Date.now()-c.age>d)){e.delete(o),s.push(void 0);continue}r.delete&&e.delete(o),s.push({key:o,...c})}return r.reverse?s.reverse():s},update:async(t,r,s)=>{a.update&&await a.update(t,r,s??{});let o=e.get(t);if(!o)return;let c={value:r,age:s&&s.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(t,c),i={key:t,...c}},updateMany:async(t,r)=>{a.updateMany&&await a.updateMany(t,r??{});for(let s of t){let o=e.get(s[0]);if(!o)return;let c={value:s[1],age:r&&r.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(s[0],c),i={key:s[0],...c}}},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 r of t)e.delete(r)},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 r of[...e.values()])t.push(r.value);return t},clear:async()=>(a.clear&&await a.clear(),await h()),memory:async()=>{a.memory&&await a.memory();let t=[...e.keys()].toString()+[...e.values()].toString(),r=Buffer.from(t);return Buffer.byteLength(r)},recent:async()=>(a.recent&&await a.recent(),i),maxAge:async t=>(a.maxAge&&await a.maxAge(t),t&&(d=typeof t=="number"?t*1e3:typeof t=="string"?(0,M.default)(t):6e5,await h()),d),maxAmount:async t=>(a.maxAmount&&await a.maxAmount(t),t&&(l=t??1e4,await h()),l),newest:async()=>{if(a.newest&&await a.newest(),e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},oldest:async()=>{if(a.oldest&&await a.oldest(),e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{(t===0||s.age<t)&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},on:async(t,r)=>{a[t]=r},dump:async()=>{if(a.dump&&await a.dump(),e.size===0)return[];let t=[],r=[...e.keys()];for(let s of r){let o=e.get(s);!o||t.push({key:s,...o})}return t}}},z=K; | ||
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}); |
{ | ||
"name": "cachu", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"description": "🦝 Simple, Minimalistic KV Cache", | ||
@@ -8,3 +8,3 @@ "types": "./types/index.d.ts", | ||
"scripts": { | ||
"build": "esbuild src/index.ts --bundle --minify --format=cjs --outfile=dist/index.js", | ||
"build": "esbuild src/index.ts --bundle --minify --format=cjs --platform=node --outfile=dist/index.js", | ||
"publish:canary": "npm run build && npm publish --tag canary", | ||
@@ -11,0 +11,0 @@ "publish:patch": "npm run build && npm version patch && npm publish", |
@@ -14,3 +14,3 @@ declare type Key = any | ||
declare type SetManyMethod = (records: [Key, Value, number | string | undefined][]) => Promise<(Record | undefined)[]> | ||
declare type SetManyMethod = (records: ([Key, Value, number | string] | [Key, Value])[]) => Promise<(Record | undefined)[]> | ||
@@ -32,3 +32,3 @@ declare type GetMethod = (key: Key, config?: { | ||
declare type UpdateManyMethod = (records: [Key, Value][], config: { | ||
declare type UpdateManyMethod = (records: [Key, Value][], config?: { | ||
updateAge: boolean | ||
@@ -90,2 +90,6 @@ }) => Promise<void> | ||
declare type ImportMethod = (path: string, key: string) => Promise<boolean> | ||
declare type ExportMethod = (path: string, key: string) => Promise<{ path: string | undefined, success: boolean, exportedAt: Date | undefined, version: number }> | ||
declare type MemoryCache = (config?: { | ||
@@ -115,3 +119,5 @@ maxAge?: string | number, | ||
on: OnMethod, | ||
dump: DumpMethod | ||
dump: DumpMethod, | ||
import: ImportMethod, | ||
export: ExportMethod | ||
} | ||
@@ -146,4 +152,6 @@ | ||
DumpMethod, | ||
ImportMethod, | ||
ExportMethod, | ||
MemoryCache, | ||
memoryCache as default | ||
} |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
28488
266
1
1