@md-oss/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 +5 -0
- package/README.md +471 -0
- package/dist/async.cjs +2 -0
- package/dist/async.cjs.map +1 -0
- package/dist/async.d.cts +92 -0
- package/dist/async.d.mts +92 -0
- package/dist/async.mjs +2 -0
- package/dist/async.mjs.map +1 -0
- package/dist/env.cjs +2 -0
- package/dist/env.cjs.map +1 -0
- package/dist/env.d.cts +5 -0
- package/dist/env.d.mts +5 -0
- package/dist/env.mjs +2 -0
- package/dist/env.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lru.cjs +2 -0
- package/dist/lru.cjs.map +1 -0
- package/dist/lru.d.cts +9 -0
- package/dist/lru.d.mts +9 -0
- package/dist/lru.mjs +2 -0
- package/dist/lru.mjs.map +1 -0
- package/dist/manager.cjs +2 -0
- package/dist/manager.cjs.map +1 -0
- package/dist/manager.d.cts +69 -0
- package/dist/manager.d.mts +69 -0
- package/dist/manager.mjs +2 -0
- package/dist/manager.mjs.map +1 -0
- package/dist/promise.cjs +2 -0
- package/dist/promise.cjs.map +1 -0
- package/dist/promise.d.cts +12 -0
- package/dist/promise.d.mts +12 -0
- package/dist/promise.mjs +2 -0
- package/dist/promise.mjs.map +1 -0
- package/dist/redis-client.cjs +2 -0
- package/dist/redis-client.cjs.map +1 -0
- package/dist/redis-client.d.cts +27 -0
- package/dist/redis-client.d.mts +27 -0
- package/dist/redis-client.mjs +2 -0
- package/dist/redis-client.mjs.map +1 -0
- package/dist/types.d.cts +60 -0
- package/dist/types.d.mts +60 -0
- package/package.json +127 -0
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import { CreateCacheOptions, Events } from 'cache-manager';
|
|
3
|
+
import Keyv from 'keyv';
|
|
4
|
+
|
|
5
|
+
type AbstractCache<T> = {
|
|
6
|
+
get: (key: string) => Promise<T | null | undefined>;
|
|
7
|
+
mget: (keys: string[]) => Promise<(T | null | undefined)[]>;
|
|
8
|
+
ttl: (key: string) => Promise<number | null>;
|
|
9
|
+
set: (key: string, value: T | null, ttl?: number) => Promise<T | null>;
|
|
10
|
+
mset: (list: SetCacheArguments<T | null>[]) => Promise<SetCacheArguments<T | null>[]>;
|
|
11
|
+
del: (key: string) => Promise<boolean>;
|
|
12
|
+
mdel: (keys: string[]) => Promise<[boolean, boolean[]]>;
|
|
13
|
+
clear: () => Promise<boolean>;
|
|
14
|
+
wrap: (key: string, fnc: () => T | Promise<T>, ttl?: number | ((value: T) => number), refreshThreshold?: number) => Promise<T>;
|
|
15
|
+
on: <E extends keyof Events>(event: E, listener: Events[E]) => EventEmitter;
|
|
16
|
+
off: <E extends keyof Events>(event: E, listener: Events[E]) => EventEmitter;
|
|
17
|
+
disconnect: () => Promise<undefined>;
|
|
18
|
+
};
|
|
19
|
+
type ResolvedCreateCacheOptions<T extends NonNullable<unknown>> = Omit<CreateCacheOptions, 'stores'> & {
|
|
20
|
+
stores: Keyv<T>[];
|
|
21
|
+
};
|
|
22
|
+
type SetCacheArguments<T> = {
|
|
23
|
+
key: string;
|
|
24
|
+
value: T;
|
|
25
|
+
ttl?: number;
|
|
26
|
+
};
|
|
27
|
+
type CacheManagerMetadata = {
|
|
28
|
+
hits: number;
|
|
29
|
+
misses: number;
|
|
30
|
+
added: number;
|
|
31
|
+
deleted: number;
|
|
32
|
+
updated: number;
|
|
33
|
+
cleared: number;
|
|
34
|
+
};
|
|
35
|
+
type WithCacheSource = 'cache' | 'no-cache';
|
|
36
|
+
type WithCacheDetails = {
|
|
37
|
+
source: WithCacheSource;
|
|
38
|
+
cached: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* - If `cached` is `true`, the time in milliseconds the data was cached for
|
|
41
|
+
* - If `cached` is `false`, the remaining time in milliseconds until the cache expires
|
|
42
|
+
*/
|
|
43
|
+
cachedFor: number | null;
|
|
44
|
+
};
|
|
45
|
+
type WithCacheDataFn<K, T, O = undefined> = O extends undefined ? (key: K) => T | null | undefined | Promise<T | null | undefined> : (key: K) => T | O | null | undefined | Promise<T | O | null | undefined>;
|
|
46
|
+
type WithCacheValidator<T, O> = (item: T | O) => item is T;
|
|
47
|
+
type WithCacheTransformer<T, O> = (item: T | O, details: WithCacheDetails) => O extends undefined ? T : T | O;
|
|
48
|
+
type WithCacheReturnType<T extends NonNullable<unknown>> = [
|
|
49
|
+
T | null | undefined,
|
|
50
|
+
WithCacheDetails
|
|
51
|
+
];
|
|
52
|
+
type WithCacheOptions<K, T, O = undefined> = {
|
|
53
|
+
key: K;
|
|
54
|
+
dataFunction: WithCacheDataFn<K, T, O>;
|
|
55
|
+
validationFunction?: WithCacheValidator<T | null | undefined, O>;
|
|
56
|
+
transformFunction?: WithCacheTransformer<T | null | undefined, O>;
|
|
57
|
+
ttl?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type { AbstractCache, CacheManagerMetadata, ResolvedCreateCacheOptions, SetCacheArguments, WithCacheDataFn, WithCacheDetails, WithCacheOptions, WithCacheReturnType, WithCacheSource, WithCacheTransformer, WithCacheValidator };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import { CreateCacheOptions, Events } from 'cache-manager';
|
|
3
|
+
import Keyv from 'keyv';
|
|
4
|
+
|
|
5
|
+
type AbstractCache<T> = {
|
|
6
|
+
get: (key: string) => Promise<T | null | undefined>;
|
|
7
|
+
mget: (keys: string[]) => Promise<(T | null | undefined)[]>;
|
|
8
|
+
ttl: (key: string) => Promise<number | null>;
|
|
9
|
+
set: (key: string, value: T | null, ttl?: number) => Promise<T | null>;
|
|
10
|
+
mset: (list: SetCacheArguments<T | null>[]) => Promise<SetCacheArguments<T | null>[]>;
|
|
11
|
+
del: (key: string) => Promise<boolean>;
|
|
12
|
+
mdel: (keys: string[]) => Promise<[boolean, boolean[]]>;
|
|
13
|
+
clear: () => Promise<boolean>;
|
|
14
|
+
wrap: (key: string, fnc: () => T | Promise<T>, ttl?: number | ((value: T) => number), refreshThreshold?: number) => Promise<T>;
|
|
15
|
+
on: <E extends keyof Events>(event: E, listener: Events[E]) => EventEmitter;
|
|
16
|
+
off: <E extends keyof Events>(event: E, listener: Events[E]) => EventEmitter;
|
|
17
|
+
disconnect: () => Promise<undefined>;
|
|
18
|
+
};
|
|
19
|
+
type ResolvedCreateCacheOptions<T extends NonNullable<unknown>> = Omit<CreateCacheOptions, 'stores'> & {
|
|
20
|
+
stores: Keyv<T>[];
|
|
21
|
+
};
|
|
22
|
+
type SetCacheArguments<T> = {
|
|
23
|
+
key: string;
|
|
24
|
+
value: T;
|
|
25
|
+
ttl?: number;
|
|
26
|
+
};
|
|
27
|
+
type CacheManagerMetadata = {
|
|
28
|
+
hits: number;
|
|
29
|
+
misses: number;
|
|
30
|
+
added: number;
|
|
31
|
+
deleted: number;
|
|
32
|
+
updated: number;
|
|
33
|
+
cleared: number;
|
|
34
|
+
};
|
|
35
|
+
type WithCacheSource = 'cache' | 'no-cache';
|
|
36
|
+
type WithCacheDetails = {
|
|
37
|
+
source: WithCacheSource;
|
|
38
|
+
cached: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* - If `cached` is `true`, the time in milliseconds the data was cached for
|
|
41
|
+
* - If `cached` is `false`, the remaining time in milliseconds until the cache expires
|
|
42
|
+
*/
|
|
43
|
+
cachedFor: number | null;
|
|
44
|
+
};
|
|
45
|
+
type WithCacheDataFn<K, T, O = undefined> = O extends undefined ? (key: K) => T | null | undefined | Promise<T | null | undefined> : (key: K) => T | O | null | undefined | Promise<T | O | null | undefined>;
|
|
46
|
+
type WithCacheValidator<T, O> = (item: T | O) => item is T;
|
|
47
|
+
type WithCacheTransformer<T, O> = (item: T | O, details: WithCacheDetails) => O extends undefined ? T : T | O;
|
|
48
|
+
type WithCacheReturnType<T extends NonNullable<unknown>> = [
|
|
49
|
+
T | null | undefined,
|
|
50
|
+
WithCacheDetails
|
|
51
|
+
];
|
|
52
|
+
type WithCacheOptions<K, T, O = undefined> = {
|
|
53
|
+
key: K;
|
|
54
|
+
dataFunction: WithCacheDataFn<K, T, O>;
|
|
55
|
+
validationFunction?: WithCacheValidator<T | null | undefined, O>;
|
|
56
|
+
transformFunction?: WithCacheTransformer<T | null | undefined, O>;
|
|
57
|
+
ttl?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type { AbstractCache, CacheManagerMetadata, ResolvedCreateCacheOptions, SetCacheArguments, WithCacheDataFn, WithCacheDetails, WithCacheOptions, WithCacheReturnType, WithCacheSource, WithCacheTransformer, WithCacheValidator };
|
package/package.json
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@md-oss/cache",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org/"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+ssh://git@github.com/Mirasaki-OSS/monorepo-template.git",
|
|
12
|
+
"directory": "vendor/cache"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"description": "Multi-layer caching with LRU, Redis, and async data fetching support",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.mjs",
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/**/*",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"require": {
|
|
28
|
+
"types": "./dist/index.d.cts",
|
|
29
|
+
"default": "./dist/index.cjs"
|
|
30
|
+
},
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"default": "./dist/index.mjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"./async": {
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/async.d.cts",
|
|
39
|
+
"default": "./dist/async.cjs"
|
|
40
|
+
},
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/async.d.mts",
|
|
43
|
+
"default": "./dist/async.mjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"./env": {
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./dist/env.d.cts",
|
|
49
|
+
"default": "./dist/env.cjs"
|
|
50
|
+
},
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/env.d.mts",
|
|
53
|
+
"default": "./dist/env.mjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"./lru": {
|
|
57
|
+
"require": {
|
|
58
|
+
"types": "./dist/lru.d.cts",
|
|
59
|
+
"default": "./dist/lru.cjs"
|
|
60
|
+
},
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/lru.d.mts",
|
|
63
|
+
"default": "./dist/lru.mjs"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"./manager": {
|
|
67
|
+
"require": {
|
|
68
|
+
"types": "./dist/manager.d.cts",
|
|
69
|
+
"default": "./dist/manager.cjs"
|
|
70
|
+
},
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/manager.d.mts",
|
|
73
|
+
"default": "./dist/manager.mjs"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"./promise": {
|
|
77
|
+
"require": {
|
|
78
|
+
"types": "./dist/promise.d.cts",
|
|
79
|
+
"default": "./dist/promise.cjs"
|
|
80
|
+
},
|
|
81
|
+
"import": {
|
|
82
|
+
"types": "./dist/promise.d.mts",
|
|
83
|
+
"default": "./dist/promise.mjs"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"./redis-client": {
|
|
87
|
+
"require": {
|
|
88
|
+
"types": "./dist/redis-client.d.cts",
|
|
89
|
+
"default": "./dist/redis-client.cjs"
|
|
90
|
+
},
|
|
91
|
+
"import": {
|
|
92
|
+
"types": "./dist/redis-client.d.mts",
|
|
93
|
+
"default": "./dist/redis-client.mjs"
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"./types": {
|
|
97
|
+
"require": {
|
|
98
|
+
"types": "./dist/types.d.cts"
|
|
99
|
+
},
|
|
100
|
+
"import": {
|
|
101
|
+
"types": "./dist/types.d.mts"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"dependencies": {
|
|
106
|
+
"@t3-oss/env-nextjs": "^0.13.10",
|
|
107
|
+
"@types/debug": "^4.1.12",
|
|
108
|
+
"cache-manager": "^7.2.8",
|
|
109
|
+
"debug": "^4.4.3",
|
|
110
|
+
"keyv": "^5.6.0",
|
|
111
|
+
"lru-cache": "^11.2.5",
|
|
112
|
+
"redis": "^5.10.0",
|
|
113
|
+
"zod": "^4.3.6",
|
|
114
|
+
"@md-oss/config": "^0.1.0"
|
|
115
|
+
},
|
|
116
|
+
"devDependencies": {
|
|
117
|
+
"@types/node": "^25.0.9",
|
|
118
|
+
"pkgroll": "^2.21.5",
|
|
119
|
+
"typescript": "^5.9.3"
|
|
120
|
+
},
|
|
121
|
+
"scripts": {
|
|
122
|
+
"build": "pkgroll --minify --clean-dist --sourcemap --define.process.env.NODE_ENV='\"production\"' --define.DEBUG=false",
|
|
123
|
+
"clean": "git clean -xdf .turbo dist node_modules tsconfig.tsbuildinfo",
|
|
124
|
+
"dev": "tsc --watch",
|
|
125
|
+
"typecheck": "tsc --noEmit"
|
|
126
|
+
}
|
|
127
|
+
}
|