@resolid/cache 1.2.1 → 1.2.2
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/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./null-cache-C6T2ju9e.mjs";function t(e){let t=e.split(`?`)[0]?.
|
|
1
|
+
import{t as e}from"./null-cache-C6T2ju9e.mjs";function t(e){let t=e.split(`?`)[0]?.replaceAll(/[/\\]/g,`:`).replaceAll(/:+/g,`:`).replaceAll(/^:|:$/g,``);if(!t)throw Error(`Cache key cannot be empty after normalization`);return t}var n=class{_store;_serializer;_defaultTtl;_inflight=new Map;constructor({store:t=new e,serializer:n={serialize:JSON.stringify,deserialize:JSON.parse},defaultTtl:r}={}){this._store=t,this._serializer=n,this._defaultTtl=r}async get(e,n){let r=await this._store.get(t(e));return r===void 0?n:this._serializer.deserialize(r)}async _set(e,n,r){return this._store.set(t(e),this._serializer.serialize(n),r)}async set(e,t,n){return this._set(e,t,n??this._defaultTtl)}async getOrSet(e,t,n){let r=await this.get(e);if(r!==void 0)return r;let i=this._inflight.get(e);if(i)return i;let a=n??this._defaultTtl,o=Promise.resolve(t({setTtl:e=>{a=e}})).then(async t=>(await this._set(e,t,a),this._inflight.delete(e),t)).catch(t=>{throw this._inflight.delete(e),t});return this._inflight.set(e,o),o}async del(e){return this._store.del(t(e))}async clear(){return this._store.clear()}async getMultiple(e,n){return this._store.getMultiple?(await this._store.getMultiple(e.map(t))).map(e=>e===void 0?n:this._serializer.deserialize(e)):Promise.all(e.map(e=>this.get(e,n)))}async setMultiple(e,n){if(this._store.setMultiple){let r={};for(let[n,i]of Object.entries(e))r[t(n)]=this._serializer.serialize(i);return this._store.setMultiple(r,n)}return(await Promise.all(Object.entries(e).map(([e,t])=>this.set(e,t,n)))).every(Boolean)}async delMultiple(e){return this._store.delMultiple?this._store.delMultiple(e.map(t)):(await Promise.all(e.map(e=>this.del(e)))).every(Boolean)}async has(e){return this._store.has?this._store.has(t(e)):await this.get(e)!==void 0}async dispose(){await this._store.dispose?.()}};export{n as Cacher};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolid/cache",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Type-safe Async Cache for TypeScript",
|
|
6
6
|
"keywords": [
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"quick-lru": "^7.3.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"tsdown": "^0.22.
|
|
47
|
+
"tsdown": "^0.22.3"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": "^22.
|
|
50
|
+
"node": "^22.22.0 || >=24"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "tsdown",
|