Skip to content

Commit 30ba014

Browse files
author
Shailesh Jagannath Padave
committed
Updated Test
1 parent d51bde3 commit 30ba014

14 files changed

Lines changed: 958 additions & 245 deletions

src/common/open-api/models/Consistency.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/common/open-api/models/ReturnStrategy.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/common/open-api/models/SignalResponse.ts

Lines changed: 256 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,282 @@
22
/* tslint:disable */
33
/* eslint-disable */
44

5-
import { Task } from './Task';
5+
import type { Task } from './Task';
6+
import type { Workflow } from './Workflow';
67

7-
export interface SignalResponse {
8-
// Common fields in all responses
8+
/**
9+
* SignalResponse represents a unified response from the signal API
10+
*/
11+
export class SignalResponse {
12+
// ========== COMMON FIELDS IN ALL RESPONSES ==========
13+
14+
/** Type of response based on return strategy */
915
responseType?: string;
16+
17+
/** ID of the target workflow */
1018
targetWorkflowId?: string;
19+
20+
/** Status of the target workflow */
1121
targetWorkflowStatus?: string;
22+
23+
/** ID of the workflow */
1224
workflowId?: string;
25+
26+
/** Input data for the workflow/task */
1327
input?: Record<string, any>;
28+
29+
/** Output data from the workflow/task */
1430
output?: Record<string, any>;
31+
32+
/** Priority of the workflow */
1533
priority?: number;
34+
35+
/** Workflow variables */
1636
variables?: Record<string, any>;
1737

18-
// Fields specific to TARGET_WORKFLOW & BLOCKING_WORKFLOW
38+
// ========== FIELDS SPECIFIC TO TARGET_WORKFLOW & BLOCKING_WORKFLOW ==========
39+
40+
/** Array of tasks in the workflow */
1941
tasks?: Array<Task>;
42+
43+
/** User who created the workflow */
2044
createdBy?: string;
45+
46+
/** Timestamp when workflow was created */
2147
createTime?: number;
48+
49+
/** Current status of the workflow */
2250
status?: string;
51+
52+
/** Timestamp when workflow was last updated */
2353
updateTime?: number;
2454

25-
// Fields specific to BLOCKING_TASK & BLOCKING_TASK_INPUT
55+
// ========== FIELDS SPECIFIC TO BLOCKING_TASK & BLOCKING_TASK_INPUT ==========
56+
57+
/** Type of the blocking task */
2658
taskType?: string;
59+
60+
/** ID of the blocking task */
2761
taskId?: string;
62+
63+
/** Reference name of the blocking task */
2864
referenceTaskName?: string;
65+
66+
/** Number of retries for the task */
2967
retryCount?: number;
68+
69+
/** Definition name of the task */
3070
taskDefName?: string;
71+
72+
/** Type of the workflow containing the task */
3173
workflowType?: string;
74+
75+
// ========== CHECK METHODS ==========
76+
77+
/**
78+
* Returns true if the response contains target workflow details
79+
*/
80+
isTargetWorkflow(): boolean {
81+
return this.responseType === 'TARGET_WORKFLOW';
82+
}
83+
84+
/**
85+
* Returns true if the response contains blocking workflow details
86+
*/
87+
isBlockingWorkflow(): boolean {
88+
return this.responseType === 'BLOCKING_WORKFLOW';
89+
}
90+
91+
/**
92+
* Returns true if the response contains blocking task details
93+
*/
94+
isBlockingTask(): boolean {
95+
return this.responseType === 'BLOCKING_TASK';
96+
}
97+
98+
/**
99+
* Returns true if the response contains blocking task input
100+
*/
101+
isBlockingTaskInput(): boolean {
102+
return this.responseType === 'BLOCKING_TASK_INPUT';
103+
}
104+
105+
// ========== EXTRACTION METHODS ==========
106+
107+
/**
108+
* Extracts workflow details from a SignalResponse
109+
* @throws Error if the response type doesn't contain workflow details
110+
*/
111+
getWorkflow(): Workflow {
112+
if (!this.isTargetWorkflow() && !this.isBlockingWorkflow()) {
113+
throw new Error(
114+
`Response type ${this.responseType} does not contain workflow details`
115+
);
116+
}
117+
118+
return {
119+
workflowId: this.workflowId!,
120+
status: this.status!,
121+
tasks: this.tasks || [],
122+
createdBy: this.createdBy,
123+
createTime: this.createTime,
124+
updateTime: this.updateTime,
125+
input: this.input || {},
126+
output: this.output || {},
127+
variables: this.variables || {},
128+
priority: this.priority
129+
} as Workflow;
130+
}
131+
132+
/**
133+
* Extracts task details from a SignalResponse
134+
* @throws Error if the response type doesn't contain task details
135+
*/
136+
getBlockingTask(): Task {
137+
if (!this.isBlockingTask() && !this.isBlockingTaskInput()) {
138+
throw new Error(
139+
`Response type ${this.responseType} does not contain task details`
140+
);
141+
}
142+
143+
return {
144+
taskId: this.taskId!,
145+
taskType: this.taskType!,
146+
taskDefName: this.taskDefName!,
147+
referenceTaskName: this.referenceTaskName!,
148+
retryCount: this.retryCount || 0,
149+
status: this.status,
150+
inputData: this.input || {},
151+
outputData: this.output || {},
152+
workflowInstanceId: this.workflowId!,
153+
workflowType: this.workflowType!
154+
} as Task;
155+
}
156+
157+
/**
158+
* Extracts task input from a SignalResponse
159+
* Only valid for BLOCKING_TASK_INPUT responses
160+
* @throws Error if the response type doesn't contain task input details
161+
*/
162+
getTaskInput(): Record<string, any> {
163+
if (!this.isBlockingTaskInput()) {
164+
throw new Error(
165+
`Response type ${this.responseType} does not contain task input details`
166+
);
167+
}
168+
169+
return this.input || {};
170+
}
171+
172+
// ========== UTILITY METHODS ==========
173+
174+
/**
175+
* Get the workflow ID from the response
176+
*/
177+
getWorkflowId(): string {
178+
return this.workflowId || this.targetWorkflowId || '';
179+
}
180+
181+
/**
182+
* Get the target workflow ID from the response
183+
*/
184+
getTargetWorkflowId(): string {
185+
return this.targetWorkflowId || this.workflowId || '';
186+
}
187+
188+
/**
189+
* Check if the response has workflow data
190+
*/
191+
hasWorkflowData(): boolean {
192+
return this.isTargetWorkflow() || this.isBlockingWorkflow();
193+
}
194+
195+
/**
196+
* Check if the response has task data
197+
*/
198+
hasTaskData(): boolean {
199+
return this.isBlockingTask() || this.isBlockingTaskInput();
200+
}
201+
202+
/**
203+
* Get response type as string
204+
*/
205+
getResponseType(): string {
206+
return this.responseType || '';
207+
}
208+
209+
/**
210+
* Check if the workflow/task is in a terminal state
211+
*/
212+
isTerminal(): boolean {
213+
const terminalStates = ['COMPLETED', 'FAILED', 'TERMINATED', 'TIMED_OUT'];
214+
return terminalStates.includes(this.status || '');
215+
}
216+
217+
/**
218+
* Check if the workflow/task is currently running
219+
*/
220+
isRunning(): boolean {
221+
return this.status === 'RUNNING';
222+
}
223+
224+
/**
225+
* Check if the workflow/task is paused
226+
*/
227+
isPaused(): boolean {
228+
return this.status === 'PAUSED';
229+
}
230+
231+
/**
232+
* Get a summary of the response for logging
233+
*/
234+
getSummary(): string {
235+
const parts = [
236+
`type=${this.responseType}`,
237+
`workflowId=${this.workflowId}`,
238+
`status=${this.status}`
239+
];
240+
241+
if (this.hasTaskData()) {
242+
parts.push(`taskId=${this.taskId}`);
243+
parts.push(`taskType=${this.taskType}`);
244+
}
245+
246+
if (this.hasWorkflowData() && this.tasks) {
247+
parts.push(`tasksCount=${this.tasks.length}`);
248+
}
249+
250+
return `SignalResponse{${parts.join(', ')}}`;
251+
}
252+
253+
/**
254+
* Convert to JSON for debugging (excludes large objects)
255+
*/
256+
toDebugJSON(): Record<string, any> {
257+
return {
258+
responseType: this.responseType,
259+
workflowId: this.workflowId,
260+
targetWorkflowId: this.targetWorkflowId,
261+
targetWorkflowStatus: this.targetWorkflowStatus,
262+
status: this.status,
263+
taskId: this.taskId,
264+
taskType: this.taskType,
265+
referenceTaskName: this.referenceTaskName,
266+
createTime: this.createTime,
267+
updateTime: this.updateTime,
268+
priority: this.priority,
269+
retryCount: this.retryCount,
270+
tasksCount: this.tasks?.length,
271+
hasInput: Boolean(this.input && Object.keys(this.input).length > 0),
272+
hasOutput: Boolean(this.output && Object.keys(this.output).length > 0),
273+
hasVariables: Boolean(this.variables && Object.keys(this.variables).length > 0)
274+
};
275+
}
276+
277+
/**
278+
* String representation for debugging
279+
*/
280+
toString(): string {
281+
return this.getSummary();
282+
}
32283
}

src/common/open-api/services/ServiceRegistryResourceService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { WorkflowTestRequest } from '../models/WorkflowTestRequest';
1717
import type { CancelablePromise } from '../core/CancelablePromise';
1818
import type { BaseHttpRequest } from '../core/BaseHttpRequest';
1919
import {TaskRun} from "../models/TaskRun";
20-
import {WorkflowSignalReturnStrategy} from "../../types";
20+
import {ReturnStrategy} from "../../types";
2121
import {
2222
CircuitBreakerTransitionResponse,
2323
ProtoRegistryEntry,

src/common/open-api/services/TaskResourceService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { CancelablePromise } from '../core/CancelablePromise';
1313
import type { BaseHttpRequest } from '../core/BaseHttpRequest';
1414
import {Workflow} from "../models/Workflow";
1515
import {TaskResultStatus} from "../../../core";
16-
import {WorkflowSignalReturnStrategy} from "../../types";
16+
import {ReturnStrategy} from "../../types";
1717
import {SignalResponse} from "../models/SignalResponse";
1818
import {WorkflowRun} from "../models/WorkflowRun";
1919
import {TaskRun} from "../models/TaskRun";
@@ -406,7 +406,7 @@ export class TaskResourceService {
406406
workflowId: string,
407407
status: TaskResultStatusEnum,
408408
output: Record<string, any>,
409-
returnStrategy: WorkflowSignalReturnStrategy = WorkflowSignalReturnStrategy.TARGET_WORKFLOW,
409+
returnStrategy: ReturnStrategy = ReturnStrategy.TARGET_WORKFLOW,
410410
): CancelablePromise<SignalResponse> {
411411
return this.httpRequest.request({
412412
method: 'POST',

src/common/open-api/services/WorkflowResourceService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { WorkflowTestRequest } from '../models/WorkflowTestRequest';
1717
import type { CancelablePromise } from '../core/CancelablePromise';
1818
import type { BaseHttpRequest } from '../core/BaseHttpRequest';
1919
import {TaskRun} from "../models/TaskRun";
20-
import {WorkflowSignalReturnStrategy} from "../../types";
20+
import {ReturnStrategy} from "../../types";
2121

2222
export class WorkflowResourceService {
2323

@@ -123,7 +123,7 @@ export class WorkflowResourceService {
123123
waitUntilTaskRef,
124124
waitForSeconds,
125125
consistency,
126-
WorkflowSignalReturnStrategy.TARGET_WORKFLOW
126+
ReturnStrategy.TARGET_WORKFLOW
127127
) as CancelablePromise<WorkflowRun>;
128128
}
129129

@@ -156,7 +156,7 @@ export class WorkflowResourceService {
156156
waitUntilTaskRef,
157157
waitForSeconds,
158158
consistency,
159-
WorkflowSignalReturnStrategy.BLOCKING_WORKFLOW
159+
ReturnStrategy.BLOCKING_WORKFLOW
160160
) as CancelablePromise<WorkflowRun>;
161161
}
162162

@@ -189,7 +189,7 @@ export class WorkflowResourceService {
189189
waitUntilTaskRef,
190190
waitForSeconds,
191191
consistency,
192-
WorkflowSignalReturnStrategy.BLOCKING_TASK
192+
ReturnStrategy.BLOCKING_TASK
193193
) as CancelablePromise<TaskRun>;
194194
}
195195

@@ -222,7 +222,7 @@ export class WorkflowResourceService {
222222
waitUntilTaskRef,
223223
waitForSeconds,
224224
consistency,
225-
WorkflowSignalReturnStrategy.BLOCKING_TASK_INPUT
225+
ReturnStrategy.BLOCKING_TASK_INPUT
226226
) as CancelablePromise<TaskRun>;
227227
}
228228

0 commit comments

Comments
 (0)