@nest-omni/core 4.1.3-2 → 4.1.3-3

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 (235) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +15 -0
  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 +8 -0
  6. package/audit/decorators/audit-controller.decorator.js +9 -0
  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 +8 -0
  10. package/audit/decorators/entity-audit.decorator.js +9 -0
  11. package/audit/dto/audit-log-query.dto.d.ts +3 -0
  12. package/audit/dto/audit-log-query.dto.js +3 -0
  13. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  14. package/audit/dto/begin-transaction.dto.js +3 -0
  15. package/audit/dto/compare-entities.dto.d.ts +3 -0
  16. package/audit/dto/compare-entities.dto.js +3 -0
  17. package/audit/dto/pre-check-restore.dto.d.ts +3 -0
  18. package/audit/dto/pre-check-restore.dto.js +3 -0
  19. package/audit/dto/restore-entity.dto.d.ts +3 -0
  20. package/audit/dto/restore-entity.dto.js +3 -0
  21. package/audit/entities/entity-audit-log.entity.d.ts +3 -0
  22. package/audit/entities/entity-audit-log.entity.js +3 -0
  23. package/audit/entities/entity-transaction.entity.d.ts +3 -0
  24. package/audit/entities/entity-transaction.entity.js +3 -0
  25. package/audit/entities/manual-operation-log.entity.d.ts +4 -0
  26. package/audit/entities/manual-operation-log.entity.js +4 -0
  27. package/audit/entities/operation-template.entity.d.ts +4 -0
  28. package/audit/entities/operation-template.entity.js +4 -0
  29. package/audit/enums/audit.enums.d.ts +17 -2
  30. package/audit/enums/audit.enums.js +15 -0
  31. package/audit/index.js +10 -0
  32. package/audit/interceptors/audit.interceptor.d.ts +15 -0
  33. package/audit/interceptors/audit.interceptor.js +23 -1
  34. package/audit/interfaces/audit.interfaces.d.ts +42 -0
  35. package/audit/services/audit-context.service.d.ts +15 -0
  36. package/audit/services/audit-context.service.js +15 -0
  37. package/audit/services/audit-strategy.service.d.ts +6 -0
  38. package/audit/services/audit-strategy.service.js +13 -0
  39. package/audit/services/entity-audit.service.d.ts +57 -0
  40. package/audit/services/entity-audit.service.js +91 -0
  41. package/audit/services/manual-audit-log.service.d.ts +124 -0
  42. package/audit/services/manual-audit-log.service.js +138 -0
  43. package/audit/services/multi-database.service.d.ts +12 -0
  44. package/audit/services/multi-database.service.js +12 -0
  45. package/audit/services/operation-description.service.d.ts +59 -0
  46. package/audit/services/operation-description.service.js +76 -2
  47. package/audit/services/transaction-audit.service.d.ts +30 -0
  48. package/audit/services/transaction-audit.service.js +47 -0
  49. package/audit/subscribers/entity-audit.subscriber.d.ts +15 -0
  50. package/audit/subscribers/entity-audit.subscriber.js +29 -1
  51. package/cache/cache-metrics.service.d.ts +67 -0
  52. package/cache/cache-metrics.service.js +68 -4
  53. package/cache/cache-serialization.service.d.ts +31 -0
  54. package/cache/cache-serialization.service.js +25 -0
  55. package/cache/cache.constants.d.ts +9 -0
  56. package/cache/cache.constants.js +9 -0
  57. package/cache/cache.health.d.ts +26 -0
  58. package/cache/cache.health.js +30 -0
  59. package/cache/cache.module.d.ts +86 -0
  60. package/cache/cache.module.js +71 -0
  61. package/cache/cache.service.d.ts +140 -0
  62. package/cache/cache.service.js +157 -0
  63. package/cache/cache.warmup.service.d.ts +39 -0
  64. package/cache/cache.warmup.service.js +32 -0
  65. package/cache/decorators/cache-evict.decorator.d.ts +47 -0
  66. package/cache/decorators/cache-evict.decorator.js +56 -0
  67. package/cache/decorators/cache-put.decorator.d.ts +34 -0
  68. package/cache/decorators/cache-put.decorator.js +39 -0
  69. package/cache/decorators/cacheable.decorator.d.ts +40 -0
  70. package/cache/decorators/cacheable.decorator.js +55 -0
  71. package/cache/dependencies/callback.dependency.d.ts +33 -0
  72. package/cache/dependencies/callback.dependency.js +39 -1
  73. package/cache/dependencies/chain.dependency.d.ts +28 -0
  74. package/cache/dependencies/chain.dependency.js +34 -0
  75. package/cache/dependencies/db.dependency.d.ts +45 -0
  76. package/cache/dependencies/db.dependency.js +48 -1
  77. package/cache/dependencies/file.dependency.d.ts +32 -0
  78. package/cache/dependencies/file.dependency.js +34 -0
  79. package/cache/dependencies/tag.dependency.d.ts +36 -0
  80. package/cache/dependencies/tag.dependency.js +36 -0
  81. package/cache/dependencies/time.dependency.d.ts +43 -0
  82. package/cache/dependencies/time.dependency.js +43 -0
  83. package/cache/examples/basic-usage.d.ts +15 -0
  84. package/cache/examples/basic-usage.js +62 -8
  85. package/cache/index.js +9 -0
  86. package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
  87. package/cache/interfaces/cache-options.interface.d.ts +81 -0
  88. package/cache/interfaces/cache-options.interface.js +6 -0
  89. package/cache/interfaces/cache-provider.interface.d.ts +78 -0
  90. package/cache/providers/base-cache.provider.d.ts +14 -0
  91. package/cache/providers/base-cache.provider.js +16 -0
  92. package/cache/providers/cls-cache.provider.d.ts +20 -0
  93. package/cache/providers/cls-cache.provider.js +28 -0
  94. package/cache/providers/memory-cache.provider.d.ts +23 -0
  95. package/cache/providers/memory-cache.provider.js +26 -0
  96. package/cache/providers/redis-cache.provider.d.ts +26 -0
  97. package/cache/providers/redis-cache.provider.js +29 -0
  98. package/cache/utils/dependency-manager.util.d.ts +52 -0
  99. package/cache/utils/dependency-manager.util.js +59 -0
  100. package/cache/utils/key-generator.util.d.ts +42 -0
  101. package/cache/utils/key-generator.util.js +53 -1
  102. package/common/abstract.entity.d.ts +14 -0
  103. package/common/abstract.entity.js +14 -0
  104. package/common/boilerplate.polyfill.d.ts +142 -0
  105. package/common/boilerplate.polyfill.js +17 -0
  106. package/common/dto/dto-container.d.ts +16 -0
  107. package/common/dto/dto-container.js +20 -0
  108. package/common/dto/dto-decorators.d.ts +18 -0
  109. package/common/dto/dto-decorators.js +14 -0
  110. package/common/dto/dto-extensions.d.ts +11 -0
  111. package/common/dto/dto-extensions.js +9 -0
  112. package/common/dto/dto-service-accessor.d.ts +17 -0
  113. package/common/dto/dto-service-accessor.js +18 -0
  114. package/common/dto/dto-transformer.d.ts +12 -0
  115. package/common/dto/dto-transformer.js +9 -0
  116. package/common/dto/index.js +2 -0
  117. package/common/examples/paginate-and-map.example.d.ts +6 -0
  118. package/common/examples/paginate-and-map.example.js +26 -0
  119. package/common/utils.d.ts +15 -0
  120. package/common/utils.js +15 -0
  121. package/constants/language-code.js +1 -0
  122. package/decorators/field.decorators.js +8 -1
  123. package/decorators/property.decorators.js +1 -0
  124. package/decorators/public-route.decorator.js +1 -0
  125. package/decorators/transform.decorators.d.ts +27 -0
  126. package/decorators/transform.decorators.js +29 -0
  127. package/decorators/translate.decorator.js +1 -0
  128. package/decorators/user.decorator.js +1 -0
  129. package/decorators/validator.decorators.d.ts +8 -18
  130. package/decorators/validator.decorators.js +22 -190
  131. package/filters/constraint-errors.js +1 -0
  132. package/helpers/common.helper.d.ts +13 -0
  133. package/helpers/common.helper.js +13 -0
  134. package/http-client/config/http-client.config.d.ts +15 -0
  135. package/http-client/config/http-client.config.js +25 -9
  136. package/http-client/decorators/http-client.decorators.d.ts +63 -0
  137. package/http-client/decorators/http-client.decorators.js +71 -3
  138. package/http-client/entities/http-log.entity.d.ts +229 -0
  139. package/http-client/entities/http-log.entity.js +6 -1
  140. package/http-client/errors/http-client.errors.d.ts +57 -0
  141. package/http-client/errors/http-client.errors.js +58 -0
  142. package/http-client/examples/advanced-usage.example.d.ts +41 -0
  143. package/http-client/examples/advanced-usage.example.js +68 -24
  144. package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
  145. package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
  146. package/http-client/examples/basic-usage.example.d.ts +60 -0
  147. package/http-client/examples/basic-usage.example.js +60 -0
  148. package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
  149. package/http-client/examples/multi-api-configuration.example.js +76 -5
  150. package/http-client/http-client.module.d.ts +13 -0
  151. package/http-client/http-client.module.js +19 -0
  152. package/http-client/index.js +8 -0
  153. package/http-client/interfaces/api-client-config.interface.d.ts +125 -0
  154. package/http-client/interfaces/api-client-config.interface.js +3 -0
  155. package/http-client/interfaces/http-client-config.interface.d.ts +60 -0
  156. package/http-client/services/api-client-registry.service.d.ts +57 -0
  157. package/http-client/services/api-client-registry.service.js +84 -1
  158. package/http-client/services/cache.service.d.ts +52 -0
  159. package/http-client/services/cache.service.js +72 -3
  160. package/http-client/services/circuit-breaker.service.d.ts +46 -0
  161. package/http-client/services/circuit-breaker.service.js +52 -0
  162. package/http-client/services/http-client.service.d.ts +67 -0
  163. package/http-client/services/http-client.service.js +105 -4
  164. package/http-client/services/http-log-query.service.d.ts +83 -0
  165. package/http-client/services/http-log-query.service.js +122 -1
  166. package/http-client/services/http-replay.service.d.ts +101 -0
  167. package/http-client/services/http-replay.service.js +86 -0
  168. package/http-client/services/log-cleanup.service.d.ts +63 -0
  169. package/http-client/services/log-cleanup.service.js +54 -2
  170. package/http-client/services/logging.service.d.ts +40 -0
  171. package/http-client/services/logging.service.js +53 -0
  172. package/http-client/utils/call-stack-extractor.util.d.ts +37 -0
  173. package/http-client/utils/call-stack-extractor.util.js +48 -0
  174. package/http-client/utils/context-extractor.util.d.ts +49 -0
  175. package/http-client/utils/context-extractor.util.js +52 -0
  176. package/http-client/utils/curl-generator.util.d.ts +21 -0
  177. package/http-client/utils/curl-generator.util.js +44 -3
  178. package/http-client/utils/request-id.util.d.ts +18 -0
  179. package/http-client/utils/request-id.util.js +20 -0
  180. package/http-client/utils/retry-recorder.util.d.ts +42 -0
  181. package/http-client/utils/retry-recorder.util.js +44 -0
  182. package/index.js +8 -0
  183. package/interceptors/translation-interceptor.service.js +5 -0
  184. package/package.json +1 -1
  185. package/providers/context.provider.js +2 -0
  186. package/providers/generator.provider.d.ts +4 -0
  187. package/providers/generator.provider.js +4 -0
  188. package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
  189. package/redis-lock/examples/lock-strategy.examples.js +130 -15
  190. package/redis-lock/index.js +3 -0
  191. package/redis-lock/redis-lock.decorator.d.ts +101 -0
  192. package/redis-lock/redis-lock.decorator.js +120 -0
  193. package/redis-lock/redis-lock.module.d.ts +60 -0
  194. package/redis-lock/redis-lock.module.js +46 -0
  195. package/redis-lock/redis-lock.service.d.ts +251 -0
  196. package/redis-lock/redis-lock.service.js +219 -3
  197. package/setup/bootstrap.setup.js +20 -0
  198. package/setup/mode.setup.d.ts +44 -0
  199. package/setup/mode.setup.js +44 -0
  200. package/setup/schedule.decorator.d.ts +226 -0
  201. package/setup/schedule.decorator.js +214 -1
  202. package/setup/worker.decorator.d.ts +86 -0
  203. package/setup/worker.decorator.js +88 -0
  204. package/shared/serviceRegistryModule.js +5 -1
  205. package/shared/services/api-config.service.d.ts +3 -0
  206. package/shared/services/api-config.service.js +20 -9
  207. package/validator-json/decorators.d.ts +17 -0
  208. package/validator-json/decorators.js +17 -2
  209. package/validator-json/default.d.ts +6 -0
  210. package/validator-json/default.js +30 -2
  211. package/validator-json/defaultConverters.js +1 -0
  212. package/validator-json/options.d.ts +23 -0
  213. package/validators/common-validators.d.ts +143 -0
  214. package/validators/common-validators.js +249 -0
  215. package/validators/custom-validate.examples.d.ts +23 -0
  216. package/validators/custom-validate.examples.js +78 -6
  217. package/validators/custom-validate.validator.d.ts +107 -0
  218. package/validators/custom-validate.validator.js +84 -0
  219. package/validators/index.d.ts +1 -0
  220. package/validators/index.js +1 -0
  221. package/validators/is-exists.validator.d.ts +11 -0
  222. package/validators/is-exists.validator.js +22 -0
  223. package/validators/is-unique.validator.d.ts +11 -0
  224. package/validators/is-unique.validator.js +18 -0
  225. package/validators/skip-empty.validator.d.ts +5 -0
  226. package/validators/skip-empty.validator.js +5 -0
  227. package/vault/interfaces/vault-options.interface.d.ts +9 -0
  228. package/vault/vault-config.loader.d.ts +30 -0
  229. package/vault/vault-config.loader.js +48 -1
  230. package/vault/vault-config.service.d.ts +53 -0
  231. package/vault/vault-config.service.js +57 -0
  232. package/vault/vault.module.d.ts +4 -0
  233. package/vault/vault.module.js +4 -0
  234. package/decorators/examples/validation-decorators.example.d.ts +0 -69
  235. package/decorators/examples/validation-decorators.example.js +0 -331
@@ -1,23 +1,249 @@
1
+ /**
2
+ * Enhanced Schedule Decorators for Worker Mode
3
+ *
4
+ * This module provides decorators for scheduled tasks that:
5
+ * - Only run in Worker or Hybrid mode (not in HTTP-only mode)
6
+ * - Support distributed locking via Redis
7
+ * - Support retry logic for failed tasks
8
+ * - Provide automatic lock key generation
9
+ * - Support task execution logging and error handling
10
+ */
1
11
  import type { CronOptions } from '@nestjs/schedule';
12
+ /**
13
+ * Options for schedule decorators with lock support
14
+ */
2
15
  export interface ScheduleWithLockOptions {
16
+ /**
17
+ * Lock TTL in milliseconds
18
+ * For Cron: defaults to 3600000 (1 hour)
19
+ * For Interval: defaults to 80% of interval duration
20
+ * For Timeout: defaults to 300000 (5 minutes)
21
+ */
3
22
  lockTtl?: number;
23
+ /**
24
+ * Number of retry attempts if task fails
25
+ * @default 0
26
+ */
4
27
  retryCount?: number;
28
+ /**
29
+ * Delay between retry attempts in milliseconds
30
+ * @default 1000
31
+ */
5
32
  retryDelay?: number;
33
+ /**
34
+ * Whether to use exponential backoff for retries
35
+ * @default false
36
+ */
6
37
  useExponentialBackoff?: boolean;
38
+ /**
39
+ * Maximum retry delay in milliseconds (for exponential backoff)
40
+ * @default 60000 (1 minute)
41
+ */
7
42
  maxRetryDelay?: number;
43
+ /**
44
+ * Whether to log task execution
45
+ * @default true
46
+ */
8
47
  logExecution?: boolean;
48
+ /**
49
+ * Custom lock key prefix
50
+ * @default 'schedule'
51
+ */
9
52
  lockKeyPrefix?: string;
53
+ /**
54
+ * Automatic lock extension interval in milliseconds
55
+ * If set, the lock will be automatically extended at this interval
56
+ * @default 0 (no automatic extension)
57
+ */
10
58
  autoExtendLock?: number;
59
+ /**
60
+ * Callback function when task execution succeeds
61
+ */
11
62
  onSuccess?: (duration: number) => void | Promise<void>;
63
+ /**
64
+ * Callback function when task execution fails
65
+ */
12
66
  onError?: (error: Error) => void | Promise<void>;
67
+ /**
68
+ * Whether to skip execution if lock cannot be acquired
69
+ * @default true
70
+ */
13
71
  skipIfLocked?: boolean;
14
72
  }
73
+ /**
74
+ * Cron decorator that only executes in Worker or Hybrid mode
75
+ *
76
+ * @param cronTime - Cron expression
77
+ * @param options - Cron options
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * @WorkerCron('0 0 * * *') // Run daily at midnight
82
+ * async dailyTask() {
83
+ * // Task logic
84
+ * }
85
+ * ```
86
+ */
15
87
  export declare function WorkerCron(cronTime: string | Date, options?: CronOptions): MethodDecorator;
88
+ /**
89
+ * Interval decorator that only executes in Worker or Hybrid mode
90
+ *
91
+ * @param timeout - Interval in milliseconds
92
+ * @param name - Optional name for the interval
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * @WorkerInterval(60000) // Run every minute
97
+ * async minutelyTask() {
98
+ * // Task logic
99
+ * }
100
+ * ```
101
+ */
16
102
  export declare function WorkerInterval(timeout: number, name?: string): MethodDecorator;
103
+ /**
104
+ * Timeout decorator that only executes in Worker or Hybrid mode
105
+ *
106
+ * @param timeout - Timeout in milliseconds
107
+ * @param name - Optional name for the timeout
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * @WorkerTimeout(5000) // Run once after 5 seconds
112
+ * async startupTask() {
113
+ * // Task logic
114
+ * }
115
+ * ```
116
+ */
17
117
  export declare function WorkerTimeout(timeout: number, name?: string): MethodDecorator;
118
+ /**
119
+ * Cron decorator with distributed lock support
120
+ * Automatically generates lock key from class and method name
121
+ *
122
+ * @param cronTime - Cron expression
123
+ * @param lockKeyOrOptions - Lock key (string) or options object
124
+ * @param lockTtl - Lock TTL in milliseconds (only if lockKeyOrOptions is a string)
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Using string lock key
129
+ * @WorkerCronWithLock('0 * * * *', 'hourly-task', 3600000)
130
+ * async hourlyTask() {
131
+ * // Task logic
132
+ * }
133
+ *
134
+ * // Using options object (auto-generates lock key)
135
+ * @WorkerCronWithLock('0 * * * *', { lockTtl: 3600000, retryCount: 3 })
136
+ * async hourlyTask() {
137
+ * // Task logic
138
+ * }
139
+ * ```
140
+ */
18
141
  export declare function WorkerCronWithLock(cronTime: string | Date, lockKeyOrOptions: string | ScheduleWithLockOptions, lockTtl?: number, cronOptions?: CronOptions): MethodDecorator;
142
+ /**
143
+ * Interval decorator with distributed lock support
144
+ *
145
+ * @param timeout - Interval in milliseconds
146
+ * @param lockKeyOrOptions - Lock key (string) or options object
147
+ * @param lockTtl - Lock TTL in milliseconds (only if lockKeyOrOptions is a string)
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * // Using string lock key
152
+ * @WorkerIntervalWithLock(60000, 'status-check', 50000)
153
+ * async checkStatus() {
154
+ * // Task logic
155
+ * }
156
+ *
157
+ * // Using options object (auto-generates lock key)
158
+ * @WorkerIntervalWithLock(60000, { retryCount: 2 })
159
+ * async checkStatus() {
160
+ * // Task logic
161
+ * }
162
+ * ```
163
+ */
19
164
  export declare function WorkerIntervalWithLock(timeout: number, lockKeyOrOptions: string | ScheduleWithLockOptions, lockTtl?: number): MethodDecorator;
165
+ /**
166
+ * Timeout decorator with distributed lock support
167
+ *
168
+ * @param timeout - Timeout in milliseconds
169
+ * @param lockKeyOrOptions - Lock key (string) or options object
170
+ * @param lockTtl - Lock TTL in milliseconds (only if lockKeyOrOptions is a string)
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // Using string lock key
175
+ * @WorkerTimeoutWithLock(5000, 'init-task', 10000)
176
+ * async initializeSystem() {
177
+ * // Task logic
178
+ * }
179
+ *
180
+ * // Using options object (auto-generates lock key)
181
+ * @WorkerTimeoutWithLock(5000, { lockTtl: 10000 })
182
+ * async initializeSystem() {
183
+ * // Task logic
184
+ * }
185
+ * ```
186
+ */
20
187
  export declare function WorkerTimeoutWithLock(timeout: number, lockKeyOrOptions: string | ScheduleWithLockOptions, lockTtl?: number): MethodDecorator;
188
+ /**
189
+ * Smart Cron decorator with auto-generated lock key and intelligent defaults
190
+ * Recommended for most use cases
191
+ *
192
+ * @param cronTime - Cron expression
193
+ * @param options - Schedule options
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * @WorkerCronSmart('0 * * * *') // Run hourly with auto-generated lock key
198
+ * async hourlyTask() {
199
+ * // Task logic
200
+ * }
201
+ *
202
+ * @WorkerCronSmart('0 0 * * *', {
203
+ * lockTtl: 7200000, // 2 hours
204
+ * retryCount: 3,
205
+ * onError: (error) => console.error('Task failed:', error),
206
+ * })
207
+ * async dailyTask() {
208
+ * // Task logic
209
+ * }
210
+ * ```
211
+ */
21
212
  export declare function WorkerCronSmart(cronTime: string | Date, options?: ScheduleWithLockOptions, cronOptions?: CronOptions): MethodDecorator;
213
+ /**
214
+ * Smart Interval decorator with auto-generated lock key and intelligent defaults
215
+ * Lock TTL is automatically set to 80% of interval duration
216
+ *
217
+ * @param timeout - Interval in milliseconds
218
+ * @param options - Schedule options
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * @WorkerIntervalSmart(120000) // Run every 2 minutes, lock for ~1.6 minutes
223
+ * async checkStatus() {
224
+ * // Task logic
225
+ * }
226
+ * ```
227
+ */
22
228
  export declare function WorkerIntervalSmart(timeout: number, options?: ScheduleWithLockOptions): MethodDecorator;
229
+ /**
230
+ * Advanced Cron decorator with full control
231
+ * Alias for WorkerCronSmart with explicit lock key parameter
232
+ *
233
+ * @param cronTime - Cron expression
234
+ * @param lockKeyOrOptions - Lock key (string) or options object
235
+ * @param options - Schedule options (only if lockKeyOrOptions is a string)
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * @WorkerCronAdvanced('0 0 * * *', 'daily-report', {
240
+ * lockTtl: 7200000,
241
+ * retryCount: 5,
242
+ * useExponentialBackoff: true,
243
+ * })
244
+ * async generateDailyReport() {
245
+ * // Task logic
246
+ * }
247
+ * ```
248
+ */
23
249
  export declare function WorkerCronAdvanced(cronTime: string | Date, lockKeyOrOptions: string | ScheduleWithLockOptions, options?: ScheduleWithLockOptions, cronOptions?: CronOptions): MethodDecorator;
@@ -1,4 +1,14 @@
1
1
  "use strict";
2
+ /**
3
+ * Enhanced Schedule Decorators for Worker Mode
4
+ *
5
+ * This module provides decorators for scheduled tasks that:
6
+ * - Only run in Worker or Hybrid mode (not in HTTP-only mode)
7
+ * - Support distributed locking via Redis
8
+ * - Support retry logic for failed tasks
9
+ * - Provide automatic lock key generation
10
+ * - Support task execution logging and error handling
11
+ */
2
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -22,9 +32,15 @@ const common_1 = require("@nestjs/common");
22
32
  const schedule_1 = require("@nestjs/schedule");
23
33
  const mode_setup_1 = require("./mode.setup");
24
34
  const redis_lock_service_1 = require("../redis-lock/redis-lock.service");
35
+ /**
36
+ * Generate a lock key from class name and method name
37
+ */
25
38
  function generateLockKey(className, methodName) {
26
39
  return `${className}.${methodName}`;
27
40
  }
41
+ /**
42
+ * Execute a function with retry logic
43
+ */
28
44
  function executeWithRetry(fn, options) {
29
45
  return __awaiter(this, void 0, void 0, function* () {
30
46
  const { retryCount = 0, retryDelay = 1000, useExponentialBackoff = false, maxRetryDelay = 60000, logger, taskName, } = options;
@@ -51,41 +67,55 @@ function executeWithRetry(fn, options) {
51
67
  throw lastError;
52
68
  });
53
69
  }
70
+ /**
71
+ * Base decorator creator for worker-mode tasks
72
+ */
54
73
  function createWorkerDecorator(baseDecorator, decoratorName) {
55
74
  return function (target, propertyKey, descriptor) {
56
75
  const originalMethod = descriptor.value;
57
76
  descriptor.value = function (...args) {
58
77
  return __awaiter(this, void 0, void 0, function* () {
78
+ // Only execute in worker or hybrid mode
59
79
  if (!(0, mode_setup_1.shouldProcessQueues)()) {
60
80
  return;
61
81
  }
62
82
  return originalMethod.apply(this, args);
63
83
  });
64
84
  };
85
+ // Apply the base decorator
65
86
  baseDecorator(target, propertyKey, descriptor);
66
87
  return descriptor;
67
88
  };
68
89
  }
90
+ /**
91
+ * Create a worker decorator with lock support
92
+ */
69
93
  function createWorkerDecoratorWithLock(baseDecorator, decoratorName, lockKey, options = {}) {
70
94
  return function (target, propertyKey, descriptor) {
71
95
  const originalMethod = descriptor.value;
72
96
  const className = target.constructor.name;
73
97
  const methodName = String(propertyKey);
74
98
  const logger = new common_1.Logger(`${className}.${methodName}`);
99
+ // Resolve lock key
75
100
  const resolvedLockKey = typeof lockKey === 'function' ? lockKey() : lockKey;
76
101
  descriptor.value = function (...args) {
77
102
  return __awaiter(this, void 0, void 0, function* () {
103
+ // Only execute in worker or hybrid mode
78
104
  if (!(0, mode_setup_1.shouldProcessQueues)()) {
79
105
  return;
80
106
  }
107
+ // Get or create global instance - auto-configures from environment variables
81
108
  const lockService = redis_lock_service_1.RedisLockService.getOrCreateGlobalInstance();
82
- const { lockTtl = 3600000, retryCount = 0, retryDelay = 1000, useExponentialBackoff = false, maxRetryDelay = 60000, logExecution = true, lockKeyPrefix = 'schedule', autoExtendLock = 0, onSuccess, onError, skipIfLocked = true, } = options;
109
+ const { lockTtl = 3600000, // 1 hour default
110
+ retryCount = 0, retryDelay = 1000, useExponentialBackoff = false, maxRetryDelay = 60000, logExecution = true, lockKeyPrefix = 'schedule', autoExtendLock = 0, onSuccess, onError, skipIfLocked = true, } = options;
83
111
  const fullLockKey = `${lockKeyPrefix}:${resolvedLockKey}`;
84
112
  const startTime = Date.now();
113
+ // Log task start
85
114
  if (logExecution) {
86
115
  logger.log(`Task starting...`);
87
116
  }
88
117
  try {
118
+ // Acquire lock
89
119
  const lockResult = yield lockService.acquireLock(resolvedLockKey, {
90
120
  ttl: lockTtl,
91
121
  keyPrefix: lockKeyPrefix,
@@ -101,6 +131,7 @@ function createWorkerDecoratorWithLock(baseDecorator, decoratorName, lockKey, op
101
131
  }
102
132
  }
103
133
  try {
134
+ // Execute with retry logic
104
135
  const result = yield executeWithRetry(() => originalMethod.apply(this, args), {
105
136
  retryCount,
106
137
  retryDelay,
@@ -113,15 +144,18 @@ function createWorkerDecoratorWithLock(baseDecorator, decoratorName, lockKey, op
113
144
  if (logExecution) {
114
145
  logger.log(`Task completed successfully in ${duration}ms`);
115
146
  }
147
+ // Call success callback with proper this context
116
148
  if (onSuccess) {
117
149
  yield onSuccess.call(this, duration);
118
150
  }
119
151
  return result;
120
152
  }
121
153
  finally {
154
+ // Clear auto-extension timer if it exists
122
155
  if (lockResult.autoExtendTimer) {
123
156
  clearInterval(lockResult.autoExtendTimer);
124
157
  }
158
+ // Always release the lock
125
159
  yield lockService.releaseLock(resolvedLockKey, lockResult.lockValue, lockKeyPrefix);
126
160
  if (logExecution) {
127
161
  logger.debug(`Lock "${fullLockKey}" released`);
@@ -133,6 +167,7 @@ function createWorkerDecoratorWithLock(baseDecorator, decoratorName, lockKey, op
133
167
  if (logExecution) {
134
168
  logger.error(`Task failed after ${duration}ms: ${error.message}`, error.stack);
135
169
  }
170
+ // Call error callback with proper this context
136
171
  if (onError) {
137
172
  yield onError.call(this, error);
138
173
  }
@@ -140,25 +175,97 @@ function createWorkerDecoratorWithLock(baseDecorator, decoratorName, lockKey, op
140
175
  }
141
176
  });
142
177
  };
178
+ // Apply the base decorator
143
179
  baseDecorator(target, propertyKey, descriptor);
144
180
  return descriptor;
145
181
  };
146
182
  }
183
+ // ============================================================================
184
+ // Basic Worker Decorators (without lock)
185
+ // ============================================================================
186
+ /**
187
+ * Cron decorator that only executes in Worker or Hybrid mode
188
+ *
189
+ * @param cronTime - Cron expression
190
+ * @param options - Cron options
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * @WorkerCron('0 0 * * *') // Run daily at midnight
195
+ * async dailyTask() {
196
+ * // Task logic
197
+ * }
198
+ * ```
199
+ */
147
200
  function WorkerCron(cronTime, options) {
148
201
  return createWorkerDecorator((0, schedule_1.Cron)(cronTime, options), 'WorkerCron');
149
202
  }
203
+ /**
204
+ * Interval decorator that only executes in Worker or Hybrid mode
205
+ *
206
+ * @param timeout - Interval in milliseconds
207
+ * @param name - Optional name for the interval
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * @WorkerInterval(60000) // Run every minute
212
+ * async minutelyTask() {
213
+ * // Task logic
214
+ * }
215
+ * ```
216
+ */
150
217
  function WorkerInterval(timeout, name) {
151
218
  if (name) {
152
219
  return createWorkerDecorator((0, schedule_1.Interval)(name, timeout), 'WorkerInterval');
153
220
  }
154
221
  return createWorkerDecorator((0, schedule_1.Interval)(timeout), 'WorkerInterval');
155
222
  }
223
+ /**
224
+ * Timeout decorator that only executes in Worker or Hybrid mode
225
+ *
226
+ * @param timeout - Timeout in milliseconds
227
+ * @param name - Optional name for the timeout
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * @WorkerTimeout(5000) // Run once after 5 seconds
232
+ * async startupTask() {
233
+ * // Task logic
234
+ * }
235
+ * ```
236
+ */
156
237
  function WorkerTimeout(timeout, name) {
157
238
  if (name) {
158
239
  return createWorkerDecorator((0, schedule_1.Timeout)(name, timeout), 'WorkerTimeout');
159
240
  }
160
241
  return createWorkerDecorator((0, schedule_1.Timeout)(timeout), 'WorkerTimeout');
161
242
  }
243
+ // ============================================================================
244
+ // Worker Decorators with Lock Support
245
+ // ============================================================================
246
+ /**
247
+ * Cron decorator with distributed lock support
248
+ * Automatically generates lock key from class and method name
249
+ *
250
+ * @param cronTime - Cron expression
251
+ * @param lockKeyOrOptions - Lock key (string) or options object
252
+ * @param lockTtl - Lock TTL in milliseconds (only if lockKeyOrOptions is a string)
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * // Using string lock key
257
+ * @WorkerCronWithLock('0 * * * *', 'hourly-task', 3600000)
258
+ * async hourlyTask() {
259
+ * // Task logic
260
+ * }
261
+ *
262
+ * // Using options object (auto-generates lock key)
263
+ * @WorkerCronWithLock('0 * * * *', { lockTtl: 3600000, retryCount: 3 })
264
+ * async hourlyTask() {
265
+ * // Task logic
266
+ * }
267
+ * ```
268
+ */
162
269
  function WorkerCronWithLock(cronTime, lockKeyOrOptions, lockTtl, cronOptions) {
163
270
  return function (target, propertyKey, descriptor) {
164
271
  let lockKey;
@@ -174,6 +281,28 @@ function WorkerCronWithLock(cronTime, lockKeyOrOptions, lockTtl, cronOptions) {
174
281
  return createWorkerDecoratorWithLock((0, schedule_1.Cron)(cronTime, cronOptions), 'WorkerCronWithLock', lockKey, options)(target, propertyKey, descriptor);
175
282
  };
176
283
  }
284
+ /**
285
+ * Interval decorator with distributed lock support
286
+ *
287
+ * @param timeout - Interval in milliseconds
288
+ * @param lockKeyOrOptions - Lock key (string) or options object
289
+ * @param lockTtl - Lock TTL in milliseconds (only if lockKeyOrOptions is a string)
290
+ *
291
+ * @example
292
+ * ```typescript
293
+ * // Using string lock key
294
+ * @WorkerIntervalWithLock(60000, 'status-check', 50000)
295
+ * async checkStatus() {
296
+ * // Task logic
297
+ * }
298
+ *
299
+ * // Using options object (auto-generates lock key)
300
+ * @WorkerIntervalWithLock(60000, { retryCount: 2 })
301
+ * async checkStatus() {
302
+ * // Task logic
303
+ * }
304
+ * ```
305
+ */
177
306
  function WorkerIntervalWithLock(timeout, lockKeyOrOptions, lockTtl) {
178
307
  return function (target, propertyKey, descriptor) {
179
308
  let lockKey;
@@ -189,6 +318,28 @@ function WorkerIntervalWithLock(timeout, lockKeyOrOptions, lockTtl) {
189
318
  return createWorkerDecoratorWithLock((0, schedule_1.Interval)(timeout), 'WorkerIntervalWithLock', lockKey, options)(target, propertyKey, descriptor);
190
319
  };
191
320
  }
321
+ /**
322
+ * Timeout decorator with distributed lock support
323
+ *
324
+ * @param timeout - Timeout in milliseconds
325
+ * @param lockKeyOrOptions - Lock key (string) or options object
326
+ * @param lockTtl - Lock TTL in milliseconds (only if lockKeyOrOptions is a string)
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * // Using string lock key
331
+ * @WorkerTimeoutWithLock(5000, 'init-task', 10000)
332
+ * async initializeSystem() {
333
+ * // Task logic
334
+ * }
335
+ *
336
+ * // Using options object (auto-generates lock key)
337
+ * @WorkerTimeoutWithLock(5000, { lockTtl: 10000 })
338
+ * async initializeSystem() {
339
+ * // Task logic
340
+ * }
341
+ * ```
342
+ */
192
343
  function WorkerTimeoutWithLock(timeout, lockKeyOrOptions, lockTtl) {
193
344
  return function (target, propertyKey, descriptor) {
194
345
  let lockKey;
@@ -204,18 +355,80 @@ function WorkerTimeoutWithLock(timeout, lockKeyOrOptions, lockTtl) {
204
355
  return createWorkerDecoratorWithLock((0, schedule_1.Timeout)(timeout), 'WorkerTimeoutWithLock', lockKey, options)(target, propertyKey, descriptor);
205
356
  };
206
357
  }
358
+ // ============================================================================
359
+ // Smart Decorators (Recommended)
360
+ // ============================================================================
361
+ /**
362
+ * Smart Cron decorator with auto-generated lock key and intelligent defaults
363
+ * Recommended for most use cases
364
+ *
365
+ * @param cronTime - Cron expression
366
+ * @param options - Schedule options
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * @WorkerCronSmart('0 * * * *') // Run hourly with auto-generated lock key
371
+ * async hourlyTask() {
372
+ * // Task logic
373
+ * }
374
+ *
375
+ * @WorkerCronSmart('0 0 * * *', {
376
+ * lockTtl: 7200000, // 2 hours
377
+ * retryCount: 3,
378
+ * onError: (error) => console.error('Task failed:', error),
379
+ * })
380
+ * async dailyTask() {
381
+ * // Task logic
382
+ * }
383
+ * ```
384
+ */
207
385
  function WorkerCronSmart(cronTime, options = {}, cronOptions) {
208
386
  return function (target, propertyKey, descriptor) {
209
387
  const lockKey = generateLockKey(target.constructor.name, String(propertyKey));
210
388
  return createWorkerDecoratorWithLock((0, schedule_1.Cron)(cronTime, cronOptions), 'WorkerCronSmart', lockKey, Object.assign({ lockTtl: 3600000, logExecution: true }, options))(target, propertyKey, descriptor);
211
389
  };
212
390
  }
391
+ /**
392
+ * Smart Interval decorator with auto-generated lock key and intelligent defaults
393
+ * Lock TTL is automatically set to 80% of interval duration
394
+ *
395
+ * @param timeout - Interval in milliseconds
396
+ * @param options - Schedule options
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * @WorkerIntervalSmart(120000) // Run every 2 minutes, lock for ~1.6 minutes
401
+ * async checkStatus() {
402
+ * // Task logic
403
+ * }
404
+ * ```
405
+ */
213
406
  function WorkerIntervalSmart(timeout, options = {}) {
214
407
  return function (target, propertyKey, descriptor) {
215
408
  const lockKey = generateLockKey(target.constructor.name, String(propertyKey));
216
409
  return createWorkerDecoratorWithLock((0, schedule_1.Interval)(timeout), 'WorkerIntervalSmart', lockKey, Object.assign({ lockTtl: Math.floor(timeout * 0.8), logExecution: true }, options))(target, propertyKey, descriptor);
217
410
  };
218
411
  }
412
+ /**
413
+ * Advanced Cron decorator with full control
414
+ * Alias for WorkerCronSmart with explicit lock key parameter
415
+ *
416
+ * @param cronTime - Cron expression
417
+ * @param lockKeyOrOptions - Lock key (string) or options object
418
+ * @param options - Schedule options (only if lockKeyOrOptions is a string)
419
+ *
420
+ * @example
421
+ * ```typescript
422
+ * @WorkerCronAdvanced('0 0 * * *', 'daily-report', {
423
+ * lockTtl: 7200000,
424
+ * retryCount: 5,
425
+ * useExponentialBackoff: true,
426
+ * })
427
+ * async generateDailyReport() {
428
+ * // Task logic
429
+ * }
430
+ * ```
431
+ */
219
432
  function WorkerCronAdvanced(cronTime, lockKeyOrOptions, options, cronOptions) {
220
433
  return function (target, propertyKey, descriptor) {
221
434
  let lockKey;
@@ -1,14 +1,100 @@
1
+ /**
2
+ * Worker Decorators for Bull Queue Processors
3
+ *
4
+ * These decorators conditionally apply Bull decorators based on the application mode.
5
+ * They only register processors when running in Worker or Hybrid mode.
6
+ */
7
+ /**
8
+ * Conditionally applies Bull's @Processor decorator
9
+ * Only registers the processor class when running in Worker or Hybrid mode
10
+ *
11
+ * @param queueName - Name of the queue to process
12
+ * @param options - Processor options (optional)
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * @WorkerProcessor('email')
17
+ * export class EmailProcessor {
18
+ * @WorkerProcess('send')
19
+ * async sendEmail(job: Job) {
20
+ * // Process email sending
21
+ * }
22
+ * }
23
+ * ```
24
+ */
1
25
  export declare function WorkerProcessor(queueName?: string): ClassDecorator;
26
+ /**
27
+ * Conditionally applies Bull's @Process decorator
28
+ * Only registers the processor method when running in Worker or Hybrid mode
29
+ *
30
+ * @param name - Job name to process (optional)
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * @WorkerProcess('send-email')
35
+ * async sendEmail(job: Job<EmailData>) {
36
+ * // Process job
37
+ * }
38
+ * ```
39
+ */
2
40
  export declare function WorkerProcess(name?: string): MethodDecorator;
41
+ /**
42
+ * Conditionally applies Bull's @OnQueueActive decorator
43
+ * Only registers when running in Worker or Hybrid mode
44
+ */
3
45
  export declare function WorkerOnQueueActive(): MethodDecorator;
46
+ /**
47
+ * Conditionally applies Bull's @OnQueueCompleted decorator
48
+ * Only registers when running in Worker or Hybrid mode
49
+ */
4
50
  export declare function WorkerOnQueueCompleted(): MethodDecorator;
51
+ /**
52
+ * Conditionally applies Bull's @OnQueueProgress decorator
53
+ * Only registers when running in Worker or Hybrid mode
54
+ */
5
55
  export declare function WorkerOnQueueProgress(): MethodDecorator;
56
+ /**
57
+ * Conditionally applies Bull's @OnQueueFailed decorator
58
+ * Only registers when running in Worker or Hybrid mode
59
+ */
6
60
  export declare function WorkerOnQueueFailed(): MethodDecorator;
61
+ /**
62
+ * Conditionally applies Bull's @OnQueueError decorator
63
+ * Only registers when running in Worker or Hybrid mode
64
+ */
7
65
  export declare function WorkerOnQueueError(): MethodDecorator;
66
+ /**
67
+ * Conditionally applies Bull's @OnQueueWaiting decorator
68
+ * Only registers when running in Worker or Hybrid mode
69
+ */
8
70
  export declare function WorkerOnQueueWaiting(): MethodDecorator;
71
+ /**
72
+ * Conditionally applies Bull's @OnQueueStalled decorator
73
+ * Only registers when running in Worker or Hybrid mode
74
+ */
9
75
  export declare function WorkerOnQueueStalled(): MethodDecorator;
76
+ /**
77
+ * Conditionally applies Bull's @OnQueueRemoved decorator
78
+ * Only registers when running in Worker or Hybrid mode
79
+ */
10
80
  export declare function WorkerOnQueueRemoved(): MethodDecorator;
81
+ /**
82
+ * Conditionally applies Bull's @OnQueueCleaned decorator
83
+ * Only registers when running in Worker or Hybrid mode
84
+ */
11
85
  export declare function WorkerOnQueueCleaned(): MethodDecorator;
86
+ /**
87
+ * Conditionally applies Bull's @OnQueueDrained decorator
88
+ * Only registers when running in Worker or Hybrid mode
89
+ */
12
90
  export declare function WorkerOnQueueDrained(): MethodDecorator;
91
+ /**
92
+ * Conditionally applies Bull's @OnQueuePaused decorator
93
+ * Only registers when running in Worker or Hybrid mode
94
+ */
13
95
  export declare function WorkerOnQueuePaused(): MethodDecorator;
96
+ /**
97
+ * Conditionally applies Bull's @OnQueueResumed decorator
98
+ * Only registers when running in Worker or Hybrid mode
99
+ */
14
100
  export declare function WorkerOnQueueResumed(): MethodDecorator;