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,202 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const debug = require('debug');
|
|
4
|
+
const EventEmitter = require('events').EventEmitter;
|
|
5
|
+
|
|
6
|
+
const internals = {};
|
|
7
|
+
|
|
8
|
+
module.exports = internals.Activity = function(activity, parentContext) {
|
|
9
|
+
this.parentContext = parentContext;
|
|
10
|
+
this.id = activity.id;
|
|
11
|
+
this.type = activity.$type;
|
|
12
|
+
this.name = activity.name;
|
|
13
|
+
this._debug = debug(`bpmn-engine:${this.type.toLowerCase()}`);
|
|
14
|
+
this.activity = activity;
|
|
15
|
+
|
|
16
|
+
this.inbound = parentContext.getInboundSequenceFlows(activity.id);
|
|
17
|
+
this.outbound = parentContext.getOutboundSequenceFlows(activity.id);
|
|
18
|
+
|
|
19
|
+
this.io = parentContext.getActivityIO(activity.id);
|
|
20
|
+
|
|
21
|
+
this.properties = parentContext.getActivityProperties(activity.id);
|
|
22
|
+
|
|
23
|
+
this.multipleInbound = this.inbound.length > 1;
|
|
24
|
+
this.isStart = this.inbound.length === 0;
|
|
25
|
+
this.isEnd = this.outbound.length === 0;
|
|
26
|
+
this.entered = false;
|
|
27
|
+
|
|
28
|
+
this._debug(`<${this.id}>`, 'init');
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
internals.Activity.prototype = Object.create(EventEmitter.prototype);
|
|
32
|
+
|
|
33
|
+
internals.Activity.prototype.activate = function() {
|
|
34
|
+
this.setupInboundListeners();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
internals.Activity.prototype.deactivate = function() {
|
|
38
|
+
this.teardownInboundListeners();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
internals.Activity.prototype.run = function() {
|
|
42
|
+
this.canceled = false;
|
|
43
|
+
this.enter();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
internals.Activity.prototype.resume = function(state) {
|
|
47
|
+
if (state.taken !== undefined) {
|
|
48
|
+
this.taken = state.taken;
|
|
49
|
+
}
|
|
50
|
+
if (state.canceled !== undefined) {
|
|
51
|
+
this.canceled = state.canceled;
|
|
52
|
+
}
|
|
53
|
+
if (!state.entered) return;
|
|
54
|
+
this._debug(`<${this.id}>`, 'resume');
|
|
55
|
+
this.run();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
internals.Activity.prototype.signal = function() {
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
internals.Activity.prototype.enter = function(flow) {
|
|
62
|
+
this._debug(`<${this.id}>`, 'enter');
|
|
63
|
+
if (this.entered) {
|
|
64
|
+
throw new Error(`Already entered <${this.id}>`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.entered = true;
|
|
68
|
+
this.emit('enter', this, flow);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
internals.Activity.prototype.leave = function() {
|
|
72
|
+
this._debug(`<${this.id}>`, 'leave');
|
|
73
|
+
if (!this.entered) {
|
|
74
|
+
throw new Error(`Already left <${this.id}>`);
|
|
75
|
+
}
|
|
76
|
+
this.pendingDiscard = false;
|
|
77
|
+
this.entered = false;
|
|
78
|
+
setImmediate(() => {
|
|
79
|
+
this.emit('leave', this);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
internals.Activity.prototype.cancel = function() {
|
|
84
|
+
this.canceled = true;
|
|
85
|
+
|
|
86
|
+
this._debug(`<${this.id}>`, 'cancel');
|
|
87
|
+
this.emit('cancel', this);
|
|
88
|
+
|
|
89
|
+
this.takeAllOutbound();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
internals.Activity.prototype.onInbound = function(flow) {
|
|
93
|
+
if (flow.discarded) {
|
|
94
|
+
return discardedInbound.apply(this, arguments);
|
|
95
|
+
}
|
|
96
|
+
const message = this.getInput();
|
|
97
|
+
return this.run(message);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
internals.Activity.prototype.onLoopedInbound = function() {
|
|
101
|
+
if (this.entered) this.leave();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
internals.Activity.prototype.discard = function(flow, rootFlow) {
|
|
105
|
+
if (!this.entered) this.enter(flow);
|
|
106
|
+
return this.discardAllOutbound(rootFlow);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
function discardedInbound(flow, rootFlow) {
|
|
110
|
+
if (!this.multipleInbound) {
|
|
111
|
+
return this.discard(flow, rootFlow);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!this.pendingDiscard) {
|
|
115
|
+
this._debug(`<${this.id}>`, `pending inbound from discarded <${flow.id}>`);
|
|
116
|
+
this.pendingDiscard = true;
|
|
117
|
+
|
|
118
|
+
// Remove one since one inbound flow must have been taken
|
|
119
|
+
this.pendingLength = this.inbound.length - 1;
|
|
120
|
+
|
|
121
|
+
// Emit leave because we are not waiting for discarded flow
|
|
122
|
+
this.emit('leave', this);
|
|
123
|
+
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
this.pendingLength--;
|
|
129
|
+
this._debug(`<${this.id}>`, `inbound from discarded <${flow.id}> - pending ${this.pendingLength}`);
|
|
130
|
+
if (this.pendingLength === 0) {
|
|
131
|
+
this.discard(flow, rootFlow);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
internals.Activity.prototype.takeAllOutbound = function(message) {
|
|
136
|
+
if (!this.isEnd) {
|
|
137
|
+
this._debug(`<${this.id}>`, `take all outbound (${this.outbound.length})`);
|
|
138
|
+
this.outbound.forEach((flow) => flow.take(message));
|
|
139
|
+
}
|
|
140
|
+
this.leave();
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
internals.Activity.prototype.discardAllOutbound = function(rootFlow) {
|
|
144
|
+
if (!this.isEnd) {
|
|
145
|
+
this._debug(`<${this.id}>`, `discard all outbound (${this.outbound.length})`);
|
|
146
|
+
this.outbound.forEach((flow) => {
|
|
147
|
+
flow.discard(rootFlow);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
this.leave(rootFlow);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
internals.Activity.prototype.setupInboundListeners = function() {
|
|
154
|
+
if (!this.inbound.length) return;
|
|
155
|
+
if (this._onInbound) return;
|
|
156
|
+
this._onInbound = this.onInbound.bind(this);
|
|
157
|
+
this._onLoopedInbound = this.onLoopedInbound.bind(this);
|
|
158
|
+
|
|
159
|
+
this.inbound.forEach((flow) => {
|
|
160
|
+
flow.on('taken', this._onInbound);
|
|
161
|
+
flow.on('discarded', this._onInbound);
|
|
162
|
+
flow.on('looped', this._onLoopedInbound);
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
internals.Activity.prototype.teardownInboundListeners = function() {
|
|
167
|
+
if (!this._onInbound) return;
|
|
168
|
+
this.inbound.forEach((flow) => {
|
|
169
|
+
flow.removeListener('taken', this._onInbound);
|
|
170
|
+
flow.removeListener('discarded', this._onInbound);
|
|
171
|
+
flow.removeListener('looped', this._onLoopedInbound);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
delete this._onInbound;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
internals.Activity.prototype.getOutput = function(message) {
|
|
178
|
+
if (!this.io) return message;
|
|
179
|
+
return this.io.getOutput(message);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
internals.Activity.prototype.getInput = function(message) {
|
|
183
|
+
if (!this.io) return message;
|
|
184
|
+
return this.io.getInput(message);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
internals.Activity.prototype.getState = function() {
|
|
188
|
+
const result = {
|
|
189
|
+
id: this.id,
|
|
190
|
+
type: this.type,
|
|
191
|
+
entered: this.entered
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
if (this.taken !== undefined) {
|
|
195
|
+
result.taken = this.taken;
|
|
196
|
+
}
|
|
197
|
+
if (this.canceled !== undefined) {
|
|
198
|
+
result.canceled = this.canceled;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return result;
|
|
202
|
+
};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Context = require('../Context');
|
|
4
|
+
const BaseTask = require('./BaseTask');
|
|
5
|
+
|
|
6
|
+
function BaseProcess(activity, moddleOrParentContext, options) {
|
|
7
|
+
this.isMainProcess = !isSubProcess(moddleOrParentContext);
|
|
8
|
+
this.context = new Context(activity.id, (this.isMainProcess ? moddleOrParentContext : moddleOrParentContext.moddleContext), options);
|
|
9
|
+
this.listener = options.listener;
|
|
10
|
+
this.pendingActivities = [];
|
|
11
|
+
|
|
12
|
+
BaseTask.call(this, activity, (this.isMainProcess ? this.context : moddleOrParentContext), options);
|
|
13
|
+
|
|
14
|
+
this._debug(`<${activity.id}>`, 'init', !this.isMainProcess ? 'sub process' : 'main process');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
BaseProcess.prototype = Object.create(BaseTask.prototype);
|
|
18
|
+
|
|
19
|
+
BaseProcess.prototype.execute = function(message) {
|
|
20
|
+
this._debug(`<${this.id}>`, 'execute');
|
|
21
|
+
this.isEnded = false;
|
|
22
|
+
|
|
23
|
+
this.context.applyMessage(message);
|
|
24
|
+
|
|
25
|
+
activateAllChildren.call(this);
|
|
26
|
+
|
|
27
|
+
this.pendingActivities = this.context.startActivities.map(c => {
|
|
28
|
+
return {
|
|
29
|
+
type: c.type,
|
|
30
|
+
id: c.id
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
this.emit('start', this);
|
|
35
|
+
if (this.isMainProcess) {
|
|
36
|
+
emitListenerEvent.call(this, 'start', this);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if(this.type == 'bpmn:SubProcess'){
|
|
40
|
+
this.waiting = true;
|
|
41
|
+
this.emit('wait', this);
|
|
42
|
+
}else{
|
|
43
|
+
if (this.context.childCount === 0) {
|
|
44
|
+
return this.completeProcess(this.context.variables);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
this.context.startActivities.forEach((activity) =>activity.run());
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
BaseProcess.prototype.completeProcess = function() {
|
|
52
|
+
this._debug(`<${this.id}>`, 'complete');
|
|
53
|
+
deactivateAllChildren.call(this);
|
|
54
|
+
|
|
55
|
+
this.variables = this.context.variables;
|
|
56
|
+
this.isEnded = true;
|
|
57
|
+
|
|
58
|
+
this.complete.call(this, this.variables);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
BaseProcess.prototype.cancel = function() {
|
|
62
|
+
deactivateAllChildren.call(this);
|
|
63
|
+
BaseTask.prototype.cancel.apply(this, arguments);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
BaseProcess.prototype.signal = function(childId, input) {
|
|
67
|
+
this._debug(`<${this.id}>`, `signal <${childId}>`);
|
|
68
|
+
|
|
69
|
+
if(this.waiting){
|
|
70
|
+
this.waiting = false;
|
|
71
|
+
if (this.context.childCount === 0) {
|
|
72
|
+
return this.completeProcess(this.context.variables);
|
|
73
|
+
}
|
|
74
|
+
this.context.startActivities.forEach((activity) =>
|
|
75
|
+
activity.run()
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
const child = this.getChildActivityById(childId);
|
|
79
|
+
if (child.isStartEvent) {
|
|
80
|
+
this.context.applyMessage(input);
|
|
81
|
+
return this.run();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (child.isStart && !this.entered) {
|
|
85
|
+
this.run();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
child.signal(input);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
BaseProcess.prototype.getChildActivityById = function(childId) {
|
|
93
|
+
return this.context.getChildActivityById(childId);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
BaseProcess.prototype.onChildEnter = async function(activity) {
|
|
97
|
+
this._debug(`<${this.id}>`, `enter <${activity.id}> (${activity.type})`);
|
|
98
|
+
|
|
99
|
+
this.pendingActivities.push({
|
|
100
|
+
id: activity.id
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
await emitListenerEvent.call(this, 'enter', activity);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
BaseProcess.prototype.onChildStart = function(activity) {
|
|
107
|
+
emitListenerEvent.call(this, 'start', activity);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
BaseProcess.prototype.onChildCancel = function(activity) {
|
|
111
|
+
emitListenerEvent.call(this, 'cancel', activity);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
BaseProcess.prototype.onChildWait = function(activity) {
|
|
115
|
+
this._debug(`<${this.id}>`, `wait for <${activity.id}> (${activity.type})`);
|
|
116
|
+
emitListenerEvent.call(this, 'wait', activity);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
BaseProcess.prototype.onChildEnd = function(activity, output) {
|
|
120
|
+
if (output) {
|
|
121
|
+
if ((activity.io && activity.io.hasOutput) || activity.saveToVariables) {
|
|
122
|
+
this._debug(`<${this.id}>`, `saving data from <${activity.id}> to variables`);
|
|
123
|
+
this.context.applyMessage(output);
|
|
124
|
+
} else {
|
|
125
|
+
this.context.saveChildOutput(activity.id, output);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
emitListenerEvent.call(this, 'end', activity, output);
|
|
130
|
+
|
|
131
|
+
if (activity.terminate) {
|
|
132
|
+
this.completeProcess();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
BaseProcess.prototype.onChildLeave = function(activity) {
|
|
137
|
+
this.pendingActivities = this.pendingActivities.filter((c) => c.id !== activity.id);
|
|
138
|
+
|
|
139
|
+
this._debug(`<${this.id}>`, `left <${activity.id}> (${activity.type}), pending activities ${this.pendingActivities.length}`);
|
|
140
|
+
emitListenerEvent.call(this, 'leave', activity);
|
|
141
|
+
|
|
142
|
+
if (this.pendingActivities.length === 0) {
|
|
143
|
+
this.completeProcess();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
BaseProcess.prototype.onChildError = function(err, child) {
|
|
148
|
+
deactivateAllChildren.call(this);
|
|
149
|
+
this.emit('error', err, child, this);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
BaseProcess.prototype.onMessage = function(message, via) {
|
|
153
|
+
this._debug(`<${this.id}>`, `message sent via <${via.id}> (${via.type})`);
|
|
154
|
+
this.emit('message', this, message, via);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
BaseProcess.prototype.onFlowDiscarded = function(flow) {
|
|
158
|
+
emitListenerEvent.call(this, 'discarded', flow);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
BaseProcess.prototype.onFlowTaken = function(flow) {
|
|
162
|
+
emitListenerEvent.call(this, 'taken', flow);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
BaseProcess.prototype.getState = function() {
|
|
166
|
+
const state = BaseTask.prototype.getState.call(this);
|
|
167
|
+
Object.assign(state, this.context.getState());
|
|
168
|
+
return state;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
BaseProcess.prototype.getPendingActivities = function() {
|
|
172
|
+
return this.context.getPendingActivities();
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
BaseProcess.prototype.resume = function(state) {
|
|
176
|
+
this._debug(`<${this.id}>`, 'resume', state.entered ? 'execution' : 'state');
|
|
177
|
+
this.context.resume(state);
|
|
178
|
+
this.entered = state.entered;
|
|
179
|
+
|
|
180
|
+
if (this.entered) {
|
|
181
|
+
activateAllChildren.call(this);
|
|
182
|
+
this.emit('enter', this);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const resumeStates = state.children.reduce((result, childState) => {
|
|
186
|
+
if (childState.entered && childState.pendingJoin) {
|
|
187
|
+
// Pending joins
|
|
188
|
+
result.pre.push(childState);
|
|
189
|
+
} else if (childState.attachedToId) {
|
|
190
|
+
// Boundary events
|
|
191
|
+
result.pre.push(childState);
|
|
192
|
+
} else {
|
|
193
|
+
result.post.push(childState);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return result;
|
|
197
|
+
}, {
|
|
198
|
+
pre: [],
|
|
199
|
+
post: []
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
resumeStates.pre.forEach((childState) => {
|
|
203
|
+
this.getChildActivityById(childState.id).resume(childState);
|
|
204
|
+
});
|
|
205
|
+
resumeStates.post.forEach((childState) => {
|
|
206
|
+
this.getChildActivityById(childState.id).resume(childState);
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
BaseProcess.prototype.deactivate = function() {
|
|
211
|
+
deactivateAllChildren.call(this);
|
|
212
|
+
BaseTask.prototype.deactivate.apply(this, arguments);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
function isSubProcess(context) {
|
|
216
|
+
return context instanceof Context;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function activateAllChildren() {
|
|
220
|
+
const scope = this;
|
|
221
|
+
|
|
222
|
+
scope._onChildEnter = scope.onChildEnter.bind(scope);
|
|
223
|
+
scope._onChildStart = scope.onChildStart.bind(scope);
|
|
224
|
+
scope._onChildWait = scope.onChildWait.bind(scope);
|
|
225
|
+
scope._onChildEnd = scope.onChildEnd.bind(scope);
|
|
226
|
+
scope._onChildCancel = scope.onChildCancel.bind(scope);
|
|
227
|
+
scope._onChildLeave = scope.onChildLeave.bind(scope);
|
|
228
|
+
scope._onChildError = scope.onChildError.bind(scope);
|
|
229
|
+
scope._onMessage = scope.onMessage.bind(scope);
|
|
230
|
+
scope._onFlowDiscarded = scope.onFlowDiscarded.bind(scope);
|
|
231
|
+
scope._onFlowTaken = scope.onFlowTaken.bind(scope);
|
|
232
|
+
|
|
233
|
+
Object.keys(scope.context.children).forEach((id) => {
|
|
234
|
+
const activity = scope.context.children[id];
|
|
235
|
+
setupChildActivity.call(scope, activity);
|
|
236
|
+
activity.activate();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
scope.context.messageFlows.forEach((flow) => {
|
|
240
|
+
flow.on('message', this._onMessage);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
scope.context.sequenceFlows.forEach((flow) => {
|
|
244
|
+
setupFlowActivity.call(scope, flow);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function deactivateAllChildren() {
|
|
249
|
+
if (!this.entered) return;
|
|
250
|
+
|
|
251
|
+
Object.keys(this.context.children).forEach((id) => {
|
|
252
|
+
const child = this.context.children[id];
|
|
253
|
+
teardownChildActivity.call(this, child);
|
|
254
|
+
child.deactivate();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
this.context.sequenceFlows.forEach((flow) => {
|
|
258
|
+
teardownFlowActivity.call(this, flow);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function setupChildActivity(activity) {
|
|
263
|
+
const self = this;
|
|
264
|
+
this._debug(`<${self.id}>`, `setup <${activity.id}>`);
|
|
265
|
+
|
|
266
|
+
activity.on('enter', this._onChildEnter);
|
|
267
|
+
activity.on('start', this._onChildStart);
|
|
268
|
+
activity.on('wait', this._onChildWait);
|
|
269
|
+
activity.on('cancel', this._onChildCancel);
|
|
270
|
+
activity.on('end', this._onChildEnd);
|
|
271
|
+
activity.on('leave', this._onChildLeave);
|
|
272
|
+
|
|
273
|
+
if (!this.context.hasAttachedErrorEvent(activity.id)) {
|
|
274
|
+
activity.on('error', this._onChildError);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function teardownChildActivity(activity) {
|
|
279
|
+
this._debug(`<${this.id}>`, `tear down <${activity.id}>`);
|
|
280
|
+
|
|
281
|
+
activity.removeListener('enter', this._onChildEnter);
|
|
282
|
+
activity.removeListener('start', this._onChildStart);
|
|
283
|
+
activity.removeListener('wait', this._onChildWait);
|
|
284
|
+
activity.removeListener('cancel', this._onChildCancel);
|
|
285
|
+
activity.removeListener('end', this._onChildEnd);
|
|
286
|
+
activity.removeListener('leave', this._onChildLeave);
|
|
287
|
+
activity.removeListener('error', this._onChildError);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function setupFlowActivity(flow) {
|
|
291
|
+
flow.on('taken', this._onFlowTaken);
|
|
292
|
+
flow.on('discarded', this._onFlowDiscarded);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function teardownFlowActivity(flow) {
|
|
296
|
+
flow.removeListener('taken', this._onFlowTaken);
|
|
297
|
+
flow.removeListener('discarded', this._onFlowDiscarded);
|
|
298
|
+
flow.removeListener('message', this._onMessage);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function emitListenerEvent(eventName, activity, parent) {
|
|
302
|
+
if (!this.listener) return;
|
|
303
|
+
if (!parent) parent = this;
|
|
304
|
+
this.listener.emit(`${eventName}-${activity.id}`, activity, parent);
|
|
305
|
+
this.listener.emit(eventName, activity, parent);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
module.exports = BaseProcess;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Activity = require('./Activity');
|
|
4
|
+
const async = require('async');
|
|
5
|
+
const PrematureStopError = require('../PrematureStopError');
|
|
6
|
+
|
|
7
|
+
function BaseTask() {
|
|
8
|
+
Activity.apply(this, arguments);
|
|
9
|
+
this.loop = this.parentContext.getLoopCharacteristics(this.activity.loopCharacteristics);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
BaseTask.prototype = Object.create(Activity.prototype);
|
|
13
|
+
|
|
14
|
+
BaseTask.prototype.run = function(message) {
|
|
15
|
+
Activity.prototype.run.apply(this, arguments);
|
|
16
|
+
|
|
17
|
+
this.inboundMessage = message;
|
|
18
|
+
|
|
19
|
+
if (this.loop) {
|
|
20
|
+
this.loop.completed = false;
|
|
21
|
+
this.loop.stop = false;
|
|
22
|
+
return this.runLoop(message, (err, output) => { // eslint-disable-line handle-callback-err
|
|
23
|
+
this.complete = BaseTask.prototype.complete.bind(this);
|
|
24
|
+
if (!(err instanceof PrematureStopError)) {
|
|
25
|
+
this.loop.reset();
|
|
26
|
+
} else {
|
|
27
|
+
this._debug(`<${this.id}>`, 'prematurely stopped');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.complete(output);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this._debug(`<${this.id}>`, 'run');
|
|
35
|
+
this.execute(message);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
BaseTask.prototype.execute = function() {
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
BaseTask.prototype.runLoop = function(message, callback) {
|
|
42
|
+
return sequentialLoop.call(this, message, callback);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
BaseTask.prototype.complete = function(loopCallbackOrOutput, output) {
|
|
46
|
+
if (typeof loopCallbackOrOutput !== 'function') {
|
|
47
|
+
output = loopCallbackOrOutput;
|
|
48
|
+
loopCallbackOrOutput = null;
|
|
49
|
+
}
|
|
50
|
+
const ioOutput = this.getOutput(output);
|
|
51
|
+
|
|
52
|
+
this.emit('end', this, ioOutput);
|
|
53
|
+
|
|
54
|
+
if (this.loop && !this.loop.completed) {
|
|
55
|
+
return loopCallbackOrOutput(null, ioOutput);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.takeAllOutbound(ioOutput);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
BaseTask.prototype.deactivate = function() {
|
|
62
|
+
Activity.prototype.deactivate.apply(this, arguments);
|
|
63
|
+
if (this.loop) {
|
|
64
|
+
this.loop.deactivate();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
BaseTask.prototype.getState = function() {
|
|
69
|
+
const state = Activity.prototype.getState.apply(this, arguments);
|
|
70
|
+
if (this.loop) state.loop = this.loop.getState();
|
|
71
|
+
return state;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
BaseTask.prototype.resume = function(state) {
|
|
75
|
+
if (this.loop) {
|
|
76
|
+
this.loop.resume(state.loop);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Activity.prototype.resume.apply(this, arguments);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
function sequentialLoop() {
|
|
83
|
+
if (this.loop.characteristics.type === 'collection') {
|
|
84
|
+
sequentialCollectionLoop.apply(this, arguments);
|
|
85
|
+
} else {
|
|
86
|
+
sequentialConditionLoop.apply(this, arguments);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function sequentialConditionLoop(message, callback) {
|
|
91
|
+
const scope = this;
|
|
92
|
+
const loopDef = scope.loop;
|
|
93
|
+
const executionContext = scope.parentContext.getFrozenVariablesAndServices(Object.assign({id: this.id, process: this}, {}));
|
|
94
|
+
|
|
95
|
+
const testFn = loopDef.run.bind(loopDef, executionContext, scope.inboundMessage);
|
|
96
|
+
|
|
97
|
+
function executeFn(next) {
|
|
98
|
+
scope._debug(`<${scope.id}>`, `iteration ${loopDef.iteration} in sequential loop`);
|
|
99
|
+
|
|
100
|
+
const messageScope = Object.assign({}, message);
|
|
101
|
+
messageScope.loop = true;
|
|
102
|
+
messageScope.index = loopDef.iteration;
|
|
103
|
+
|
|
104
|
+
scope.complete = BaseTask.prototype.complete.bind(scope, next);
|
|
105
|
+
|
|
106
|
+
scope.execute(messageScope);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async.doUntil(executeFn, testFn, callback);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function sequentialCollectionLoop(message, callback) {
|
|
113
|
+
const scope = this;
|
|
114
|
+
|
|
115
|
+
const loopDef = scope.loop;
|
|
116
|
+
const collection = loopDef.getCollection();
|
|
117
|
+
const executionContext = scope.parentContext.getVariablesAndServices();
|
|
118
|
+
|
|
119
|
+
function executeFn(item, next) {
|
|
120
|
+
scope._debug(`<${scope.id}>`, `iteration ${loopDef.iteration} in sequential collection loop`);
|
|
121
|
+
|
|
122
|
+
const messageScope = Object.assign({}, message);
|
|
123
|
+
messageScope.loop = true;
|
|
124
|
+
messageScope.index = loopDef.iteration;
|
|
125
|
+
messageScope.item = item;
|
|
126
|
+
|
|
127
|
+
scope.complete = BaseTask.prototype.complete.bind(scope, getLoopCallback(loopDef, executionContext, scope.inboundMessage, next));
|
|
128
|
+
|
|
129
|
+
scope.execute(messageScope);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async.eachSeries(collection, executeFn, callback);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getLoopCallback(loopDef, executionContext, inboundMessage, callback) {
|
|
136
|
+
return (err, result) => {
|
|
137
|
+
if (err) return callback(err, result);
|
|
138
|
+
|
|
139
|
+
loopDef.run(executionContext, inboundMessage, result, (loopErr) => {
|
|
140
|
+
callback(loopErr, result);
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = BaseTask;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const mapper = require('../mapper');
|
|
4
|
+
|
|
5
|
+
function BoundaryEvent(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 = BoundaryEvent;
|