@camunda/task-testing 0.2.1 → 0.2.2

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.
package/dist/index.js CHANGED
@@ -362,30 +362,18 @@ __webpack_require__.r(__webpack_exports__);
362
362
  * except in compliance with the MIT License.
363
363
  */
364
364
 
365
- /**
366
- * @import {
367
- * TaskExecutionApi,
368
- * TaskExecutionResult,
369
- * TaskExecutionError,
370
- * TaskExecutionStatus } from './types';
371
- */
365
+
366
+ const INTERVAL_MS = 1000;
372
367
 
373
368
  /**
374
- * @import {
375
- * CreateProcessInstanceResponse,
376
- * DeployResourceResponse
377
- * } from '@camunda8/sdk/dist/c8/lib/C8Dto';
369
+ * @import { TaskExecutionApi, TaskExecutionResult, TaskExecutionError, TaskExecutionStatus } from './types';
378
370
  */
379
371
 
380
-
381
- const INTERVAL_MS = 1000;
382
-
383
372
  /**
384
373
  * Emits:
385
374
  * - `taskExecution.status.changed` with one of {@link TaskExecutionStatus}
386
375
  * - `taskExecution.finished` with {@link TaskExecutionResult}
387
376
  * - `taskExecution.error` with {@link TaskExecutionError}
388
- * - `taskExecution.interrupted` when execution is interrupted by switching focus
389
377
  */
390
378
  class TaskExecution extends (events__WEBPACK_IMPORTED_MODULE_0___default()) {
391
379
  /**
@@ -403,8 +391,10 @@ class TaskExecution extends (events__WEBPACK_IMPORTED_MODULE_0___default()) {
403
391
  this._status = 'idle';
404
392
  const eventBus = injector.get('eventBus');
405
393
  eventBus.on(['selection.changed', 'commandStack.changed'], () => {
394
+ if (this._status !== 'idle') {
395
+ this.emit('taskExecution.interrupted');
396
+ }
406
397
  this.cancelTaskExecution();
407
- this.emit('taskExecution.interrupted');
408
398
  });
409
399
  }
410
400
 
@@ -551,11 +541,14 @@ class TaskExecution extends (events__WEBPACK_IMPORTED_MODULE_0___default()) {
551
541
  /**
552
542
  * Get the process ID from the deployment response.
553
543
  *
554
- * @param {DeployResourceResponse} response
544
+ * @param {import('./types').DeploymentResponse} [response]
555
545
  *
556
546
  * @returns {string|null} The process ID or null if not found.
557
547
  */
558
548
  function getProcessId(response) {
549
+ if (!response) {
550
+ return null;
551
+ }
559
552
  const {
560
553
  processes = []
561
554
  } = response;
@@ -570,11 +563,14 @@ function getProcessId(response) {
570
563
  /**
571
564
  * Get the process instance key from the response.
572
565
  *
573
- * @param {CreateProcessInstanceResponse} response
566
+ * @param {import('./types').StartInstanceResponse} [response]
574
567
  *
575
568
  * @returns {string|null} The process instance key or null if not found.
576
569
  */
577
570
  function getProcessInstanceKey(response) {
571
+ if (!response) {
572
+ return null;
573
+ }
578
574
  const {
579
575
  processInstanceKey
580
576
  } = response;
@@ -1352,7 +1348,8 @@ const NO_ELEMENT_TEXT = 'Select a task to start testing';
1352
1348
  * @param {import('../../types').Config|undefined} [props.config]
1353
1349
  * @param {Function} [props.onConfigChanged=() => {}]
1354
1350
  * @param {string} [props.operateBaseUrl]
1355
- * @param {Function} [props.onTaskExecution=() => {}]
1351
+ * @param {Function} [props.onTaskExecutionStarted=() => {}]
1352
+ * @param {Function} [props.onTaskExecutionFinished=() => {}]
1356
1353
  * @param {Function} [props.onTaskExecutionInterrupted=() => {}]
1357
1354
  */
1358
1355
  function TaskTesting({
@@ -1366,7 +1363,8 @@ function TaskTesting({
1366
1363
  config,
1367
1364
  onConfigChanged = () => {},
1368
1365
  operateBaseUrl,
1369
- onTaskExecution = () => {},
1366
+ onTaskExecutionStarted = () => {},
1367
+ onTaskExecutionFinished = () => {},
1370
1368
  onTaskExecutionInterrupted = () => {}
1371
1369
  }) {
1372
1370
  /**
@@ -1503,6 +1501,7 @@ function TaskTesting({
1503
1501
  ...output,
1504
1502
  operateUrl
1505
1503
  });
1504
+ onTaskExecutionFinished(element, output);
1506
1505
  };
1507
1506
  taskExecutionRef === null || taskExecutionRef === void 0 || (_taskExecutionRef$cur = taskExecutionRef.current) === null || _taskExecutionRef$cur === void 0 || _taskExecutionRef$cur.on('taskExecution.finished', handleFinished);
1508
1507
  taskExecutionRef === null || taskExecutionRef === void 0 || (_taskExecutionRef$cur2 = taskExecutionRef.current) === null || _taskExecutionRef$cur2 === void 0 || _taskExecutionRef$cur2.on('taskExecution.status.changed', handleStatusChange);
@@ -1550,11 +1549,14 @@ function TaskTesting({
1550
1549
  const inputConfig = await elementConfigRef.current.getInputConfigForElement(element);
1551
1550
  elementConfigRef.current.setOutputConfigForElement(element, null);
1552
1551
  taskExecutionRef.current.executeTask(element.id, JSON.parse(inputConfig));
1553
- onTaskExecution();
1552
+ onTaskExecutionStarted(element);
1554
1553
  };
1555
1554
  const handleCancelTaskExecution = () => {
1556
- if (taskExecutionRef.current) {
1557
- taskExecutionRef.current.cancelTaskExecution();
1555
+ var _taskExecutionRef$cur5;
1556
+ taskExecutionRef === null || taskExecutionRef === void 0 || (_taskExecutionRef$cur5 = taskExecutionRef.current) === null || _taskExecutionRef$cur5 === void 0 || _taskExecutionRef$cur5.cancelTaskExecution();
1557
+ if (output !== null && output !== void 0 && output.operateUrl && Object.keys(output).length === 1) {
1558
+ var _elementConfigRef$cur7;
1559
+ elementConfigRef === null || elementConfigRef === void 0 || (_elementConfigRef$cur7 = elementConfigRef.current) === null || _elementConfigRef$cur7 === void 0 || _elementConfigRef$cur7.setOutputConfigForElement(element, null);
1558
1560
  }
1559
1561
  };
1560
1562
  const handleResetOutput = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(() => {
@@ -2831,8 +2833,6 @@ __webpack_require__.r(__webpack_exports__);
2831
2833
  /* harmony import */ var bpmn_js_lib_util_ModelUtil__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! bpmn-js/lib/util/ModelUtil */ "./node_modules/bpmn-js/lib/util/ModelUtil.js");
2832
2834
  /* harmony import */ var _util_CachedValue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util/CachedValue */ "./node_modules/@bpmn-io/variable-resolver/lib/base/util/CachedValue.js");
2833
2835
  /* harmony import */ var _util_scopeUtil__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./util/scopeUtil */ "./node_modules/@bpmn-io/variable-resolver/lib/base/util/scopeUtil.js");
2834
- /* harmony import */ var min_dash__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! min-dash */ "./node_modules/min-dash/dist/index.esm.js");
2835
-
2836
2836
 
2837
2837
 
2838
2838
 
@@ -2851,6 +2851,7 @@ __webpack_require__.r(__webpack_exports__);
2851
2851
  * @typedef {AdditionalVariable} ProcessVariable
2852
2852
  * @property {Array<ModdleElement>} origin
2853
2853
  * @property {ModdleElement} scope
2854
+ * @property {Array<Object>} provider
2854
2855
  */
2855
2856
 
2856
2857
  /**
@@ -2883,7 +2884,7 @@ class BaseVariableResolver {
2883
2884
  }
2884
2885
 
2885
2886
  /**
2886
- * To be implemented by super class. This should be an instance of `getProcessVariables` from `@bpmn-io/extract-process-variables`,
2887
+ * To be implemented by a subclass. This should be an instance of `getProcessVariables` from `@bpmn-io/extract-process-variables`,
2887
2888
  * either C7 or C8.
2888
2889
  *
2889
2890
  * @returns {Promise<Array<ProcessVariable>>}
@@ -3092,24 +3093,40 @@ class BaseVariableResolver {
3092
3093
  const root = getRootElement(bo);
3093
3094
  const allVariables = await this.getProcessVariables(root);
3094
3095
 
3095
- // keep only unique variables based on name property
3096
- const uniqueVariables = (0,min_dash__WEBPACK_IMPORTED_MODULE_3__.uniqueBy)('name', allVariables.reverse());
3097
-
3098
3096
  // (1) get variables for given scope
3099
- var scopeVariables = uniqueVariables.filter(function(variable) {
3097
+ var scopeVariables = allVariables.filter(function(variable) {
3100
3098
  return variable.scope.id === bo.id;
3101
3099
  });
3102
3100
 
3103
3101
  // (2) get variables for parent scopes
3104
3102
  var parents = (0,_util_scopeUtil__WEBPACK_IMPORTED_MODULE_1__.getParents)(bo);
3105
3103
 
3106
- var parentsScopeVariables = uniqueVariables.filter(function(variable) {
3104
+ var parentsScopeVariables = allVariables.filter(function(variable) {
3107
3105
  return parents.find(function(parent) {
3108
3106
  return parent.id === variable.scope.id;
3109
3107
  });
3110
3108
  });
3111
3109
 
3112
- return [ ...scopeVariables, ...parentsScopeVariables ];
3110
+ const reversedVariables = [ ...scopeVariables, ...parentsScopeVariables ].reverse();
3111
+
3112
+ const seenNames = new Set();
3113
+
3114
+ return reversedVariables.filter(variable => {
3115
+
3116
+ // if external variable, keep
3117
+ if (variable.provider.find(extractor => extractor !== this._baseExtractor)) {
3118
+ return true;
3119
+ }
3120
+
3121
+ // if not external, keep only the first occurrence of each name
3122
+ if (!seenNames.has(variable.name)) {
3123
+ seenNames.add(variable.name);
3124
+
3125
+ return true;
3126
+ }
3127
+
3128
+ return false;
3129
+ });
3113
3130
  }
3114
3131
  }
3115
3132