@nest-omni/core 4.1.3-20 → 4.1.3-23
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/audit/audit.module.d.ts +1 -0
- package/audit/audit.module.js +5 -3
- package/audit/controllers/audit.controller.d.ts +3 -11
- package/audit/controllers/audit.controller.js +12 -19
- package/audit/decorators/audit-operation.decorator.d.ts +0 -7
- package/audit/decorators/audit-operation.decorator.js +0 -7
- package/audit/dto/audit-action-query.dto.d.ts +13 -0
- package/audit/dto/audit-action-query.dto.js +77 -0
- package/audit/dto/index.d.ts +1 -0
- package/audit/dto/index.js +1 -0
- package/audit/entities/entity-audit-log.entity.d.ts +1 -4
- package/audit/entities/entity-audit-log.entity.js +1 -17
- package/audit/entities/manual-operation-log.entity.d.ts +0 -2
- package/audit/entities/manual-operation-log.entity.js +0 -8
- package/audit/enums/audit.enums.d.ts +0 -8
- package/audit/enums/audit.enums.js +1 -10
- package/audit/examples/decorator-value-mapping.example.d.ts +70 -0
- package/audit/examples/decorator-value-mapping.example.js +414 -0
- package/audit/index.d.ts +1 -0
- package/audit/index.js +5 -1
- package/audit/interceptors/audit.interceptor.d.ts +1 -0
- package/audit/interceptors/audit.interceptor.js +19 -11
- package/audit/interfaces/audit.interfaces.d.ts +2 -17
- package/audit/services/audit-context.service.d.ts +9 -0
- package/audit/services/entity-audit.service.d.ts +65 -24
- package/audit/services/entity-audit.service.js +280 -93
- package/audit/services/manual-audit-log.service.d.ts +0 -1
- package/audit/services/manual-audit-log.service.js +1 -3
- package/audit/subscribers/entity-audit.subscriber.d.ts +1 -0
- package/audit/subscribers/entity-audit.subscriber.js +22 -5
- package/cache/cache.module.d.ts +7 -2
- package/cache/cache.module.js +9 -7
- package/cache/cache.service.d.ts +4 -4
- package/cache/cache.service.js +5 -5
- package/cache/entities/index.d.ts +1 -0
- package/cache/entities/index.js +17 -0
- package/cache/entities/typeorm-cache.entity.d.ts +71 -0
- package/cache/entities/typeorm-cache.entity.js +110 -0
- package/cache/index.d.ts +2 -1
- package/cache/index.js +19 -2
- package/cache/providers/index.d.ts +2 -1
- package/cache/providers/index.js +2 -1
- package/cache/providers/lrucache.provider.d.ts +76 -0
- package/cache/providers/lrucache.provider.js +226 -0
- package/cache/providers/typeorm-cache.provider.d.ts +211 -0
- package/cache/providers/typeorm-cache.provider.js +483 -0
- package/common/boilerplate.polyfill.d.ts +1 -0
- package/common/boilerplate.polyfill.js +17 -0
- package/common/helpers/validation-metadata-helper.d.ts +55 -0
- package/common/helpers/validation-metadata-helper.js +60 -0
- package/common/index.d.ts +1 -0
- package/common/index.js +4 -0
- package/decorators/field.decorators.d.ts +71 -2
- package/decorators/field.decorators.js +147 -18
- package/decorators/transform.decorators.d.ts +0 -2
- package/decorators/transform.decorators.js +0 -23
- package/filters/bad-request.filter.js +19 -4
- package/http-client/examples/axios-config-extended.example.d.ts +17 -0
- package/http-client/examples/axios-config-extended.example.js +313 -0
- package/http-client/examples/index.d.ts +2 -0
- package/http-client/examples/index.js +2 -0
- package/http-client/examples/ssl-certificate.example.d.ts +47 -0
- package/http-client/examples/ssl-certificate.example.js +431 -0
- package/http-client/index.d.ts +1 -1
- package/http-client/interfaces/http-client-config.interface.d.ts +73 -0
- package/http-client/services/http-client.service.js +46 -5
- package/http-client/utils/context-extractor.util.js +2 -0
- package/ip-filter/constants.d.ts +21 -0
- package/ip-filter/constants.js +24 -0
- package/ip-filter/decorators/index.d.ts +1 -0
- package/ip-filter/decorators/index.js +17 -0
- package/ip-filter/decorators/ip-filter.decorator.d.ts +58 -0
- package/ip-filter/decorators/ip-filter.decorator.js +79 -0
- package/ip-filter/guards/index.d.ts +1 -0
- package/ip-filter/guards/index.js +17 -0
- package/ip-filter/guards/ip-filter.guard.d.ts +62 -0
- package/ip-filter/guards/ip-filter.guard.js +174 -0
- package/ip-filter/index.d.ts +7 -0
- package/ip-filter/index.js +23 -0
- package/ip-filter/interfaces/index.d.ts +4 -0
- package/ip-filter/interfaces/index.js +20 -0
- package/ip-filter/interfaces/ip-filter-async-options.interface.d.ts +15 -0
- package/ip-filter/interfaces/ip-filter-async-options.interface.js +2 -0
- package/ip-filter/interfaces/ip-filter-metadata.interface.d.ts +26 -0
- package/ip-filter/interfaces/ip-filter-metadata.interface.js +2 -0
- package/ip-filter/interfaces/ip-filter-options.interface.d.ts +34 -0
- package/ip-filter/interfaces/ip-filter-options.interface.js +2 -0
- package/ip-filter/interfaces/ip-rule.interface.d.ts +36 -0
- package/ip-filter/interfaces/ip-rule.interface.js +2 -0
- package/ip-filter/ip-filter.module.d.ts +55 -0
- package/ip-filter/ip-filter.module.js +105 -0
- package/ip-filter/services/index.d.ts +1 -0
- package/ip-filter/services/index.js +17 -0
- package/ip-filter/services/ip-filter.service.d.ts +92 -0
- package/ip-filter/services/ip-filter.service.js +238 -0
- package/ip-filter/utils/index.d.ts +1 -0
- package/ip-filter/utils/index.js +17 -0
- package/ip-filter/utils/ip-utils.d.ts +61 -0
- package/ip-filter/utils/ip-utils.js +162 -0
- package/package.json +23 -24
- package/providers/context.provider.d.ts +9 -0
- package/providers/context.provider.js +13 -0
- package/setup/bootstrap.setup.d.ts +1 -1
- package/setup/bootstrap.setup.js +1 -1
- package/shared/service-registry.module.js +0 -1
- package/cache/providers/memory-cache.provider.d.ts +0 -69
- package/cache/providers/memory-cache.provider.js +0 -237
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-omni/core",
|
|
3
|
-
"version": "4.1.3-
|
|
3
|
+
"version": "4.1.3-23",
|
|
4
4
|
"description": "A comprehensive NestJS framework for building enterprise-grade applications with best practices",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/compression": "^1.8.1",
|
|
44
|
-
"@types/express": "^5.0.
|
|
44
|
+
"@types/express": "^5.0.6",
|
|
45
45
|
"@types/express-session": "^1.18.2",
|
|
46
|
-
"@types/lodash": "^4.17.
|
|
47
|
-
"@types/node": "^
|
|
48
|
-
"@types/sharp": "^0.
|
|
46
|
+
"@types/lodash": "^4.17.21",
|
|
47
|
+
"@types/node": "^25.0.3",
|
|
48
|
+
"@types/sharp": "^0.32.0",
|
|
49
49
|
"@types/sprintf-js": "^1.1.4",
|
|
50
50
|
"@types/uuid": "^11.0.0",
|
|
51
51
|
"sqlite3": "^5.1.7",
|
|
@@ -56,49 +56,48 @@
|
|
|
56
56
|
"@dataui/crud-typeorm": "^5.3.4",
|
|
57
57
|
"@nest-omni/transaction": "*",
|
|
58
58
|
"@nestjs/bull": "^11.0.4",
|
|
59
|
-
"@nestjs/common": "^11.1.
|
|
59
|
+
"@nestjs/common": "^11.1.11",
|
|
60
60
|
"@nestjs/config": "^4.0.2",
|
|
61
|
-
"@nestjs/core": "^11.1.
|
|
62
|
-
"@nestjs/platform-express": "^11.1.
|
|
63
|
-
"@nestjs/schedule": "^6.0
|
|
64
|
-
"@nestjs/swagger": "^11.2.
|
|
61
|
+
"@nestjs/core": "^11.1.11",
|
|
62
|
+
"@nestjs/platform-express": "^11.1.11",
|
|
63
|
+
"@nestjs/schedule": "^6.1.0",
|
|
64
|
+
"@nestjs/swagger": "^11.2.4",
|
|
65
65
|
"@nestjs/terminus": "^11.0.0",
|
|
66
66
|
"@nestjs/typeorm": "^11.0.0",
|
|
67
|
-
"@sentry/nestjs": "^10.
|
|
68
|
-
"@sentry/profiling-node": "^10.
|
|
67
|
+
"@sentry/nestjs": "^10.32.1",
|
|
68
|
+
"@sentry/profiling-node": "^10.32.1",
|
|
69
69
|
"@songkeys/nestjs-redis": "^11.0.0",
|
|
70
70
|
"@songkeys/nestjs-redis-health": "^11.0.0",
|
|
71
71
|
"axios": "^1.13.2",
|
|
72
72
|
"axios-retry": "^4.5.0",
|
|
73
73
|
"bcrypt": "^6.0.0",
|
|
74
|
-
"body-parser": "^2.2.
|
|
74
|
+
"body-parser": "^2.2.1",
|
|
75
75
|
"bull": "^4.16.5",
|
|
76
76
|
"class-transformer": "^0.5.1",
|
|
77
|
-
"class-validator": "^0.14.
|
|
77
|
+
"class-validator": "^0.14.3",
|
|
78
78
|
"compression": "^1.8.1",
|
|
79
79
|
"connect-redis": "^9.0.0",
|
|
80
80
|
"dotenv": "^17.2.3",
|
|
81
|
-
"express": "^5.1
|
|
81
|
+
"express": "^5.2.1",
|
|
82
82
|
"express-session": "^1.18.2",
|
|
83
83
|
"fast-csv": "^5.0.5",
|
|
84
84
|
"hygen": "^6.2.11",
|
|
85
|
-
"ioredis": "^5.
|
|
86
|
-
"libphonenumber-js": "^1.12.25",
|
|
85
|
+
"ioredis": "^5.9.0",
|
|
87
86
|
"lodash": "^4.17.21",
|
|
88
|
-
"mime-types": "^3.0.
|
|
87
|
+
"mime-types": "^3.0.2",
|
|
89
88
|
"moment": "^2.30.1",
|
|
90
|
-
"mysql2": "^3.
|
|
91
|
-
"nestjs-cls": "^6.0
|
|
92
|
-
"nestjs-i18n": "^10.
|
|
93
|
-
"nestjs-pino": "^4.
|
|
89
|
+
"mysql2": "^3.16.0",
|
|
90
|
+
"nestjs-cls": "^6.2.0",
|
|
91
|
+
"nestjs-i18n": "^10.6.0",
|
|
92
|
+
"nestjs-pino": "^4.5.0",
|
|
94
93
|
"node-vault": "^0.10.9",
|
|
95
94
|
"pino-http": "^11.0.0",
|
|
96
|
-
"pino-pretty": "^13.1.
|
|
95
|
+
"pino-pretty": "^13.1.3",
|
|
97
96
|
"reflect-metadata": "^0.2.2",
|
|
98
97
|
"rxjs": "^7.8.2",
|
|
99
98
|
"source-map-support": "^0.5.21",
|
|
100
99
|
"sprintf-js": "^1.1.3",
|
|
101
|
-
"typeorm": "^0.3.
|
|
100
|
+
"typeorm": "^0.3.28",
|
|
102
101
|
"uuid": "^13.0.0",
|
|
103
102
|
"xlsx": "git+https://git.sheetjs.com/sheetjs/sheetjs.git#v0.20.3"
|
|
104
103
|
},
|
|
@@ -3,6 +3,7 @@ export declare class ContextProvider {
|
|
|
3
3
|
private static readonly nameSpace;
|
|
4
4
|
private static readonly authUserKey;
|
|
5
5
|
private static readonly routerKey;
|
|
6
|
+
private static readonly sourceKey;
|
|
6
7
|
private static readonly languageKey;
|
|
7
8
|
private static readonly requestKey;
|
|
8
9
|
static get<T>(key: string): import("nestjs-cls/dist/src/types/type-if-type.type").TypeIfUndefined<T, import("nestjs-cls").ClsStore, T>;
|
|
@@ -31,4 +32,12 @@ export declare class ContextProvider {
|
|
|
31
32
|
static getRole(): string;
|
|
32
33
|
static getAdmin(): boolean;
|
|
33
34
|
static getTenantId(): string;
|
|
35
|
+
/**
|
|
36
|
+
* 设置请求来源(如业务主键ID等)
|
|
37
|
+
*/
|
|
38
|
+
static setSource(source: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* 获取请求来源
|
|
41
|
+
*/
|
|
42
|
+
static getSource(): string | undefined;
|
|
34
43
|
}
|
|
@@ -73,10 +73,23 @@ class ContextProvider {
|
|
|
73
73
|
static getTenantId() {
|
|
74
74
|
return ContextProvider.getAuthUserField('tenantId');
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* 设置请求来源(如业务主键ID等)
|
|
78
|
+
*/
|
|
79
|
+
static setSource(source) {
|
|
80
|
+
ContextProvider.set(ContextProvider.sourceKey, source);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 获取请求来源
|
|
84
|
+
*/
|
|
85
|
+
static getSource() {
|
|
86
|
+
return ContextProvider.get(ContextProvider.sourceKey);
|
|
87
|
+
}
|
|
76
88
|
}
|
|
77
89
|
exports.ContextProvider = ContextProvider;
|
|
78
90
|
ContextProvider.nameSpace = 'request';
|
|
79
91
|
ContextProvider.authUserKey = 'user_key';
|
|
80
92
|
ContextProvider.routerKey = 'router_key';
|
|
93
|
+
ContextProvider.sourceKey = 'source_key';
|
|
81
94
|
ContextProvider.languageKey = 'language_key';
|
|
82
95
|
ContextProvider.requestKey = 'request_key';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import '../common/boilerplate.polyfill';
|
|
2
2
|
import type { NestExpressApplication } from '@nestjs/platform-express';
|
|
3
|
-
export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>>;
|
|
3
|
+
export declare function bootstrapSetup(AppModule: any, SetupSwagger: any): Promise<NestExpressApplication<import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse>>>;
|
package/setup/bootstrap.setup.js
CHANGED
|
@@ -173,7 +173,7 @@ function bootstrapSetup(AppModule, SetupSwagger) {
|
|
|
173
173
|
errorHttpStatusCode: common_1.HttpStatus.UNPROCESSABLE_ENTITY,
|
|
174
174
|
transform: true,
|
|
175
175
|
stopAtFirstError: true,
|
|
176
|
-
validationError: { target:
|
|
176
|
+
validationError: { target: true, value: true },
|
|
177
177
|
}));
|
|
178
178
|
// 可选功能模块 - 仅在 HTTP 或 Hybrid 模式下启用
|
|
179
179
|
if (shouldStartHttp) {
|
|
@@ -126,7 +126,6 @@ if (services_1.ApiConfigService.toBoolean(process.env.CACHE_ENABLED)) {
|
|
|
126
126
|
return {
|
|
127
127
|
isGlobal: true,
|
|
128
128
|
redisClient,
|
|
129
|
-
dataSource,
|
|
130
129
|
memoryTtl: config.getNumber('CACHE_TTL'),
|
|
131
130
|
memoryNamespace: config.getString('CACHE_NAMESPACE', 'default'),
|
|
132
131
|
enableCompression: config.getBoolean('CACHE_COMPRESSION_ENABLED', false),
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { BaseCacheProvider } from './base-cache.provider';
|
|
2
|
-
/**
|
|
3
|
-
* Memory cache provider using native Map with TTL support
|
|
4
|
-
*
|
|
5
|
-
* This is the L2 cache layer - process-level caching.
|
|
6
|
-
* Data is stored in memory and shared across all requests in the same process.
|
|
7
|
-
*
|
|
8
|
-
* Faster than Redis but not shared across multiple processes/servers.
|
|
9
|
-
*
|
|
10
|
-
* **Automatic Cleanup**: Includes periodic cleanup of expired items to prevent memory leaks.
|
|
11
|
-
*/
|
|
12
|
-
export declare class MemoryCacheProvider extends BaseCacheProvider {
|
|
13
|
-
private cache;
|
|
14
|
-
private keys;
|
|
15
|
-
private defaultTtl?;
|
|
16
|
-
private namespace;
|
|
17
|
-
private cleanupTimer?;
|
|
18
|
-
/**
|
|
19
|
-
* Cleanup interval in milliseconds
|
|
20
|
-
* @default 300000 (5 minutes)
|
|
21
|
-
*/
|
|
22
|
-
private readonly CLEANUP_INTERVAL;
|
|
23
|
-
constructor(options?: {
|
|
24
|
-
ttl?: number;
|
|
25
|
-
namespace?: string;
|
|
26
|
-
});
|
|
27
|
-
/**
|
|
28
|
-
* Start periodic cleanup of expired items
|
|
29
|
-
*/
|
|
30
|
-
private startCleanupTimer;
|
|
31
|
-
/**
|
|
32
|
-
* Stop automatic cleanup timer
|
|
33
|
-
*/
|
|
34
|
-
private stopCleanupTimer;
|
|
35
|
-
/**
|
|
36
|
-
* Destroy the provider and cleanup resources
|
|
37
|
-
*/
|
|
38
|
-
destroy(): void;
|
|
39
|
-
getName(): string;
|
|
40
|
-
get<T>(key: string): Promise<T | null>;
|
|
41
|
-
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
42
|
-
delete(key: string | string[]): Promise<void>;
|
|
43
|
-
deletePattern(pattern: string): Promise<number>;
|
|
44
|
-
clear(): Promise<void>;
|
|
45
|
-
has(key: string): Promise<boolean>;
|
|
46
|
-
/**
|
|
47
|
-
* Get all keys (for debugging/testing)
|
|
48
|
-
*/
|
|
49
|
-
getAllKeys(): string[];
|
|
50
|
-
/**
|
|
51
|
-
* Get cache size
|
|
52
|
-
*/
|
|
53
|
-
getSize(): number;
|
|
54
|
-
/**
|
|
55
|
-
* Clean up expired items (optional maintenance method)
|
|
56
|
-
*/
|
|
57
|
-
cleanup(): number;
|
|
58
|
-
/**
|
|
59
|
-
* Optimized mget with batch cleanup
|
|
60
|
-
*/
|
|
61
|
-
mget<T>(keys: string[]): Promise<(T | null)[]>;
|
|
62
|
-
/**
|
|
63
|
-
* Optimized mset
|
|
64
|
-
*/
|
|
65
|
-
mset(items: Array<{
|
|
66
|
-
key: string;
|
|
67
|
-
value: any;
|
|
68
|
-
}>, ttl?: number): Promise<void>;
|
|
69
|
-
}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.MemoryCacheProvider = void 0;
|
|
13
|
-
const base_cache_provider_1 = require("./base-cache.provider");
|
|
14
|
-
/**
|
|
15
|
-
* Memory cache provider using native Map with TTL support
|
|
16
|
-
*
|
|
17
|
-
* This is the L2 cache layer - process-level caching.
|
|
18
|
-
* Data is stored in memory and shared across all requests in the same process.
|
|
19
|
-
*
|
|
20
|
-
* Faster than Redis but not shared across multiple processes/servers.
|
|
21
|
-
*
|
|
22
|
-
* **Automatic Cleanup**: Includes periodic cleanup of expired items to prevent memory leaks.
|
|
23
|
-
*/
|
|
24
|
-
class MemoryCacheProvider extends base_cache_provider_1.BaseCacheProvider {
|
|
25
|
-
constructor(options) {
|
|
26
|
-
super();
|
|
27
|
-
this.cache = new Map();
|
|
28
|
-
this.keys = new Set();
|
|
29
|
-
/**
|
|
30
|
-
* Cleanup interval in milliseconds
|
|
31
|
-
* @default 300000 (5 minutes)
|
|
32
|
-
*/
|
|
33
|
-
this.CLEANUP_INTERVAL = 5 * 60 * 1000;
|
|
34
|
-
this.defaultTtl = options === null || options === void 0 ? void 0 : options.ttl;
|
|
35
|
-
this.namespace = (options === null || options === void 0 ? void 0 : options.namespace) || 'cache:memory';
|
|
36
|
-
// Start automatic cleanup timer
|
|
37
|
-
this.startCleanupTimer();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Start periodic cleanup of expired items
|
|
41
|
-
*/
|
|
42
|
-
startCleanupTimer() {
|
|
43
|
-
this.cleanupTimer = setInterval(() => {
|
|
44
|
-
const cleaned = this.cleanup();
|
|
45
|
-
if (cleaned > 0) {
|
|
46
|
-
console.debug(`[MemoryCache] Cleaned up ${cleaned} expired items from namespace: ${this.namespace}`);
|
|
47
|
-
}
|
|
48
|
-
}, this.CLEANUP_INTERVAL);
|
|
49
|
-
// Allow Node.js to exit if this is the only active timer
|
|
50
|
-
if (this.cleanupTimer.unref) {
|
|
51
|
-
this.cleanupTimer.unref();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Stop automatic cleanup timer
|
|
56
|
-
*/
|
|
57
|
-
stopCleanupTimer() {
|
|
58
|
-
if (this.cleanupTimer) {
|
|
59
|
-
clearInterval(this.cleanupTimer);
|
|
60
|
-
this.cleanupTimer = undefined;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Destroy the provider and cleanup resources
|
|
65
|
-
*/
|
|
66
|
-
destroy() {
|
|
67
|
-
this.stopCleanupTimer();
|
|
68
|
-
this.clear();
|
|
69
|
-
}
|
|
70
|
-
getName() {
|
|
71
|
-
return 'Memory';
|
|
72
|
-
}
|
|
73
|
-
get(key) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
try {
|
|
76
|
-
const item = this.cache.get(key);
|
|
77
|
-
if (!item) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
// Check if item has expired
|
|
81
|
-
if (item.expiresAt && Date.now() > item.expiresAt) {
|
|
82
|
-
this.cache.delete(key);
|
|
83
|
-
this.keys.delete(key);
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
return item.value;
|
|
87
|
-
}
|
|
88
|
-
catch (_a) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
set(key, value, ttl) {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
try {
|
|
96
|
-
const effectiveTtl = ttl !== null && ttl !== void 0 ? ttl : this.defaultTtl;
|
|
97
|
-
const expiresAt = effectiveTtl ? Date.now() + effectiveTtl : undefined;
|
|
98
|
-
const item = {
|
|
99
|
-
value,
|
|
100
|
-
expiresAt,
|
|
101
|
-
};
|
|
102
|
-
this.cache.set(key, item);
|
|
103
|
-
this.keys.add(key);
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
throw new Error(`MemoryCacheProvider: Failed to set key ${key}: ${error instanceof Error ? error.message : String(error)}`);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
delete(key) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
try {
|
|
113
|
-
if (Array.isArray(key)) {
|
|
114
|
-
key.forEach((k) => {
|
|
115
|
-
this.cache.delete(k);
|
|
116
|
-
this.keys.delete(k);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
this.cache.delete(key);
|
|
121
|
-
this.keys.delete(key);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
throw new Error(`MemoryCacheProvider: Failed to delete key(s): ${error instanceof Error ? error.message : String(error)}`);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
deletePattern(pattern) {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
try {
|
|
132
|
-
const regex = this.patternToRegex(pattern);
|
|
133
|
-
const matchedKeys = Array.from(this.keys).filter((key) => regex.test(key));
|
|
134
|
-
if (matchedKeys.length > 0) {
|
|
135
|
-
yield this.delete(matchedKeys);
|
|
136
|
-
}
|
|
137
|
-
return matchedKeys.length;
|
|
138
|
-
}
|
|
139
|
-
catch (_a) {
|
|
140
|
-
return 0;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
clear() {
|
|
145
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
try {
|
|
147
|
-
this.cache.clear();
|
|
148
|
-
this.keys.clear();
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
throw new Error(`MemoryCacheProvider: Failed to clear cache: ${error instanceof Error ? error.message : String(error)}`);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
has(key) {
|
|
156
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
try {
|
|
158
|
-
const item = this.cache.get(key);
|
|
159
|
-
if (!item) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
// Check if item has expired
|
|
163
|
-
if (item.expiresAt && Date.now() > item.expiresAt) {
|
|
164
|
-
this.cache.delete(key);
|
|
165
|
-
this.keys.delete(key);
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
catch (_a) {
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Get all keys (for debugging/testing)
|
|
177
|
-
*/
|
|
178
|
-
getAllKeys() {
|
|
179
|
-
return Array.from(this.keys);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Get cache size
|
|
183
|
-
*/
|
|
184
|
-
getSize() {
|
|
185
|
-
return this.keys.size;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Clean up expired items (optional maintenance method)
|
|
189
|
-
*/
|
|
190
|
-
cleanup() {
|
|
191
|
-
let cleaned = 0;
|
|
192
|
-
const now = Date.now();
|
|
193
|
-
for (const [key, item] of this.cache.entries()) {
|
|
194
|
-
if (item.expiresAt && now > item.expiresAt) {
|
|
195
|
-
this.cache.delete(key);
|
|
196
|
-
this.keys.delete(key);
|
|
197
|
-
cleaned++;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return cleaned;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Optimized mget with batch cleanup
|
|
204
|
-
*/
|
|
205
|
-
mget(keys) {
|
|
206
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
-
const results = [];
|
|
208
|
-
const now = Date.now();
|
|
209
|
-
for (const key of keys) {
|
|
210
|
-
const item = this.cache.get(key);
|
|
211
|
-
if (!item) {
|
|
212
|
-
results.push(null);
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
// Check if item has expired
|
|
216
|
-
if (item.expiresAt && now > item.expiresAt) {
|
|
217
|
-
this.cache.delete(key);
|
|
218
|
-
this.keys.delete(key);
|
|
219
|
-
results.push(null);
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
results.push(item.value);
|
|
223
|
-
}
|
|
224
|
-
return results;
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Optimized mset
|
|
229
|
-
*/
|
|
230
|
-
mset(items, ttl) {
|
|
231
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
-
const promises = items.map((item) => this.set(item.key, item.value, ttl));
|
|
233
|
-
yield Promise.all(promises);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
exports.MemoryCacheProvider = MemoryCacheProvider;
|