@lark-apaas/cache-service 0.1.1-alpha.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.
@@ -0,0 +1,56 @@
1
+ import { OnApplicationShutdown, DynamicModule, ModuleMetadata, InjectionToken } from '@nestjs/common';
2
+ import { a as CacheStoreHandle } from '../types-CFj87Od0.js';
3
+ import 'keyv';
4
+
5
+ /**
6
+ * 用户传入的运行时配置
7
+ */
8
+ interface NestjsCacheModuleOptions {
9
+ /**
10
+ * Redis 连接串(redis:// 或 rediss://)
11
+ */
12
+ connectionString: string;
13
+ /**
14
+ * ZTI Token 文件路径。存在则启动 watchFile 热刷新。
15
+ */
16
+ connectionTokenFilePath?: string;
17
+ /**
18
+ * Socket connect timeout(毫秒)。默认 10_000。
19
+ */
20
+ connectTimeoutMs?: number;
21
+ /**
22
+ * Socket idle timeout(毫秒)。默认 5_000。
23
+ */
24
+ socketTimeoutMs?: number;
25
+ }
26
+ /**
27
+ * 异步配置选项
28
+ */
29
+ interface NestjsCacheModuleAsyncOptions {
30
+ imports?: ModuleMetadata['imports'];
31
+ useFactory: (...args: unknown[]) => Promise<NestjsCacheModuleOptions> | NestjsCacheModuleOptions;
32
+ inject?: InjectionToken[];
33
+ }
34
+ declare class NestjsCacheModule implements OnApplicationShutdown {
35
+ private readonly storeHandle;
36
+ constructor(storeHandle: CacheStoreHandle);
37
+ onApplicationShutdown(): Promise<void>;
38
+ /**
39
+ * 同步注册
40
+ */
41
+ static forRoot(options: NestjsCacheModuleOptions): DynamicModule;
42
+ /**
43
+ * 异步注册(从 ConfigService 等异步源读配置)
44
+ */
45
+ static forRootAsync(options: NestjsCacheModuleAsyncOptions): DynamicModule;
46
+ }
47
+
48
+ /**
49
+ * @lark-apaas/cache-service - NestJS 层 DI tokens
50
+ */
51
+ declare const NESTJS_CACHE_OPTIONS: unique symbol;
52
+ declare const CACHE_STORE_HANDLE: unique symbol;
53
+ declare const CACHE_OBSERVABLE_ADAPTER: unique symbol;
54
+ declare const CACHE_LOGGER_ADAPTER: unique symbol;
55
+
56
+ export { CACHE_LOGGER_ADAPTER, CACHE_OBSERVABLE_ADAPTER, CACHE_STORE_HANDLE, NESTJS_CACHE_OPTIONS, NestjsCacheModule, type NestjsCacheModuleAsyncOptions, type NestjsCacheModuleOptions };
@@ -0,0 +1,16 @@
1
+ import {
2
+ CACHE_LOGGER_ADAPTER,
3
+ CACHE_OBSERVABLE_ADAPTER,
4
+ CACHE_STORE_HANDLE,
5
+ NESTJS_CACHE_OPTIONS,
6
+ NestjsCacheModule
7
+ } from "../chunk-SSW7W3K6.js";
8
+ import "../chunk-BSJRPCEN.js";
9
+ export {
10
+ CACHE_LOGGER_ADAPTER,
11
+ CACHE_OBSERVABLE_ADAPTER,
12
+ CACHE_STORE_HANDLE,
13
+ NESTJS_CACHE_OPTIONS,
14
+ NestjsCacheModule
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,38 @@
1
+ import Keyv from 'keyv';
2
+
3
+ /**
4
+ * Cache Store 构造选项
5
+ */
6
+ interface CacheStoreOptions {
7
+ connectionString: string;
8
+ connectionTokenFilePath?: string;
9
+ connectTimeoutMs?: number;
10
+ socketTimeoutMs?: number;
11
+ observable: ObservableAdapter;
12
+ logger?: LoggerAdapter;
13
+ }
14
+ /**
15
+ * 框架无关的 Observable 契约
16
+ * NestJS 层用 @lark-apaas/nestjs-common 的 ObservableService 适配到这里
17
+ */
18
+ interface ObservableAdapter {
19
+ log(level: 'debug' | 'info' | 'warn' | 'error', event: string, attrs: Record<string, unknown>): void;
20
+ }
21
+ /**
22
+ * 框架无关的 Logger 契约
23
+ */
24
+ interface LoggerAdapter {
25
+ warn(message: string, attrs?: Record<string, unknown>): void;
26
+ error(message: string, err?: unknown): void;
27
+ }
28
+ /**
29
+ * Cache Store 句柄,允许外层控制生命周期
30
+ */
31
+ interface CacheStoreHandle {
32
+ keyv: Keyv;
33
+ dispose(): Promise<void>;
34
+ }
35
+ type CacheTraceEvent = 'cache.read' | 'cache.write' | 'cache.delete' | 'cache.error';
36
+ type CacheReadResult = 'hit' | 'miss';
37
+
38
+ export type { CacheStoreOptions as C, LoggerAdapter as L, ObservableAdapter as O, CacheStoreHandle as a, CacheReadResult as b, CacheTraceEvent as c };
@@ -0,0 +1,38 @@
1
+ import Keyv from 'keyv';
2
+
3
+ /**
4
+ * Cache Store 构造选项
5
+ */
6
+ interface CacheStoreOptions {
7
+ connectionString: string;
8
+ connectionTokenFilePath?: string;
9
+ connectTimeoutMs?: number;
10
+ socketTimeoutMs?: number;
11
+ observable: ObservableAdapter;
12
+ logger?: LoggerAdapter;
13
+ }
14
+ /**
15
+ * 框架无关的 Observable 契约
16
+ * NestJS 层用 @lark-apaas/nestjs-common 的 ObservableService 适配到这里
17
+ */
18
+ interface ObservableAdapter {
19
+ log(level: 'debug' | 'info' | 'warn' | 'error', event: string, attrs: Record<string, unknown>): void;
20
+ }
21
+ /**
22
+ * 框架无关的 Logger 契约
23
+ */
24
+ interface LoggerAdapter {
25
+ warn(message: string, attrs?: Record<string, unknown>): void;
26
+ error(message: string, err?: unknown): void;
27
+ }
28
+ /**
29
+ * Cache Store 句柄,允许外层控制生命周期
30
+ */
31
+ interface CacheStoreHandle {
32
+ keyv: Keyv;
33
+ dispose(): Promise<void>;
34
+ }
35
+ type CacheTraceEvent = 'cache.read' | 'cache.write' | 'cache.delete' | 'cache.error';
36
+ type CacheReadResult = 'hit' | 'miss';
37
+
38
+ export type { CacheStoreOptions as C, LoggerAdapter as L, ObservableAdapter as O, CacheStoreHandle as a, CacheReadResult as b, CacheTraceEvent as c };
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@lark-apaas/cache-service",
3
+ "version": "0.1.1-alpha.0",
4
+ "description": "FullStack cache SDK, NestJS today, Express-ready tomorrow",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "plugin",
14
+ "nestjs",
15
+ "server",
16
+ "cache",
17
+ "typescript"
18
+ ],
19
+ "engines": {
20
+ "node": ">=18.0.0"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "import": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "require": "./dist/index.cjs"
30
+ },
31
+ "./nestjs": {
32
+ "import": "./dist/nestjs/index.js",
33
+ "types": "./dist/nestjs/index.d.ts",
34
+ "require": "./dist/nestjs/index.cjs"
35
+ },
36
+ "./core": {
37
+ "import": "./dist/core/index.js",
38
+ "types": "./dist/core/index.d.ts",
39
+ "require": "./dist/core/index.cjs"
40
+ }
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "clean": "rm -rf dist",
46
+ "lint": "eslint src/**/*.ts",
47
+ "typecheck": "tsc --noEmit",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest --watch",
50
+ "prepublishOnly": "npm run build"
51
+ },
52
+ "dependencies": {
53
+ "@keyv/redis": "^5.1.6",
54
+ "@nestjs/cache-manager": "^3.1.3",
55
+ "cache-manager": "^6.4.3",
56
+ "keyv": "^5.6.0",
57
+ "reflect-metadata": "^0.1.13"
58
+ },
59
+ "devDependencies": {
60
+ "@lark-apaas/nestjs-common": "^0.1.9",
61
+ "@lark-apaas/nestjs-logger": "workspace:*",
62
+ "@lark-apaas/nestjs-observable": "^0.0.12",
63
+ "@nestjs/testing": "^10.0.0",
64
+ "@types/node": "^20.0.0",
65
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
66
+ "@typescript-eslint/parser": "^6.0.0",
67
+ "eslint": "^8.42.0",
68
+ "tsup": "^8.0.0",
69
+ "typescript": "^5.0.0",
70
+ "vitest": "^3.2.4"
71
+ },
72
+ "peerDependencies": {
73
+ "@lark-apaas/nestjs-common": "^0.1.9",
74
+ "@lark-apaas/nestjs-logger": "*",
75
+ "@lark-apaas/nestjs-observable": "^0.0.12",
76
+ "@nestjs/common": "^10.0.0",
77
+ "@nestjs/core": "^10.0.0"
78
+ }
79
+ }