@nest-omni/core 4.1.3-20 → 4.1.3-22
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/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
|
@@ -17,6 +17,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
17
17
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
|
+
var EntityAuditSubscriber_1;
|
|
20
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
22
|
exports.EntityAuditSubscriber = void 0;
|
|
22
23
|
const common_1 = require("@nestjs/common");
|
|
@@ -29,11 +30,12 @@ const decorators_1 = require("../decorators");
|
|
|
29
30
|
/**
|
|
30
31
|
* 实体审计订阅者
|
|
31
32
|
*/
|
|
32
|
-
let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
33
|
+
let EntityAuditSubscriber = EntityAuditSubscriber_1 = class EntityAuditSubscriber {
|
|
33
34
|
constructor(entityAuditService, contextService, auditStrategy, dataSource) {
|
|
34
35
|
this.entityAuditService = entityAuditService;
|
|
35
36
|
this.contextService = contextService;
|
|
36
37
|
this.auditStrategy = auditStrategy;
|
|
38
|
+
this.logger = new common_1.Logger(EntityAuditSubscriber_1.name);
|
|
37
39
|
dataSource.subscribers.push(this);
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
@@ -46,6 +48,11 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
46
48
|
return;
|
|
47
49
|
const entityType = entity.constructor.name;
|
|
48
50
|
const entityId = entity.id;
|
|
51
|
+
// 空值安全检查:确保实体 ID 存在
|
|
52
|
+
if (!entityId) {
|
|
53
|
+
this.logger.warn(`Entity ID is missing for ${entityType}, skipping audit`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
49
56
|
// 检查是否启用了审计
|
|
50
57
|
if (!this.isAuditEnabled(entity)) {
|
|
51
58
|
return;
|
|
@@ -75,7 +82,7 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
75
82
|
});
|
|
76
83
|
}
|
|
77
84
|
catch (error) {
|
|
78
|
-
|
|
85
|
+
this.logger.error('Failed to log audit for insert:', error);
|
|
79
86
|
}
|
|
80
87
|
});
|
|
81
88
|
}
|
|
@@ -90,6 +97,11 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
90
97
|
return;
|
|
91
98
|
const entityType = entity.constructor.name;
|
|
92
99
|
const entityId = entity.id;
|
|
100
|
+
// 空值安全检查:确保实体 ID 存在
|
|
101
|
+
if (!entityId) {
|
|
102
|
+
this.logger.warn(`Entity ID is missing for ${entityType}, skipping audit`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
93
105
|
// 检查是否启用了审计
|
|
94
106
|
if (!this.isAuditEnabled(entity)) {
|
|
95
107
|
return;
|
|
@@ -120,7 +132,7 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
120
132
|
});
|
|
121
133
|
}
|
|
122
134
|
catch (error) {
|
|
123
|
-
|
|
135
|
+
this.logger.error('Failed to log audit for update:', error);
|
|
124
136
|
}
|
|
125
137
|
});
|
|
126
138
|
}
|
|
@@ -134,6 +146,11 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
134
146
|
return;
|
|
135
147
|
const entityType = entity.constructor.name;
|
|
136
148
|
const entityId = entity.id;
|
|
149
|
+
// 空值安全检查:确保实体 ID 存在
|
|
150
|
+
if (!entityId) {
|
|
151
|
+
this.logger.warn(`Entity ID is missing for ${entityType}, skipping audit`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
137
154
|
// 检查是否启用了审计
|
|
138
155
|
if (!this.isAuditEnabled(entity)) {
|
|
139
156
|
return;
|
|
@@ -163,7 +180,7 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
163
180
|
});
|
|
164
181
|
}
|
|
165
182
|
catch (error) {
|
|
166
|
-
|
|
183
|
+
this.logger.error('Failed to log audit for delete:', error);
|
|
167
184
|
}
|
|
168
185
|
});
|
|
169
186
|
}
|
|
@@ -201,7 +218,7 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
201
218
|
}
|
|
202
219
|
};
|
|
203
220
|
exports.EntityAuditSubscriber = EntityAuditSubscriber;
|
|
204
|
-
exports.EntityAuditSubscriber = EntityAuditSubscriber = __decorate([
|
|
221
|
+
exports.EntityAuditSubscriber = EntityAuditSubscriber = EntityAuditSubscriber_1 = __decorate([
|
|
205
222
|
(0, common_1.Injectable)(),
|
|
206
223
|
(0, typeorm_1.EventSubscriber)(),
|
|
207
224
|
__metadata("design:paramtypes", [entity_audit_service_1.EntityAuditService,
|
package/cache/cache.module.d.ts
CHANGED
|
@@ -20,13 +20,18 @@ export interface CacheModuleOptions {
|
|
|
20
20
|
*/
|
|
21
21
|
redisClient?: Redis;
|
|
22
22
|
/**
|
|
23
|
-
* Default TTL for
|
|
23
|
+
* Default TTL for LRU cache in milliseconds
|
|
24
24
|
*/
|
|
25
25
|
memoryTtl?: number;
|
|
26
26
|
/**
|
|
27
|
-
* Namespace for
|
|
27
|
+
* Namespace for LRU cache
|
|
28
28
|
*/
|
|
29
29
|
memoryNamespace?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Max size for LRU cache
|
|
32
|
+
* @default 500
|
|
33
|
+
*/
|
|
34
|
+
lruMaxSize?: number;
|
|
30
35
|
/**
|
|
31
36
|
* Enable compression for cache values
|
|
32
37
|
* @default false
|
package/cache/cache.module.js
CHANGED
|
@@ -80,7 +80,7 @@ let CacheModule = CacheModule_1 = class CacheModule {
|
|
|
80
80
|
* Register cache module with options
|
|
81
81
|
*/
|
|
82
82
|
static forRoot(options = {}) {
|
|
83
|
-
const { isGlobal = true, redisClient, memoryTtl, memoryNamespace, enableCompression = false, compressionThreshold = 1024, } = options;
|
|
83
|
+
const { isGlobal = true, redisClient, memoryTtl, memoryNamespace, lruMaxSize = 500, enableCompression = false, compressionThreshold = 1024, } = options;
|
|
84
84
|
// Set Redis client for TagDependency for distributed tag support
|
|
85
85
|
if (redisClient) {
|
|
86
86
|
dependencies_1.TagDependency.setRedisClient(redisClient);
|
|
@@ -92,10 +92,11 @@ let CacheModule = CacheModule_1 = class CacheModule {
|
|
|
92
92
|
// Providers
|
|
93
93
|
providers_1.ClsCacheProvider,
|
|
94
94
|
{
|
|
95
|
-
provide: providers_1.
|
|
96
|
-
useValue: new providers_1.
|
|
95
|
+
provide: providers_1.LRUCacheProvider,
|
|
96
|
+
useValue: new providers_1.LRUCacheProvider({
|
|
97
|
+
maxSize: lruMaxSize,
|
|
97
98
|
ttl: memoryTtl,
|
|
98
|
-
namespace: memoryNamespace,
|
|
99
|
+
namespace: memoryNamespace || 'cache:lru',
|
|
99
100
|
}),
|
|
100
101
|
},
|
|
101
102
|
// Redis client provider (optional)
|
|
@@ -159,15 +160,16 @@ let CacheModule = CacheModule_1 = class CacheModule {
|
|
|
159
160
|
// Providers
|
|
160
161
|
providers_1.ClsCacheProvider,
|
|
161
162
|
{
|
|
162
|
-
provide: providers_1.
|
|
163
|
+
provide: providers_1.LRUCacheProvider,
|
|
163
164
|
useFactory: (moduleOptions) => {
|
|
164
165
|
// Set Redis client for TagDependency for distributed tag support
|
|
165
166
|
if (moduleOptions.redisClient) {
|
|
166
167
|
dependencies_1.TagDependency.setRedisClient(moduleOptions.redisClient);
|
|
167
168
|
}
|
|
168
|
-
return new providers_1.
|
|
169
|
+
return new providers_1.LRUCacheProvider({
|
|
170
|
+
maxSize: moduleOptions.lruMaxSize || 500,
|
|
169
171
|
ttl: moduleOptions.memoryTtl,
|
|
170
|
-
namespace: moduleOptions.memoryNamespace,
|
|
172
|
+
namespace: moduleOptions.memoryNamespace || 'cache:lru',
|
|
171
173
|
});
|
|
172
174
|
},
|
|
173
175
|
inject: ['CACHE_MODULE_OPTIONS'],
|
package/cache/cache.service.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import type { CacheOptions, CacheStats } from './interfaces';
|
|
2
2
|
import { CacheLayer } from './interfaces';
|
|
3
|
-
import { ClsCacheProvider,
|
|
3
|
+
import { ClsCacheProvider, LRUCacheProvider, RedisCacheProvider } from './providers';
|
|
4
4
|
/**
|
|
5
5
|
* Unified cache service with three-tier architecture
|
|
6
6
|
*
|
|
7
7
|
* L1: CLS (request-level)
|
|
8
|
-
* L2:
|
|
8
|
+
* L2: LRU (process-level with automatic eviction)
|
|
9
9
|
* L3: Redis (distributed)
|
|
10
10
|
*
|
|
11
11
|
* Supports automatic fallback, backfill, and dependency-based invalidation.
|
|
12
12
|
*/
|
|
13
13
|
export declare class CacheService {
|
|
14
14
|
private readonly clsProvider;
|
|
15
|
-
private readonly
|
|
15
|
+
private readonly lruProvider;
|
|
16
16
|
private readonly redisProvider;
|
|
17
17
|
private readonly enableCompression;
|
|
18
18
|
private readonly compressionThreshold;
|
|
19
19
|
private readonly logger;
|
|
20
20
|
private readonly providers;
|
|
21
21
|
private readonly stats;
|
|
22
|
-
constructor(clsProvider: ClsCacheProvider,
|
|
22
|
+
constructor(clsProvider: ClsCacheProvider, lruProvider: LRUCacheProvider, redisProvider: RedisCacheProvider, enableCompression?: boolean, compressionThreshold?: number);
|
|
23
23
|
/**
|
|
24
24
|
* Get or set cache value with factory function
|
|
25
25
|
*
|
package/cache/cache.service.js
CHANGED
|
@@ -34,15 +34,15 @@ const cache_constants_1 = require("./cache.constants");
|
|
|
34
34
|
* Unified cache service with three-tier architecture
|
|
35
35
|
*
|
|
36
36
|
* L1: CLS (request-level)
|
|
37
|
-
* L2:
|
|
37
|
+
* L2: LRU (process-level with automatic eviction)
|
|
38
38
|
* L3: Redis (distributed)
|
|
39
39
|
*
|
|
40
40
|
* Supports automatic fallback, backfill, and dependency-based invalidation.
|
|
41
41
|
*/
|
|
42
42
|
let CacheService = CacheService_1 = class CacheService {
|
|
43
|
-
constructor(clsProvider,
|
|
43
|
+
constructor(clsProvider, lruProvider, redisProvider, enableCompression = false, compressionThreshold = 1024) {
|
|
44
44
|
this.clsProvider = clsProvider;
|
|
45
|
-
this.
|
|
45
|
+
this.lruProvider = lruProvider;
|
|
46
46
|
this.redisProvider = redisProvider;
|
|
47
47
|
this.enableCompression = enableCompression;
|
|
48
48
|
this.compressionThreshold = compressionThreshold;
|
|
@@ -59,7 +59,7 @@ let CacheService = CacheService_1 = class CacheService {
|
|
|
59
59
|
totalClears: 0,
|
|
60
60
|
};
|
|
61
61
|
this.providers.set(interfaces_1.CacheLayer.CLS, clsProvider);
|
|
62
|
-
this.providers.set(interfaces_1.CacheLayer.MEMORY,
|
|
62
|
+
this.providers.set(interfaces_1.CacheLayer.MEMORY, lruProvider);
|
|
63
63
|
this.providers.set(interfaces_1.CacheLayer.REDIS, redisProvider);
|
|
64
64
|
this.initializeStats();
|
|
65
65
|
}
|
|
@@ -472,6 +472,6 @@ exports.CacheService = CacheService = CacheService_1 = __decorate([
|
|
|
472
472
|
__param(4, (0, common_1.Optional)()),
|
|
473
473
|
__param(4, (0, common_1.Inject)(cache_constants_1.CACHE_COMPRESSION_THRESHOLD)),
|
|
474
474
|
__metadata("design:paramtypes", [providers_1.ClsCacheProvider,
|
|
475
|
-
providers_1.
|
|
475
|
+
providers_1.LRUCacheProvider,
|
|
476
476
|
providers_1.RedisCacheProvider, Boolean, Number])
|
|
477
477
|
], CacheService);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typeorm-cache.entity';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./typeorm-cache.entity"), exports);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeORM Cache Entity
|
|
3
|
+
*
|
|
4
|
+
* Stores cached data in the database with automatic expiration support.
|
|
5
|
+
* Used by TypeormCacheProvider for persistent caching.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Namespace isolation for different cache segments
|
|
9
|
+
* - Automatic expiration handling
|
|
10
|
+
* - TTL tracking
|
|
11
|
+
* - Value JSON serialization
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // In your TypeORM configuration:
|
|
16
|
+
* {
|
|
17
|
+
* entities: [TypeormCacheEntity],
|
|
18
|
+
* // ... other options
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare class TypeormCacheEntity {
|
|
23
|
+
/**
|
|
24
|
+
* Composite key: namespace + key
|
|
25
|
+
* Allows same key in different namespaces
|
|
26
|
+
*/
|
|
27
|
+
key: string;
|
|
28
|
+
/**
|
|
29
|
+
* Namespace for cache isolation
|
|
30
|
+
* Multiple applications can share the same table
|
|
31
|
+
*/
|
|
32
|
+
namespace: string;
|
|
33
|
+
/**
|
|
34
|
+
* Cached value (JSON serialized)
|
|
35
|
+
*/
|
|
36
|
+
value: string;
|
|
37
|
+
/**
|
|
38
|
+
* Expiration timestamp
|
|
39
|
+
* NULL means no expiration
|
|
40
|
+
*/
|
|
41
|
+
expires_at: Date | null;
|
|
42
|
+
/**
|
|
43
|
+
* Time to live in seconds
|
|
44
|
+
* Stored for reference and debugging
|
|
45
|
+
*/
|
|
46
|
+
ttl: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* Creation timestamp
|
|
49
|
+
*/
|
|
50
|
+
created_at: Date;
|
|
51
|
+
/**
|
|
52
|
+
* Last update timestamp
|
|
53
|
+
*/
|
|
54
|
+
updated_at: Date;
|
|
55
|
+
/**
|
|
56
|
+
* Check if entry is expired
|
|
57
|
+
*/
|
|
58
|
+
isExpired(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Check if entry is valid (not expired)
|
|
61
|
+
*/
|
|
62
|
+
isValid(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Update value and expiration
|
|
65
|
+
*/
|
|
66
|
+
updateValue(newValue: string, ttl?: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Get remaining time to live in milliseconds
|
|
69
|
+
*/
|
|
70
|
+
getRemainingTTL(): number;
|
|
71
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TypeormCacheEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
/**
|
|
15
|
+
* TypeORM Cache Entity
|
|
16
|
+
*
|
|
17
|
+
* Stores cached data in the database with automatic expiration support.
|
|
18
|
+
* Used by TypeormCacheProvider for persistent caching.
|
|
19
|
+
*
|
|
20
|
+
* Features:
|
|
21
|
+
* - Namespace isolation for different cache segments
|
|
22
|
+
* - Automatic expiration handling
|
|
23
|
+
* - TTL tracking
|
|
24
|
+
* - Value JSON serialization
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // In your TypeORM configuration:
|
|
29
|
+
* {
|
|
30
|
+
* entities: [TypeormCacheEntity],
|
|
31
|
+
* // ... other options
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
let TypeormCacheEntity = class TypeormCacheEntity {
|
|
36
|
+
/**
|
|
37
|
+
* Check if entry is expired
|
|
38
|
+
*/
|
|
39
|
+
isExpired() {
|
|
40
|
+
if (!this.expires_at) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return new Date() > this.expires_at;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if entry is valid (not expired)
|
|
47
|
+
*/
|
|
48
|
+
isValid() {
|
|
49
|
+
return !this.isExpired();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Update value and expiration
|
|
53
|
+
*/
|
|
54
|
+
updateValue(newValue, ttl) {
|
|
55
|
+
this.value = newValue;
|
|
56
|
+
if (ttl && ttl > 0) {
|
|
57
|
+
this.ttl = Math.floor(ttl / 1000);
|
|
58
|
+
this.expires_at = new Date(Date.now() + ttl);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.ttl = null;
|
|
62
|
+
this.expires_at = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get remaining time to live in milliseconds
|
|
67
|
+
*/
|
|
68
|
+
getRemainingTTL() {
|
|
69
|
+
if (!this.expires_at) {
|
|
70
|
+
return -1; // No expiration
|
|
71
|
+
}
|
|
72
|
+
const remaining = this.expires_at.getTime() - Date.now();
|
|
73
|
+
return Math.max(0, remaining);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.TypeormCacheEntity = TypeormCacheEntity;
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, typeorm_1.PrimaryColumn)({ type: 'varchar', length: 255 }),
|
|
79
|
+
(0, typeorm_1.Index)(),
|
|
80
|
+
__metadata("design:type", String)
|
|
81
|
+
], TypeormCacheEntity.prototype, "key", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, typeorm_1.PrimaryColumn)({ type: 'varchar', length: 255 }),
|
|
84
|
+
(0, typeorm_1.Index)(),
|
|
85
|
+
__metadata("design:type", String)
|
|
86
|
+
], TypeormCacheEntity.prototype, "namespace", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, typeorm_1.Column)({ type: 'text' }),
|
|
89
|
+
__metadata("design:type", String)
|
|
90
|
+
], TypeormCacheEntity.prototype, "value", void 0);
|
|
91
|
+
__decorate([
|
|
92
|
+
(0, typeorm_1.Column)({ type: 'datetime', nullable: true }),
|
|
93
|
+
(0, typeorm_1.Index)(),
|
|
94
|
+
__metadata("design:type", Date)
|
|
95
|
+
], TypeormCacheEntity.prototype, "expires_at", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
(0, typeorm_1.Column)({ type: 'int', nullable: true }),
|
|
98
|
+
__metadata("design:type", Number)
|
|
99
|
+
], TypeormCacheEntity.prototype, "ttl", void 0);
|
|
100
|
+
__decorate([
|
|
101
|
+
(0, typeorm_1.CreateDateColumn)({ type: 'datetime', name: 'created_at' }),
|
|
102
|
+
__metadata("design:type", Date)
|
|
103
|
+
], TypeormCacheEntity.prototype, "created_at", void 0);
|
|
104
|
+
__decorate([
|
|
105
|
+
(0, typeorm_1.UpdateDateColumn)({ type: 'datetime', name: 'updated_at' }),
|
|
106
|
+
__metadata("design:type", Date)
|
|
107
|
+
], TypeormCacheEntity.prototype, "updated_at", void 0);
|
|
108
|
+
exports.TypeormCacheEntity = TypeormCacheEntity = __decorate([
|
|
109
|
+
(0, typeorm_1.Entity)('typeorm_cache')
|
|
110
|
+
], TypeormCacheEntity);
|
package/cache/index.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ export { CacheWarmupService, type CacheWarmupConfig, type CacheWarmupResult, } f
|
|
|
6
6
|
export { CacheMetricsService, type CacheMetrics, type CacheOperationRecord, } from './cache-metrics.service';
|
|
7
7
|
export { CacheSerializationService, type CacheSerializationOptions, type SerializationResult, type DeserializationResult, } from './cache-serialization.service';
|
|
8
8
|
export { Cacheable, CacheEvict, CachePut, getCacheService, setCacheService, } from './decorators';
|
|
9
|
-
export { ClsCacheProvider,
|
|
9
|
+
export { ClsCacheProvider, LRUCacheProvider, TypeormCacheProvider, RedisCacheProvider, BaseCacheProvider, } from './providers';
|
|
10
10
|
export { REDIS_CLIENT } from './providers/redis-cache.provider';
|
|
11
11
|
export type { CacheProvider } from './interfaces/cache-provider.interface';
|
|
12
|
+
export * from './entities';
|
|
12
13
|
export { CallbackDependency, ChainDependency, DbDependency, FileDependency, TagDependency, TimeDependency, } from './dependencies';
|
|
13
14
|
export { CacheLayer, type CacheDependency, type CacheEvictOptions, type CacheOptions, type CachePutOptions, type CacheableOptions, type CacheStats, type DependencyData, } from './interfaces';
|
|
14
15
|
export { DependencyManager, KeyGenerator, type CachedValueWithDependencies, } from './utils';
|
package/cache/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyGenerator = exports.DependencyManager = exports.CacheLayer = exports.TimeDependency = exports.TagDependency = exports.FileDependency = exports.DbDependency = exports.ChainDependency = exports.CallbackDependency = exports.REDIS_CLIENT = exports.BaseCacheProvider = exports.RedisCacheProvider = exports.
|
|
17
|
+
exports.KeyGenerator = exports.DependencyManager = exports.CacheLayer = exports.TimeDependency = exports.TagDependency = exports.FileDependency = exports.DbDependency = exports.ChainDependency = exports.CallbackDependency = exports.REDIS_CLIENT = exports.BaseCacheProvider = exports.RedisCacheProvider = exports.TypeormCacheProvider = exports.LRUCacheProvider = exports.ClsCacheProvider = exports.setCacheService = exports.getCacheService = exports.CachePut = exports.CacheEvict = exports.Cacheable = exports.CacheSerializationService = exports.CacheMetricsService = exports.CacheWarmupService = exports.CacheHealthChecker = exports.CacheService = exports.CACHE_COMPRESSION_THRESHOLD = exports.CACHE_COMPRESSION_ENABLED = exports.CACHE_SERVICE = exports.CacheModule = void 0;
|
|
4
18
|
// Module
|
|
5
19
|
var cache_module_1 = require("./cache.module");
|
|
6
20
|
Object.defineProperty(exports, "CacheModule", { enumerable: true, get: function () { return cache_module_1.CacheModule; } });
|
|
@@ -31,11 +45,14 @@ Object.defineProperty(exports, "setCacheService", { enumerable: true, get: funct
|
|
|
31
45
|
// Providers
|
|
32
46
|
var providers_1 = require("./providers");
|
|
33
47
|
Object.defineProperty(exports, "ClsCacheProvider", { enumerable: true, get: function () { return providers_1.ClsCacheProvider; } });
|
|
34
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "LRUCacheProvider", { enumerable: true, get: function () { return providers_1.LRUCacheProvider; } });
|
|
49
|
+
Object.defineProperty(exports, "TypeormCacheProvider", { enumerable: true, get: function () { return providers_1.TypeormCacheProvider; } });
|
|
35
50
|
Object.defineProperty(exports, "RedisCacheProvider", { enumerable: true, get: function () { return providers_1.RedisCacheProvider; } });
|
|
36
51
|
Object.defineProperty(exports, "BaseCacheProvider", { enumerable: true, get: function () { return providers_1.BaseCacheProvider; } });
|
|
37
52
|
var redis_cache_provider_1 = require("./providers/redis-cache.provider");
|
|
38
53
|
Object.defineProperty(exports, "REDIS_CLIENT", { enumerable: true, get: function () { return redis_cache_provider_1.REDIS_CLIENT; } });
|
|
54
|
+
// Entities
|
|
55
|
+
__exportStar(require("./entities"), exports);
|
|
39
56
|
// Dependencies
|
|
40
57
|
var dependencies_1 = require("./dependencies");
|
|
41
58
|
Object.defineProperty(exports, "CallbackDependency", { enumerable: true, get: function () { return dependencies_1.CallbackDependency; } });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './base-cache.provider';
|
|
2
2
|
export * from './cls-cache.provider';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './lrucache.provider';
|
|
4
|
+
export * from './typeorm-cache.provider';
|
|
4
5
|
export { REDIS_CLIENT, RedisCacheProvider } from './redis-cache.provider';
|
package/cache/providers/index.js
CHANGED
|
@@ -17,7 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.RedisCacheProvider = exports.REDIS_CLIENT = void 0;
|
|
18
18
|
__exportStar(require("./base-cache.provider"), exports);
|
|
19
19
|
__exportStar(require("./cls-cache.provider"), exports);
|
|
20
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./lrucache.provider"), exports);
|
|
21
|
+
__exportStar(require("./typeorm-cache.provider"), exports);
|
|
21
22
|
var redis_cache_provider_1 = require("./redis-cache.provider");
|
|
22
23
|
Object.defineProperty(exports, "REDIS_CLIENT", { enumerable: true, get: function () { return redis_cache_provider_1.REDIS_CLIENT; } });
|
|
23
24
|
Object.defineProperty(exports, "RedisCacheProvider", { enumerable: true, get: function () { return redis_cache_provider_1.RedisCacheProvider; } });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { BaseCacheProvider } from './base-cache.provider';
|
|
3
|
+
/**
|
|
4
|
+
* LRU Memory Cache Provider
|
|
5
|
+
*
|
|
6
|
+
* High-performance in-memory LRU (Least Recently Used) cache provider.
|
|
7
|
+
* This is an L2 cache layer with fast access and automatic eviction.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - O(1) get/set operations
|
|
11
|
+
* - Automatic LRU eviction when cache is full
|
|
12
|
+
* - Optional TTL (Time To Live) support
|
|
13
|
+
* - Namespace isolation
|
|
14
|
+
* - Cache statistics (size, hit rate, usage percentage)
|
|
15
|
+
*
|
|
16
|
+
* Use Cases:
|
|
17
|
+
* - Session data caching
|
|
18
|
+
* - Frequently accessed configuration
|
|
19
|
+
* - API response caching
|
|
20
|
+
* - Temporary data storage
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const provider = new LRUCacheProvider({
|
|
25
|
+
* maxSize: 1000,
|
|
26
|
+
* ttl: 60000, // optional TTL
|
|
27
|
+
* namespace: 'my-cache',
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class LRUCacheProvider extends BaseCacheProvider implements OnModuleDestroy {
|
|
32
|
+
private cache;
|
|
33
|
+
private namespace;
|
|
34
|
+
private defaultTtl?;
|
|
35
|
+
constructor(options?: {
|
|
36
|
+
maxSize?: number;
|
|
37
|
+
ttl?: number;
|
|
38
|
+
namespace?: string;
|
|
39
|
+
});
|
|
40
|
+
getName(): string;
|
|
41
|
+
get<T>(key: string): Promise<T | null>;
|
|
42
|
+
set<T>(key: string, value: T, ttl?: number): Promise<void>;
|
|
43
|
+
delete(key: string | string[]): Promise<void>;
|
|
44
|
+
deletePattern(pattern: string): Promise<number>;
|
|
45
|
+
clear(): Promise<void>;
|
|
46
|
+
has(key: string): Promise<boolean>;
|
|
47
|
+
mget<T>(keys: string[]): Promise<(T | null)[]>;
|
|
48
|
+
mset(items: Array<{
|
|
49
|
+
key: string;
|
|
50
|
+
value: any;
|
|
51
|
+
}>, ttl?: number): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Get cache size
|
|
54
|
+
*/
|
|
55
|
+
getSize(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Get cache statistics
|
|
58
|
+
*/
|
|
59
|
+
getStats(): {
|
|
60
|
+
provider: string;
|
|
61
|
+
namespace: string;
|
|
62
|
+
size: any;
|
|
63
|
+
maxSize: any;
|
|
64
|
+
calculatedSize: any;
|
|
65
|
+
usagePercentage: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Clean up expired items
|
|
69
|
+
*/
|
|
70
|
+
cleanup(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Destroy the provider
|
|
73
|
+
*/
|
|
74
|
+
onModuleDestroy(): void;
|
|
75
|
+
private getFullKey;
|
|
76
|
+
}
|