@nest-omni/core 4.1.3-1 → 4.1.3-11

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.
Files changed (249) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +39 -1
  3. package/audit/controllers/audit.controller.d.ts +24 -0
  4. package/audit/controllers/audit.controller.js +24 -0
  5. package/audit/decorators/audit-controller.decorator.d.ts +9 -1
  6. package/audit/decorators/audit-controller.decorator.js +11 -2
  7. package/audit/decorators/audit-operation.decorator.d.ts +45 -0
  8. package/audit/decorators/audit-operation.decorator.js +49 -0
  9. package/audit/decorators/entity-audit.decorator.d.ts +76 -1
  10. package/audit/decorators/entity-audit.decorator.js +135 -3
  11. package/audit/decorators/index.d.ts +1 -0
  12. package/audit/decorators/index.js +1 -0
  13. package/audit/dto/audit-log-query.dto.d.ts +3 -0
  14. package/audit/dto/audit-log-query.dto.js +3 -0
  15. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  16. package/audit/dto/begin-transaction.dto.js +3 -0
  17. package/audit/dto/compare-entities.dto.d.ts +3 -0
  18. package/audit/dto/compare-entities.dto.js +3 -0
  19. package/audit/dto/pre-check-restore.dto.d.ts +3 -0
  20. package/audit/dto/pre-check-restore.dto.js +3 -0
  21. package/audit/dto/restore-entity.dto.d.ts +3 -0
  22. package/audit/dto/restore-entity.dto.js +3 -0
  23. package/audit/entities/entity-audit-log.entity.d.ts +8 -0
  24. package/audit/entities/entity-audit-log.entity.js +33 -1
  25. package/audit/entities/entity-transaction.entity.d.ts +10 -0
  26. package/audit/entities/entity-transaction.entity.js +33 -1
  27. package/audit/entities/index.d.ts +2 -0
  28. package/audit/entities/index.js +2 -0
  29. package/audit/entities/manual-operation-log.entity.d.ts +4 -0
  30. package/audit/entities/manual-operation-log.entity.js +4 -0
  31. package/audit/entities/operation-template.entity.d.ts +4 -0
  32. package/audit/entities/operation-template.entity.js +4 -0
  33. package/audit/enums/audit.enums.d.ts +45 -5
  34. package/audit/enums/audit.enums.js +47 -4
  35. package/audit/index.d.ts +3 -1
  36. package/audit/index.js +30 -1
  37. package/audit/interceptors/audit.interceptor.d.ts +15 -0
  38. package/audit/interceptors/audit.interceptor.js +23 -1
  39. package/audit/interfaces/audit.interfaces.d.ts +182 -2
  40. package/audit/services/audit-context.service.d.ts +15 -0
  41. package/audit/services/audit-context.service.js +15 -0
  42. package/audit/services/audit-strategy.service.d.ts +6 -0
  43. package/audit/services/audit-strategy.service.js +13 -0
  44. package/audit/services/entity-audit.service.d.ts +129 -3
  45. package/audit/services/entity-audit.service.js +301 -6
  46. package/audit/services/index.d.ts +2 -0
  47. package/audit/services/index.js +2 -0
  48. package/audit/services/manual-audit-log.service.d.ts +124 -0
  49. package/audit/services/manual-audit-log.service.js +138 -0
  50. package/audit/services/multi-database.service.d.ts +12 -0
  51. package/audit/services/multi-database.service.js +12 -0
  52. package/audit/services/operation-description.service.d.ts +59 -0
  53. package/audit/services/operation-description.service.js +76 -2
  54. package/audit/services/transaction-audit.service.d.ts +30 -0
  55. package/audit/services/transaction-audit.service.js +47 -0
  56. package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
  57. package/audit/subscribers/entity-audit.subscriber.js +29 -1
  58. package/cache/cache-metrics.service.d.ts +67 -0
  59. package/cache/cache-metrics.service.js +68 -4
  60. package/cache/cache-serialization.service.d.ts +31 -0
  61. package/cache/cache-serialization.service.js +25 -0
  62. package/cache/cache.constants.d.ts +9 -0
  63. package/cache/cache.constants.js +9 -0
  64. package/cache/cache.health.d.ts +26 -0
  65. package/cache/cache.health.js +30 -0
  66. package/cache/cache.module.d.ts +86 -0
  67. package/cache/cache.module.js +71 -0
  68. package/cache/cache.service.d.ts +140 -0
  69. package/cache/cache.service.js +157 -0
  70. package/cache/cache.warmup.service.d.ts +39 -0
  71. package/cache/cache.warmup.service.js +32 -0
  72. package/cache/decorators/cache-evict.decorator.d.ts +47 -0
  73. package/cache/decorators/cache-evict.decorator.js +56 -0
  74. package/cache/decorators/cache-put.decorator.d.ts +34 -0
  75. package/cache/decorators/cache-put.decorator.js +39 -0
  76. package/cache/decorators/cacheable.decorator.d.ts +40 -0
  77. package/cache/decorators/cacheable.decorator.js +55 -0
  78. package/cache/dependencies/callback.dependency.d.ts +33 -0
  79. package/cache/dependencies/callback.dependency.js +39 -1
  80. package/cache/dependencies/chain.dependency.d.ts +28 -0
  81. package/cache/dependencies/chain.dependency.js +34 -0
  82. package/cache/dependencies/db.dependency.d.ts +45 -0
  83. package/cache/dependencies/db.dependency.js +48 -1
  84. package/cache/dependencies/file.dependency.d.ts +32 -0
  85. package/cache/dependencies/file.dependency.js +34 -0
  86. package/cache/dependencies/tag.dependency.d.ts +36 -0
  87. package/cache/dependencies/tag.dependency.js +36 -0
  88. package/cache/dependencies/time.dependency.d.ts +43 -0
  89. package/cache/dependencies/time.dependency.js +43 -0
  90. package/cache/examples/basic-usage.d.ts +15 -0
  91. package/cache/examples/basic-usage.js +62 -8
  92. package/cache/index.js +9 -0
  93. package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
  94. package/cache/interfaces/cache-options.interface.d.ts +81 -0
  95. package/cache/interfaces/cache-options.interface.js +6 -0
  96. package/cache/interfaces/cache-provider.interface.d.ts +78 -0
  97. package/cache/providers/base-cache.provider.d.ts +14 -0
  98. package/cache/providers/base-cache.provider.js +16 -0
  99. package/cache/providers/cls-cache.provider.d.ts +20 -0
  100. package/cache/providers/cls-cache.provider.js +28 -0
  101. package/cache/providers/memory-cache.provider.d.ts +23 -0
  102. package/cache/providers/memory-cache.provider.js +26 -0
  103. package/cache/providers/redis-cache.provider.d.ts +26 -0
  104. package/cache/providers/redis-cache.provider.js +29 -0
  105. package/cache/utils/dependency-manager.util.d.ts +52 -0
  106. package/cache/utils/dependency-manager.util.js +59 -0
  107. package/cache/utils/key-generator.util.d.ts +42 -0
  108. package/cache/utils/key-generator.util.js +53 -1
  109. package/common/abstract.entity.d.ts +14 -0
  110. package/common/abstract.entity.js +14 -0
  111. package/common/boilerplate.polyfill.d.ts +142 -4
  112. package/common/boilerplate.polyfill.js +24 -100
  113. package/common/dto/dto-container.d.ts +16 -0
  114. package/common/dto/dto-container.js +20 -0
  115. package/common/dto/dto-decorators.d.ts +18 -0
  116. package/common/dto/dto-decorators.js +14 -0
  117. package/common/dto/dto-extensions.d.ts +11 -0
  118. package/common/dto/dto-extensions.js +9 -0
  119. package/common/dto/dto-service-accessor.d.ts +17 -0
  120. package/common/dto/dto-service-accessor.js +18 -0
  121. package/common/dto/dto-transformer.d.ts +12 -0
  122. package/common/dto/dto-transformer.js +9 -0
  123. package/common/dto/index.js +2 -0
  124. package/common/examples/paginate-and-map.example.d.ts +6 -0
  125. package/common/examples/paginate-and-map.example.js +26 -0
  126. package/common/utils.d.ts +15 -0
  127. package/common/utils.js +15 -0
  128. package/constants/language-code.js +1 -0
  129. package/decorators/field.decorators.js +8 -1
  130. package/decorators/property.decorators.js +1 -0
  131. package/decorators/public-route.decorator.js +1 -0
  132. package/decorators/transform.decorators.d.ts +27 -0
  133. package/decorators/transform.decorators.js +29 -0
  134. package/decorators/translate.decorator.js +1 -0
  135. package/decorators/user.decorator.js +1 -0
  136. package/decorators/validator.decorators.d.ts +8 -18
  137. package/decorators/validator.decorators.js +22 -190
  138. package/filters/constraint-errors.js +1 -0
  139. package/helpers/common.helper.d.ts +13 -0
  140. package/helpers/common.helper.js +13 -0
  141. package/http-client/config/http-client.config.d.ts +15 -0
  142. package/http-client/config/http-client.config.js +25 -9
  143. package/http-client/decorators/http-client.decorators.d.ts +63 -0
  144. package/http-client/decorators/http-client.decorators.js +71 -3
  145. package/http-client/entities/http-log.entity.d.ts +229 -0
  146. package/http-client/entities/http-log.entity.js +6 -1
  147. package/http-client/errors/http-client.errors.d.ts +57 -0
  148. package/http-client/errors/http-client.errors.js +58 -0
  149. package/http-client/examples/advanced-usage.example.d.ts +41 -0
  150. package/http-client/examples/advanced-usage.example.js +68 -24
  151. package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
  152. package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
  153. package/http-client/examples/basic-usage.example.d.ts +60 -0
  154. package/http-client/examples/basic-usage.example.js +60 -0
  155. package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
  156. package/http-client/examples/multi-api-configuration.example.js +76 -5
  157. package/http-client/http-client.module.d.ts +13 -0
  158. package/http-client/http-client.module.js +20 -5
  159. package/http-client/index.js +8 -0
  160. package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
  161. package/http-client/interfaces/api-client-config.interface.js +3 -0
  162. package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
  163. package/http-client/services/api-client-registry.service.d.ts +57 -0
  164. package/http-client/services/api-client-registry.service.js +84 -1
  165. package/http-client/services/cache.service.d.ts +52 -0
  166. package/http-client/services/cache.service.js +72 -3
  167. package/http-client/services/circuit-breaker.service.d.ts +46 -0
  168. package/http-client/services/circuit-breaker.service.js +52 -0
  169. package/http-client/services/http-client.service.d.ts +67 -0
  170. package/http-client/services/http-client.service.js +105 -4
  171. package/http-client/services/http-log-query.service.d.ts +83 -0
  172. package/http-client/services/http-log-query.service.js +122 -1
  173. package/http-client/services/http-replay.service.d.ts +101 -0
  174. package/http-client/services/http-replay.service.js +86 -0
  175. package/http-client/services/log-cleanup.service.d.ts +63 -0
  176. package/http-client/services/log-cleanup.service.js +54 -2
  177. package/http-client/services/logging.service.d.ts +40 -0
  178. package/http-client/services/logging.service.js +53 -0
  179. package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
  180. package/http-client/utils/call-stack-extractor.util.js +48 -0
  181. package/http-client/utils/context-extractor.util.d.ts +49 -0
  182. package/http-client/utils/context-extractor.util.js +52 -0
  183. package/http-client/utils/curl-generator.util.d.ts +21 -0
  184. package/http-client/utils/curl-generator.util.js +44 -3
  185. package/http-client/utils/request-id.util.d.ts +18 -0
  186. package/http-client/utils/request-id.util.js +20 -0
  187. package/http-client/utils/retry-recorder.util.d.ts +42 -0
  188. package/http-client/utils/retry-recorder.util.js +44 -0
  189. package/i18n/en_US/validation.json +2 -1
  190. package/i18n/zh_CN/validation.json +2 -1
  191. package/index.js +8 -0
  192. package/interceptors/translation-interceptor.service.js +5 -0
  193. package/package.json +1 -1
  194. package/providers/context.provider.js +2 -0
  195. package/providers/generator.provider.d.ts +4 -0
  196. package/providers/generator.provider.js +4 -0
  197. package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
  198. package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
  199. package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
  200. package/redis-lock/examples/lock-strategy.examples.js +130 -15
  201. package/redis-lock/index.d.ts +2 -0
  202. package/redis-lock/index.js +8 -1
  203. package/redis-lock/lock-heartbeat.service.d.ts +78 -0
  204. package/redis-lock/lock-heartbeat.service.js +222 -0
  205. package/redis-lock/redis-lock.decorator.d.ts +101 -0
  206. package/redis-lock/redis-lock.decorator.js +120 -0
  207. package/redis-lock/redis-lock.module.d.ts +66 -0
  208. package/redis-lock/redis-lock.module.js +175 -70
  209. package/redis-lock/redis-lock.service.d.ts +278 -0
  210. package/redis-lock/redis-lock.service.js +282 -12
  211. package/setup/bootstrap.setup.js +20 -0
  212. package/setup/mode.setup.d.ts +44 -0
  213. package/setup/mode.setup.js +44 -0
  214. package/setup/schedule.decorator.d.ts +227 -0
  215. package/setup/schedule.decorator.js +235 -12
  216. package/setup/worker.decorator.d.ts +86 -0
  217. package/setup/worker.decorator.js +88 -0
  218. package/shared/serviceRegistryModule.js +27 -14
  219. package/shared/services/api-config.service.d.ts +3 -0
  220. package/shared/services/api-config.service.js +20 -9
  221. package/validator-json/decorators.d.ts +17 -0
  222. package/validator-json/decorators.js +17 -2
  223. package/validator-json/default.d.ts +6 -0
  224. package/validator-json/default.js +30 -2
  225. package/validator-json/defaultConverters.js +1 -0
  226. package/validator-json/options.d.ts +23 -0
  227. package/validators/common-validators.d.ts +143 -0
  228. package/validators/common-validators.js +249 -0
  229. package/validators/custom-validate.examples.d.ts +96 -0
  230. package/validators/custom-validate.examples.js +400 -0
  231. package/validators/custom-validate.validator.d.ts +134 -0
  232. package/validators/custom-validate.validator.js +214 -0
  233. package/validators/index.d.ts +2 -0
  234. package/validators/index.js +2 -0
  235. package/validators/is-exists.validator.d.ts +18 -4
  236. package/validators/is-exists.validator.js +67 -6
  237. package/validators/is-unique.validator.d.ts +32 -5
  238. package/validators/is-unique.validator.js +99 -17
  239. package/validators/skip-empty.validator.d.ts +5 -0
  240. package/validators/skip-empty.validator.js +5 -0
  241. package/vault/interfaces/vault-options.interface.d.ts +9 -0
  242. package/vault/vault-config.loader.d.ts +30 -0
  243. package/vault/vault-config.loader.js +48 -1
  244. package/vault/vault-config.service.d.ts +53 -0
  245. package/vault/vault-config.service.js +57 -0
  246. package/vault/vault.module.d.ts +4 -0
  247. package/vault/vault.module.js +4 -0
  248. package/decorators/examples/validation-decorators.example.d.ts +0 -69
  249. package/decorators/examples/validation-decorators.example.js +0 -331
@@ -1,6 +1,17 @@
1
1
  import type Redis from 'ioredis';
2
2
  import { BaseCacheProvider } from './base-cache.provider';
3
+ /**
4
+ * Token for injecting Redis client
5
+ */
3
6
  export declare const REDIS_CLIENT: unique symbol;
7
+ /**
8
+ * Redis cache provider using ioredis
9
+ *
10
+ * This is the L3 cache layer - distributed caching using Redis.
11
+ * Data is persisted in Redis and shared across all processes/servers.
12
+ *
13
+ * Slowest but most persistent and widely shared cache layer.
14
+ */
4
15
  export declare class RedisCacheProvider extends BaseCacheProvider {
5
16
  private readonly redis?;
6
17
  private readonly keyPrefix;
@@ -12,12 +23,27 @@ export declare class RedisCacheProvider extends BaseCacheProvider {
12
23
  deletePattern(pattern: string): Promise<number>;
13
24
  clear(): Promise<void>;
14
25
  has(key: string): Promise<boolean>;
26
+ /**
27
+ * Batch get using Redis MGET
28
+ */
15
29
  mget<T>(keys: string[]): Promise<(T | null)[]>;
30
+ /**
31
+ * Batch set using Redis pipeline
32
+ */
16
33
  mset(items: Array<{
17
34
  key: string;
18
35
  value: any;
19
36
  }>, ttl?: number): Promise<void>;
37
+ /**
38
+ * Check if Redis client is available
39
+ */
20
40
  isAvailable(): boolean;
41
+ /**
42
+ * Get Redis client (for advanced usage)
43
+ */
21
44
  getClient(): Redis | undefined;
45
+ /**
46
+ * Get full key with prefix
47
+ */
22
48
  private getFullKey;
23
49
  }
@@ -24,7 +24,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.RedisCacheProvider = exports.REDIS_CLIENT = void 0;
25
25
  const common_1 = require("@nestjs/common");
26
26
  const base_cache_provider_1 = require("./base-cache.provider");
27
+ /**
28
+ * Token for injecting Redis client
29
+ */
27
30
  exports.REDIS_CLIENT = Symbol('REDIS_CLIENT');
31
+ /**
32
+ * Redis cache provider using ioredis
33
+ *
34
+ * This is the L3 cache layer - distributed caching using Redis.
35
+ * Data is persisted in Redis and shared across all processes/servers.
36
+ *
37
+ * Slowest but most persistent and widely shared cache layer.
38
+ */
28
39
  let RedisCacheProvider = class RedisCacheProvider extends base_cache_provider_1.BaseCacheProvider {
29
40
  constructor(redis) {
30
41
  super();
@@ -65,6 +76,7 @@ let RedisCacheProvider = class RedisCacheProvider extends base_cache_provider_1.
65
76
  const fullKey = this.getFullKey(key);
66
77
  const serialized = JSON.stringify(value);
67
78
  if (ttl && ttl > 0) {
79
+ // TTL in milliseconds, Redis expects seconds
68
80
  yield this.redis.setex(fullKey, Math.ceil(ttl / 1000), serialized);
69
81
  }
70
82
  else {
@@ -102,6 +114,7 @@ let RedisCacheProvider = class RedisCacheProvider extends base_cache_provider_1.
102
114
  const fullPattern = this.getFullKey(pattern);
103
115
  let cursor = '0';
104
116
  let deletedCount = 0;
117
+ // Use SCAN to find matching keys (more efficient than KEYS)
105
118
  do {
106
119
  const [nextCursor, keys] = yield this.redis.scan(cursor, 'MATCH', fullPattern, 'COUNT', 100);
107
120
  cursor = nextCursor;
@@ -124,6 +137,7 @@ let RedisCacheProvider = class RedisCacheProvider extends base_cache_provider_1.
124
137
  return;
125
138
  }
126
139
  try {
140
+ // Clear all keys with our prefix
127
141
  yield this.deletePattern('*');
128
142
  }
129
143
  catch (error) {
@@ -146,6 +160,9 @@ let RedisCacheProvider = class RedisCacheProvider extends base_cache_provider_1.
146
160
  }
147
161
  });
148
162
  }
163
+ /**
164
+ * Batch get using Redis MGET
165
+ */
149
166
  mget(keys) {
150
167
  return __awaiter(this, void 0, void 0, function* () {
151
168
  if (!this.redis || keys.length === 0) {
@@ -172,6 +189,9 @@ let RedisCacheProvider = class RedisCacheProvider extends base_cache_provider_1.
172
189
  }
173
190
  });
174
191
  }
192
+ /**
193
+ * Batch set using Redis pipeline
194
+ */
175
195
  mset(items, ttl) {
176
196
  return __awaiter(this, void 0, void 0, function* () {
177
197
  if (!this.redis || items.length === 0) {
@@ -196,12 +216,21 @@ let RedisCacheProvider = class RedisCacheProvider extends base_cache_provider_1.
196
216
  }
197
217
  });
198
218
  }
219
+ /**
220
+ * Check if Redis client is available
221
+ */
199
222
  isAvailable() {
200
223
  return !!this.redis && this.redis.status === 'ready';
201
224
  }
225
+ /**
226
+ * Get Redis client (for advanced usage)
227
+ */
202
228
  getClient() {
203
229
  return this.redis;
204
230
  }
231
+ /**
232
+ * Get full key with prefix
233
+ */
205
234
  getFullKey(key) {
206
235
  return `${this.keyPrefix}${key}`;
207
236
  }
@@ -1,15 +1,67 @@
1
1
  import type { CacheDependency, DependencyData } from '../interfaces';
2
+ /**
3
+ * Wrapper for cached value with dependency data
4
+ */
2
5
  export interface CachedValueWithDependencies<T> {
3
6
  value: T;
4
7
  dependencies?: DependencyData[];
5
8
  cachedAt: number;
6
9
  }
10
+ /**
11
+ * Utility class for managing cache dependencies
12
+ */
7
13
  export declare class DependencyManager {
14
+ /**
15
+ * Wrap a value with its dependencies
16
+ *
17
+ * @param value - The value to cache
18
+ * @param dependencies - Array of dependencies
19
+ * @returns Wrapped value with dependency data
20
+ */
8
21
  static wrapWithDependencies<T>(value: T, dependencies?: CacheDependency[]): Promise<CachedValueWithDependencies<T>>;
22
+ /**
23
+ * Capture current state of all dependencies
24
+ *
25
+ * @param dependencies - Array of dependencies
26
+ * @returns Array of dependency data snapshots
27
+ */
9
28
  static captureDependencies(dependencies: CacheDependency[]): Promise<DependencyData[]>;
29
+ /**
30
+ * Check if any dependencies have changed
31
+ *
32
+ * @param dependencies - Current dependencies
33
+ * @param cachedDependencies - Previously captured dependency data
34
+ * @returns true if any dependency has changed
35
+ */
10
36
  static areDependenciesChanged(dependencies: CacheDependency[], cachedDependencies?: DependencyData[]): Promise<boolean>;
37
+ /**
38
+ * Unwrap cached value and validate dependencies
39
+ *
40
+ * @param wrapped - Wrapped cached value
41
+ * @param dependencies - Current dependencies to check
42
+ * @returns Unwrapped value if valid, null if dependencies changed
43
+ */
11
44
  static unwrapAndValidate<T>(wrapped: CachedValueWithDependencies<T> | null, dependencies?: CacheDependency[]): Promise<T | null>;
45
+ /**
46
+ * Get which dependencies have changed
47
+ *
48
+ * @param dependencies - Current dependencies
49
+ * @param cachedDependencies - Previously captured dependency data
50
+ * @returns Array of changed dependency keys
51
+ */
12
52
  static getChangedDependencies(dependencies: CacheDependency[], cachedDependencies?: DependencyData[]): Promise<string[]>;
53
+ /**
54
+ * Serialize dependencies for storage
55
+ *
56
+ * @param dependencies - Dependency data
57
+ * @returns Serialized string
58
+ */
13
59
  static serializeDependencies(dependencies: DependencyData[]): string;
60
+ /**
61
+ * Deserialize dependencies from storage
62
+ *
63
+ * @param serialized - Serialized string
64
+ * @returns Dependency data array
65
+ */
14
66
  static deserializeDependencies(serialized: string): DependencyData[];
15
67
  }
@@ -10,7 +10,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DependencyManager = void 0;
13
+ /**
14
+ * Utility class for managing cache dependencies
15
+ */
13
16
  class DependencyManager {
17
+ /**
18
+ * Wrap a value with its dependencies
19
+ *
20
+ * @param value - The value to cache
21
+ * @param dependencies - Array of dependencies
22
+ * @returns Wrapped value with dependency data
23
+ */
14
24
  static wrapWithDependencies(value, dependencies) {
15
25
  return __awaiter(this, void 0, void 0, function* () {
16
26
  const wrapped = {
@@ -23,6 +33,12 @@ class DependencyManager {
23
33
  return wrapped;
24
34
  });
25
35
  }
36
+ /**
37
+ * Capture current state of all dependencies
38
+ *
39
+ * @param dependencies - Array of dependencies
40
+ * @returns Array of dependency data snapshots
41
+ */
26
42
  static captureDependencies(dependencies) {
27
43
  return __awaiter(this, void 0, void 0, function* () {
28
44
  const results = [];
@@ -36,6 +52,7 @@ class DependencyManager {
36
52
  });
37
53
  }
38
54
  catch (error) {
55
+ // Store error state
39
56
  results.push({
40
57
  key: dep.getKey(),
41
58
  data: {
@@ -48,44 +65,67 @@ class DependencyManager {
48
65
  return results;
49
66
  });
50
67
  }
68
+ /**
69
+ * Check if any dependencies have changed
70
+ *
71
+ * @param dependencies - Current dependencies
72
+ * @param cachedDependencies - Previously captured dependency data
73
+ * @returns true if any dependency has changed
74
+ */
51
75
  static areDependenciesChanged(dependencies, cachedDependencies) {
52
76
  return __awaiter(this, void 0, void 0, function* () {
77
+ // No dependencies means never changed
53
78
  if (!dependencies || dependencies.length === 0) {
54
79
  return false;
55
80
  }
81
+ // No cached dependency data means changed (first time)
56
82
  if (!cachedDependencies || cachedDependencies.length === 0) {
57
83
  return true;
58
84
  }
85
+ // Different number of dependencies means changed
59
86
  if (dependencies.length !== cachedDependencies.length) {
60
87
  return true;
61
88
  }
89
+ // Check each dependency
62
90
  for (let i = 0; i < dependencies.length; i++) {
63
91
  const dep = dependencies[i];
64
92
  const cached = cachedDependencies[i];
93
+ // Key mismatch means dependencies changed
65
94
  if (dep.getKey() !== cached.key) {
66
95
  return true;
67
96
  }
68
97
  try {
98
+ // Check if this dependency has changed
69
99
  const changed = yield dep.isChanged(cached.data);
70
100
  if (changed) {
71
101
  return true;
72
102
  }
73
103
  }
74
104
  catch (_a) {
105
+ // If check fails, consider it changed to be safe
75
106
  return true;
76
107
  }
77
108
  }
78
109
  return false;
79
110
  });
80
111
  }
112
+ /**
113
+ * Unwrap cached value and validate dependencies
114
+ *
115
+ * @param wrapped - Wrapped cached value
116
+ * @param dependencies - Current dependencies to check
117
+ * @returns Unwrapped value if valid, null if dependencies changed
118
+ */
81
119
  static unwrapAndValidate(wrapped, dependencies) {
82
120
  return __awaiter(this, void 0, void 0, function* () {
83
121
  if (!wrapped) {
84
122
  return null;
85
123
  }
124
+ // No dependencies to check, return value
86
125
  if (!dependencies || dependencies.length === 0) {
87
126
  return wrapped.value;
88
127
  }
128
+ // Check if dependencies have changed
89
129
  const changed = yield this.areDependenciesChanged(dependencies, wrapped.dependencies);
90
130
  if (changed) {
91
131
  return null;
@@ -93,6 +133,13 @@ class DependencyManager {
93
133
  return wrapped.value;
94
134
  });
95
135
  }
136
+ /**
137
+ * Get which dependencies have changed
138
+ *
139
+ * @param dependencies - Current dependencies
140
+ * @param cachedDependencies - Previously captured dependency data
141
+ * @returns Array of changed dependency keys
142
+ */
96
143
  static getChangedDependencies(dependencies, cachedDependencies) {
97
144
  return __awaiter(this, void 0, void 0, function* () {
98
145
  if (!dependencies || dependencies.length === 0) {
@@ -121,6 +168,12 @@ class DependencyManager {
121
168
  return changed;
122
169
  });
123
170
  }
171
+ /**
172
+ * Serialize dependencies for storage
173
+ *
174
+ * @param dependencies - Dependency data
175
+ * @returns Serialized string
176
+ */
124
177
  static serializeDependencies(dependencies) {
125
178
  try {
126
179
  return JSON.stringify(dependencies);
@@ -129,6 +182,12 @@ class DependencyManager {
129
182
  return '[]';
130
183
  }
131
184
  }
185
+ /**
186
+ * Deserialize dependencies from storage
187
+ *
188
+ * @param serialized - Serialized string
189
+ * @returns Dependency data array
190
+ */
132
191
  static deserializeDependencies(serialized) {
133
192
  try {
134
193
  return JSON.parse(serialized);
@@ -1,10 +1,52 @@
1
1
  import type { CacheKeyOptions } from '../interfaces';
2
+ /**
3
+ * Utility class for generating cache keys
4
+ */
2
5
  export declare class KeyGenerator {
6
+ /**
7
+ * Generate cache key from options and method arguments
8
+ *
9
+ * @param options - Cache key options
10
+ * @param args - Method arguments
11
+ * @returns Generated cache key
12
+ */
3
13
  static generate(options: CacheKeyOptions, args: any[]): string;
14
+ /**
15
+ * Generate key from method arguments
16
+ *
17
+ * @param args - Method arguments
18
+ * @returns Serialized key
19
+ */
4
20
  static generateFromArgs(args: any[]): string;
21
+ /**
22
+ * Normalize key (remove invalid characters, enforce length limits)
23
+ *
24
+ * @param key - Raw key
25
+ * @param maxLength - Maximum key length (default 250)
26
+ * @returns Normalized key
27
+ */
5
28
  static normalize(key: string, maxLength?: number): string;
29
+ /**
30
+ * Add namespace to key
31
+ *
32
+ * @param key - Original key
33
+ * @param namespace - Namespace
34
+ * @returns Namespaced key
35
+ */
6
36
  static addNamespace(key: string, namespace?: string): string;
37
+ /**
38
+ * Generate hash code for a string
39
+ *
40
+ * @param str - Input string
41
+ * @returns Hash code as string
42
+ */
7
43
  static hashCode(str: string): string;
44
+ /**
45
+ * Parse pattern into segments for matching
46
+ *
47
+ * @param pattern - Pattern with wildcards
48
+ * @returns Pattern segments
49
+ */
8
50
  static parsePattern(pattern: string): {
9
51
  prefix: string;
10
52
  suffix: string;
@@ -1,60 +1,112 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KeyGenerator = void 0;
4
+ /**
5
+ * Utility class for generating cache keys
6
+ */
4
7
  class KeyGenerator {
8
+ /**
9
+ * Generate cache key from options and method arguments
10
+ *
11
+ * @param options - Cache key options
12
+ * @param args - Method arguments
13
+ * @returns Generated cache key
14
+ */
5
15
  static generate(options, args) {
6
16
  let key;
7
17
  if (typeof options.key === 'function') {
18
+ // Dynamic key generation using function
8
19
  key = options.key(...args);
9
20
  }
10
21
  else if (typeof options.key === 'string') {
22
+ // Static key
11
23
  key = options.key;
12
24
  }
13
25
  else if (options.includeAllArgs) {
26
+ // Auto-generate key from all arguments
14
27
  key = this.generateFromArgs(args);
15
28
  }
16
29
  else {
30
+ // Default: use first argument as key
17
31
  key = args.length > 0 ? String(args[0]) : 'default';
18
32
  }
33
+ // Add prefix if specified
19
34
  if (options.prefix) {
20
35
  key = `${options.prefix}${key}`;
21
36
  }
22
37
  return key;
23
38
  }
39
+ /**
40
+ * Generate key from method arguments
41
+ *
42
+ * @param args - Method arguments
43
+ * @returns Serialized key
44
+ */
24
45
  static generateFromArgs(args) {
25
46
  if (args.length === 0) {
26
47
  return 'default';
27
48
  }
28
49
  try {
50
+ // Serialize arguments to JSON
29
51
  return JSON.stringify(args);
30
52
  }
31
53
  catch (_a) {
54
+ // Fallback to string concatenation
32
55
  return args.map((arg) => String(arg)).join(':');
33
56
  }
34
57
  }
58
+ /**
59
+ * Normalize key (remove invalid characters, enforce length limits)
60
+ *
61
+ * @param key - Raw key
62
+ * @param maxLength - Maximum key length (default 250)
63
+ * @returns Normalized key
64
+ */
35
65
  static normalize(key, maxLength = 250) {
66
+ // Remove or replace invalid characters
36
67
  let normalized = key.replace(/[\s\n\r\t]/g, '_');
68
+ // Enforce length limit
37
69
  if (normalized.length > maxLength) {
70
+ // Use hash for long keys
38
71
  const hash = this.hashCode(normalized);
39
72
  normalized = normalized.substring(0, maxLength - 10) + '_' + hash;
40
73
  }
41
74
  return normalized;
42
75
  }
76
+ /**
77
+ * Add namespace to key
78
+ *
79
+ * @param key - Original key
80
+ * @param namespace - Namespace
81
+ * @returns Namespaced key
82
+ */
43
83
  static addNamespace(key, namespace) {
44
84
  if (!namespace) {
45
85
  return key;
46
86
  }
47
87
  return `${namespace}:${key}`;
48
88
  }
89
+ /**
90
+ * Generate hash code for a string
91
+ *
92
+ * @param str - Input string
93
+ * @returns Hash code as string
94
+ */
49
95
  static hashCode(str) {
50
96
  let hash = 0;
51
97
  for (let i = 0; i < str.length; i++) {
52
98
  const char = str.charCodeAt(i);
53
99
  hash = (hash << 5) - hash + char;
54
- hash = hash & hash;
100
+ hash = hash & hash; // Convert to 32bit integer
55
101
  }
56
102
  return Math.abs(hash).toString(36);
57
103
  }
104
+ /**
105
+ * Parse pattern into segments for matching
106
+ *
107
+ * @param pattern - Pattern with wildcards
108
+ * @returns Pattern segments
109
+ */
58
110
  static parsePattern(pattern) {
59
111
  const wildcardIndex = pattern.indexOf('*');
60
112
  if (wildcardIndex === -1) {
@@ -1,9 +1,23 @@
1
1
  import type { AbstractDto, AbstractTranslationDto } from './dto/abstract.dto';
2
2
  import { LanguageCode } from '../constants';
3
+ /**
4
+ * Abstract DTO-able Entity
5
+ *
6
+ * @description Base class that provides toDto functionality without any database fields.
7
+ * Use this for view entities or other entities that don't need createdAt/updatedAt fields.
8
+ */
3
9
  export declare abstract class AbstractDtoEntity<DTO, O = never> {
4
10
  translations?: AbstractTranslationEntity[];
5
11
  toDto(options?: O): DTO;
6
12
  }
13
+ /**
14
+ * Abstract Entity
15
+ *
16
+ * @description This class is an abstract class for all entities.
17
+ * It's experimental and recommended using it only in microservice architecture,
18
+ * otherwise just delete and use your own entity.
19
+ * Extends AbstractDtoEntity and adds createdAt/updatedAt timestamp fields.
20
+ */
7
21
  export declare abstract class AbstractBaseEntity<DTO, O> extends AbstractDtoEntity<DTO, O> {
8
22
  createdAt: Date;
9
23
  updatedAt: Date;
@@ -14,6 +14,12 @@ const typeorm_1 = require("typeorm");
14
14
  const decorators_1 = require("../decorators");
15
15
  const constants_1 = require("../constants");
16
16
  const uuid_1 = require("uuid");
17
+ /**
18
+ * Abstract DTO-able Entity
19
+ *
20
+ * @description Base class that provides toDto functionality without any database fields.
21
+ * Use this for view entities or other entities that don't need createdAt/updatedAt fields.
22
+ */
17
23
  class AbstractDtoEntity {
18
24
  toDto(options) {
19
25
  const dtoClass = Object.getPrototypeOf(this).dtoClass;
@@ -24,6 +30,14 @@ class AbstractDtoEntity {
24
30
  }
25
31
  }
26
32
  exports.AbstractDtoEntity = AbstractDtoEntity;
33
+ /**
34
+ * Abstract Entity
35
+ *
36
+ * @description This class is an abstract class for all entities.
37
+ * It's experimental and recommended using it only in microservice architecture,
38
+ * otherwise just delete and use your own entity.
39
+ * Extends AbstractDtoEntity and adds createdAt/updatedAt timestamp fields.
40
+ */
27
41
  class AbstractBaseEntity extends AbstractDtoEntity {
28
42
  }
29
43
  exports.AbstractBaseEntity = AbstractBaseEntity;