🚀 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
0.2.0
to
1.0.0
+26
dist/index.d.mts
import { t as CacheStore } from "./types-D3cbGkJC.mjs";
//#region src/index.d.ts
interface CacheOptions {
store?: CacheStore;
defaultTtl?: number;
}
declare class Cacher {
private readonly _store;
private readonly _defaultTtl?;
constructor({
store,
defaultTtl
}?: CacheOptions);
get<T>(key: string, defaultValue?: T): Promise<T | undefined>;
set<T>(key: string, value: T, ttl?: number): Promise<boolean>;
del(key: string): Promise<boolean>;
clear(): Promise<boolean>;
getMultiple<T>(keys: string[], defaultValue?: T): Promise<(T | undefined)[]>;
setMultiple<T>(values: Record<string, T>, ttl?: number): Promise<boolean>;
delMultiple(keys: string[]): Promise<boolean>;
has(key: string): Promise<boolean>;
dispose(): Promise<void>;
}
//#endregion
export { CacheOptions, Cacher };
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};
var e=class{async get(e){}async set(e,t,n){return!0}async del(e){return!0}async clear(){return!0}async getMultiple(e){return e.map(()=>void 0)}async setMultiple(e,t){return!0}async delMultiple(e){return!0}async has(e){return!1}async dispose(){}};export{e as t};
import { t as CacheStore } from "./types-D3cbGkJC.mjs";
//#region src/stores/memory-cache.d.ts
declare class MemoryCache implements CacheStore {
private readonly _lru;
constructor(maxSize?: number);
get(key: string): Promise<string | undefined>;
set(key: string, value: string, ttl?: number): Promise<boolean>;
del(key: string): Promise<boolean>;
clear(): Promise<boolean>;
dispose(): Promise<void>;
}
//#endregion
//#region src/stores/null-cache.d.ts
declare class NullCache implements Required<CacheStore> {
get<T>(_key: string): Promise<T>;
set(__key: string, _value: string, _ttl?: number): Promise<boolean>;
del(_key: string): Promise<boolean>;
clear(): Promise<boolean>;
getMultiple<T>(keys: string[]): Promise<(T | undefined)[]>;
setMultiple(_values: Record<string, string>, _ttl?: number): Promise<boolean>;
delMultiple(_keys: string[]): Promise<boolean>;
has(_key: string): Promise<boolean>;
dispose(): Promise<void>;
}
//#endregion
export { CacheStore, MemoryCache, NullCache };
import{t as e}from"./null-cache-DGPituGm.mjs";import t from"quick-lru";var n=class{_lru;constructor(e=1e3){this._lru=new t({maxSize:e})}async get(e){return this._lru.get(e)}async set(e,t,n){return this._lru.set(e,t,n?{maxAge:n*1e3}:void 0),!0}async del(e){return this._lru.delete(e)}async clear(){return this._lru.clear(),!0}async dispose(){this._lru.clear()}};export{n as MemoryCache,e as NullCache};
//#region src/stores/types.d.ts
interface CacheStore {
get: (key: string) => Promise<string | undefined>;
set: (key: string, value: string, ttl?: number) => Promise<boolean>;
del: (key: string) => Promise<boolean>;
clear: () => Promise<boolean>;
getMultiple?: (keys: string[]) => Promise<(string | undefined)[]>;
setMultiple?: (values: Record<string, string>, ttl?: number) => Promise<boolean>;
delMultiple?: (keys: string[]) => Promise<boolean>;
has?: (key: string) => Promise<boolean>;
dispose?: () => Promise<void> | void;
}
//#endregion
export { CacheStore as t };
+26
-37
{
"name": "@resolid/cache",
"version": "0.2.0",
"version": "1.0.0",
"private": false,
"description": "The Resolid Cache package.",
"description": "Type-safe Async Cache for TypeScript",
"keywords": [
"resolid",
"cache",
"cache manager"
"cache manager",
"resolid"
],
"homepage": "https://www.resolid.tech",
"license": "MIT",
"author": {
"name": "Huijie Wei",
"email": "hello@resolid.tech"
},
"repository": {

@@ -17,32 +22,22 @@ "type": "git",

},
"license": "MIT",
"author": {
"name": "Huijie Wei",
"email": "hello@resolid.tech"
},
"files": [
"dist"
],
"type": "module",
"sideEffects": false,
"type": "module",
"types": "./dist/index.d.mts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
"types": "./dist/index.d.mts",
"import": "./dist/index.mjs"
},
"./stores": {
"types": "./dist/stores.d.ts",
"import": "./dist/stores.js"
},
"./utils": {
"types": "./dist/utils.d.ts",
"import": "./dist/utils.js"
},
"./types": {
"types": "./dist/types.d.ts",
"import": "./dist/types.js"
"types": "./dist/stores.d.mts",
"import": "./dist/stores.mjs"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"publishConfig": {
"access": "public",
"provenance": true
},
"dependencies": {

@@ -53,17 +48,11 @@ "destr": "^2.0.5",

"devDependencies": {
"@vitest/coverage-v8": "^4.0.3",
"tsdown": "^0.15.10",
"typescript": "^5.9.3",
"vitest": "^4.0.3"
"tsdown": "^0.20.3",
"typescript": "^5.9.3"
},
"engines": {
"node": "^20.19.0 || ^22.13.0 || >=24"
"node": "^22.13.0 || >=24"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"scripts": {
"build": "tsdown",
"lint": "eslint .",
"lint": "oxlint",
"test": "vitest run",

@@ -70,0 +59,0 @@ "typecheck": "tsc --noEmit"

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

# Resolid: Cache Package
# Type-safe Async Cache for TypeScript

@@ -8,4 +8,2 @@ ![GitHub License](https://img.shields.io/github/license/resolid/framework)

## Type-safe Async Cache for TypeScript
A fully-typed, flexible cache system for modern TypeScript projects.

@@ -15,3 +13,3 @@ Supports single and batch operations, optional TTL, and pluggable storage backends.

### Feature
## Feature

@@ -26,3 +24,3 @@ - Fully typed with TypeScript — no `any`.

### Installation
## Installation

@@ -39,3 +37,3 @@ ```shell

### Usage
## Usage

@@ -69,3 +67,3 @@ ```js

### Options
## Options

@@ -79,3 +77,3 @@ ```ts

### Store Interface
## Store Interface

@@ -82,0 +80,0 @@ Your custom store should implement `CacheStore`:

//#region src/types/index.d.ts
type CacheStore = {
get: (key: string) => Promise<string | undefined>;
set: (key: string, value: string, ttl?: number) => Promise<boolean>;
del: (key: string) => Promise<boolean>;
clear: () => Promise<boolean>;
getMultiple?: (keys: string[]) => Promise<(string | undefined)[]>;
setMultiple?: (values: Record<string, string>, ttl?: number) => Promise<boolean>;
delMultiple?: (keys: string[]) => Promise<boolean>;
has?: (key: string) => Promise<boolean>;
dispose?: () => Promise<void> | void;
};
//#endregion
export { CacheStore as t };
import { t as CacheStore } from "./index-DvzAtk0z.js";
//#region src/index.d.ts
interface CacheOptions {
store?: CacheStore;
defaultTtl?: number;
}
declare class Cacher {
private readonly store;
private readonly defaultTtl?;
constructor({
store,
defaultTtl
}?: CacheOptions);
get<T>(key: string, defaultValue?: T): Promise<T | undefined>;
set<T>(key: string, value: T, ttl?: number): Promise<boolean>;
del(key: string): Promise<boolean>;
clear(): Promise<boolean>;
getMultiple<T>(keys: string[], defaultValue?: T): Promise<(T | undefined)[]>;
setMultiple<T>(values: Record<string, T>, ttl?: number): Promise<boolean>;
delMultiple(keys: string[]): Promise<boolean>;
has(key: string): Promise<boolean>;
dispose(): Promise<void>;
}
//#endregion
export { CacheOptions, Cacher };
import{t as e}from"./null-cache-95ZKDSid.js";import{t}from"./utils-CV58ddJF.js";import{destr as n}from"destr";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(t(e));return i===void 0?r:n(i)}set(e,n,r){return this.store.set(t(e),JSON.stringify(n),r??this.defaultTtl)}del(e){return this.store.del(t(e))}clear(){return this.store.clear()}async getMultiple(e,r){return this.store.getMultiple?(await this.store.getMultiple(e.map(t))).map(e=>e===void 0?r:n(e)):Promise.all(e.map(e=>this.get(e,r)))}async setMultiple(e,n){if(this.store.setMultiple){let r=Object.entries(e).reduce((e,[n,r])=>(e[t(n)]=JSON.stringify(r),e),{});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{r as Cacher};
var e=class{async get(e){}async set(e,t,n){return!0}async del(e){return!0}async clear(){return!0}async getMultiple(e){return e.map(()=>void 0)}async setMultiple(e,t){return!0}async delMultiple(e){return!0}async has(e){return!1}async dispose(){}};export{e as t};
import { t as CacheStore } from "./index-DvzAtk0z.js";
//#region src/stores/memory-cache.d.ts
declare class MemoryCache implements CacheStore {
private readonly lru;
constructor(maxSize?: number);
get(key: string): Promise<string | undefined>;
set(key: string, value: string, ttl?: number): Promise<boolean>;
del(key: string): Promise<boolean>;
clear(): Promise<boolean>;
dispose(): Promise<void>;
}
//#endregion
//#region src/stores/null-cache.d.ts
declare class NullCache implements Required<CacheStore> {
get<T>(_: string): Promise<T>;
set(_key: string, _value: string, _ttl?: number): Promise<boolean>;
del(_key: string): Promise<boolean>;
clear(): Promise<boolean>;
getMultiple<T>(_keys: string[]): Promise<(T | undefined)[]>;
setMultiple(_values: Record<string, string>, _ttl?: number): Promise<boolean>;
delMultiple(_keys: string[]): Promise<boolean>;
has(_key: string): Promise<boolean>;
dispose(): Promise<void>;
}
//#endregion
export { MemoryCache, NullCache };
import{t as e}from"./null-cache-95ZKDSid.js";import t from"quick-lru";var n=class{lru;constructor(e=1e3){this.lru=new t({maxSize:e})}async get(e){return this.lru.get(e)}async set(e,t,n){return this.lru.set(e,t,n?{maxAge:n*1e3}:void 0),!0}async del(e){return this.lru.delete(e)}async clear(){return this.lru.clear(),!0}async dispose(){this.lru.clear()}};export{n as MemoryCache,e as NullCache};
import { t as CacheStore } from "./index-DvzAtk0z.js";
export { CacheStore };
export{};
const e=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};export{e as t};
//#region src/utils/index.d.ts
declare const normalizeKey: (key: string) => string;
//#endregion
export { normalizeKey };
import{t as e}from"./utils-CV58ddJF.js";export{e as normalizeKey};