Skip to content

Commit a8a6435

Browse files
committed
feat(types): update types to orchestration-cluster-api types
* add type additional type checks in TaskExecution.js
1 parent 5415047 commit a8a6435

File tree

4 files changed

+193
-110
lines changed

4 files changed

+193
-110
lines changed

lib/TaskExecution.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export default class TaskExecution extends EventEmitter {
182182
incident = getIncident(getProcessInstanceIncidentResult.response);
183183
}
184184

185-
const isCompleted = [ 'COMPLETED', 'TERMINATED', 'CANCELED' ].includes(state);
185+
const isCompleted = [ 'COMPLETED', 'TERMINATED', 'CANCELED' ].includes(state ?? '');
186186

187187
if (isCompleted || hasIncident) {
188188
const getProcessInstanceVariablesResult = await this._api.getProcessInstanceVariables(processInstanceKey);
@@ -215,7 +215,7 @@ export default class TaskExecution extends EventEmitter {
215215

216216
const variables = getVariables(
217217
getProcessInstanceVariablesResult.response.items,
218-
getProcessInstanceElementInstancesResult.response.items,
218+
getProcessInstanceElementInstancesResult.response.items ?? [],
219219
processInstance,
220220
element.id
221221
);
@@ -282,7 +282,7 @@ export default class TaskExecution extends EventEmitter {
282282
/**
283283
* Get the process instance key from the response.
284284
*
285-
* @param {CreateProcessInstanceResponse} response
285+
* @param {import('./types').CreateProcessInstanceResult} response
286286
*
287287
* @returns {string|null} The process instance key or null if not found.
288288
*/
@@ -292,6 +292,11 @@ function getProcessInstanceKey(response) {
292292
return processInstanceKey || null;
293293
}
294294

295+
/**
296+
* @param {import('./types').ProcessInstanceSearchQueryResult} response
297+
* @param {string} processInstanceKey
298+
* @return {import('./types').ProcessInstanceResult | null}
299+
*/
295300
function getProcessInstance(response, processInstanceKey) {
296301
const { items = [] } = response;
297302

@@ -302,6 +307,11 @@ function getProcessInstance(response, processInstanceKey) {
302307
return items.find(item => item.processInstanceKey === processInstanceKey) || null;
303308
}
304309

310+
/**
311+
* @param {import('./types').ProcessInstanceSearchQueryResult} response
312+
* @param {string} processInstanceKey
313+
* @return { import('./types').ProcessInstanceStateEnum |null}
314+
*/
305315
function getProcessInstanceState(response, processInstanceKey) {
306316
const processInstance = getProcessInstance(response, processInstanceKey);
307317

@@ -312,6 +322,11 @@ function getProcessInstanceState(response, processInstanceKey) {
312322
return processInstance.state;
313323
}
314324

325+
/**
326+
* @param {import('./types').ProcessInstanceSearchQueryResult }response
327+
* @param {string} processInstanceKey
328+
* @return {boolean}
329+
*/
315330
function hasProcessInstanceIncident(response, processInstanceKey) {
316331
const processInstance = getProcessInstance(response, processInstanceKey);
317332

@@ -322,6 +337,14 @@ function hasProcessInstanceIncident(response, processInstanceKey) {
322337
return processInstance.hasIncident || false;
323338
}
324339

340+
/**
341+
*
342+
* @param {import('./types').VariableSearchResult[]} getVariablesResponseItems
343+
* @param {import('./types').ElementInstanceResult[]} getElementInstancesResponseItems
344+
* @param {import('./types').ProcessInstanceResult} processInstance
345+
* @param elementId
346+
* @return {object}
347+
*/
325348
export function getVariables(getVariablesResponseItems, getElementInstancesResponseItems, processInstance, elementId) {
326349
const variables = {};
327350

@@ -348,6 +371,11 @@ export function getVariables(getVariablesResponseItems, getElementInstancesRespo
348371
return variables;
349372
}
350373

374+
/**
375+
*
376+
* @param {import('./types').IncidentSearchQueryResult} response
377+
* @return {*|null}
378+
*/
351379
function getIncident(response) {
352380
const { items = [] } = response;
353381

@@ -358,11 +386,19 @@ function getIncident(response) {
358386
return items[0];
359387
}
360388

389+
/**
390+
*
391+
* @param {import('./types').VariableSearchResult} variable
392+
* @param {import('./types').ElementInstanceResult[]} elementInstances
393+
* @param {import('./types').ProcessInstanceResult} processInstance
394+
* @param {string} elementId
395+
* @return {null|string}
396+
*/
361397
function getScope(variable, elementInstances, processInstance, elementId) {
362398
const { scopeKey } = variable;
363399

364400
const elementInstance = elementInstances.find(elementInstance => {
365-
return elementInstance.elementInstanceKey === scopeKey && elementInstance.elementId === elementId;
401+
return String(elementInstance.elementInstanceKey) === String(scopeKey) && elementInstance.elementId === elementId;
366402
});
367403

368404
if (elementInstance) {
@@ -371,7 +407,7 @@ function getScope(variable, elementInstances, processInstance, elementId) {
371407

372408
const { processInstanceKey } = processInstance;
373409

374-
if (scopeKey === processInstanceKey) {
410+
if (String(scopeKey) === String(processInstanceKey)) {
375411
return SCOPES.PROCESS;
376412
}
377413

@@ -381,7 +417,7 @@ function getScope(variable, elementInstances, processInstance, elementId) {
381417
/**
382418
* Get the process definition key from the deployment response.
383419
*
384-
* @param {import('@camunda8/sdk/dist/c8/lib/C8Dto').DeployResourceResponse} deployResponse
420+
* @param {import('./types').ExtendedDeploymentResult} deployResponse
385421
* @param {string} processId
386422
*
387423
* @returns {string|null}
@@ -390,7 +426,7 @@ export function getProcessDefinitionKey(deployResponse, processId) {
390426
const { deployments = [] } = deployResponse;
391427

392428
for (const deployment of deployments) {
393-
if ('processDefinition' in deployment) {
429+
if (deployment.processDefinition) {
394430
const { processDefinition } = deployment;
395431

396432
if (processDefinition.processDefinitionId === processId) {

lib/types.ts

Lines changed: 87 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,136 @@
11
import type {
2-
CreateProcessInstanceResponse,
3-
DeployResourceResponse,
4-
SearchProcessInstanceResponse,
5-
SearchVariablesResponse,
6-
SearchElementInstancesResponse,
7-
SearchIncidentsResponse
8-
} from '@camunda8/sdk/dist/c8/lib/C8Dto';
2+
CreateProcessInstanceResult,
3+
ElementInstanceSearchQueryResult,
4+
IncidentSearchQueryResult,
5+
ProcessInstanceSearchQueryResult,
6+
ProcessInstanceResult,
7+
VariableSearchQueryResult,
8+
VariableSearchResult,
9+
CamundaClient,
10+
ProcessInstanceStateEnum,
11+
ElementInstanceResult,
12+
} from '@camunda8/orchestration-cluster-api';
13+
14+
declare type ExtendedDeploymentResult = Awaited<ReturnType<CamundaClient['createDeployment']>>
15+
16+
export type {
17+
CreateProcessInstanceResult,
18+
ElementInstanceSearchQueryResult,
19+
IncidentSearchQueryResult,
20+
ProcessInstanceSearchQueryResult,
21+
ProcessInstanceResult,
22+
VariableSearchQueryResult,
23+
ExtendedDeploymentResult,
24+
ProcessInstanceStateEnum,
25+
VariableSearchResult,
26+
ElementInstanceResult
27+
}
28+
929

1030
import type {
1131
ModdleElement
1232
} from "bpmn-js/lib/model/Types";
1333

1434
export type Input = {
15-
[elementId: string]: string;
35+
[elementId: string]: string;
1636
};
1737

1838
export type Output = {
19-
[elementId: string]: ElementOutput
39+
[elementId: string]: ElementOutput
2040
};
2141

2242
export type VARIABLE_SCOPE = 'LOCAL' | 'PROCESS';
2343

2444
export type ElementOutputVariables = {
25-
[id: string]: {
26-
name: string;
27-
value: any;
28-
scope: VARIABLE_SCOPE;
29-
}
45+
[id: string]: {
46+
name: string;
47+
value: any;
48+
scope: VARIABLE_SCOPE;
49+
}
3050
};
3151

3252
export type ElementOutput = {
33-
success: boolean;
34-
variables?: ElementOutputVariables;
35-
error?: TaskExecutionError;
36-
incident?: any;
37-
operateUrl?: string;
38-
[key: string]: any;
53+
success: boolean;
54+
variables?: ElementOutputVariables;
55+
error?: TaskExecutionError;
56+
incident?: any;
57+
operateUrl?: string;
58+
[key: string]: any;
3959
} | undefined;
4060

4161
export type Config = {
42-
input: Input;
43-
output: Output;
62+
input: Input;
63+
output: Output;
4464
};
4565

4666
export type Variable = {
47-
name: string;
48-
type?: string;
49-
info?: string;
50-
isList?: boolean;
51-
entries?: Variable[];
52-
scope?: ModdleElement;
67+
name: string;
68+
type?: string;
69+
info?: string;
70+
isList?: boolean;
71+
entries?: Variable[];
72+
scope?: ModdleElement;
5373
};
5474

5575
export type Variables = Variable[];
5676

5777
export type ApiResponse<T> =
58-
| {
59-
success: true;
60-
response: T;
61-
}
62-
| {
63-
success: false;
64-
error: string;
65-
}
78+
| {
79+
success: true;
80+
response: T;
81+
}
82+
| {
83+
success: false;
84+
error: string;
85+
}
6686

6787
export type TaskExecutionApi = {
68-
deploy: () => Promise<ApiResponse<DeployResourceResponse>>;
69-
startInstance: (processDefinitionKey: string, elementId: string, variables: { [key: string]: any }) => Promise<ApiResponse<CreateProcessInstanceResponse>>;
70-
getProcessInstance: (processInstanceKey: string) => Promise<ApiResponse<SearchProcessInstanceResponse>>;
71-
getProcessInstanceVariables: (processInstanceKey: string) => Promise<ApiResponse<SearchVariablesResponse>>;
72-
getProcessInstanceElementInstances: (processInstanceKey: string) => Promise<ApiResponse<SearchElementInstancesResponse>>;
73-
getProcessInstanceIncident: (processInstanceKey: string) => Promise<ApiResponse<SearchIncidentsResponse>>;
88+
deploy: () => Promise<ApiResponse<ExtendedDeploymentResult>>;
89+
startInstance: (processDefinitionKey: string, elementId: string, variables: {
90+
[key: string]: any
91+
}) => Promise<ApiResponse<CreateProcessInstanceResult>>;
92+
getProcessInstance: (processInstanceKey: string) => Promise<ApiResponse<ProcessInstanceSearchQueryResult>>;
93+
getProcessInstanceVariables: (processInstanceKey: string) => Promise<ApiResponse<VariableSearchQueryResult>>;
94+
getProcessInstanceElementInstances: (processInstanceKey: string) => Promise<ApiResponse<ElementInstanceSearchQueryResult>>;
95+
getProcessInstanceIncident: (processInstanceKey: string) => Promise<ApiResponse<IncidentSearchQueryResult>>;
7496
};
7597

7698
export type TaskExecutionStatus =
77-
'idle' |
78-
'deploying' |
79-
'starting-instance' |
80-
'executing';
99+
'idle' |
100+
'deploying' |
101+
'starting-instance' |
102+
'executing';
81103

82104
export type TaskExecutionEvents =
83-
'taskExecution.status.changed' |
84-
'taskExecution.finished' |
85-
'taskExecution.error' |
86-
'taskExecution.interrupted';
105+
'taskExecution.status.changed' |
106+
'taskExecution.finished' |
107+
'taskExecution.error' |
108+
'taskExecution.interrupted';
87109

88110
export type TaskExecutionResult = {
89-
success: boolean;
90-
variables?: ElementOutputVariables;
91-
error?: TaskExecutionError;
92-
incident?: any;
111+
success: boolean;
112+
variables?: ElementOutputVariables;
113+
error?: TaskExecutionError;
114+
incident?: any;
93115
}
94116

95117
export type TaskExecutionError = {
96-
message: string;
97-
response?: any;
118+
message: string;
119+
response?: any;
98120
};
99121

100-
export type { Element, ModdleElement } from 'bpmn-js/lib/model/Types';
122+
export type {Element, ModdleElement} from 'bpmn-js/lib/model/Types';
101123

102124
export type Plugin = {
103-
priority?: number;
104-
render: Function;
105-
type: string;
106-
[key: string]: any;
125+
priority?: number;
126+
render: Function;
127+
type: string;
128+
[key: string]: any;
107129
};
108130

109131
export type PluginContextValue = {
110-
plugins: Plugin[];
111-
registerPlugin: (plugin: Plugin) => void;
112-
unregisterPlugin: (plugin: Plugin) => void;
113-
getPlugins: (pluginPoint: string) => Plugin[];
132+
plugins: Plugin[];
133+
registerPlugin: (plugin: Plugin) => void;
134+
unregisterPlugin: (plugin: Plugin) => void;
135+
getPlugins: (pluginPoint: string) => Plugin[];
114136
};

0 commit comments

Comments
 (0)