@logicflow/engine 0.0.8 → 0.0.10-beta.0

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.
Files changed (190) hide show
  1. package/README.md +5 -2
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.map +1 -0
  4. package/es/EventEmitter.d.ts +34 -4
  5. package/es/EventEmitter.js +70 -48
  6. package/es/EventEmitter.js.map +1 -0
  7. package/es/FlowModel.d.ts +75 -73
  8. package/es/FlowModel.js +130 -173
  9. package/es/FlowModel.js.map +1 -0
  10. package/es/Scheduler.d.ts +50 -34
  11. package/es/Scheduler.js +134 -209
  12. package/es/Scheduler.js.map +1 -0
  13. package/es/constant/{constant.js → index.js} +8 -7
  14. package/es/constant/index.js.map +1 -0
  15. package/es/constant/logCode.js +29 -0
  16. package/es/constant/logCode.js.map +1 -0
  17. package/es/expression/brewserVm.d.ts +2 -0
  18. package/es/expression/brewserVm.js +30 -0
  19. package/es/expression/brewserVm.js.map +1 -0
  20. package/es/expression/index.d.ts +1 -1
  21. package/es/expression/index.js +16 -59
  22. package/es/expression/index.js.map +1 -0
  23. package/es/expression/nodeVm.d.ts +4 -2
  24. package/es/expression/nodeVm.js +10 -50
  25. package/es/expression/nodeVm.js.map +1 -0
  26. package/es/index.d.ts +135 -38
  27. package/es/index.js +93 -145
  28. package/es/index.js.map +1 -0
  29. package/es/nodes/base.d.ts +108 -0
  30. package/es/nodes/base.js +149 -0
  31. package/es/nodes/base.js.map +1 -0
  32. package/es/nodes/index.d.ts +3 -0
  33. package/es/nodes/index.js +4 -0
  34. package/es/nodes/index.js.map +1 -0
  35. package/es/nodes/{StartNode.d.ts → start.d.ts} +3 -2
  36. package/es/nodes/start.js +11 -0
  37. package/es/nodes/start.js.map +1 -0
  38. package/es/nodes/{TaskNode.d.ts → task.d.ts} +3 -2
  39. package/es/nodes/task.js +11 -0
  40. package/es/nodes/task.js.map +1 -0
  41. package/es/platform/browser/browserVm.d.ts +4 -0
  42. package/es/platform/browser/browserVm.js +44 -0
  43. package/es/platform/browser/browserVm.js.map +1 -0
  44. package/es/platform/browser/index.d.ts +4 -0
  45. package/es/platform/browser/index.js +23 -0
  46. package/es/platform/browser/index.js.map +1 -0
  47. package/es/platform/index.d.ts +1 -0
  48. package/es/platform/index.js +2 -0
  49. package/es/platform/index.js.map +1 -0
  50. package/es/platform/node/index.d.ts +4 -0
  51. package/es/platform/node/index.js +23 -0
  52. package/es/platform/node/index.js.map +1 -0
  53. package/es/platform/node/nodeVm.d.ts +1 -0
  54. package/es/platform/node/nodeVm.js +9 -0
  55. package/es/platform/node/nodeVm.js.map +1 -0
  56. package/es/recorder/index.d.ts +36 -10
  57. package/es/recorder/index.js +82 -135
  58. package/es/recorder/index.js.map +1 -0
  59. package/es/utils/global.d.ts +5 -0
  60. package/es/utils/global.js +27 -0
  61. package/es/utils/global.js.map +1 -0
  62. package/es/utils/id.js +14 -0
  63. package/es/utils/id.js.map +1 -0
  64. package/es/utils/index.d.ts +4 -0
  65. package/es/utils/index.js +5 -0
  66. package/es/utils/index.js.map +1 -0
  67. package/es/{util → utils}/storage.js +17 -16
  68. package/es/utils/storage.js.map +1 -0
  69. package/lib/EventEmitter.d.ts +37 -0
  70. package/lib/EventEmitter.js +94 -0
  71. package/lib/EventEmitter.js.map +1 -0
  72. package/lib/FlowModel.d.ts +146 -0
  73. package/lib/FlowModel.js +236 -0
  74. package/lib/FlowModel.js.map +1 -0
  75. package/lib/Scheduler.d.ts +78 -0
  76. package/lib/Scheduler.js +179 -0
  77. package/lib/Scheduler.js.map +1 -0
  78. package/lib/constant/index.d.ts +16 -0
  79. package/{cjs/constant/constant.js → lib/constant/index.js} +4 -3
  80. package/lib/constant/index.js.map +1 -0
  81. package/lib/constant/logCode.d.ts +12 -0
  82. package/{cjs/constant/LogCode.js → lib/constant/logCode.js} +16 -13
  83. package/lib/constant/logCode.js.map +1 -0
  84. package/lib/expression/brewserVm.d.ts +2 -0
  85. package/lib/expression/brewserVm.js +33 -0
  86. package/lib/expression/brewserVm.js.map +1 -0
  87. package/lib/expression/index.d.ts +2 -0
  88. package/lib/expression/index.js +20 -0
  89. package/lib/expression/index.js.map +1 -0
  90. package/lib/expression/nodeVm.d.ts +4 -0
  91. package/lib/expression/nodeVm.js +13 -0
  92. package/lib/expression/nodeVm.js.map +1 -0
  93. package/lib/index.d.ts +157 -0
  94. package/lib/index.js +159 -0
  95. package/lib/index.js.map +1 -0
  96. package/lib/nodes/base.d.ts +108 -0
  97. package/lib/nodes/base.js +152 -0
  98. package/lib/nodes/base.js.map +1 -0
  99. package/lib/nodes/index.d.ts +3 -0
  100. package/lib/nodes/index.js +7 -0
  101. package/lib/nodes/index.js.map +1 -0
  102. package/lib/nodes/start.d.ts +6 -0
  103. package/lib/nodes/start.js +15 -0
  104. package/lib/nodes/start.js.map +1 -0
  105. package/lib/nodes/task.d.ts +6 -0
  106. package/lib/nodes/task.js +15 -0
  107. package/lib/nodes/task.js.map +1 -0
  108. package/lib/platform/browser/browserVm.d.ts +4 -0
  109. package/lib/platform/browser/browserVm.js +49 -0
  110. package/lib/platform/browser/browserVm.js.map +1 -0
  111. package/lib/platform/browser/index.d.ts +4 -0
  112. package/lib/platform/browser/index.js +28 -0
  113. package/lib/platform/browser/index.js.map +1 -0
  114. package/lib/platform/index.d.ts +1 -0
  115. package/lib/platform/index.js +5 -0
  116. package/lib/platform/index.js.map +1 -0
  117. package/lib/platform/node/index.d.ts +4 -0
  118. package/lib/platform/node/index.js +28 -0
  119. package/lib/platform/node/index.js.map +1 -0
  120. package/lib/platform/node/nodeVm.d.ts +1 -0
  121. package/lib/platform/node/nodeVm.js +13 -0
  122. package/lib/platform/node/nodeVm.js.map +1 -0
  123. package/lib/recorder/index.d.ts +46 -0
  124. package/lib/recorder/index.js +117 -0
  125. package/lib/recorder/index.js.map +1 -0
  126. package/lib/utils/global.d.ts +5 -0
  127. package/lib/utils/global.js +31 -0
  128. package/lib/utils/global.js.map +1 -0
  129. package/lib/utils/id.d.ts +3 -0
  130. package/lib/utils/id.js +20 -0
  131. package/lib/utils/id.js.map +1 -0
  132. package/lib/utils/index.d.ts +4 -0
  133. package/lib/utils/index.js +9 -0
  134. package/lib/utils/index.js.map +1 -0
  135. package/lib/utils/storage.d.ts +7 -0
  136. package/{cjs/util → lib/utils}/storage.js +18 -17
  137. package/lib/utils/storage.js.map +1 -0
  138. package/package.json +30 -71
  139. package/src/EventEmitter.ts +103 -0
  140. package/src/FlowModel.ts +325 -0
  141. package/src/Scheduler.ts +244 -0
  142. package/src/constant/index.ts +23 -0
  143. package/src/constant/logCode.ts +34 -0
  144. package/src/expression/brewserVm.ts +36 -0
  145. package/src/expression/index.ts +17 -0
  146. package/src/expression/nodeVm.ts +14 -0
  147. package/src/index.ts +300 -0
  148. package/src/nodes/base.ts +234 -0
  149. package/src/nodes/index.ts +3 -0
  150. package/src/nodes/start.ts +8 -0
  151. package/src/nodes/task.ts +8 -0
  152. package/src/platform/browser/browserVm.ts +52 -0
  153. package/src/platform/browser/index.ts +28 -0
  154. package/src/platform/index.ts +1 -0
  155. package/src/platform/node/index.ts +28 -0
  156. package/src/platform/node/nodeVm.ts +12 -0
  157. package/src/recorder/index.ts +137 -0
  158. package/src/typings.d.ts +0 -0
  159. package/src/utils/global.ts +41 -0
  160. package/src/utils/id.ts +16 -0
  161. package/src/utils/index.ts +5 -0
  162. package/src/utils/storage.ts +55 -0
  163. package/cjs/EventEmitter.js +0 -70
  164. package/cjs/FlowModel.js +0 -277
  165. package/cjs/Scheduler.js +0 -252
  166. package/cjs/expression/browserVm.js +0 -81
  167. package/cjs/expression/index.js +0 -63
  168. package/cjs/expression/nodeVm.js +0 -53
  169. package/cjs/index.js +0 -210
  170. package/cjs/nodes/BaseNode.js +0 -252
  171. package/cjs/nodes/StartNode.js +0 -27
  172. package/cjs/nodes/TaskNode.js +0 -27
  173. package/cjs/recorder/index.js +0 -168
  174. package/cjs/util/ID.js +0 -16
  175. package/cjs/util/global.js +0 -32
  176. package/es/constant/LogCode.js +0 -28
  177. package/es/expression/browserVm.d.ts +0 -4
  178. package/es/expression/browserVm.js +0 -76
  179. package/es/nodes/BaseNode.d.ts +0 -110
  180. package/es/nodes/BaseNode.js +0 -250
  181. package/es/nodes/StartNode.js +0 -25
  182. package/es/nodes/TaskNode.js +0 -25
  183. package/es/util/ID.js +0 -13
  184. package/es/util/global.d.ts +0 -5
  185. package/es/util/global.js +0 -26
  186. package/lib/main.js +0 -1
  187. /package/es/constant/{constant.d.ts → index.d.ts} +0 -0
  188. /package/es/constant/{LogCode.d.ts → logCode.d.ts} +0 -0
  189. /package/es/{util/ID.d.ts → utils/id.d.ts} +0 -0
  190. /package/es/{util → utils}/storage.d.ts +0 -0
@@ -1,168 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- var storage_1 = require("../util/storage");
40
- var LOGICFLOW_ENGINE_INSTANCES = 'LOGICFLOW_ENGINE_INSTANCES';
41
- var MAX_RECORDER = 100;
42
- var MAX_INSTANCE = 100;
43
- var Recorder = /** @class */ (function () {
44
- function Recorder(_a) {
45
- var instanceId = _a.instanceId;
46
- this.maxRecorder = MAX_RECORDER;
47
- this.instanceId = instanceId;
48
- var instances = this.getItem(LOGICFLOW_ENGINE_INSTANCES) || [];
49
- if (instances.indexOf(instanceId) === -1) {
50
- instances.push(instanceId);
51
- }
52
- if (instances.length > MAX_INSTANCE) {
53
- var clearInstance = instances.shift();
54
- this.clearInstance(clearInstance);
55
- }
56
- this.setItem(LOGICFLOW_ENGINE_INSTANCES, instances);
57
- }
58
- Recorder.prototype.setMaxRecorderNumber = function (maxRecorder) {
59
- this.maxRecorder = maxRecorder;
60
- };
61
- // 将存储 storage 的方法收敛到此处,并在此处做异常处理 - setItem
62
- Recorder.prototype.setItem = function (key, value) {
63
- try {
64
- storage_1.default.setItem(key, value);
65
- }
66
- catch (error) {
67
- console.log('Ops, something wrong with storage.setItem');
68
- storage_1.default.clear();
69
- storage_1.default.setItem(key, value);
70
- }
71
- };
72
- // getItem 方法
73
- Recorder.prototype.getItem = function (key) {
74
- return storage_1.default.getItem(key);
75
- };
76
- /*
77
- * @param {Object} action
78
- * {
79
- * actionId: '',
80
- * nodeId: '',
81
- * executionId: '',
82
- * nodeType: '',
83
- * timestamp: '',
84
- * properties: {},
85
- * }
86
- */
87
- Recorder.prototype.addActionRecord = function (action) {
88
- return __awaiter(this, void 0, void 0, function () {
89
- var executionId, actionId, instanceData;
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0:
93
- executionId = action.executionId, actionId = action.actionId;
94
- return [4 /*yield*/, this.getExecutionActions(executionId)];
95
- case 1:
96
- instanceData = _a.sent();
97
- if (!instanceData) {
98
- this.pushExecution(executionId);
99
- }
100
- this.pushActionToExecution(executionId, actionId);
101
- this.setItem(actionId, action);
102
- return [2 /*return*/];
103
- }
104
- });
105
- });
106
- };
107
- Recorder.prototype.getActionRecord = function (actionId) {
108
- return __awaiter(this, void 0, void 0, function () {
109
- return __generator(this, function (_a) {
110
- return [2 /*return*/, this.getItem(actionId)];
111
- });
112
- });
113
- };
114
- Recorder.prototype.getExecutionActions = function (executionId) {
115
- return __awaiter(this, void 0, void 0, function () {
116
- return __generator(this, function (_a) {
117
- return [2 /*return*/, this.getItem(executionId)];
118
- });
119
- });
120
- };
121
- Recorder.prototype.getExecutionList = function () {
122
- return __awaiter(this, void 0, void 0, function () {
123
- var instances;
124
- return __generator(this, function (_a) {
125
- instances = this.getItem(this.instanceId) || [];
126
- return [2 /*return*/, instances];
127
- });
128
- });
129
- };
130
- Recorder.prototype.clear = function () {
131
- this.clearInstance(this.instanceId);
132
- };
133
- Recorder.prototype.clearInstance = function (instanceId) {
134
- var _this = this;
135
- var instanceExecutions = this.getItem(instanceId) || [];
136
- instanceExecutions.forEach(function (executionId) {
137
- storage_1.default.removeItem(executionId);
138
- var instanceData = _this.getItem(executionId) || [];
139
- instanceData.forEach(function (actionId) {
140
- storage_1.default.removeItem(actionId);
141
- });
142
- });
143
- storage_1.default.removeItem(instanceId);
144
- };
145
- Recorder.prototype.pushExecution = function (executionId) {
146
- var instanceExecutions = this.getItem(this.instanceId) || [];
147
- if (instanceExecutions.length >= this.maxRecorder) {
148
- var removeItem = instanceExecutions.shift();
149
- this.popExecution(removeItem);
150
- }
151
- instanceExecutions.push(executionId);
152
- this.setItem(this.instanceId, instanceExecutions);
153
- };
154
- Recorder.prototype.popExecution = function (executionId) {
155
- var instanceData = this.getItem(executionId) || [];
156
- instanceData.forEach(function (actionId) {
157
- storage_1.default.removeItem(actionId);
158
- });
159
- storage_1.default.removeItem(executionId);
160
- };
161
- Recorder.prototype.pushActionToExecution = function (executionId, actionId) {
162
- var actions = this.getItem(executionId) || [];
163
- actions.push(actionId);
164
- this.setItem(executionId, actions);
165
- };
166
- return Recorder;
167
- }());
168
- exports.default = Recorder;
package/cjs/util/ID.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEngineId = exports.createActionId = exports.createExecId = void 0;
4
- var uuid_1 = require("uuid");
5
- exports.createExecId = function () {
6
- var uuid = uuid_1.v4();
7
- return "exec-" + uuid;
8
- };
9
- exports.createActionId = function () {
10
- var uuid = uuid_1.v4();
11
- return "action-" + uuid;
12
- };
13
- exports.createEngineId = function () {
14
- var uuid = uuid_1.v4();
15
- return "engine-" + uuid;
16
- };
@@ -1,32 +0,0 @@
1
- "use strict";
2
- // The one and only way of getting global scope in all environments
3
- // https://stackoverflow.com/q/3277182/1008999
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.isInNodeJS = exports.isInWebWorker = exports.isInBrowser = exports.globalScope = void 0;
6
- var isInBrowser = typeof window === 'object' && window.window === window;
7
- exports.isInBrowser = isInBrowser;
8
- var isInNodeJS = typeof global === 'object' && global.global === global;
9
- exports.isInNodeJS = isInNodeJS;
10
- // eslint-disable-next-line no-restricted-globals
11
- var isInWebWorker = !isInBrowser && typeof self === 'object' && self.constructor;
12
- exports.isInWebWorker = isInWebWorker;
13
- var globalScope = (function () {
14
- if (isInBrowser) {
15
- return window;
16
- }
17
- // eslint-disable-next-line no-restricted-globals
18
- if (typeof self === 'object' && self.self === self) { // web workers
19
- // eslint-disable-next-line no-restricted-globals
20
- return self;
21
- }
22
- if (isInNodeJS) {
23
- return global;
24
- }
25
- if (typeof globalThis === 'object') {
26
- return globalThis;
27
- }
28
- return {
29
- eval: function () { return undefined; },
30
- };
31
- })();
32
- exports.globalScope = globalScope;
@@ -1,28 +0,0 @@
1
- var _a, _b;
2
- export var ErrorCode;
3
- (function (ErrorCode) {
4
- // 模型数据错误
5
- ErrorCode[ErrorCode["NONE_START_NODE"] = 1000] = "NONE_START_NODE";
6
- ErrorCode[ErrorCode["NONE_NODE_ID"] = 1001] = "NONE_NODE_ID";
7
- // 表达式错误
8
- ErrorCode[ErrorCode["NO_DOCUMENT_BODY"] = 2001] = "NO_DOCUMENT_BODY";
9
- })(ErrorCode || (ErrorCode = {}));
10
- export var WarningCode;
11
- (function (WarningCode) {
12
- WarningCode[WarningCode["NONE_START_NODE_IN_DATA"] = 2000] = "NONE_START_NODE_IN_DATA";
13
- WarningCode[WarningCode["START_NODE_INCOMING"] = 2001] = "START_NODE_INCOMING";
14
- // 表达式判断异常
15
- WarningCode[WarningCode["EXPRESSION_EXEC_ERROR"] = 3000] = "EXPRESSION_EXEC_ERROR";
16
- })(WarningCode || (WarningCode = {}));
17
- var errorMsgMapCn = (_a = {},
18
- _a[ErrorCode.NONE_START_NODE] = '未找到入度为0的节点',
19
- _a[ErrorCode.NONE_NODE_ID] = '流程数据中存在没有此节点',
20
- _a[ErrorCode.NO_DOCUMENT_BODY] = '找不到document.body, 请在DOM加载完成后再执行',
21
- _a);
22
- var warningMsgMapCn = (_b = {},
23
- _b[WarningCode.NONE_START_NODE_IN_DATA] = '初始化数据中未找到入度为0的节点',
24
- _b[WarningCode.START_NODE_INCOMING] = '开始节点不允许被连入',
25
- _b[WarningCode.EXPRESSION_EXEC_ERROR] = '表达式执行异常',
26
- _b);
27
- export var getErrorMsg = function (code) { return "error[" + code + "]: " + errorMsgMapCn[code]; };
28
- export var getWarningMsg = function (code) { return "warning[" + code + "]: " + warningMsgMapCn[code]; };
@@ -1,4 +0,0 @@
1
- declare const createContext: (globalData: any) => any;
2
- declare const runInContext: (code: any, context: any) => any;
3
- declare const runInBrowserContext: (code: string, globalData?: any) => Promise<any>;
4
- export { runInBrowserContext, createContext, runInContext, };
@@ -1,76 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import { ErrorCode, WarningCode, getErrorMsg, getWarningMsg, } from '../constant/LogCode';
38
- var createContext = function (globalData) {
39
- var iframe = document.createElement('iframe');
40
- iframe.style.display = 'none';
41
- if (!document || !document.body) {
42
- console.error(getErrorMsg(ErrorCode.NO_DOCUMENT_BODY));
43
- }
44
- document.body.appendChild(iframe);
45
- var iframeWindow = iframe.contentWindow;
46
- iframeWindow.parent = null;
47
- Object.keys(globalData).forEach(function (key) {
48
- iframeWindow[key] = globalData[key];
49
- });
50
- return iframeWindow;
51
- };
52
- var runInContext = function (code, context) {
53
- try {
54
- var iframeEval = context.eval;
55
- iframeEval.call(context, code);
56
- if (context.frameElement) {
57
- document.body.removeChild(context.frameElement);
58
- }
59
- }
60
- catch (e) {
61
- console.warn(getWarningMsg(WarningCode.EXPRESSION_EXEC_ERROR), { code: code, context: context, e: e });
62
- }
63
- return context;
64
- };
65
- var runInBrowserContext = function (code, globalData) {
66
- if (globalData === void 0) { globalData = {}; }
67
- return __awaiter(void 0, void 0, void 0, function () {
68
- var context;
69
- return __generator(this, function (_a) {
70
- context = createContext(globalData);
71
- runInContext(code, context);
72
- return [2 /*return*/, context];
73
- });
74
- });
75
- };
76
- export { runInBrowserContext, createContext, runInContext, };
@@ -1,110 +0,0 @@
1
- import type { NextActionParam, ActionResult, ExecResumeParams, ExecParams, OutgoingConfig } from '../types.d';
2
- export interface BaseNodeInterface {
3
- outgoing: Record<string, any>[];
4
- incoming: Record<string, any>[];
5
- nodeId: string;
6
- type: string;
7
- readonly baseType: string;
8
- execute(actionParam: any): Promise<NextActionParam>;
9
- }
10
- export declare type NodeConstructor = {
11
- new (config: {
12
- nodeConfig: NodeConfig;
13
- context: Record<string, any>;
14
- globalData: Record<string, any>;
15
- }): BaseNode;
16
- action(params: {
17
- executionId: string;
18
- actionId: string;
19
- nodeId: string;
20
- }): Promise<NextActionParam>;
21
- onResume(params: {
22
- executionId: string;
23
- actionId: string;
24
- nodeId: string;
25
- data?: Record<string, any>;
26
- }): Promise<void>;
27
- };
28
- export declare type IncomingConfig = {
29
- id: string;
30
- properties?: Record<string, any>;
31
- source: string;
32
- };
33
- export declare type NodeConfig = {
34
- id: string;
35
- type: string;
36
- properties?: Record<string, any>;
37
- incoming: IncomingConfig[];
38
- outgoing: OutgoingConfig[];
39
- };
40
- export default class BaseNode implements BaseNodeInterface {
41
- static nodeTypeName: string;
42
- /**
43
- * 节点的出边
44
- */
45
- outgoing: OutgoingConfig[];
46
- /**
47
- * 节点的入边
48
- */
49
- incoming: IncomingConfig[];
50
- /**
51
- * 节点的属性
52
- */
53
- properties?: Record<string, any>;
54
- nodeId: string;
55
- type: string;
56
- /**
57
- * 节点的上下文,是调用流程时传入的上下文
58
- */
59
- context: Record<string, any>;
60
- /**
61
- * 节点的全局数据,是调用流程时传入的全局数据。
62
- * 在计算表达式时,即基于全局数据进行计算。
63
- */
64
- globalData: Record<string, any>;
65
- readonly baseType: string;
66
- constructor({ nodeConfig, context, globalData }: {
67
- nodeConfig: any;
68
- context: any;
69
- globalData: any;
70
- });
71
- /**
72
- * 节点的每一次执行都会生成一个唯一的actionId
73
- */
74
- execute(params: ExecParams): Promise<NextActionParam>;
75
- /**
76
- * 节点在执行中断后,可以通过resume方法恢复执行。
77
- * 自定义节点时不建议重写此方法
78
- */
79
- resume(params: ExecResumeParams): Promise<undefined>;
80
- private getOutgoing;
81
- private isPass;
82
- /**
83
- * 节点的执行逻辑
84
- * @overridable 可以自定义节点重写此方法。
85
- * @param params.executionId 流程执行记录ID
86
- * @param params.actionId 此节点执行记录ID
87
- * @param params.nodeId 节点ID
88
- * @returns 返回下一步的执行参数
89
- * 当不返回时,表示此节点执行成功,流程会继续执行下一步。
90
- * 当返回时,返回格式
91
- */
92
- action(params: {
93
- executionId: string;
94
- actionId: string;
95
- nodeId: string;
96
- }): Promise<ActionResult>;
97
- /**
98
- * 节点的重新恢复执行逻辑
99
- * @overridable 可以自定义节点重写此方法。
100
- * @param params.executionId 流程执行记录ID
101
- * @param params.actionId 此节点执行记录ID
102
- * @param params.nodeId 节点ID
103
- */
104
- onResume(params: {
105
- executionId: string;
106
- actionId: string;
107
- nodeId: string;
108
- data?: Record<string, any>;
109
- }): Promise<void>;
110
- }