@resolid/cache-manager-sqlite
Advanced tools
Comparing version 5.0.0 to 5.1.0
import O from 'better-sqlite3'; | ||
import 'cache-manager'; | ||
var h=()=>new Date().getTime(),w=a=>{let u=a?.isCacheable??(t=>t!=null),s=new O(a.sqliteFile),i=a.cacheTableName;s.exec(` | ||
CREATE TABLE IF NOT EXISTS ${i} ( | ||
var h=()=>new Date().getTime(),b=i=>{let u=i?.isCacheable??(t=>t!=null),s=new O(i.sqliteFile),a=i.cacheTableName;s.exec(` | ||
CREATE TABLE IF NOT EXISTS ${a} ( | ||
'cacheKey' TEXT PRIMARY KEY, | ||
@@ -11,5 +10,5 @@ 'cacheData' TEXT, | ||
); | ||
CREATE INDEX IF NOT EXISTS idx_expired_caches ON ${i}(expiredAt); | ||
`);let E=s.prepare(`SELECT * FROM ${i} WHERE cacheKey = ?`),y=s.prepare(`INSERT OR REPLACE INTO ${i}(cacheKey, cacheData, createdAt, expiredAt) VALUES (?, ?, ?, ?)`),g=s.prepare(`DELETE FROM ${i} WHERE cacheKey = ?`),S=s.prepare(`SELECT cacheKey FROM ${i} WHERE cacheKey LIKE ?`),T=s.prepare(`DELETE FROM ${i}`),d=(...t)=>{let r=h();return s.transaction(e=>e.map(c=>E.get(c)).filter(c=>c!=null&&(c.expiredAt==-1||c.expiredAt>r)))(t)},p=(...t)=>{s.transaction(n=>{for(let e of n)g.run(e);})(t);},m=(t,r)=>{let n=r??a?.ttl,e=h(),c=n!=null&&n!=0?e+n:-1;s.transaction((f,A,C)=>{for(let l of f){if(!u(l[1]))throw new Error(`no cacheable value ${JSON.stringify(l[1])}`);y.run(l[0],JSON.stringify(l[1]),A,C);}})(t,e,c);};return {del(t){return new Promise((r,n)=>{try{p(t),r();}catch(e){n(e);}})},get(t){return new Promise((r,n)=>{try{let e=d(t);e.length==0?r(void 0):r(JSON.parse(e[0].cacheData));}catch(e){n(e);}})},keys(t){return new Promise((r,n)=>{try{let e=S.all(t?.replace("*","%")??"%").map(c=>c.cacheKey);r(e);}catch(e){n(e);}})},mdel(...t){return new Promise((r,n)=>{try{p(...t),r();}catch(e){n(e);}})},mget(...t){return new Promise((r,n)=>{try{let e=d(...t).map(o=>JSON.parse(o.cacheData)),c=t.length-e.length;r(c?e.concat(Array(c).fill(void 0)):e);}catch(e){n(e);}})},mset(t,r){return new Promise((n,e)=>{try{m(t,r),n();}catch(c){e(c);}})},reset(){return new Promise((t,r)=>{try{T.run(),t();}catch(n){r(n);}})},set(t,r,n){return new Promise((e,c)=>{try{m([[t,r]],n),e();}catch(o){c(o);}})},ttl(t){return new Promise((r,n)=>{try{let e=d(t);e.length==0?r(-2):r(e[0].expiredAt==-1?-1:e[0].expiredAt-h());}catch(e){n(e);}})},get client(){return s}}}; | ||
CREATE INDEX IF NOT EXISTS idx_expired_caches ON ${a}(expiredAt); | ||
`);let E=s.prepare(`SELECT * FROM ${a} WHERE cacheKey = ?`),g=s.prepare(`INSERT OR REPLACE INTO ${a}(cacheKey, cacheData, createdAt, expiredAt) VALUES (?, ?, ?, ?)`),y=s.prepare(`DELETE FROM ${a} WHERE cacheKey = ?`),S=s.prepare(`SELECT cacheKey FROM ${a} WHERE cacheKey LIKE ?`),T=s.prepare(`DELETE FROM ${a}`),d=(...t)=>{let r=h();return s.transaction(e=>e.map(c=>E.get(c)).filter(c=>c!=null&&(c.expiredAt==-1||c.expiredAt>r)))(t)},m=(...t)=>{s.transaction(n=>{for(let e of n)y.run(e);})(t);},p=(t,r)=>{let n=r??i?.ttl,e=h(),c=n!=null&&n!=0?e+n:-1;s.transaction((f,A,C)=>{for(let l of f){if(!u(l[1]))throw new Error(`no cacheable value ${JSON.stringify(l[1])}`);g.run(l[0],JSON.stringify(l[1]),A,C);}})(t,e,c);};return {del(t){return new Promise((r,n)=>{try{m(t),r();}catch(e){n(e);}})},get(t){return new Promise((r,n)=>{try{let e=d(t);e.length==0?r(void 0):r(JSON.parse(e[0].cacheData));}catch(e){n(e);}})},keys(t){return new Promise((r,n)=>{try{let e=S.all(t?.replace("*","%")??"%").map(c=>c.cacheKey);r(e);}catch(e){n(e);}})},mdel(...t){return new Promise((r,n)=>{try{m(...t),r();}catch(e){n(e);}})},mget(...t){return new Promise((r,n)=>{try{let e=d(...t).map(o=>JSON.parse(o.cacheData)),c=t.length-e.length;r(c?e.concat(Array(c).fill(void 0)):e);}catch(e){n(e);}})},mset(t,r){return new Promise((n,e)=>{try{p(t,r),n();}catch(c){e(c);}})},reset(){return new Promise((t,r)=>{try{T.run(),t();}catch(n){r(n);}})},set(t,r,n){return new Promise((e,c)=>{try{p([[t,r]],n),e();}catch(o){c(o);}})},ttl(t){return new Promise((r,n)=>{try{let e=d(t);e.length==0?r(-2):r(e[0].expiredAt==-1?-1:e[0].expiredAt-h());}catch(e){n(e);}})},get client(){return s}}}; | ||
export { w as sqliteStore }; | ||
export { b as sqliteStore }; |
{ | ||
"name": "@resolid/cache-manager-sqlite", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "A new SQLite store for cache-manager", | ||
"keywords": [ | ||
"cache-manager", | ||
"sqlite", | ||
"better-sqlite3" | ||
], | ||
"keywords": ["cache-manager", "sqlite", "better-sqlite3"], | ||
"license": "MIT", | ||
@@ -17,29 +13,37 @@ "sideEffects": false, | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"scripts": { | ||
"build": "tsup", | ||
"test": "vitest --ui", | ||
"format": "biome format ./src" | ||
"check": "biome check --apply ./src" | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
} | ||
} | ||
}, | ||
"devDependencies": { | ||
"@faker-js/faker": "^8.4.0", | ||
"@types/better-sqlite3": "^7.6.9", | ||
"@vitest/ui": "^1.2.2", | ||
"better-sqlite3": "^9.3.0", | ||
"cache-manager": "^5.4.0", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.2.2" | ||
"@biomejs/biome": "^1.7.1", | ||
"@faker-js/faker": "^8.4.1", | ||
"@types/better-sqlite3": "^7.6.10", | ||
"@vitest/ui": "^1.5.2", | ||
"better-sqlite3": "^9.6.0", | ||
"cache-manager": "^5.5.1", | ||
"tsup": "^8.0.2", | ||
"typescript": "^5.4.5", | ||
"vitest": "^1.5.2" | ||
}, | ||
"peerDependencies": { | ||
"better-sqlite3": "^9.3.0", | ||
"cache-manager": "^5.4.0" | ||
"better-sqlite3": "^9.6.0", | ||
"cache-manager": "^5.5.1" | ||
}, | ||
@@ -46,0 +50,0 @@ "repository": { |
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
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
8602
7
49
9
2