nestjs-temporal-core 3.0.9 → 3.0.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 (122) hide show
  1. package/README.md +1451 -721
  2. package/dist/constants.d.ts +49 -151
  3. package/dist/constants.js +38 -141
  4. package/dist/constants.js.map +1 -1
  5. package/dist/decorators/activity.decorator.js +75 -15
  6. package/dist/decorators/activity.decorator.js.map +1 -1
  7. package/dist/decorators/index.d.ts +1 -3
  8. package/dist/decorators/index.js +4 -13
  9. package/dist/decorators/index.js.map +1 -1
  10. package/dist/decorators/workflow.decorator.d.ts +7 -3
  11. package/dist/decorators/workflow.decorator.js +161 -48
  12. package/dist/decorators/workflow.decorator.js.map +1 -1
  13. package/dist/health/temporal-health.controller.d.ts +7 -0
  14. package/dist/health/temporal-health.controller.js +77 -0
  15. package/dist/health/temporal-health.controller.js.map +1 -0
  16. package/dist/health/temporal-health.module.d.ts +2 -0
  17. package/dist/health/temporal-health.module.js +20 -0
  18. package/dist/health/temporal-health.module.js.map +1 -0
  19. package/dist/index.d.ts +10 -20
  20. package/dist/index.js +15 -30
  21. package/dist/index.js.map +1 -1
  22. package/dist/interfaces.d.ts +740 -160
  23. package/dist/interfaces.js +1 -2
  24. package/dist/interfaces.js.map +1 -1
  25. package/dist/providers/temporal-connection.factory.d.ts +28 -0
  26. package/dist/providers/temporal-connection.factory.js +194 -0
  27. package/dist/providers/temporal-connection.factory.js.map +1 -0
  28. package/dist/services/temporal-client.service.d.ts +33 -0
  29. package/dist/services/temporal-client.service.js +285 -0
  30. package/dist/services/temporal-client.service.js.map +1 -0
  31. package/dist/services/temporal-discovery.service.d.ts +34 -0
  32. package/dist/services/temporal-discovery.service.js +348 -0
  33. package/dist/services/temporal-discovery.service.js.map +1 -0
  34. package/dist/services/temporal-metadata.service.d.ts +37 -0
  35. package/dist/services/temporal-metadata.service.js +512 -0
  36. package/dist/services/temporal-metadata.service.js.map +1 -0
  37. package/dist/services/temporal-schedule.service.d.ts +35 -0
  38. package/dist/services/temporal-schedule.service.js +380 -0
  39. package/dist/services/temporal-schedule.service.js.map +1 -0
  40. package/dist/services/temporal-worker.service.d.ts +54 -0
  41. package/dist/services/temporal-worker.service.js +605 -0
  42. package/dist/services/temporal-worker.service.js.map +1 -0
  43. package/dist/services/temporal.service.d.ts +85 -0
  44. package/dist/services/temporal.service.js +572 -0
  45. package/dist/services/temporal.service.js.map +1 -0
  46. package/dist/temporal.module.d.ts +6 -9
  47. package/dist/temporal.module.js +160 -109
  48. package/dist/temporal.module.js.map +1 -1
  49. package/dist/tsconfig.tsbuildinfo +1 -1
  50. package/dist/utils/index.d.ts +2 -2
  51. package/dist/utils/index.js +5 -8
  52. package/dist/utils/index.js.map +1 -1
  53. package/dist/utils/logger.d.ts +10 -4
  54. package/dist/utils/logger.js +77 -106
  55. package/dist/utils/logger.js.map +1 -1
  56. package/dist/utils/metadata.d.ts +1 -3
  57. package/dist/utils/metadata.js +8 -18
  58. package/dist/utils/metadata.js.map +1 -1
  59. package/dist/utils/validation.d.ts +16 -2
  60. package/dist/utils/validation.js +103 -9
  61. package/dist/utils/validation.js.map +1 -1
  62. package/package.json +37 -26
  63. package/dist/activity/index.d.ts +0 -2
  64. package/dist/activity/index.js +0 -19
  65. package/dist/activity/index.js.map +0 -1
  66. package/dist/activity/temporal-activity.module.d.ts +0 -11
  67. package/dist/activity/temporal-activity.module.js +0 -52
  68. package/dist/activity/temporal-activity.module.js.map +0 -1
  69. package/dist/activity/temporal-activity.service.d.ts +0 -46
  70. package/dist/activity/temporal-activity.service.js +0 -192
  71. package/dist/activity/temporal-activity.service.js.map +0 -1
  72. package/dist/client/index.d.ts +0 -3
  73. package/dist/client/index.js +0 -20
  74. package/dist/client/index.js.map +0 -1
  75. package/dist/client/temporal-client.module.d.ts +0 -18
  76. package/dist/client/temporal-client.module.js +0 -198
  77. package/dist/client/temporal-client.module.js.map +0 -1
  78. package/dist/client/temporal-client.service.d.ts +0 -35
  79. package/dist/client/temporal-client.service.js +0 -187
  80. package/dist/client/temporal-client.service.js.map +0 -1
  81. package/dist/client/temporal-schedule.service.d.ts +0 -41
  82. package/dist/client/temporal-schedule.service.js +0 -204
  83. package/dist/client/temporal-schedule.service.js.map +0 -1
  84. package/dist/decorators/parameter.decorator.d.ts +0 -5
  85. package/dist/decorators/parameter.decorator.js +0 -57
  86. package/dist/decorators/parameter.decorator.js.map +0 -1
  87. package/dist/decorators/scheduling.decorator.d.ts +0 -4
  88. package/dist/decorators/scheduling.decorator.js +0 -44
  89. package/dist/decorators/scheduling.decorator.js.map +0 -1
  90. package/dist/discovery/index.d.ts +0 -2
  91. package/dist/discovery/index.js +0 -19
  92. package/dist/discovery/index.js.map +0 -1
  93. package/dist/discovery/temporal-discovery.service.d.ts +0 -39
  94. package/dist/discovery/temporal-discovery.service.js +0 -191
  95. package/dist/discovery/temporal-discovery.service.js.map +0 -1
  96. package/dist/discovery/temporal-schedule-manager.service.d.ts +0 -41
  97. package/dist/discovery/temporal-schedule-manager.service.js +0 -238
  98. package/dist/discovery/temporal-schedule-manager.service.js.map +0 -1
  99. package/dist/schedules/index.d.ts +0 -2
  100. package/dist/schedules/index.js +0 -19
  101. package/dist/schedules/index.js.map +0 -1
  102. package/dist/schedules/temporal-schedules.module.d.ts +0 -11
  103. package/dist/schedules/temporal-schedules.module.js +0 -55
  104. package/dist/schedules/temporal-schedules.module.js.map +0 -1
  105. package/dist/schedules/temporal-schedules.service.d.ts +0 -52
  106. package/dist/schedules/temporal-schedules.service.js +0 -221
  107. package/dist/schedules/temporal-schedules.service.js.map +0 -1
  108. package/dist/temporal.service.d.ts +0 -77
  109. package/dist/temporal.service.js +0 -243
  110. package/dist/temporal.service.js.map +0 -1
  111. package/dist/worker/index.d.ts +0 -3
  112. package/dist/worker/index.js +0 -20
  113. package/dist/worker/index.js.map +0 -1
  114. package/dist/worker/temporal-metadata.accessor.d.ts +0 -32
  115. package/dist/worker/temporal-metadata.accessor.js +0 -208
  116. package/dist/worker/temporal-metadata.accessor.js.map +0 -1
  117. package/dist/worker/temporal-worker-manager.service.d.ts +0 -49
  118. package/dist/worker/temporal-worker-manager.service.js +0 -389
  119. package/dist/worker/temporal-worker-manager.service.js.map +0 -1
  120. package/dist/worker/temporal-worker.module.d.ts +0 -18
  121. package/dist/worker/temporal-worker.module.js +0 -156
  122. package/dist/worker/temporal-worker.module.js.map +0 -1
@@ -0,0 +1,85 @@
1
+ import { OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2
+ import { TemporalOptions, WorkflowStartOptions, ServiceHealth, WorkerStatus, ActivityMethodInfo, MetadataInfo, TemporalServiceInitResult, WorkflowExecutionResult, WorkflowSignalResult, WorkflowQueryResult, WorkflowTerminationResult, WorkflowCancellationResult, ActivityExecutionResult, OverallHealthStatus, ServiceStatistics } from '../interfaces';
3
+ import { TemporalClientService } from './temporal-client.service';
4
+ import { TemporalWorkerManagerService } from './temporal-worker.service';
5
+ import { TemporalScheduleService } from './temporal-schedule.service';
6
+ import { TemporalDiscoveryService } from './temporal-discovery.service';
7
+ import { TemporalMetadataAccessor } from './temporal-metadata.service';
8
+ export declare class TemporalService implements OnModuleInit, OnModuleDestroy {
9
+ private readonly options;
10
+ private readonly clientService;
11
+ private readonly workerService;
12
+ private readonly scheduleService;
13
+ private readonly discoveryService;
14
+ private readonly metadataAccessor;
15
+ private readonly logger;
16
+ private readonly temporalLogger;
17
+ private isInitialized;
18
+ private shutdownPromise;
19
+ constructor(options: TemporalOptions, clientService: TemporalClientService, workerService: TemporalWorkerManagerService, scheduleService: TemporalScheduleService, discoveryService: TemporalDiscoveryService, metadataAccessor: TemporalMetadataAccessor);
20
+ onModuleInit(): Promise<TemporalServiceInitResult>;
21
+ onModuleDestroy(): Promise<void>;
22
+ private waitForServicesInitialization;
23
+ private performShutdown;
24
+ startWorkflow<T = unknown>(workflowType: string, args?: unknown[], options?: WorkflowStartOptions): Promise<WorkflowExecutionResult<T>>;
25
+ signalWorkflow(workflowId: string, signalName: string, args?: unknown[]): Promise<WorkflowSignalResult>;
26
+ queryWorkflow<T = unknown>(workflowId: string, queryName: string, args?: unknown[]): Promise<WorkflowQueryResult<T>>;
27
+ getWorkflowHandle<T = unknown>(workflowId: string, runId?: string): Promise<T>;
28
+ terminateWorkflow(workflowId: string, reason?: string): Promise<WorkflowTerminationResult>;
29
+ cancelWorkflow(workflowId: string): Promise<WorkflowCancellationResult>;
30
+ startWorker(): Promise<void>;
31
+ stopWorker(): Promise<void>;
32
+ isWorkerRunning(): boolean;
33
+ hasWorker(): boolean;
34
+ getWorkerStatus(): WorkerStatus | null;
35
+ executeActivity<T = unknown>(name: string, ...args: unknown[]): Promise<ActivityExecutionResult<T>>;
36
+ getActivity(name: string): Function | undefined;
37
+ getAllActivities(): Record<string, Function>;
38
+ hasActivity(name: string): boolean;
39
+ getActivityNames(): string[];
40
+ isActivity(target: Function): boolean;
41
+ isActivityMethod(target: object, methodName: string): boolean;
42
+ getActivityMetadata(target: Function): MetadataInfo | null;
43
+ extractActivityMethods(target: Function): ActivityMethodInfo[];
44
+ getOverallHealth(): Promise<OverallHealthStatus>;
45
+ getWorkerHealth(): Promise<{
46
+ status: 'healthy' | 'unhealthy' | 'degraded' | 'not_available';
47
+ details?: WorkerStatus;
48
+ }>;
49
+ getHealth(): {
50
+ status: 'healthy' | 'unhealthy' | 'degraded';
51
+ services: {
52
+ client: ServiceHealth;
53
+ worker: ServiceHealth;
54
+ schedule: ServiceHealth;
55
+ activity: ServiceHealth;
56
+ discovery: ServiceHealth;
57
+ };
58
+ isInitialized: boolean;
59
+ namespace: string;
60
+ summary: {
61
+ totalActivities: number;
62
+ totalSchedules: number;
63
+ workerRunning: boolean;
64
+ clientConnected: boolean;
65
+ };
66
+ };
67
+ getStats(): ServiceStatistics;
68
+ private logServiceStatus;
69
+ private ensureInitialized;
70
+ private enhanceWorkflowOptions;
71
+ private getClientHealth;
72
+ private getWorkerHealthStatus;
73
+ private getScheduleHealth;
74
+ private getActivityHealth;
75
+ private getDiscoveryHealth;
76
+ private getActivityCount;
77
+ private getScheduleCount;
78
+ get client(): TemporalClientService;
79
+ get worker(): TemporalWorkerManagerService;
80
+ get schedule(): TemporalScheduleService;
81
+ get activity(): TemporalDiscoveryService;
82
+ get discovery(): TemporalDiscoveryService;
83
+ get metadata(): TemporalMetadataAccessor;
84
+ private extractErrorMessage;
85
+ }
@@ -0,0 +1,572 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var TemporalService_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.TemporalService = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const constants_1 = require("../constants");
19
+ const temporal_client_service_1 = require("./temporal-client.service");
20
+ const temporal_worker_service_1 = require("./temporal-worker.service");
21
+ const temporal_schedule_service_1 = require("./temporal-schedule.service");
22
+ const temporal_discovery_service_1 = require("./temporal-discovery.service");
23
+ const temporal_metadata_service_1 = require("./temporal-metadata.service");
24
+ const logger_1 = require("../utils/logger");
25
+ const constants_2 = require("../constants");
26
+ let TemporalService = TemporalService_1 = class TemporalService {
27
+ constructor(options, clientService, workerService, scheduleService, discoveryService, metadataAccessor) {
28
+ this.options = options;
29
+ this.clientService = clientService;
30
+ this.workerService = workerService;
31
+ this.scheduleService = scheduleService;
32
+ this.discoveryService = discoveryService;
33
+ this.metadataAccessor = metadataAccessor;
34
+ this.logger = new common_1.Logger(TemporalService_1.name);
35
+ this.temporalLogger = new logger_1.TemporalLogger(TemporalService_1.name);
36
+ this.isInitialized = false;
37
+ this.shutdownPromise = null;
38
+ }
39
+ async onModuleInit() {
40
+ const startTime = Date.now();
41
+ try {
42
+ this.logger.log('Initializing Temporal Service...');
43
+ const initResult = await this.waitForServicesInitialization();
44
+ this.isInitialized = true;
45
+ this.logger.log('Temporal Service initialized successfully');
46
+ return {
47
+ success: true,
48
+ servicesInitialized: initResult,
49
+ initializationTime: Date.now() - startTime,
50
+ };
51
+ }
52
+ catch (error) {
53
+ const errorMessage = this.extractErrorMessage(error);
54
+ this.logger.error(`Failed to initialize Temporal Service: ${errorMessage}`);
55
+ return {
56
+ success: false,
57
+ error: error instanceof Error ? error : new Error(errorMessage),
58
+ servicesInitialized: {
59
+ client: false,
60
+ worker: false,
61
+ schedule: false,
62
+ discovery: false,
63
+ metadata: false,
64
+ },
65
+ initializationTime: Date.now() - startTime,
66
+ };
67
+ }
68
+ }
69
+ async onModuleDestroy() {
70
+ if (this.shutdownPromise) {
71
+ return this.shutdownPromise;
72
+ }
73
+ this.shutdownPromise = this.performShutdown();
74
+ return this.shutdownPromise;
75
+ }
76
+ async waitForServicesInitialization() {
77
+ const maxWaitTime = 30000;
78
+ const startTime = Date.now();
79
+ const servicesStatus = {
80
+ client: false,
81
+ worker: false,
82
+ schedule: false,
83
+ discovery: false,
84
+ metadata: false,
85
+ };
86
+ while (Date.now() - startTime < maxWaitTime) {
87
+ try {
88
+ servicesStatus.client = this.clientService.isHealthy();
89
+ servicesStatus.discovery = this.discoveryService.getHealthStatus().isComplete;
90
+ servicesStatus.worker = this.workerService?.isWorkerAvailable() || false;
91
+ servicesStatus.schedule = this.scheduleService.isHealthy();
92
+ servicesStatus.metadata = true;
93
+ if (servicesStatus.client && servicesStatus.discovery) {
94
+ this.logger.debug('All critical services are ready');
95
+ return servicesStatus;
96
+ }
97
+ await new Promise((resolve) => setTimeout(resolve, 100));
98
+ }
99
+ catch (error) {
100
+ this.logger.warn('Service readiness check failed', error);
101
+ }
102
+ }
103
+ this.logger.warn('Service initialization timeout - continuing anyway');
104
+ return servicesStatus;
105
+ }
106
+ async performShutdown() {
107
+ try {
108
+ this.logger.log('Shutting down Temporal Service...');
109
+ if (this.workerService && this.workerService.isWorkerRunning()) {
110
+ await this.workerService.stopWorker();
111
+ }
112
+ this.isInitialized = false;
113
+ this.logger.log('Temporal Service shut down successfully');
114
+ }
115
+ catch (error) {
116
+ this.logger.error(`Error during service shutdown: ${this.extractErrorMessage(error)}`);
117
+ }
118
+ finally {
119
+ this.shutdownPromise = null;
120
+ }
121
+ }
122
+ async startWorkflow(workflowType, args, options) {
123
+ const startTime = Date.now();
124
+ try {
125
+ this.ensureInitialized();
126
+ const enhancedOptions = this.enhanceWorkflowOptions(options || {});
127
+ const result = await this.clientService.startWorkflow(workflowType, args || [], enhancedOptions);
128
+ return {
129
+ success: true,
130
+ result: result,
131
+ executionTime: Date.now() - startTime,
132
+ };
133
+ }
134
+ catch (error) {
135
+ this.logger.error(`Failed to start workflow '${workflowType}': ${this.extractErrorMessage(error)}`);
136
+ throw error instanceof Error ? error : new Error(this.extractErrorMessage(error));
137
+ }
138
+ }
139
+ async signalWorkflow(workflowId, signalName, args) {
140
+ if (!workflowId || workflowId.trim() === '') {
141
+ throw new Error('Workflow ID is required');
142
+ }
143
+ try {
144
+ this.ensureInitialized();
145
+ await this.clientService.signalWorkflow(workflowId, signalName, args || []);
146
+ return {
147
+ success: true,
148
+ workflowId,
149
+ signalName,
150
+ };
151
+ }
152
+ catch (error) {
153
+ this.logger.error(`Failed to signal workflow '${workflowId}' with signal '${signalName}': ${this.extractErrorMessage(error)}`);
154
+ throw error instanceof Error ? error : new Error(this.extractErrorMessage(error));
155
+ }
156
+ }
157
+ async queryWorkflow(workflowId, queryName, args) {
158
+ if (!workflowId || workflowId.trim() === '') {
159
+ throw new Error('Workflow ID is required');
160
+ }
161
+ try {
162
+ this.ensureInitialized();
163
+ const result = await this.clientService.queryWorkflow(workflowId, queryName, args || []);
164
+ return {
165
+ success: true,
166
+ result: result,
167
+ workflowId,
168
+ queryName,
169
+ };
170
+ }
171
+ catch (error) {
172
+ this.logger.error(`Failed to query workflow '${workflowId}' with query '${queryName}': ${this.extractErrorMessage(error)}`);
173
+ throw error instanceof Error ? error : new Error(this.extractErrorMessage(error));
174
+ }
175
+ }
176
+ async getWorkflowHandle(workflowId, runId) {
177
+ this.ensureInitialized();
178
+ const handle = this.clientService.getWorkflowHandle(workflowId, runId);
179
+ return handle;
180
+ }
181
+ async terminateWorkflow(workflowId, reason) {
182
+ try {
183
+ this.ensureInitialized();
184
+ await this.clientService.terminateWorkflow(workflowId, reason);
185
+ return {
186
+ success: true,
187
+ workflowId,
188
+ reason,
189
+ };
190
+ }
191
+ catch (error) {
192
+ return {
193
+ success: false,
194
+ error: error instanceof Error ? error : new Error(this.extractErrorMessage(error)),
195
+ workflowId,
196
+ reason,
197
+ };
198
+ }
199
+ }
200
+ async cancelWorkflow(workflowId) {
201
+ try {
202
+ this.ensureInitialized();
203
+ await this.clientService.cancelWorkflow(workflowId);
204
+ return {
205
+ success: true,
206
+ workflowId,
207
+ };
208
+ }
209
+ catch (error) {
210
+ return {
211
+ success: false,
212
+ error: error instanceof Error ? error : new Error(this.extractErrorMessage(error)),
213
+ workflowId,
214
+ };
215
+ }
216
+ }
217
+ async startWorker() {
218
+ this.ensureInitialized();
219
+ return this.workerService.startWorker();
220
+ }
221
+ async stopWorker() {
222
+ this.ensureInitialized();
223
+ return this.workerService.stopWorker();
224
+ }
225
+ isWorkerRunning() {
226
+ this.ensureInitialized();
227
+ if (!this.workerService) {
228
+ return false;
229
+ }
230
+ return this.workerService.isWorkerRunning();
231
+ }
232
+ hasWorker() {
233
+ return this.workerService?.isWorkerAvailable() || false;
234
+ }
235
+ getWorkerStatus() {
236
+ this.ensureInitialized();
237
+ if (!this.workerService) {
238
+ return null;
239
+ }
240
+ return this.workerService.getStatus();
241
+ }
242
+ async executeActivity(name, ...args) {
243
+ const startTime = Date.now();
244
+ try {
245
+ this.ensureInitialized();
246
+ const result = await this.discoveryService.executeActivity(name, ...args);
247
+ return {
248
+ success: true,
249
+ result: result,
250
+ activityName: name,
251
+ executionTime: Date.now() - startTime,
252
+ args,
253
+ };
254
+ }
255
+ catch (error) {
256
+ return {
257
+ success: false,
258
+ error: error instanceof Error ? error : new Error(this.extractErrorMessage(error)),
259
+ activityName: name,
260
+ executionTime: Date.now() - startTime,
261
+ args,
262
+ };
263
+ }
264
+ }
265
+ getActivity(name) {
266
+ this.ensureInitialized();
267
+ return this.discoveryService.getActivity(name);
268
+ }
269
+ getAllActivities() {
270
+ this.ensureInitialized();
271
+ return this.discoveryService.getAllActivities();
272
+ }
273
+ hasActivity(name) {
274
+ this.ensureInitialized();
275
+ return this.discoveryService.hasActivity(name);
276
+ }
277
+ getActivityNames() {
278
+ this.ensureInitialized();
279
+ return this.discoveryService.getActivityNames();
280
+ }
281
+ isActivity(target) {
282
+ return this.metadataAccessor.isActivity(target);
283
+ }
284
+ isActivityMethod(target, methodName) {
285
+ try {
286
+ const targetObj = target;
287
+ return (Reflect.hasMetadata('TEMPORAL_ACTIVITY_METHOD', target, methodName) ||
288
+ (targetObj.constructor?.prototype !== undefined &&
289
+ Reflect.hasMetadata('TEMPORAL_ACTIVITY_METHOD', targetObj.constructor.prototype, methodName)));
290
+ }
291
+ catch {
292
+ return false;
293
+ }
294
+ }
295
+ getActivityMetadata(target) {
296
+ const metadata = this.metadataAccessor.getActivityMetadata(target);
297
+ return metadata;
298
+ }
299
+ extractActivityMethods(target) {
300
+ return this.metadataAccessor.extractActivityMethodsFromClass(target);
301
+ }
302
+ async getOverallHealth() {
303
+ const health = this.getHealth();
304
+ return {
305
+ status: health.status,
306
+ components: {
307
+ client: {
308
+ status: health.services.client.status,
309
+ isInitialized: this.isInitialized,
310
+ lastError: undefined,
311
+ uptime: undefined,
312
+ details: health.services.client.details || {},
313
+ },
314
+ worker: {
315
+ status: health.services.worker.status,
316
+ isInitialized: this.isInitialized,
317
+ lastError: undefined,
318
+ uptime: undefined,
319
+ details: health.services.worker.details || {},
320
+ },
321
+ schedule: {
322
+ status: health.services.schedule.status,
323
+ isInitialized: this.isInitialized,
324
+ lastError: undefined,
325
+ uptime: undefined,
326
+ details: health.services.schedule.details || {},
327
+ },
328
+ activity: {
329
+ status: health.services.activity.status,
330
+ isInitialized: this.isInitialized,
331
+ lastError: undefined,
332
+ uptime: undefined,
333
+ details: health.services.activity.details || {},
334
+ },
335
+ discovery: {
336
+ status: health.services.discovery.status,
337
+ isInitialized: this.isInitialized,
338
+ lastError: undefined,
339
+ uptime: undefined,
340
+ details: health.services.discovery.details || {},
341
+ },
342
+ },
343
+ isInitialized: health.isInitialized,
344
+ namespace: health.namespace,
345
+ summary: health.summary,
346
+ timestamp: new Date(),
347
+ };
348
+ }
349
+ async getWorkerHealth() {
350
+ try {
351
+ if (!this.hasWorker()) {
352
+ return { status: 'not_available' };
353
+ }
354
+ if (!this.workerService) {
355
+ return { status: 'not_available' };
356
+ }
357
+ const workerStatus = this.workerService.getWorkerStatus();
358
+ let status;
359
+ if (workerStatus.isHealthy) {
360
+ status = 'healthy';
361
+ }
362
+ else if (workerStatus.isRunning) {
363
+ status = 'degraded';
364
+ }
365
+ else {
366
+ status = 'unhealthy';
367
+ }
368
+ return {
369
+ status,
370
+ details: workerStatus,
371
+ };
372
+ }
373
+ catch {
374
+ return {
375
+ status: 'unhealthy',
376
+ details: undefined,
377
+ };
378
+ }
379
+ }
380
+ getHealth() {
381
+ const clientHealth = this.getClientHealth();
382
+ const workerHealth = this.getWorkerHealthStatus();
383
+ const scheduleHealth = this.getScheduleHealth();
384
+ const activityHealth = this.getActivityHealth();
385
+ const discoveryHealth = this.getDiscoveryHealth();
386
+ const services = {
387
+ client: clientHealth,
388
+ worker: workerHealth,
389
+ schedule: scheduleHealth,
390
+ activity: activityHealth,
391
+ discovery: discoveryHealth,
392
+ };
393
+ const allHealthy = Object.values(services).every((service) => service.status === 'healthy');
394
+ const anyUnhealthy = Object.values(services).some((service) => service.status === 'unhealthy');
395
+ let overallStatus;
396
+ if (allHealthy) {
397
+ overallStatus = 'healthy';
398
+ }
399
+ else if (anyUnhealthy) {
400
+ overallStatus = 'unhealthy';
401
+ }
402
+ else {
403
+ overallStatus = 'degraded';
404
+ }
405
+ return {
406
+ status: overallStatus,
407
+ services,
408
+ isInitialized: this.isInitialized,
409
+ namespace: this.options.connection?.namespace || 'default',
410
+ summary: {
411
+ totalActivities: activityHealth.activitiesCount?.total || 0,
412
+ totalSchedules: scheduleHealth.schedulesCount || 0,
413
+ workerRunning: workerHealth.status === 'healthy',
414
+ clientConnected: clientHealth.status === 'healthy',
415
+ },
416
+ };
417
+ }
418
+ getStats() {
419
+ this.ensureInitialized();
420
+ const activityCount = this.getActivityCount();
421
+ const scheduleCount = this.getScheduleCount();
422
+ const workerStatus = this.workerService.getWorkerStatus();
423
+ const clientHealth = this.getClientHealth();
424
+ const discoveryStats = this.discoveryService.getStats();
425
+ return {
426
+ activities: {
427
+ classes: activityCount.classes,
428
+ methods: activityCount.methods,
429
+ total: activityCount.total,
430
+ registered: activityCount.total,
431
+ available: activityCount.total,
432
+ },
433
+ schedules: {
434
+ total: scheduleCount,
435
+ active: scheduleCount,
436
+ paused: 0,
437
+ },
438
+ worker: {
439
+ isRunning: workerStatus.isRunning,
440
+ isHealthy: workerStatus.isHealthy,
441
+ activitiesCount: workerStatus.activitiesCount,
442
+ uptime: workerStatus.uptime,
443
+ },
444
+ client: {
445
+ isConnected: clientHealth.status === 'healthy',
446
+ isHealthy: clientHealth.status === 'healthy',
447
+ namespace: this.options.connection?.namespace || 'default',
448
+ },
449
+ discovery: {
450
+ isComplete: this.discoveryService.getHealthStatus().isComplete,
451
+ discoveredCount: discoveryStats.methods,
452
+ errors: 0,
453
+ },
454
+ };
455
+ }
456
+ logServiceStatus() {
457
+ const health = this.getHealth();
458
+ const stats = this.getStats();
459
+ this.temporalLogger.debug(`Service Status - Overall: ${health.status}`);
460
+ this.temporalLogger.debug(`Client: ${health.services.client.status}, Worker: ${health.services.worker.status}`);
461
+ this.temporalLogger.debug(`Activities: ${stats.activities.total}, Schedules: ${stats.schedules}`);
462
+ this.temporalLogger.debug(`Namespace: ${health.namespace}`);
463
+ }
464
+ ensureInitialized() {
465
+ if (!this.isInitialized) {
466
+ throw new Error('Temporal Service is not initialized');
467
+ }
468
+ }
469
+ enhanceWorkflowOptions(options) {
470
+ if (!options.taskQueue) {
471
+ options.taskQueue = this.options.taskQueue || constants_2.DEFAULT_TASK_QUEUE;
472
+ }
473
+ return options;
474
+ }
475
+ getClientHealth() {
476
+ const isHealthy = this.clientService.isHealthy();
477
+ return { status: isHealthy ? 'healthy' : 'unhealthy' };
478
+ }
479
+ getWorkerHealthStatus() {
480
+ if (!this.workerService) {
481
+ return {
482
+ status: 'unhealthy',
483
+ details: { error: 'Worker service not available' },
484
+ };
485
+ }
486
+ const workerStatus = this.workerService.getWorkerStatus();
487
+ return {
488
+ status: workerStatus.isHealthy ? 'healthy' : 'degraded',
489
+ details: {
490
+ isInitialized: workerStatus.isInitialized,
491
+ isRunning: workerStatus.isRunning,
492
+ isHealthy: workerStatus.isHealthy,
493
+ taskQueue: workerStatus.taskQueue,
494
+ namespace: workerStatus.namespace,
495
+ workflowSource: workerStatus.workflowSource,
496
+ activitiesCount: workerStatus.activitiesCount,
497
+ workflowsCount: workerStatus.workflowsCount,
498
+ lastError: workerStatus.lastError,
499
+ startedAt: workerStatus.startedAt,
500
+ uptime: workerStatus.uptime,
501
+ },
502
+ };
503
+ }
504
+ getScheduleHealth() {
505
+ const isHealthy = this.scheduleService.isHealthy();
506
+ const stats = this.scheduleService.getScheduleStats();
507
+ return { status: isHealthy ? 'healthy' : 'unhealthy', schedulesCount: stats.total };
508
+ }
509
+ getActivityHealth() {
510
+ const healthStatus = this.discoveryService.getHealthStatus();
511
+ const count = this.discoveryService.getActivityNames().length;
512
+ return {
513
+ status: healthStatus.status === 'healthy' ? 'healthy' : 'unhealthy',
514
+ activitiesCount: { total: count },
515
+ };
516
+ }
517
+ getDiscoveryHealth() {
518
+ const healthStatus = this.discoveryService.getHealthStatus();
519
+ return { status: healthStatus.status };
520
+ }
521
+ getActivityCount() {
522
+ const names = this.discoveryService.getActivityNames();
523
+ return { classes: names.length, methods: names.length, total: names.length };
524
+ }
525
+ getScheduleCount() {
526
+ const stats = this.scheduleService.getScheduleStats();
527
+ return stats.total;
528
+ }
529
+ get client() {
530
+ this.ensureInitialized();
531
+ return this.clientService;
532
+ }
533
+ get worker() {
534
+ this.ensureInitialized();
535
+ return this.workerService;
536
+ }
537
+ get schedule() {
538
+ this.ensureInitialized();
539
+ return this.scheduleService;
540
+ }
541
+ get activity() {
542
+ this.ensureInitialized();
543
+ return this.discoveryService;
544
+ }
545
+ get discovery() {
546
+ this.ensureInitialized();
547
+ return this.discoveryService;
548
+ }
549
+ get metadata() {
550
+ return this.metadataAccessor;
551
+ }
552
+ extractErrorMessage(error) {
553
+ if (error instanceof Error) {
554
+ return error.message;
555
+ }
556
+ if (typeof error === 'string') {
557
+ return error;
558
+ }
559
+ return 'Unknown error';
560
+ }
561
+ };
562
+ exports.TemporalService = TemporalService;
563
+ exports.TemporalService = TemporalService = TemporalService_1 = __decorate([
564
+ (0, common_1.Injectable)(),
565
+ __param(0, (0, common_1.Inject)(constants_1.TEMPORAL_MODULE_OPTIONS)),
566
+ __metadata("design:paramtypes", [Object, temporal_client_service_1.TemporalClientService,
567
+ temporal_worker_service_1.TemporalWorkerManagerService,
568
+ temporal_schedule_service_1.TemporalScheduleService,
569
+ temporal_discovery_service_1.TemporalDiscoveryService,
570
+ temporal_metadata_service_1.TemporalMetadataAccessor])
571
+ ], TemporalService);
572
+ //# sourceMappingURL=temporal.service.js.map