@resolid/cache 0.1.0
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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/index-DvzAtk0z.d.ts +14 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +1 -0
- package/dist/null-cache-2iHFUXTp.js +1 -0
- package/dist/stores.d.ts +9 -0
- package/dist/stores.js +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/dist/utils-CV58ddJF.js +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-present, Resolid Tech
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Resolid: Cache Package
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
<b>[Documentation](https://www.resolid.tech/docs/cache)</b> | [Framework Bundle](https://github.com/resolid/framework)
|
|
7
|
+
|
|
8
|
+
## License
|
|
9
|
+
|
|
10
|
+
MIT License (MIT). Please see [LICENSE](./LICENSE) for more information.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/types/index.d.ts
|
|
2
|
+
type CacheStore = {
|
|
3
|
+
get: (key: string) => Promise<string | undefined>;
|
|
4
|
+
set: (key: string, value: string, ttl?: number) => Promise<boolean>;
|
|
5
|
+
del: (key: string) => Promise<boolean>;
|
|
6
|
+
clear: () => Promise<boolean>;
|
|
7
|
+
getMultiple?: (keys: string[]) => Promise<(string | undefined)[]>;
|
|
8
|
+
setMultiple?: (values: Record<string, string>, ttl?: number) => Promise<boolean>;
|
|
9
|
+
delMultiple?: (keys: string[]) => Promise<boolean>;
|
|
10
|
+
has?: (key: string) => Promise<boolean>;
|
|
11
|
+
dispose?: () => Promise<void> | void;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { CacheStore as t };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { t as CacheStore } from "./index-DvzAtk0z.js";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type CreateCacheOptions = {
|
|
5
|
+
store?: CacheStore;
|
|
6
|
+
defaultTtl?: number;
|
|
7
|
+
};
|
|
8
|
+
type CacheInstance = {
|
|
9
|
+
get: <T>(key: string, defaultValue?: T) => Promise<T | undefined>;
|
|
10
|
+
set: <T>(key: string, value: T, ttl?: number) => Promise<boolean>;
|
|
11
|
+
del: (key: string) => Promise<boolean>;
|
|
12
|
+
clear: () => Promise<boolean>;
|
|
13
|
+
getMultiple: <T>(keys: string[], defaultValue?: T) => Promise<(T | undefined)[]>;
|
|
14
|
+
setMultiple: <T>(values: Record<string, T>, ttl?: number) => Promise<boolean>;
|
|
15
|
+
delMultiple: (keys: string[]) => Promise<boolean>;
|
|
16
|
+
has: (key: string) => Promise<boolean>;
|
|
17
|
+
dispose: () => Promise<void> | void;
|
|
18
|
+
};
|
|
19
|
+
declare const createCache: (options?: CreateCacheOptions) => CacheInstance;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CacheInstance, CreateCacheOptions, createCache };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./null-cache-2iHFUXTp.js";import{t}from"./utils-CV58ddJF.js";import{destr as n}from"destr";const r=(r={})=>{let{defaultTtl:i,store:a=e}=r,o=async(e,r)=>{let i=await a.get(t(e));return i===void 0?r:n(i)},s=(e,n,r)=>a.set(t(e),JSON.stringify(n),r??i),c=e=>a.del(t(e));return{get:o,set:s,del:c,clear:()=>a.clear(),getMultiple:(e,r)=>typeof a.getMultiple==`function`?a.getMultiple(e.map(e=>t(e))).then(e=>e.map(e=>e===void 0?r:n(e))):Promise.all(e.map(e=>o(e,r))),setMultiple:(e,n)=>typeof a.setMultiple==`function`?a.setMultiple(Object.entries(e).reduce((e,[n,r])=>(e[t(n)]=JSON.stringify(r),e),{}),n):Promise.all(Object.entries(e).map(([e,t])=>s(e,t,n))).then(e=>e.every(Boolean)),delMultiple:e=>typeof a.delMultiple==`function`?a.delMultiple(e.map(e=>t(e))):Promise.all(e.map(c)).then(e=>e.every(Boolean)),has:async e=>typeof a.has==`function`?a.has(t(e)):o(e).then(e=>e!==void 0),dispose:async()=>{a.dispose&&await a.dispose()}}};export{r as createCache};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={get:async()=>{},set:async()=>!0,del:async()=>!0,clear:async()=>!0,getMultiple:async e=>e.map(()=>void 0),setMultiple:async()=>!0,delMultiple:async()=>!0,has:async()=>!1,dispose:async()=>{}};export{e as t};
|
package/dist/stores.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as CacheStore } from "./index-DvzAtk0z.js";
|
|
2
|
+
|
|
3
|
+
//#region src/stores/memory-cache.d.ts
|
|
4
|
+
declare const createMemoryCache: (maxSize?: number) => CacheStore;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/stores/null-cache.d.ts
|
|
7
|
+
declare const nullCache: Required<CacheStore>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { createMemoryCache, nullCache };
|
package/dist/stores.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./null-cache-2iHFUXTp.js";import t from"quick-lru";const n=(e=1e3)=>{let n=new t({maxSize:e});return{get:async e=>n.get(e),set:async(e,t,r)=>(n.set(e,t,r?{maxAge:r*1e3}:void 0),!0),del:async e=>n.delete(e),clear:async()=>(n.clear(),!0),dispose:async()=>{n.clear()}}};export{n as createMemoryCache,e as nullCache};
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./utils-CV58ddJF.js";export{e as normalizeKey};
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@resolid/cache",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "The Resolid Cache package.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"resolid",
|
|
8
|
+
"cache",
|
|
9
|
+
"cache manager"
|
|
10
|
+
],
|
|
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
|
+
"license": "MIT",
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Huijie Wei",
|
|
20
|
+
"email": "hello@resolid.tech"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./stores": {
|
|
30
|
+
"types": "./dist/stores.d.ts",
|
|
31
|
+
"import": "./dist/stores.js"
|
|
32
|
+
},
|
|
33
|
+
"./utils": {
|
|
34
|
+
"types": "./dist/utils.d.ts",
|
|
35
|
+
"import": "./dist/utils.js"
|
|
36
|
+
},
|
|
37
|
+
"./types": {
|
|
38
|
+
"types": "./dist/types.d.ts",
|
|
39
|
+
"import": "./dist/types.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"main": "./dist/index.js",
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsdown",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"destr": "^2.0.5",
|
|
55
|
+
"quick-lru": "^7.3.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@vitest/coverage-v8": "beta",
|
|
59
|
+
"tsdown": "^0.15.9",
|
|
60
|
+
"typescript": "^5.9.3",
|
|
61
|
+
"vitest": "beta"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public",
|
|
68
|
+
"provenance": true
|
|
69
|
+
}
|
|
70
|
+
}
|