Skip to content

Commit 3a536a3

Browse files
committed
WIP refactor
1 parent d39024a commit 3a536a3

File tree

5 files changed

+16
-42
lines changed

5 files changed

+16
-42
lines changed

demo/App.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ function App() {
6767
const deploy = async () => {
6868
const { xml } = await modeler.saveXML();
6969

70-
const payload = { xml };
70+
const resources = [ { name: 'diagram.bpmn', content: xml } ];
7171

7272
if (form) {
73-
payload.form = form;
73+
resources.push({ name: 'form.form', content: form });
7474
}
7575

7676
const response = await fetch('/api/deploy', {
7777
method: 'POST',
7878
headers: {
7979
'Content-Type': 'application/json'
8080
},
81-
body: JSON.stringify(payload)
81+
body: JSON.stringify({ resources })
8282
});
8383

8484
return await response.json();

demo/api.mjs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,12 @@ export function createApi(client) {
107107
}
108108

109109
// ---------------------------------------------------------------------------
110-
// Response-shape helpers
110+
// Response-shape helpers — canonical implementations live in lib/TaskExecution.js
111111
// ---------------------------------------------------------------------------
112112

113-
export function getProcessDefinitionKey(deployResponse, processId) {
114-
const items = deployResponse && (deployResponse.deployments || deployResponse.processes || []);
115-
for (const item of items) {
116-
const def = item.processDefinition || item;
117-
if (def.processDefinitionId === processId) {
118-
return def.processDefinitionKey;
119-
}
120-
}
121-
return null;
122-
}
123-
124-
export function getProcessInstanceKey(startResponse) {
125-
if (!startResponse) return null;
126-
return String(
127-
startResponse.processInstanceKey ||
128-
(startResponse.items && startResponse.items[0] && startResponse.items[0].processInstanceKey) ||
129-
''
130-
) || null;
131-
}
132-
133-
export function getProcessInstanceState(piResult) {
134-
const items = piResult && piResult.response && piResult.response.items;
135-
return items && items[0] && items[0].state;
136-
}
137-
138-
export function hasProcessInstanceIncident(piResult) {
139-
const items = piResult && piResult.response && piResult.response.items;
140-
return !!(items && items[0] && items[0].hasIncident);
141-
}
113+
export {
114+
getProcessDefinitionKey,
115+
getProcessInstanceKey,
116+
getProcessInstanceState,
117+
hasProcessInstanceIncident
118+
} from '../lib/TaskExecution.js';

demo/server.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ app.post('/api/deploy', async (req, res) => {
9797
return res.json({ success: false, error: 'Camunda environment not configured' });
9898
}
9999

100-
const { xml, form } = req.body;
101-
102-
const resources = [ { name: 'diagram.bpmn', content: xml } ];
103-
if (form) resources.push({ name: 'form.form', content: form });
100+
const { resources } = req.body;
104101

105102
const result = await api.deployResources(resources);
106103
recorder.record('deploy', result);

lib/TaskExecution.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export default class TaskExecution extends EventEmitter {
324324
*
325325
* @returns {string|null} The process instance key or null if not found.
326326
*/
327-
function getProcessInstanceKey(response) {
327+
export function getProcessInstanceKey(response) {
328328
const { processInstanceKey } = response;
329329

330330
return processInstanceKey || null;
@@ -340,7 +340,7 @@ function getProcessInstance(response, processInstanceKey) {
340340
return items.find(item => item.processInstanceKey === processInstanceKey) || null;
341341
}
342342

343-
function getProcessInstanceState(response, processInstanceKey) {
343+
export function getProcessInstanceState(response, processInstanceKey) {
344344
const processInstance = getProcessInstance(response, processInstanceKey);
345345

346346
if (!processInstance) {
@@ -350,7 +350,7 @@ function getProcessInstanceState(response, processInstanceKey) {
350350
return processInstance.state;
351351
}
352352

353-
function hasProcessInstanceIncident(response, processInstanceKey) {
353+
export function hasProcessInstanceIncident(response, processInstanceKey) {
354354
const processInstance = getProcessInstance(response, processInstanceKey);
355355

356356
if (!processInstance) {

test/scenarios/run.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ async function runScenario(scenarioPath) {
247247
};
248248

249249
// Append incidentResult when the process instance has an active incident
250-
const hasIncident = hasProcessInstanceIncident(processInstanceResult);
250+
const hasIncident = hasProcessInstanceIncident(processInstanceResult.response, processInstanceKey);
251251
if (hasIncident) {
252252
pollData.incidentResult = await api.searchIncidents(processInstanceKey);
253253
}
254254

255255
recorder.record('poll', pollData);
256256

257-
const state = getProcessInstanceState(processInstanceResult);
257+
const state = getProcessInstanceState(processInstanceResult.response, processInstanceKey);
258258
const isTerminal = [ 'COMPLETED', 'TERMINATED', 'CANCELED' ].includes(state);
259259

260260
if (isTerminal) {

0 commit comments

Comments
 (0)