@resolid/cache-file 1.0.1 → 1.1.1

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/README.md CHANGED
@@ -23,7 +23,7 @@ bun add @resolid/cache @resolid/cache-file
23
23
 
24
24
  ```ts
25
25
  import { Cacher } from "@resolid/cache";
26
- import { FileCache } from "@resolid/cache";
26
+ import { FileCache } from "@resolid/cache-file";
27
27
 
28
28
  const cache = new Cacher({ store: new FileCache("./.tmp/cache"), defaultTtl: 1000 });
29
29
  ```
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{access as e,mkdir as t,readFile as n,rm as r,writeFile as i}from"node:fs/promises";import{dirname as a,join as o}from"node:path";const s=/(\.\/|\.\.\/)/;var c=class{_basePath;_locks=new Map;constructor(e){this._basePath=e}_resolve(e){if(s.test(e))throw Error(`Invalid key: ${e}. Should not contain relative paths.`);return o(this._basePath,e.replaceAll(`:`,`/`))}async _exists(t){try{return await e(t),!0}catch{return!1}}async _lockedRun(e,t){let n=this._locks.get(e)??Promise.resolve(),r,i=new Promise(e=>r=e);this._locks.set(e,n.then(()=>i));try{return await n,await t()}finally{r(),this._locks.get(e)===i&&this._locks.delete(e)}}async get(e){let t=this._resolve(e);try{let e=await n(t,{encoding:`utf-8`}),[i,a]=JSON.parse(e);if(a!==-1&&a<Date.now()){await r(t,{force:!0});return}return i}catch{return}}async set(e,n,r){let o=this._resolve(e);return this._lockedRun(e,async()=>(await t(a(o),{recursive:!0}),await i(o,JSON.stringify([n,r?Date.now()+r*1e3:-1])),!0))}async del(e){let t=this._resolve(e);return await this._exists(t)?this._lockedRun(e,async()=>(await r(t),!0)):!1}async clear(){return await r(this._basePath,{recursive:!0,force:!0}),this._locks.clear(),!0}};export{c as FileCache};
1
+ import{access as e,mkdir as t,readFile as n,rm as r,writeFile as i}from"node:fs/promises";import a from"node:path";const o=/(\.\/|\.\.\/)/;var s=class{_basePath;_locks=new Map;constructor(e){this._basePath=e}_resolve(e){if(o.test(e))throw Error(`Invalid key: ${e}. Should not contain relative paths.`);return a.join(this._basePath,e.replaceAll(`:`,`/`))}async _exists(t){try{return await e(t),!0}catch{return!1}}async _lockedRun(e,t){let n=this._locks.get(e)??Promise.resolve(),r,i=new Promise(e=>r=e);this._locks.set(e,n.then(()=>i));try{return await n,await t()}finally{r(),this._locks.get(e)===i&&this._locks.delete(e)}}async get(e){let t=this._resolve(e);try{let e=await n(t,{encoding:`utf-8`}),[i,a]=JSON.parse(e);if(a!==-1&&a<Date.now()){await r(t,{force:!0});return}return i}catch{return}}async set(e,n,r){let o=this._resolve(e);return this._lockedRun(e,async()=>(await t(a.dirname(o),{recursive:!0}),await i(o,JSON.stringify([n,r?Date.now()+r*1e3:-1])),!0))}async del(e){let t=this._resolve(e);return await this._exists(t)?this._lockedRun(e,async()=>(await r(t),!0)):!1}async clear(){return await r(this._basePath,{recursive:!0,force:!0}),this._locks.clear(),!0}};export{s as FileCache};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolid/cache-file",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "private": false,
5
5
  "description": "File Cache store for @resolid/cache",
6
6
  "keywords": [
@@ -38,13 +38,13 @@
38
38
  "provenance": true
39
39
  },
40
40
  "devDependencies": {
41
- "tsdown": "^0.21.5"
41
+ "tsdown": "^0.22.3"
42
42
  },
43
43
  "peerDependencies": {
44
- "@resolid/cache": "^1.0.1"
44
+ "@resolid/cache": "^1.2.2"
45
45
  },
46
46
  "engines": {
47
- "node": "^22.13.0 || >=24"
47
+ "node": "^22.22.0 || >=24"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsdown",