@resolid/cache 0.2.0 → 1.0.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 +6 -8
- package/dist/{index.d.ts → index.d.mts} +3 -3
- package/dist/index.mjs +1 -0
- package/dist/{stores.d.ts → stores.d.mts} +6 -6
- package/dist/stores.mjs +1 -0
- package/dist/{index-DvzAtk0z.d.ts → types-BvLwqpdf.d.mts} +3 -3
- package/package.json +26 -37
- package/dist/index.js +0 -1
- package/dist/stores.js +0 -1
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -1
- package/dist/utils-CV58ddJF.js +0 -1
- package/dist/utils.d.ts +0 -4
- package/dist/utils.js +0 -1
- /package/dist/{null-cache-95ZKDSid.js → null-cache-DGPituGm.mjs} +0 -0
package/README.md
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Type-safe Async Cache for TypeScript
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
5
5
|
|
|
6
6
|
<b>[Documentation](https://www.resolid.tech/docs/cache)</b> | [Framework Bundle](https://github.com/resolid/framework)
|
|
7
7
|
|
|
8
|
-
## Type-safe Async Cache for TypeScript
|
|
9
|
-
|
|
10
8
|
A fully-typed, flexible cache system for modern TypeScript projects.
|
|
11
9
|
Supports single and batch operations, optional TTL, and pluggable storage backends.
|
|
12
10
|
Designed for libraries, frameworks, and applications needing predictable async caching.
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
## Feature
|
|
15
13
|
|
|
16
14
|
- Fully typed with TypeScript — no `any`.
|
|
17
15
|
- Supports get/set/del/clear operations.
|
|
@@ -21,7 +19,7 @@ Designed for libraries, frameworks, and applications needing predictable async c
|
|
|
21
19
|
- Detects existence of keys via `has`.
|
|
22
20
|
- Handles disposal of resources via `dispose`.
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
## Installation
|
|
25
23
|
|
|
26
24
|
```shell
|
|
27
25
|
pnpm add @resolid/cache
|
|
@@ -33,7 +31,7 @@ yarn add @resolid/cache
|
|
|
33
31
|
bun add @resolid/cache
|
|
34
32
|
```
|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
## Usage
|
|
37
35
|
|
|
38
36
|
```js
|
|
39
37
|
import { Cacher } from "@resolid/cache";
|
|
@@ -62,7 +60,7 @@ await cache.clear();
|
|
|
62
60
|
await cache.dispose();
|
|
63
61
|
```
|
|
64
62
|
|
|
65
|
-
|
|
63
|
+
## Options
|
|
66
64
|
|
|
67
65
|
```ts
|
|
68
66
|
export interface CacheOptions {
|
|
@@ -71,7 +69,7 @@ export interface CacheOptions {
|
|
|
71
69
|
}
|
|
72
70
|
```
|
|
73
71
|
|
|
74
|
-
|
|
72
|
+
## Store Interface
|
|
75
73
|
|
|
76
74
|
Your custom store should implement `CacheStore`:
|
|
77
75
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as CacheStore } from "./
|
|
1
|
+
import { t as CacheStore } from "./types-BvLwqpdf.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
interface CacheOptions {
|
|
@@ -6,8 +6,8 @@ interface CacheOptions {
|
|
|
6
6
|
defaultTtl?: number;
|
|
7
7
|
}
|
|
8
8
|
declare class Cacher {
|
|
9
|
-
private readonly
|
|
10
|
-
private readonly
|
|
9
|
+
private readonly _store;
|
|
10
|
+
private readonly _defaultTtl?;
|
|
11
11
|
constructor({
|
|
12
12
|
store,
|
|
13
13
|
defaultTtl
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as CacheStore } from "./
|
|
1
|
+
import { t as CacheStore } from "./types-BvLwqpdf.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/stores/memory-cache.d.ts
|
|
4
4
|
declare class MemoryCache implements CacheStore {
|
|
5
|
-
private readonly
|
|
5
|
+
private readonly _lru;
|
|
6
6
|
constructor(maxSize?: number);
|
|
7
7
|
get(key: string): Promise<string | undefined>;
|
|
8
8
|
set(key: string, value: string, ttl?: number): Promise<boolean>;
|
|
@@ -13,15 +13,15 @@ declare class MemoryCache implements CacheStore {
|
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/stores/null-cache.d.ts
|
|
15
15
|
declare class NullCache implements Required<CacheStore> {
|
|
16
|
-
get<T>(
|
|
17
|
-
set(
|
|
16
|
+
get<T>(_key: string): Promise<T>;
|
|
17
|
+
set(__key: string, _value: string, _ttl?: number): Promise<boolean>;
|
|
18
18
|
del(_key: string): Promise<boolean>;
|
|
19
19
|
clear(): Promise<boolean>;
|
|
20
|
-
getMultiple<T>(
|
|
20
|
+
getMultiple<T>(keys: string[]): Promise<(T | undefined)[]>;
|
|
21
21
|
setMultiple(_values: Record<string, string>, _ttl?: number): Promise<boolean>;
|
|
22
22
|
delMultiple(_keys: string[]): Promise<boolean>;
|
|
23
23
|
has(_key: string): Promise<boolean>;
|
|
24
24
|
dispose(): Promise<void>;
|
|
25
25
|
}
|
|
26
26
|
//#endregion
|
|
27
|
-
export { MemoryCache, NullCache };
|
|
27
|
+
export { CacheStore, MemoryCache, NullCache };
|
package/dist/stores.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//#region src/types
|
|
2
|
-
|
|
1
|
+
//#region src/stores/types.d.ts
|
|
2
|
+
interface CacheStore {
|
|
3
3
|
get: (key: string) => Promise<string | undefined>;
|
|
4
4
|
set: (key: string, value: string, ttl?: number) => Promise<boolean>;
|
|
5
5
|
del: (key: string) => Promise<boolean>;
|
|
@@ -9,6 +9,6 @@ type CacheStore = {
|
|
|
9
9
|
delMultiple?: (keys: string[]) => Promise<boolean>;
|
|
10
10
|
has?: (key: string) => Promise<boolean>;
|
|
11
11
|
dispose?: () => Promise<void> | void;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
//#endregion
|
|
14
14
|
export { CacheStore as t };
|
package/package.json
CHANGED
|
@@ -1,69 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolid/cache",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Type-safe Async Cache for TypeScript",
|
|
6
6
|
"keywords": [
|
|
7
|
-
"resolid",
|
|
8
7
|
"cache",
|
|
9
|
-
"cache manager"
|
|
8
|
+
"cache manager",
|
|
9
|
+
"resolid"
|
|
10
10
|
],
|
|
11
11
|
"homepage": "https://www.resolid.tech",
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/resolid/framework.git",
|
|
15
|
-
"directory": "packages/cache"
|
|
16
|
-
},
|
|
17
12
|
"license": "MIT",
|
|
18
13
|
"author": {
|
|
19
14
|
"name": "Huijie Wei",
|
|
20
15
|
"email": "hello@resolid.tech"
|
|
21
16
|
},
|
|
22
|
-
"
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/resolid/framework.git",
|
|
20
|
+
"directory": "packages/cache"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
23
25
|
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
24
28
|
"exports": {
|
|
25
29
|
".": {
|
|
26
|
-
"types": "./dist/index.d.
|
|
27
|
-
"import": "./dist/index.
|
|
30
|
+
"types": "./dist/index.d.mts",
|
|
31
|
+
"import": "./dist/index.mjs"
|
|
28
32
|
},
|
|
29
33
|
"./stores": {
|
|
30
|
-
"types": "./dist/stores.d.
|
|
31
|
-
"import": "./dist/stores.
|
|
32
|
-
},
|
|
33
|
-
"./utils": {
|
|
34
|
-
"types": "./dist/utils.d.ts",
|
|
35
|
-
"import": "./dist/utils.js"
|
|
34
|
+
"types": "./dist/stores.d.mts",
|
|
35
|
+
"import": "./dist/stores.mjs"
|
|
36
36
|
},
|
|
37
|
-
"./
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true
|
|
41
42
|
},
|
|
42
|
-
"main": "./dist/index.js",
|
|
43
|
-
"types": "./dist/index.d.ts",
|
|
44
|
-
"files": [
|
|
45
|
-
"dist"
|
|
46
|
-
],
|
|
47
43
|
"dependencies": {
|
|
48
44
|
"destr": "^2.0.5",
|
|
49
45
|
"quick-lru": "^7.3.0"
|
|
50
46
|
},
|
|
51
47
|
"devDependencies": {
|
|
52
|
-
"
|
|
53
|
-
"tsdown": "^0.15.10",
|
|
54
|
-
"typescript": "^5.9.3",
|
|
55
|
-
"vitest": "^4.0.3"
|
|
48
|
+
"tsdown": "^0.21.5"
|
|
56
49
|
},
|
|
57
50
|
"engines": {
|
|
58
|
-
"node": "^
|
|
59
|
-
},
|
|
60
|
-
"publishConfig": {
|
|
61
|
-
"access": "public",
|
|
62
|
-
"provenance": true
|
|
51
|
+
"node": "^22.13.0 || >=24"
|
|
63
52
|
},
|
|
64
53
|
"scripts": {
|
|
65
54
|
"build": "tsdown",
|
|
66
|
-
"lint": "
|
|
55
|
+
"lint": "oxlint",
|
|
67
56
|
"test": "vitest run",
|
|
68
57
|
"typecheck": "tsc --noEmit"
|
|
69
58
|
}
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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};
|
package/dist/stores.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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};
|
package/dist/types.d.ts
DELETED
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{};
|
package/dist/utils-CV58ddJF.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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};
|
package/dist/utils.d.ts
DELETED
package/dist/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./utils-CV58ddJF.js";export{e as normalizeKey};
|
|
File without changes
|