octoparse-cli 0.1.14
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/README.md +271 -0
- package/RUNTIME_SECURITY_NOTICE.txt +41 -0
- package/SECURITY.md +24 -0
- package/dist/cli/args.js +34 -0
- package/dist/cli/help.js +214 -0
- package/dist/cli/output.js +39 -0
- package/dist/commands/auth.js +283 -0
- package/dist/commands/capabilities.js +118 -0
- package/dist/commands/cloud.js +241 -0
- package/dist/commands/data.js +220 -0
- package/dist/commands/doctor.js +73 -0
- package/dist/commands/env.js +63 -0
- package/dist/commands/local.js +251 -0
- package/dist/commands/run.js +622 -0
- package/dist/commands/runs.js +171 -0
- package/dist/commands/task.js +101 -0
- package/dist/index.js +133 -0
- package/dist/runtime/account-capabilities.js +71 -0
- package/dist/runtime/api-client.js +290 -0
- package/dist/runtime/artifacts.js +33 -0
- package/dist/runtime/auth.js +94 -0
- package/dist/runtime/bridge-hub.js +173 -0
- package/dist/runtime/client-headers.js +23 -0
- package/dist/runtime/cloud-data.js +75 -0
- package/dist/runtime/config.js +48 -0
- package/dist/runtime/data-exporter.js +267 -0
- package/dist/runtime/engine-host.js +449 -0
- package/dist/runtime/local-runs.js +92 -0
- package/dist/runtime/naming.js +13 -0
- package/dist/runtime/run-control.js +363 -0
- package/dist/runtime/run-services.js +380 -0
- package/dist/runtime/security-notice.js +78 -0
- package/dist/runtime/task-definition-provider.js +282 -0
- package/dist/types.js +4 -0
- package/examples/minimal-task.json +6 -0
- package/examples/navigate-example-task.json +6 -0
- package/node_modules/@octopus/bpmn/index.js +3 -0
- package/node_modules/@octopus/bpmn/lib/Context.js +245 -0
- package/node_modules/@octopus/bpmn/lib/Definition.js +258 -0
- package/node_modules/@octopus/bpmn/lib/Engine.js +275 -0
- package/node_modules/@octopus/bpmn/lib/PrematureStopError.js +7 -0
- package/node_modules/@octopus/bpmn/lib/activities/Activity.js +202 -0
- package/node_modules/@octopus/bpmn/lib/activities/BaseProcess.js +308 -0
- package/node_modules/@octopus/bpmn/lib/activities/BaseTask.js +145 -0
- package/node_modules/@octopus/bpmn/lib/activities/BoundaryEvent.js +12 -0
- package/node_modules/@octopus/bpmn/lib/activities/Dummy.js +10 -0
- package/node_modules/@octopus/bpmn/lib/activities/EventDefinition.js +99 -0
- package/node_modules/@octopus/bpmn/lib/activities/Flow.js +52 -0
- package/node_modules/@octopus/bpmn/lib/activities/Form.js +67 -0
- package/node_modules/@octopus/bpmn/lib/activities/InputOutput.js +53 -0
- package/node_modules/@octopus/bpmn/lib/activities/IntermediateCatchEvent.js +12 -0
- package/node_modules/@octopus/bpmn/lib/activities/MessageFlow.js +19 -0
- package/node_modules/@octopus/bpmn/lib/activities/MultiInstanceLoopCharacteristics.js +160 -0
- package/node_modules/@octopus/bpmn/lib/activities/Properties.js +27 -0
- package/node_modules/@octopus/bpmn/lib/activities/SequenceFlow.js +56 -0
- package/node_modules/@octopus/bpmn/lib/activities/ServiceConnector.js +71 -0
- package/node_modules/@octopus/bpmn/lib/context-helper.js +198 -0
- package/node_modules/@octopus/bpmn/lib/events/EndEvent.js +22 -0
- package/node_modules/@octopus/bpmn/lib/events/ErrorEvent.js +41 -0
- package/node_modules/@octopus/bpmn/lib/events/MessageEvent.js +19 -0
- package/node_modules/@octopus/bpmn/lib/events/StartEvent.js +55 -0
- package/node_modules/@octopus/bpmn/lib/events/TimerEvent.js +75 -0
- package/node_modules/@octopus/bpmn/lib/expressions.js +41 -0
- package/node_modules/@octopus/bpmn/lib/gateways/ExclusiveGateway.js +86 -0
- package/node_modules/@octopus/bpmn/lib/gateways/InclusiveGateway.js +56 -0
- package/node_modules/@octopus/bpmn/lib/gateways/ParallelGateway.js +195 -0
- package/node_modules/@octopus/bpmn/lib/getPropertyValue.js +83 -0
- package/node_modules/@octopus/bpmn/lib/index.js +6 -0
- package/node_modules/@octopus/bpmn/lib/mapper.js +55 -0
- package/node_modules/@octopus/bpmn/lib/parameter.js +119 -0
- package/node_modules/@octopus/bpmn/lib/script-helper.js +45 -0
- package/node_modules/@octopus/bpmn/lib/tasks/ManualTask.js +31 -0
- package/node_modules/@octopus/bpmn/lib/tasks/ReceiveTask.js +31 -0
- package/node_modules/@octopus/bpmn/lib/tasks/ScriptTask.js +35 -0
- package/node_modules/@octopus/bpmn/lib/tasks/SendTask.js +16 -0
- package/node_modules/@octopus/bpmn/lib/tasks/ServiceTask.js +68 -0
- package/node_modules/@octopus/bpmn/lib/tasks/SubProcess.js +17 -0
- package/node_modules/@octopus/bpmn/lib/tasks/Task.js +16 -0
- package/node_modules/@octopus/bpmn/lib/tasks/UserTask.js +47 -0
- package/node_modules/@octopus/bpmn/lib/transformer.js +13 -0
- package/node_modules/@octopus/bpmn/lib/validation.js +111 -0
- package/node_modules/@octopus/bpmn/package.json +17 -0
- package/node_modules/@octopus/bpmn/types/bpmn.d.ts +85 -0
- package/node_modules/@octopus/engine/README.md +370 -0
- package/node_modules/@octopus/engine/dist/actions/BackPreWebPageAction.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/actions/BackPreWebPageAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/BaseAction.d.ts +339 -0
- package/node_modules/@octopus/engine/dist/actions/BaseAction.js +1559 -0
- package/node_modules/@octopus/engine/dist/actions/BranchAction.d.ts +9 -0
- package/node_modules/@octopus/engine/dist/actions/BranchAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/ClickAction.d.ts +22 -0
- package/node_modules/@octopus/engine/dist/actions/ClickAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/ConditionAction.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/actions/ConditionAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/EmptyAction.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/actions/EmptyAction.js +12 -0
- package/node_modules/@octopus/engine/dist/actions/EnterCaptchaAction.d.ts +28 -0
- package/node_modules/@octopus/engine/dist/actions/EnterCaptchaAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/EnterTextAction.d.ts +20 -0
- package/node_modules/@octopus/engine/dist/actions/EnterTextAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/ExtractDataAction.d.ts +40 -0
- package/node_modules/@octopus/engine/dist/actions/ExtractDataAction.js +1 -0
- package/node_modules/@octopus/engine/dist/actions/LoopAction.d.ts +41 -0
- package/node_modules/@octopus/engine/dist/actions/LoopAction.js +526 -0
- package/node_modules/@octopus/engine/dist/actions/LoopStartAction.d.ts +47 -0
- package/node_modules/@octopus/engine/dist/actions/LoopStartAction.js +607 -0
- package/node_modules/@octopus/engine/dist/actions/MouseOverAction.d.ts +8 -0
- package/node_modules/@octopus/engine/dist/actions/MouseOverAction.js +34 -0
- package/node_modules/@octopus/engine/dist/actions/NavigateAction.d.ts +38 -0
- package/node_modules/@octopus/engine/dist/actions/NavigateAction.js +535 -0
- package/node_modules/@octopus/engine/dist/actions/SwitchComboAction.d.ts +13 -0
- package/node_modules/@octopus/engine/dist/actions/SwitchComboAction.js +69 -0
- package/node_modules/@octopus/engine/dist/browser.d.ts +17 -0
- package/node_modules/@octopus/engine/dist/browser.js +157 -0
- package/node_modules/@octopus/engine/dist/browserProxy.d.ts +90 -0
- package/node_modules/@octopus/engine/dist/browserProxy.js +1 -0
- package/node_modules/@octopus/engine/dist/configs/BaseConfig.d.ts +20 -0
- package/node_modules/@octopus/engine/dist/configs/BaseConfig.js +88 -0
- package/node_modules/@octopus/engine/dist/configs/BranchConfig.d.ts +7 -0
- package/node_modules/@octopus/engine/dist/configs/BranchConfig.js +1 -0
- package/node_modules/@octopus/engine/dist/configs/ClickConfig.d.ts +36 -0
- package/node_modules/@octopus/engine/dist/configs/ClickConfig.js +65 -0
- package/node_modules/@octopus/engine/dist/configs/EnterCaptchaConfig.d.ts +19 -0
- package/node_modules/@octopus/engine/dist/configs/EnterCaptchaConfig.js +25 -0
- package/node_modules/@octopus/engine/dist/configs/EnterTextConfig.d.ts +24 -0
- package/node_modules/@octopus/engine/dist/configs/EnterTextConfig.js +36 -0
- package/node_modules/@octopus/engine/dist/configs/ExtractDataConfig.d.ts +12 -0
- package/node_modules/@octopus/engine/dist/configs/ExtractDataConfig.js +1 -0
- package/node_modules/@octopus/engine/dist/configs/LoopConfig.d.ts +25 -0
- package/node_modules/@octopus/engine/dist/configs/LoopConfig.js +40 -0
- package/node_modules/@octopus/engine/dist/configs/LoopStartConfig.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/configs/LoopStartConfig.js +12 -0
- package/node_modules/@octopus/engine/dist/configs/MouseOverConfig.d.ts +8 -0
- package/node_modules/@octopus/engine/dist/configs/MouseOverConfig.js +15 -0
- package/node_modules/@octopus/engine/dist/configs/NavigateConfig.d.ts +41 -0
- package/node_modules/@octopus/engine/dist/configs/NavigateConfig.js +121 -0
- package/node_modules/@octopus/engine/dist/configs/SwitchComboConfig.d.ts +8 -0
- package/node_modules/@octopus/engine/dist/configs/SwitchComboConfig.js +15 -0
- package/node_modules/@octopus/engine/dist/enums/index.d.ts +419 -0
- package/node_modules/@octopus/engine/dist/enums/index.js +314 -0
- package/node_modules/@octopus/engine/dist/extension/BrowserWebSocketTransport-D_zAGZMQ.js +1 -0
- package/node_modules/@octopus/engine/dist/extension/LaunchOptions-DxvePrV4.js +6 -0
- package/node_modules/@octopus/engine/dist/extension/NodeWebSocketTransport-BTgRVB7Z.js +6 -0
- package/node_modules/@octopus/engine/dist/extension/background.js +396 -0
- package/node_modules/@octopus/engine/dist/extension/bidi-C_GIZ8Uz.js +131 -0
- package/node_modules/@octopus/engine/dist/extension/manifest.json +27 -0
- package/node_modules/@octopus/engine/dist/extension/src/content/anti-detection.js +1 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/BaseExtensionBridge.d.ts +21 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/BaseExtensionBridge.js +117 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/SessionExtensionBridge.d.ts +17 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/SessionExtensionBridge.js +29 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/index.d.ts +2 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/index.js +5 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/types.d.ts +159 -0
- package/node_modules/@octopus/engine/dist/extension-bridge/types.js +5 -0
- package/node_modules/@octopus/engine/dist/extensions/ublock-origin/uBlock0.chromium.tar.xz +0 -0
- package/node_modules/@octopus/engine/dist/extensions/ublock-origin-lite/uBOLite.chromium.tar.xz +0 -0
- package/node_modules/@octopus/engine/dist/index.d.ts +169 -0
- package/node_modules/@octopus/engine/dist/index.js +1 -0
- package/node_modules/@octopus/engine/dist/models/actionItem.d.ts +16 -0
- package/node_modules/@octopus/engine/dist/models/actionItem.js +15 -0
- package/node_modules/@octopus/engine/dist/models/conditionCheckArgs.d.ts +11 -0
- package/node_modules/@octopus/engine/dist/models/conditionCheckArgs.js +11 -0
- package/node_modules/@octopus/engine/dist/models/customizeCookie.d.ts +14 -0
- package/node_modules/@octopus/engine/dist/models/customizeCookie.js +6 -0
- package/node_modules/@octopus/engine/dist/models/downloadFileConfig.d.ts +17 -0
- package/node_modules/@octopus/engine/dist/models/downloadFileConfig.js +26 -0
- package/node_modules/@octopus/engine/dist/models/elementNotFoundArgs.d.ts +8 -0
- package/node_modules/@octopus/engine/dist/models/elementNotFoundArgs.js +12 -0
- package/node_modules/@octopus/engine/dist/models/elementNotFoundError.d.ts +2 -0
- package/node_modules/@octopus/engine/dist/models/elementNotFoundError.js +6 -0
- package/node_modules/@octopus/engine/dist/models/extractItem.d.ts +37 -0
- package/node_modules/@octopus/engine/dist/models/extractItem.js +35 -0
- package/node_modules/@octopus/engine/dist/models/extractTemplate.d.ts +11 -0
- package/node_modules/@octopus/engine/dist/models/extractTemplate.js +48 -0
- package/node_modules/@octopus/engine/dist/models/extractTextItem.d.ts +10 -0
- package/node_modules/@octopus/engine/dist/models/extractTextItem.js +17 -0
- package/node_modules/@octopus/engine/dist/models/globalConfig.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/models/globalConfig.js +1 -0
- package/node_modules/@octopus/engine/dist/models/httpHeader.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/models/httpHeader.js +10 -0
- package/node_modules/@octopus/engine/dist/models/operation.d.ts +27 -0
- package/node_modules/@octopus/engine/dist/models/operation.js +242 -0
- package/node_modules/@octopus/engine/dist/models/retryCondition.d.ts +7 -0
- package/node_modules/@octopus/engine/dist/models/retryCondition.js +10 -0
- package/node_modules/@octopus/engine/dist/models/task.d.ts +89 -0
- package/node_modules/@octopus/engine/dist/models/task.js +120 -0
- package/node_modules/@octopus/engine/dist/models/trigger.d.ts +66 -0
- package/node_modules/@octopus/engine/dist/models/trigger.js +117 -0
- package/node_modules/@octopus/engine/dist/package.json +26 -0
- package/node_modules/@octopus/engine/dist/public-types.d.ts +13 -0
- package/node_modules/@octopus/engine/dist/public-types.js +2 -0
- package/node_modules/@octopus/engine/dist/settings.d.ts +41 -0
- package/node_modules/@octopus/engine/dist/settings.js +20 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/ClickCaptchaSolver.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/ClickCaptchaSolver.js +1 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/HCaptchaSolver.d.ts +4 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/HCaptchaSolver.js +73 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/ImageCaptchaSolver.d.ts +2 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/ImageCaptchaSolver.js +74 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/RecaptchaSolver.d.ts +9 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/RecaptchaSolver.js +371 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/SliderCaptchaSolver.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/SliderCaptchaSolver.js +184 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/SlidingTrajectory.d.ts +50 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/SlidingTrajectory.js +125 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/types.d.ts +68 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/types.js +34 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/utils.d.ts +2 -0
- package/node_modules/@octopus/engine/dist/solvers/captcha/utils.js +15 -0
- package/node_modules/@octopus/engine/dist/translator/actionFactory.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/translator/actionFactory.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/activityTypeEnum.d.ts +22 -0
- package/node_modules/@octopus/engine/dist/translator/activityTypeEnum.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/backPreWebPageAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/backPreWebPageAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/baseAction.d.ts +31 -0
- package/node_modules/@octopus/engine/dist/translator/baseAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/breakActivity.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/breakActivity.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/clickAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/clickAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/completeWF.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/completeWF.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/conditionAction.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/translator/conditionAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/emptyAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/emptyAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/enterCapachaAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/enterCapachaAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/enterTextAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/enterTextAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/extractDataAction.d.ts +13 -0
- package/node_modules/@octopus/engine/dist/translator/extractDataAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/loopAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/loopAction.js +1 -0
- package/node_modules/@octopus/engine/dist/translator/mouseOverAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/mouseOverAction.js +19 -0
- package/node_modules/@octopus/engine/dist/translator/navigateAction.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/navigateAction.js +117 -0
- package/node_modules/@octopus/engine/dist/translator/rootAction.d.ts +6 -0
- package/node_modules/@octopus/engine/dist/translator/rootAction.js +80 -0
- package/node_modules/@octopus/engine/dist/translator/switchCombo2Action.d.ts +5 -0
- package/node_modules/@octopus/engine/dist/translator/switchCombo2Action.js +19 -0
- package/node_modules/@octopus/engine/dist/translator/translator.d.ts +1 -0
- package/node_modules/@octopus/engine/dist/translator/translator.js +36 -0
- package/node_modules/@octopus/engine/dist/type.d.ts +25 -0
- package/node_modules/@octopus/engine/dist/type.js +2 -0
- package/node_modules/@octopus/engine/dist/types/browser.d.ts +191 -0
- package/node_modules/@octopus/engine/dist/types/browser.js +1 -0
- package/node_modules/@octopus/engine/dist/types/browserManager.d.ts +41 -0
- package/node_modules/@octopus/engine/dist/types/browserManager.js +1 -0
- package/node_modules/@octopus/engine/dist/types/index.d.ts +40 -0
- package/node_modules/@octopus/engine/dist/types/index.js +2 -0
- package/node_modules/@octopus/engine/dist/types/plugin.d.ts +29 -0
- package/node_modules/@octopus/engine/dist/types/plugin.js +2 -0
- package/node_modules/@octopus/engine/dist/utils/AsyncEmitter.d.ts +15 -0
- package/node_modules/@octopus/engine/dist/utils/AsyncEmitter.js +1 -0
- package/node_modules/@octopus/engine/dist/utils/DataStore.d.ts +58 -0
- package/node_modules/@octopus/engine/dist/utils/DataStore.js +1 -0
- package/node_modules/@octopus/engine/dist/utils/DateTimeFormatHelper.d.ts +22 -0
- package/node_modules/@octopus/engine/dist/utils/DateTimeFormatHelper.js +173 -0
- package/node_modules/@octopus/engine/dist/utils/FileDownloader.d.ts +108 -0
- package/node_modules/@octopus/engine/dist/utils/FileDownloader.js +1 -0
- package/node_modules/@octopus/engine/dist/utils/HttpRequester.d.ts +43 -0
- package/node_modules/@octopus/engine/dist/utils/HttpRequester.js +174 -0
- package/node_modules/@octopus/engine/dist/utils/JsonParser.d.ts +95 -0
- package/node_modules/@octopus/engine/dist/utils/JsonParser.js +439 -0
- package/node_modules/@octopus/engine/dist/utils/Operations.d.ts +27 -0
- package/node_modules/@octopus/engine/dist/utils/Operations.js +115 -0
- package/node_modules/@octopus/engine/dist/utils/index.d.ts +28 -0
- package/node_modules/@octopus/engine/dist/utils/index.js +356 -0
- package/node_modules/@octopus/engine/package.json +58 -0
- package/package.json +79 -0
- package/schemas/capabilities-v1.schema.json +234 -0
- package/schemas/detached-bootstrap-v1.schema.json +42 -0
- package/schemas/json-envelope-v1.schema.json +39 -0
- package/schemas/run-event-v1.schema.json +47 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Activity = require('./Activity');
|
|
4
|
+
const debug = require('debug');
|
|
5
|
+
|
|
6
|
+
function EventDefinition() {
|
|
7
|
+
Activity.apply(this, arguments);
|
|
8
|
+
this.eventDefinition = this.activity.eventDefinitions[0];
|
|
9
|
+
this.type = this.eventDefinition.$type;
|
|
10
|
+
this.attachedTo = this.parentContext.getAttachedToActivity(this.id);
|
|
11
|
+
|
|
12
|
+
if (this.attachedTo) {
|
|
13
|
+
this.isStart = false;
|
|
14
|
+
}
|
|
15
|
+
this._debug = debug(`bpmn-engine:${this.type.toLowerCase()}`);
|
|
16
|
+
|
|
17
|
+
this.cancelActivity = this.activity.hasOwnProperty('cancelActivity') ? this.activity.cancelActivity : true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
EventDefinition.prototype = Object.create(Activity.prototype);
|
|
21
|
+
|
|
22
|
+
EventDefinition.prototype.run = function() {
|
|
23
|
+
this.taken = false;
|
|
24
|
+
Activity.prototype.run.apply(this, arguments);
|
|
25
|
+
|
|
26
|
+
this._debug(`<${this.id}>`, 'run');
|
|
27
|
+
this.emit('start', this);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
EventDefinition.prototype.complete = function(message) {
|
|
31
|
+
this._debug(`<${this.id}>`, 'completed');
|
|
32
|
+
this.taken = true;
|
|
33
|
+
this.emit('end', this, message);
|
|
34
|
+
if (this.attachedTo && this.cancelActivity) {
|
|
35
|
+
this._debug(`<${this.id}>`, `discard <${this.attachedTo.id}>`);
|
|
36
|
+
this.attachedTo.discard();
|
|
37
|
+
}
|
|
38
|
+
this.takeAllOutbound();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
EventDefinition.prototype.resume = function() {
|
|
42
|
+
// No op
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
EventDefinition.prototype.onAttachedStart = function(activity) {
|
|
46
|
+
this._debug(`<${this.id}>`, `activity <${activity.id}> started`);
|
|
47
|
+
this.run();
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
EventDefinition.prototype.onAttachedEnd = function(activity) {
|
|
51
|
+
this._debug(`<${this.id}>`, `activity <${activity.id}> ended`);
|
|
52
|
+
this.discard();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
EventDefinition.prototype.onAttachedCancel = function(activity) {
|
|
56
|
+
this._debug(`<${this.id}>`, `activity <${activity.id}> canceled`);
|
|
57
|
+
this.discard();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
EventDefinition.prototype.onAttachedError = function() {
|
|
61
|
+
// No op
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
EventDefinition.prototype.onAttachedLeave = function(activity) {
|
|
65
|
+
if (this.entered && !this.taken) {
|
|
66
|
+
this._debug(`<${this.id}>`, `activity <${activity.id}> leave`);
|
|
67
|
+
this.discard();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
EventDefinition.prototype.setupInboundListeners = function() {
|
|
72
|
+
if (this.attachedTo) {
|
|
73
|
+
this._onAttachedStart = this.onAttachedStart.bind(this);
|
|
74
|
+
this._onAttachedEnd = this.onAttachedEnd.bind(this);
|
|
75
|
+
this._onAttachedCancel = this.onAttachedCancel.bind(this);
|
|
76
|
+
this._onAttachedError = this.onAttachedError.bind(this);
|
|
77
|
+
this._onAttachedLeave = this.onAttachedLeave.bind(this);
|
|
78
|
+
|
|
79
|
+
this.attachedTo.on('start', this._onAttachedStart);
|
|
80
|
+
this.attachedTo.on('end', this._onAttachedEnd);
|
|
81
|
+
this.attachedTo.on('cancel', this._onAttachedCancel);
|
|
82
|
+
this.attachedTo.on('error', this._onAttachedError);
|
|
83
|
+
this.attachedTo.on('leave', this._onAttachedLeave);
|
|
84
|
+
}
|
|
85
|
+
Activity.prototype.setupInboundListeners.apply(this, arguments);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
EventDefinition.prototype.teardownInboundListeners = function() {
|
|
89
|
+
if (this.attachedTo) {
|
|
90
|
+
this.attachedTo.removeListener('start', this._onAttachedStart);
|
|
91
|
+
this.attachedTo.removeListener('end', this._onAttachedEnd);
|
|
92
|
+
this.attachedTo.removeListener('cancel', this._onAttachedCancel);
|
|
93
|
+
this.attachedTo.removeListener('error', this._onAttachedError);
|
|
94
|
+
this.attachedTo.removeListener('leave', this._onAttachedLeave);
|
|
95
|
+
}
|
|
96
|
+
Activity.prototype.teardownInboundListeners.apply(this, arguments);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
module.exports = EventDefinition;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug');
|
|
4
|
+
const EventEmitter = require('events').EventEmitter;
|
|
5
|
+
|
|
6
|
+
function Flow(activity, parentContext) {
|
|
7
|
+
this.id = activity.element.id;
|
|
8
|
+
this.type = activity.element.$type;
|
|
9
|
+
this.activity = activity;
|
|
10
|
+
this.parentContext = parentContext;
|
|
11
|
+
this.sourceId = activity.id;
|
|
12
|
+
this.targetId = this.parentContext.getSequenceFlowTargetId(this.id);
|
|
13
|
+
|
|
14
|
+
this.taken = false;
|
|
15
|
+
|
|
16
|
+
this._debug = debug(`bpmn-engine:${this.type.toLowerCase()}`);
|
|
17
|
+
|
|
18
|
+
this._debug(`<${this.id}>`, `init, <${this.sourceId}> -> <${this.targetId}>`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Flow.prototype = Object.create(EventEmitter.prototype);
|
|
22
|
+
|
|
23
|
+
Flow.prototype.take = function() {
|
|
24
|
+
this.taken = true;
|
|
25
|
+
this.discarded = false;
|
|
26
|
+
delete this.looped;
|
|
27
|
+
this._debug(`<${this.id}>`, `taken, target <${this.targetId}>`);
|
|
28
|
+
asyncEmitEvent.call(this, 'taken');
|
|
29
|
+
return this.taken;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
Flow.prototype.discard = function(rootFlow) {
|
|
33
|
+
if (rootFlow && rootFlow.sourceId === this.targetId) {
|
|
34
|
+
this._debug(`<${this.id}>`, `detected loop <${rootFlow.sourceId}>. Stop.`);
|
|
35
|
+
this.looped = true;
|
|
36
|
+
this.emit('looped', this, rootFlow);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this._debug(`<${this.id}>`, `discarded, target <${this.targetId}>`);
|
|
41
|
+
delete this.looped;
|
|
42
|
+
this.discarded = true;
|
|
43
|
+
asyncEmitEvent.call(this, 'discarded', rootFlow || this);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function asyncEmitEvent(eventName, rootFlow) {
|
|
47
|
+
setImmediate(() => {
|
|
48
|
+
this.emit(eventName, this, rootFlow);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = Flow;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('bpmn-engine:form');
|
|
4
|
+
const expressions = require('../expressions');
|
|
5
|
+
|
|
6
|
+
function Form(formData, parentContext) {
|
|
7
|
+
this.formData = formData;
|
|
8
|
+
this.parentContext = parentContext;
|
|
9
|
+
this.fields = [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Form.prototype.init = function(message) {
|
|
13
|
+
if (this.formData.formKey) {
|
|
14
|
+
this.key = getFormKey.call(this, message);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!this.formData.fields) return;
|
|
18
|
+
this.fields = initFields.call(this, message);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
Form.prototype.getFields = function() {
|
|
22
|
+
return this.fields;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
Form.prototype.getState = function() {
|
|
26
|
+
const state = {};
|
|
27
|
+
if (this.key) {
|
|
28
|
+
state.key = this.key;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.formData.fields) {
|
|
32
|
+
state.fields = this.formData.fields.map((field) => {
|
|
33
|
+
return {
|
|
34
|
+
id: field.id,
|
|
35
|
+
label: field.label,
|
|
36
|
+
type: field.type
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return state;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function getFormKey(message) {
|
|
45
|
+
if (!expressions.hasExpression(this.formData.formKey)) return this.formData.formKey;
|
|
46
|
+
|
|
47
|
+
const contextVariables = this.parentContext.getFrozenVariablesAndServices(message);
|
|
48
|
+
debug(`resolve formKey "${this.formData.formKey}" value expression`);
|
|
49
|
+
return expressions(this.formData.formKey, contextVariables);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function initFields(message) {
|
|
53
|
+
const contextVariables = this.parentContext.getFrozenVariablesAndServices(message);
|
|
54
|
+
|
|
55
|
+
return this.formData.fields.map((formField) => {
|
|
56
|
+
const field = Object.assign({}, formField);
|
|
57
|
+
|
|
58
|
+
if (expressions.hasExpression(field.defaultValue)) {
|
|
59
|
+
debug(`resolve field <${field.id}> default value expression`);
|
|
60
|
+
field.defaultValue = expressions(field.defaultValue, contextVariables);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return field;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = Form;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug');
|
|
4
|
+
const Parameter = require('../parameter');
|
|
5
|
+
|
|
6
|
+
function InputOutput(activity, parentContext) {
|
|
7
|
+
this.type = activity.$type;
|
|
8
|
+
this.parentContext = parentContext;
|
|
9
|
+
this._debug = debug(`bpmn-engine:io:${this.type.toLowerCase()}`);
|
|
10
|
+
this.activity = activity;
|
|
11
|
+
initParameters.call(this);
|
|
12
|
+
this.hasOutput = this.output && this.output.length;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
InputOutput.prototype.getInput = function(message, editableContextVariables) {
|
|
16
|
+
const result = {};
|
|
17
|
+
|
|
18
|
+
if (!this.input) {
|
|
19
|
+
this._debug('no input parameters, return variables and services');
|
|
20
|
+
return this.parentContext.getVariablesAndServices(message, !editableContextVariables);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this._debug('get input from', message || 'variables');
|
|
24
|
+
|
|
25
|
+
const frozenVariablesAndServices = this.parentContext && this.parentContext.getFrozenVariablesAndServices();
|
|
26
|
+
this.input.forEach((parm) => {
|
|
27
|
+
result[parm.name] = parm.getInputValue(message, frozenVariablesAndServices);
|
|
28
|
+
});
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
InputOutput.prototype.getOutput = function(output) {
|
|
33
|
+
const result = {};
|
|
34
|
+
if (!this.output) {
|
|
35
|
+
return output;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const frozenVariablesAndServices = this.parentContext && this.parentContext.getFrozenVariablesAndServices();
|
|
39
|
+
|
|
40
|
+
this._debug('get output', output);
|
|
41
|
+
this.output.forEach((parm) => {
|
|
42
|
+
result[parm.name] = parm.getOutputValue(output, frozenVariablesAndServices);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function initParameters() {
|
|
49
|
+
this.input = this.activity.inputParameters && this.activity.inputParameters.map(Parameter);
|
|
50
|
+
this.output = this.activity.outputParameters && this.activity.outputParameters.map(Parameter);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = InputOutput;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const mapper = require('../mapper');
|
|
4
|
+
|
|
5
|
+
function IntermediateCatchEvent(activity) {
|
|
6
|
+
const ctorArgs = Array.prototype.slice.call(arguments);
|
|
7
|
+
const Type = mapper(activity.eventDefinitions[0].$type);
|
|
8
|
+
const event = new (Function.prototype.bind.apply(Type, [null].concat(ctorArgs)))();
|
|
9
|
+
return event;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = IntermediateCatchEvent;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Flow = require('./Flow');
|
|
4
|
+
|
|
5
|
+
function MessageFlow() {
|
|
6
|
+
Flow.apply(this, arguments);
|
|
7
|
+
this.outboundMessage = true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
MessageFlow.prototype = Object.create(Flow.prototype);
|
|
11
|
+
|
|
12
|
+
MessageFlow.prototype.take = function(message) {
|
|
13
|
+
const taken = Flow.prototype.take.apply(this, arguments);
|
|
14
|
+
this._debug(`<${this.id}>`, 'send message:', message);
|
|
15
|
+
this.emit('message', message, this);
|
|
16
|
+
return taken;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = MessageFlow;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('bpmn-engine:bpmn:multiinstanceloopcharacteristics');
|
|
4
|
+
const expressions = require('../expressions');
|
|
5
|
+
const scriptHelper = require('../script-helper');
|
|
6
|
+
const PrematureStopError = require('../PrematureStopError');
|
|
7
|
+
|
|
8
|
+
function MultiInstanceLoopCharacteristics(activity, parentContext) {
|
|
9
|
+
this.type = activity.$type;
|
|
10
|
+
|
|
11
|
+
this.isSequential = activity.isSequential;
|
|
12
|
+
this.parentContext = parentContext;
|
|
13
|
+
|
|
14
|
+
this.characteristics = getLoopCharacteristics(activity);
|
|
15
|
+
if (!this.characteristics.type) throw new Error('Cardinality, condition expression, or collection must be defined');
|
|
16
|
+
|
|
17
|
+
debug(`${this.characteristics.type} loop type`);
|
|
18
|
+
|
|
19
|
+
this.iteration = 0;
|
|
20
|
+
this.completed = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
MultiInstanceLoopCharacteristics.prototype.run = function(variables, message, result, callback) {
|
|
24
|
+
if (this.stop) {
|
|
25
|
+
this.completed = true;
|
|
26
|
+
return callback && callback(new PrematureStopError('Stopped'), true);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
debug('run', variables, message);
|
|
30
|
+
|
|
31
|
+
this.iteration++;
|
|
32
|
+
this.completed = false;
|
|
33
|
+
|
|
34
|
+
if (this.characteristics.collection) {
|
|
35
|
+
const collection = this.getCollection(variables);
|
|
36
|
+
if ( collection.length <= 1) {
|
|
37
|
+
this.completed = true;
|
|
38
|
+
debug('completed collection', this.completed);
|
|
39
|
+
} else {
|
|
40
|
+
this.item = collection[0];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!this.completed && (this.characteristics.condition || this.characteristics.conditionExpression)) {
|
|
45
|
+
// let conditionResObj = executeCondition(this.characteristics, variables, message);
|
|
46
|
+
|
|
47
|
+
// if(conditionResObj.then){
|
|
48
|
+
// this.completed = conditionResObj;
|
|
49
|
+
// }else{
|
|
50
|
+
// this.completed = conditionResObj
|
|
51
|
+
// }
|
|
52
|
+
this.completed = executeCondition(this.characteristics, variables, message);
|
|
53
|
+
debug('completed condition', this.completed);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!this.completed) {
|
|
57
|
+
const cardinality = getCardinality(this.characteristics, variables);
|
|
58
|
+
if (cardinality !== undefined) {
|
|
59
|
+
this.completed = this.iteration >= cardinality;
|
|
60
|
+
debug('cardinality check', this.completed);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (callback) {
|
|
65
|
+
callback(null, this.completed);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return this.completed;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
MultiInstanceLoopCharacteristics.prototype.getCollection = function() {
|
|
72
|
+
let collection = expressions(this.characteristics.collection, this.parentContext.getVariablesAndServices());
|
|
73
|
+
if (this.iteration > 0) {
|
|
74
|
+
collection = collection.slice(this.iteration);
|
|
75
|
+
}
|
|
76
|
+
return collection;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
MultiInstanceLoopCharacteristics.prototype.deactivate = function() {
|
|
80
|
+
debug('stopped');
|
|
81
|
+
this.stop = true;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
MultiInstanceLoopCharacteristics.prototype.getState = function() {
|
|
85
|
+
const state = {
|
|
86
|
+
isSequential: this.isSequential,
|
|
87
|
+
iteration: this.iteration,
|
|
88
|
+
characteristics: {
|
|
89
|
+
type: this.characteristics.type
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
if (this.characteristics.hasOwnProperty('cardinality')) {
|
|
93
|
+
state.characteristics.cardinality = this.characteristics.cardinality;
|
|
94
|
+
}
|
|
95
|
+
return state;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
MultiInstanceLoopCharacteristics.prototype.reset = function() {
|
|
99
|
+
this.iteration = 0;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
MultiInstanceLoopCharacteristics.prototype.resume = function(state) {
|
|
103
|
+
this.iteration = state.iteration + 1;
|
|
104
|
+
debug(`resume at iteration ${state.iteration}`);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
function getLoopCharacteristics(activity) {
|
|
108
|
+
const characteristics = {};
|
|
109
|
+
|
|
110
|
+
if (activity.collection) {
|
|
111
|
+
characteristics.type = 'collection';
|
|
112
|
+
characteristics.collection = activity.collection;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (activity.completionCondition && activity.completionCondition.body) {
|
|
116
|
+
if (expressions.isExpression(activity.completionCondition.body)) {
|
|
117
|
+
characteristics.conditionExpression = activity.completionCondition.body;
|
|
118
|
+
} else {
|
|
119
|
+
characteristics.condition = scriptHelper.parse('characteristics.condition', activity.completionCondition.body);
|
|
120
|
+
}
|
|
121
|
+
characteristics.type = characteristics.type || 'condition';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (activity.loopCardinality && activity.loopCardinality.body) {
|
|
125
|
+
if (expressions.isExpression(activity.loopCardinality.body)) {
|
|
126
|
+
characteristics.cardinalityExpression = activity.loopCardinality.body;
|
|
127
|
+
} else {
|
|
128
|
+
const cardinality = Number(activity.loopCardinality.body);
|
|
129
|
+
if (!isNaN(cardinality)) {
|
|
130
|
+
characteristics.cardinality = cardinality;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!characteristics.type && (characteristics.cardinalityExpression || !isNaN(characteristics.cardinality))) {
|
|
134
|
+
characteristics.type = 'cardinality';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return characteristics;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function executeCondition(characteristics, variables, message) {
|
|
142
|
+
if (characteristics.condition) {
|
|
143
|
+
return scriptHelper.execute(characteristics.condition, variables, message);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return expressions(characteristics.conditionExpression, variables);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function getCardinality(characteristics, variables) {
|
|
150
|
+
let cardinality;
|
|
151
|
+
if (characteristics.cardinality > -1) {
|
|
152
|
+
cardinality = characteristics.cardinality;
|
|
153
|
+
} else if (characteristics.cardinalityExpression) {
|
|
154
|
+
cardinality = Number(expressions(characteristics.cardinalityExpression, variables));
|
|
155
|
+
if (isNaN(cardinality)) throw new Error(`Cardinality expression ${characteristics.cardinalityExpression} returned not a number`);
|
|
156
|
+
}
|
|
157
|
+
return cardinality;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = MultiInstanceLoopCharacteristics;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug');
|
|
4
|
+
const expressions = require('../expressions');
|
|
5
|
+
|
|
6
|
+
function Properties(activity) {
|
|
7
|
+
this.type = activity.$type;
|
|
8
|
+
this._debug = debug(`bpmn-engine:properties:${this.type.toLowerCase()}`);
|
|
9
|
+
this.activity = activity;
|
|
10
|
+
initProperties.call(this);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Properties.prototype.getValues = function(context) {
|
|
14
|
+
const result = {};
|
|
15
|
+
|
|
16
|
+
this.propertyValues.forEach((prop) => {
|
|
17
|
+
this._debug('get property value', prop.name);
|
|
18
|
+
result[prop.name] = expressions.hasExpression(prop.value) ? expressions(prop.value, context) : prop.value;
|
|
19
|
+
});
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function initProperties() {
|
|
24
|
+
this.propertyValues = this.activity.values.filter((prop) => prop.name);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = Properties;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const expressions = require('../expressions');
|
|
4
|
+
const Flow = require('./Flow');
|
|
5
|
+
const scriptHelper = require('../script-helper');
|
|
6
|
+
|
|
7
|
+
function SequenceFlow(activity) {
|
|
8
|
+
this.condition = getCondition.call(this, activity.element);
|
|
9
|
+
Flow.apply(this, arguments);
|
|
10
|
+
this.isDefault = this.parentContext.isDefaultSequenceFlow(this.id);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
SequenceFlow.prototype = Object.create(Flow.prototype);
|
|
14
|
+
|
|
15
|
+
SequenceFlow.prototype.executeCondition = function(context) {
|
|
16
|
+
const result = this.condition.execute(context);
|
|
17
|
+
this._debug(`<${this.id}>`, `condition result evaluated to ${result}`, context);
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
SequenceFlow.prototype.evaluateCondition = function(input) {
|
|
22
|
+
if (this.condition) {
|
|
23
|
+
const executionContext = this.parentContext.getFrozenVariablesAndServices(Object.assign({id: this.id, flow: this , $attrs: this.activity.element.$attrs}, input || {}));
|
|
24
|
+
let res = this.executeCondition(executionContext);
|
|
25
|
+
// console.log("evaluateCondition " + res);
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function getCondition(element) {
|
|
32
|
+
if (!element.conditionExpression) return null;
|
|
33
|
+
|
|
34
|
+
if (!element.conditionExpression.hasOwnProperty('language')) {
|
|
35
|
+
return new ExpressionCondition(element.conditionExpression.body);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!scriptHelper.isJavascript(element.conditionExpression.language)) throw Error(`Script format ${element.conditionExpression.language} is unsupported (<${element.id}>)`);
|
|
39
|
+
|
|
40
|
+
return new ScriptCondition(scriptHelper.parse(`${element.id}.condition`, element.conditionExpression.body));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ScriptCondition(script) {
|
|
44
|
+
this.execute = (executionContext) => {
|
|
45
|
+
return scriptHelper.execute(script, executionContext);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function ExpressionCondition(expression) {
|
|
50
|
+
this.execute = (executionContext) => {
|
|
51
|
+
let res = expressions(expression, executionContext);
|
|
52
|
+
return res;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = SequenceFlow;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')('bpmn-engine:service');
|
|
4
|
+
const Parameter = require('../parameter');
|
|
5
|
+
|
|
6
|
+
function ServiceConnector(connector, parentContext) {
|
|
7
|
+
this.type = connector.$type || 'string';
|
|
8
|
+
this.name = connector.connectorId || connector.name;
|
|
9
|
+
debug(`<${this.name}>`, 'type', this.type);
|
|
10
|
+
this.connector = connector;
|
|
11
|
+
this.parentContext = parentContext;
|
|
12
|
+
|
|
13
|
+
if (this.connector.inputOutput) {
|
|
14
|
+
initParameters.call(this, connector);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
ServiceConnector.prototype.execute = function(executeOnBehalfOf, message, callback) {
|
|
19
|
+
const scope = this;
|
|
20
|
+
const executeArgs = this.getInputArguments(message);
|
|
21
|
+
|
|
22
|
+
function serviceCallback() {
|
|
23
|
+
const resultArgs = Array.prototype.slice.call(arguments, 0);
|
|
24
|
+
const err = resultArgs[0];
|
|
25
|
+
|
|
26
|
+
const output = scope.getOutput(resultArgs.slice(1));
|
|
27
|
+
|
|
28
|
+
debug(`<${scope.name}>`, 'completed');
|
|
29
|
+
|
|
30
|
+
return callback.apply(null, [err, output]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
executeArgs.push(serviceCallback);
|
|
34
|
+
|
|
35
|
+
debug(`<${this.name}>`, 'execute with', executeArgs);
|
|
36
|
+
|
|
37
|
+
const serviceFn = scope.parentContext.getServiceByName(this.name);
|
|
38
|
+
|
|
39
|
+
return serviceFn.apply(null, executeArgs);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
ServiceConnector.prototype.getInputArguments = function(variables) {
|
|
43
|
+
if (this.input) {
|
|
44
|
+
return this.input.map((parm) => parm.getInputValue(variables));
|
|
45
|
+
}
|
|
46
|
+
return [variables];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
ServiceConnector.prototype.getOutput = function(result) {
|
|
50
|
+
if (!this.output) return result;
|
|
51
|
+
|
|
52
|
+
return this.output.reduce((output, parm, idx) => {
|
|
53
|
+
output[parm.name] = result[idx];
|
|
54
|
+
return output;
|
|
55
|
+
}, {});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function initParameters(connector) {
|
|
59
|
+
if (connector.inputOutput.inputParameters) {
|
|
60
|
+
this.input = connector.inputOutput.inputParameters.map(formatParameter);
|
|
61
|
+
}
|
|
62
|
+
if (connector.inputOutput.outputParameters) {
|
|
63
|
+
this.output = connector.inputOutput.outputParameters.map(formatParameter);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function formatParameter(parm) {
|
|
68
|
+
return Parameter(Object.assign({ positional: true}, parm));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = ServiceConnector;
|