🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@resolid/cache

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@resolid/cache - npm Package Compare versions

Comparing version
1.0.1
to
1.1.0
+7
-0
dist/index.d.mts
import { t as CacheStore } from "./types-BvLwqpdf.mjs";
//#region src/index.d.ts
type Serializer = {
serialize: <T = unknown>(value: T) => string;
deserialize: <T = unknown>(value: string) => T;
};
interface CacheOptions {
store?: CacheStore;
serializer?: Serializer;
defaultTtl?: number;

@@ -10,5 +15,7 @@ }

private readonly _store;
private readonly _serializer;
private readonly _defaultTtl?;
constructor({
store,
serializer,
defaultTtl

@@ -15,0 +22,0 @@ }?: CacheOptions);

+1
-1

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

import{t as e}from"./null-cache-DGPituGm.mjs";import{destr as t}from"destr";const n=e=>{let t=e.split(`?`)[0]?.replace(/[/\\]/g,`:`).replace(/:+/g,`:`).replace(/^:|:$/g,``);if(!t)throw Error(`Cache key cannot be empty after normalization`);return t};var r=class{_store;_defaultTtl;constructor({store:t=new e,defaultTtl:n}={}){this._store=t,this._defaultTtl=n}async get(e,r){let i=await this._store.get(n(e));return i===void 0?r:t(i)}set(e,t,r){return this._store.set(n(e),JSON.stringify(t),r??this._defaultTtl)}del(e){return this._store.del(n(e))}clear(){return this._store.clear()}async getMultiple(e,r){return this._store.getMultiple?(await this._store.getMultiple(e.map(n))).map(e=>e===void 0?r:t(e)):Promise.all(e.map(e=>this.get(e,r)))}async setMultiple(e,t){if(this._store.setMultiple){let r=Object.entries(e).reduce((e,[t,r])=>(e[n(t)]=JSON.stringify(r),e),{});return this._store.setMultiple(r,t)}return(await Promise.all(Object.entries(e).map(([e,n])=>this.set(e,n,t)))).every(Boolean)}async delMultiple(e){return this._store.delMultiple?this._store.delMultiple(e.map(n)):(await Promise.all(e.map(e=>this.del(e)))).every(Boolean)}async has(e){return this._store.has?this._store.has(n(e)):await this.get(e)!==void 0}async dispose(){await this._store.dispose?.()}};export{r as Cacher};
import{t as e}from"./null-cache-DGPituGm.mjs";function t(e){let t=e.split(`?`)[0]?.replace(/[/\\]/g,`:`).replace(/:+/g,`:`).replace(/^:|:$/g,``);if(!t)throw Error(`Cache key cannot be empty after normalization`);return t}var n=class{_store;_serializer;_defaultTtl;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)}set(e,n,r){return this._store.set(t(e),this._serializer.serialize(n),r??this._defaultTtl)}del(e){return this._store.del(t(e))}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){return this._store.setMultiple?this._store.setMultiple(Object.entries(e).reduce((e,[n,r])=>(e[t(n)]=this._serializer.serialize(r),e),{}),n):(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};
{
"name": "@resolid/cache",
"version": "1.0.1",
"version": "1.1.0",
"private": false,

@@ -44,7 +44,6 @@ "description": "Type-safe Async Cache for TypeScript",

"dependencies": {
"destr": "^2.0.5",
"quick-lru": "^7.3.0"
},
"devDependencies": {
"tsdown": "^0.21.5"
"tsdown": "^0.22.0"
},

@@ -51,0 +50,0 @@ "engines": {

@@ -68,2 +68,7 @@ # Type-safe Async Cache for TypeScript

store?: CacheStore;
// A custom serializer to use when storing and retrieving values from the cache.
// For example, you could use superjson to serialize and deserialize your values instead of JSON.stringify and JSON.parse.
serializer?: Serializer;
defaultTtl?: number;

@@ -70,0 +75,0 @@ }