@nocobase/plugin-workflow 0.9.0-alpha.2 → 0.9.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +9 -0
  2. package/README.zh-CN.md +9 -0
  3. package/lib/client/AddButton.d.ts +1 -1
  4. package/lib/client/AddButton.js +43 -27
  5. package/lib/client/Branch.d.ts +1 -1
  6. package/lib/client/ExecutionCanvas.js +5 -10
  7. package/lib/client/WorkflowCanvas.js +12 -42
  8. package/lib/client/WorkflowProvider.js +10 -1
  9. package/lib/client/components/CollectionBlockInitializer.d.ts +7 -0
  10. package/lib/client/components/CollectionBlockInitializer.js +81 -0
  11. package/lib/client/components/CollectionFieldInitializers.d.ts +2 -0
  12. package/lib/client/components/CollectionFieldInitializers.js +89 -0
  13. package/lib/client/components/CollectionFieldset.js +25 -33
  14. package/lib/client/components/FilterDynamicComponent.d.ts +6 -0
  15. package/lib/client/components/FilterDynamicComponent.js +43 -0
  16. package/lib/client/components/NullRender.d.ts +1 -0
  17. package/lib/client/components/NullRender.js +10 -0
  18. package/lib/client/components/RadioWithTooltip.d.ts +7 -0
  19. package/lib/client/components/RadioWithTooltip.js +94 -0
  20. package/lib/client/constants.d.ts +10 -8
  21. package/lib/client/constants.js +52 -14
  22. package/lib/client/index.d.ts +0 -1
  23. package/lib/client/index.js +1 -10
  24. package/lib/client/locale/en-US.d.ts +18 -18
  25. package/lib/client/locale/en-US.js +19 -19
  26. package/lib/client/locale/zh-CN.d.ts +47 -20
  27. package/lib/client/locale/zh-CN.js +48 -21
  28. package/lib/client/nodes/calculation.d.ts +39 -7
  29. package/lib/client/nodes/calculation.js +165 -19
  30. package/lib/client/nodes/condition.d.ts +67 -4
  31. package/lib/client/nodes/condition.js +283 -31
  32. package/lib/client/nodes/create.d.ts +10 -10
  33. package/lib/client/nodes/create.js +28 -42
  34. package/lib/client/nodes/delay.d.ts +4 -4
  35. package/lib/client/nodes/delay.js +10 -8
  36. package/lib/client/nodes/destroy.d.ts +4 -7
  37. package/lib/client/nodes/destroy.js +4 -5
  38. package/lib/client/nodes/index.d.ts +10 -2
  39. package/lib/client/nodes/index.js +217 -110
  40. package/lib/client/nodes/manual/AssigneesSelect.d.ts +6 -0
  41. package/lib/client/nodes/manual/AssigneesSelect.js +65 -0
  42. package/lib/client/nodes/manual/ModeConfig.d.ts +5 -0
  43. package/lib/client/nodes/manual/ModeConfig.js +160 -0
  44. package/lib/client/nodes/manual/SchemaConfig.d.ts +6 -0
  45. package/lib/client/nodes/manual/SchemaConfig.js +715 -0
  46. package/lib/client/nodes/manual/WorkflowTodo.d.ts +8 -0
  47. package/lib/client/nodes/manual/WorkflowTodo.js +691 -0
  48. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +5 -0
  49. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +75 -0
  50. package/lib/client/nodes/manual/index.d.ts +62 -0
  51. package/lib/client/nodes/manual/index.js +137 -0
  52. package/lib/client/nodes/parallel.d.ts +12 -7
  53. package/lib/client/nodes/parallel.js +32 -39
  54. package/lib/client/nodes/query.d.ts +11 -19
  55. package/lib/client/nodes/query.js +40 -47
  56. package/lib/client/nodes/request.d.ts +77 -42
  57. package/lib/client/nodes/request.js +123 -69
  58. package/lib/client/nodes/update.d.ts +33 -29
  59. package/lib/client/nodes/update.js +14 -7
  60. package/lib/client/schemas/collection.d.ts +0 -3
  61. package/lib/client/schemas/collection.js +2 -7
  62. package/lib/client/schemas/executions.js +1 -1
  63. package/lib/client/schemas/workflows.js +1 -1
  64. package/lib/client/style.js +51 -9
  65. package/lib/client/triggers/collection.d.ts +44 -15
  66. package/lib/client/triggers/collection.js +104 -82
  67. package/lib/client/triggers/index.d.ts +6 -3
  68. package/lib/client/triggers/index.js +167 -74
  69. package/lib/client/triggers/schedule/DateFieldsSelect.js +1 -3
  70. package/lib/client/triggers/schedule/ScheduleConfig.js +15 -17
  71. package/lib/client/triggers/schedule/index.d.ts +7 -6
  72. package/lib/client/triggers/schedule/index.js +39 -81
  73. package/lib/client/utils.d.ts +1 -0
  74. package/lib/client/utils.js +38 -0
  75. package/lib/client/variable.d.ts +21 -0
  76. package/lib/client/variable.js +147 -0
  77. package/lib/server/Plugin.d.ts +3 -3
  78. package/lib/server/Plugin.js +12 -21
  79. package/lib/server/Processor.d.ts +9 -2
  80. package/lib/server/Processor.js +33 -33
  81. package/lib/server/actions/index.js +2 -4
  82. package/lib/server/actions/workflows.d.ts +1 -0
  83. package/lib/server/actions/workflows.js +80 -23
  84. package/lib/server/collections/executions.js +5 -7
  85. package/lib/server/collections/flow_nodes.js +6 -18
  86. package/lib/server/collections/jobs.js +3 -1
  87. package/lib/server/collections/workflows.js +8 -4
  88. package/lib/server/constants.d.ts +9 -3
  89. package/lib/server/constants.js +11 -5
  90. package/lib/server/functions/index.d.ts +4 -0
  91. package/lib/server/functions/index.js +38 -0
  92. package/lib/server/index.d.ts +0 -1
  93. package/lib/server/index.js +0 -14
  94. package/lib/server/instructions/calculation.d.ts +2 -7
  95. package/lib/server/instructions/calculation.js +32 -37
  96. package/lib/server/instructions/condition.d.ts +4 -4
  97. package/lib/server/instructions/condition.js +126 -54
  98. package/lib/server/instructions/index.js +1 -1
  99. package/lib/server/instructions/manual/actions.js +101 -0
  100. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts +2 -0
  101. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.js +2 -1
  102. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js +10 -10
  103. package/lib/server/instructions/manual/index.d.ts +25 -0
  104. package/lib/server/instructions/manual/index.js +200 -0
  105. package/lib/server/instructions/parallel.js +11 -7
  106. package/lib/server/instructions/request.d.ts +5 -4
  107. package/lib/server/instructions/request.js +60 -79
  108. package/lib/server/migrations/20230221032941-change-request-body-type.d.ts +5 -0
  109. package/lib/server/migrations/20230221032941-change-request-body-type.js +113 -0
  110. package/lib/server/migrations/20230221071831-calculation-expression.d.ts +4 -0
  111. package/lib/server/migrations/20230221071831-calculation-expression.js +143 -0
  112. package/lib/server/migrations/20230221121203-condition-calculation.d.ts +4 -0
  113. package/lib/server/migrations/20230221121203-condition-calculation.js +126 -0
  114. package/lib/server/migrations/20230221162902-jsonb-to-json.d.ts +4 -0
  115. package/lib/server/migrations/20230221162902-jsonb-to-json.js +81 -0
  116. package/lib/server/triggers/schedule.js +11 -3
  117. package/package.json +10 -10
  118. package/lib/client/calculators.d.ts +0 -89
  119. package/lib/client/calculators.js +0 -668
  120. package/lib/client/components/CollectionFieldSelect.d.ts +0 -2
  121. package/lib/client/components/CollectionFieldSelect.js +0 -106
  122. package/lib/client/components/EjsTextArea.d.ts +0 -2
  123. package/lib/client/components/EjsTextArea.js +0 -232
  124. package/lib/server/actions/jobs.d.ts +0 -2
  125. package/lib/server/actions/jobs.js +0 -39
  126. package/lib/server/calculators/index.d.ts +0 -40
  127. package/lib/server/calculators/index.js +0 -187
  128. package/lib/server/extensions/assignees/actions.js +0 -75
  129. package/lib/server/extensions/assignees/index.d.ts +0 -2
  130. package/lib/server/extensions/assignees/index.js +0 -273
  131. package/lib/server/extensions/index.d.ts +0 -3
  132. package/lib/server/extensions/index.js +0 -13
  133. package/lib/server/instructions/prompt.d.ts +0 -19
  134. package/lib/server/instructions/prompt.js +0 -131
  135. /package/lib/server/{extensions/assignees → instructions/manual}/actions.d.ts +0 -0
  136. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.d.ts +0 -0
  137. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.js +0 -0
  138. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.d.ts +0 -0
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = _default;
7
-
8
- function _react() {
9
- const data = _interopRequireDefault(require("react"));
10
-
11
- _react = function _react() {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- function _antd() {
19
- const data = require("antd");
20
-
21
- _antd = function _antd() {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _reactI18next() {
29
- const data = require("react-i18next");
30
-
31
- _reactI18next = function _reactI18next() {
32
- return data;
33
- };
34
-
35
- return data;
36
- }
37
-
38
- function _client() {
39
- const data = require("@nocobase/client");
40
-
41
- _client = function _client() {
42
- return data;
43
- };
44
-
45
- return data;
46
- }
47
-
48
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
49
-
50
- function _default(props) {
51
- const collection = props.collection,
52
- value = props.value,
53
- onChange = props.onChange;
54
-
55
- const _useTranslation = (0, _reactI18next().useTranslation)(),
56
- t = _useTranslation.t;
57
-
58
- const compile = (0, _client().useCompile)();
59
-
60
- const _useCollectionManager = (0, _client().useCollectionManager)(),
61
- getCollectionFields = _useCollectionManager.getCollectionFields;
62
-
63
- const fields = getCollectionFields(collection).filter(field => field.interface && (!field.target || field.type === 'belongsTo')).map(field => {
64
- var _field$uiSchema, _field$uiSchema2;
65
-
66
- return field.type === 'belongsTo' ? {
67
- title: `${compile(((_field$uiSchema = field.uiSchema) === null || _field$uiSchema === void 0 ? void 0 : _field$uiSchema.title) || field.name)} ID`,
68
- name: field.foreignKey
69
- } : {
70
- title: compile(((_field$uiSchema2 = field.uiSchema) === null || _field$uiSchema2 === void 0 ? void 0 : _field$uiSchema2.title) || field.name),
71
- name: field.name
72
- };
73
- });
74
- return _react().default.createElement(_antd().Select, {
75
- placeholder: t('Fields'),
76
- value: value,
77
- onChange: onChange
78
- }, fields.map(field => _react().default.createElement(_antd().Select.Option, {
79
- key: field.name,
80
- value: field.name
81
- }, field.title)));
82
- }
83
-
84
- function SelectWithAssociations(props) {
85
- const collection = props.collection,
86
- value = props.value,
87
- onChange = props.onChange;
88
-
89
- const _useTranslation2 = (0, _reactI18next().useTranslation)(),
90
- t = _useTranslation2.t;
91
-
92
- const compile = (0, _client().useCompile)();
93
- const fields = (0, _client().useCollectionFilterOptions)(collection);
94
- return _react().default.createElement(_antd().Cascader, {
95
- fieldNames: {
96
- label: 'title',
97
- value: 'name',
98
- children: 'children'
99
- },
100
- changeOnSelect: false,
101
- value: Array.isArray(value) ? value : value === null || value === void 0 ? void 0 : value.split('.'),
102
- options: compile(fields),
103
- onChange: onChange,
104
- placeholder: t('Select Field')
105
- });
106
- }
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export default function (props: any): JSX.Element;
@@ -1,232 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = _default;
7
-
8
- function _react() {
9
- const data = _interopRequireWildcard(require("react"));
10
-
11
- _react = function _react() {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- function _antd() {
19
- const data = require("antd");
20
-
21
- _antd = function _antd() {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _icons() {
29
- const data = require("@ant-design/icons");
30
-
31
- _icons = function _icons() {
32
- return data;
33
- };
34
-
35
- return data;
36
- }
37
-
38
- function _reactCopyToClipboard() {
39
- const data = require("react-copy-to-clipboard");
40
-
41
- _reactCopyToClipboard = function _reactCopyToClipboard() {
42
- return data;
43
- };
44
-
45
- return data;
46
- }
47
-
48
- var _calculators = require("../calculators");
49
-
50
- var _FlowContext = require("../FlowContext");
51
-
52
- function _client() {
53
- const data = require("@nocobase/client");
54
-
55
- _client = function _client() {
56
- return data;
57
- };
58
-
59
- return data;
60
- }
61
-
62
- var _locale = require("../locale");
63
-
64
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
65
-
66
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
67
-
68
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
69
-
70
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
71
-
72
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
73
-
74
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
75
-
76
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
77
-
78
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
79
-
80
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
81
-
82
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
83
-
84
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
85
-
86
- function getVal(operand) {
87
- const _useWorkflowTranslati = (0, _locale.useWorkflowTranslation)(),
88
- t = _useWorkflowTranslati.t;
89
-
90
- const compile = (0, _client().useCompile)();
91
-
92
- const _useCollectionManager = (0, _client().useCollectionManager)(),
93
- getCollectionFields = _useCollectionManager.getCollectionFields;
94
-
95
- const _useFlowContext = (0, _FlowContext.useFlowContext)(),
96
- nodes = _useFlowContext.nodes;
97
-
98
- if (typeof operand === 'string') {
99
- let pathArr = operand.replace('{{', '').replace('}}', '').split('.');
100
-
101
- if (pathArr.length > 0) {
102
- const type = pathArr[0];
103
-
104
- if (type == '$context') {
105
- return `<%=${pathArr.map((value, index) => {
106
- if (index === 0) {
107
- return 'ctx';
108
- }
109
-
110
- return value;
111
- }).join('.')}%>`;
112
- }
113
-
114
- if (pathArr.length > 1 && type == '$jobsMapByNodeId') {
115
- const nodeId = pathArr[1];
116
- const node = nodes.find(n => n.id == nodeId);
117
-
118
- if (node) {
119
- var _node$config;
120
-
121
- if (node.type === 'calculation') {
122
- return `<%= node[${nodeId}] // ${t('Calculation result')} %>`;
123
- }
124
-
125
- if (pathArr.length > 2 && (node === null || node === void 0 ? void 0 : (_node$config = node.config) === null || _node$config === void 0 ? void 0 : _node$config.collection)) {
126
- var _node$config2;
127
-
128
- const fieldName = pathArr[2];
129
- const fields = getCollectionFields(node === null || node === void 0 ? void 0 : (_node$config2 = node.config) === null || _node$config2 === void 0 ? void 0 : _node$config2.collection);
130
- const field = fields.find(f => f.name == fieldName);
131
-
132
- if (field) {
133
- var _field$uiSchema;
134
-
135
- return `<%= node[${nodeId}].${fieldName} // ${compile(((_field$uiSchema = field.uiSchema) === null || _field$uiSchema === void 0 ? void 0 : _field$uiSchema.title) || field.name)} %>`;
136
- }
137
-
138
- return `<%= node[${nodeId}].${fieldName}%>`;
139
- }
140
- }
141
- }
142
- }
143
- }
144
-
145
- return '';
146
- }
147
-
148
- const AvailableVariableTool = props => {
149
- const _useWorkflowTranslati2 = (0, _locale.useWorkflowTranslation)(),
150
- t = _useWorkflowTranslati2.t;
151
-
152
- const _useState = (0, _react().useState)(''),
153
- _useState2 = _slicedToArray(_useState, 2),
154
- operand = _useState2[0],
155
- setOperand = _useState2[1];
156
-
157
- return _react().default.createElement(_antd().Row, {
158
- style: {
159
- width: '100%'
160
- }
161
- }, _react().default.createElement(_antd().Col, {
162
- span: 10
163
- }, _react().default.createElement(_calculators.Operand, {
164
- value: operand,
165
- onChange: v => setOperand(v)
166
- })), _react().default.createElement(_antd().Col, {
167
- span: 10
168
- }, _react().default.createElement(_antd().Input, {
169
- value: getVal(operand),
170
- disabled: true
171
- })), _react().default.createElement(_antd().Col, {
172
- span: 4
173
- }, _react().default.createElement(_reactCopyToClipboard().CopyToClipboard, {
174
- text: getVal(operand),
175
- onCopy: () => {
176
- _antd().message.success({
177
- content: t('Copy success!'),
178
- duration: 1,
179
- style: {
180
- marginTop: '20vh'
181
- }
182
- });
183
- }
184
- }, _react().default.createElement(_antd().Tooltip, {
185
- title: t('Copy variable output template statement')
186
- }, _react().default.createElement(_antd().Button, {
187
- icon: _react().default.createElement(_icons().CopyOutlined, null)
188
- })))));
189
- };
190
-
191
- function _default(props) {
192
- const _useState3 = (0, _react().useState)(false),
193
- _useState4 = _slicedToArray(_useState3, 2),
194
- showTool = _useState4[0],
195
- setShowTool = _useState4[1];
196
-
197
- const _useWorkflowTranslati3 = (0, _locale.useWorkflowTranslation)(),
198
- t = _useWorkflowTranslati3.t;
199
-
200
- const requestVariableTypes = {
201
- $context: _calculators.VariableTypes.$context,
202
- $jobsMapByNodeId: _calculators.VariableTypes.$jobsMapByNodeId
203
- };
204
- return _react().default.createElement(_calculators.VariableTypesContext.Provider, {
205
- value: requestVariableTypes
206
- }, _react().default.createElement(_antd().Row, {
207
- style: {
208
- width: '100%'
209
- }
210
- }, _react().default.createElement(_antd().Col, {
211
- span: 24
212
- }, _react().default.createElement(_antd().Tooltip, {
213
- title: t('Show available variable tool')
214
- }, _react().default.createElement(_antd().Button, {
215
- type: 'text',
216
- icon: _react().default.createElement(_icons().ToolOutlined, null),
217
- onClick: () => setShowTool(!showTool)
218
- })))), showTool && _react().default.createElement(AvailableVariableTool, null), _react().default.createElement(_antd().Row, {
219
- style: {
220
- width: '100%'
221
- }
222
- }, _react().default.createElement(_antd().Col, {
223
- span: 24
224
- }, _react().default.createElement(_antd().Input.TextArea, _objectSpread({}, props)))), showTool && _react().default.createElement(_antd().Row, null, _react().default.createElement(_antd().Col, {
225
- span: 24
226
- }, _react().default.createElement("div", {
227
- className: "ant-formily-item-extra"
228
- }, props.description, " ", t('Syntax see'), ' ', _react().default.createElement("a", {
229
- target: '_blank',
230
- href: 'https://ejs.co'
231
- }, "ejs"), ' '))));
232
- }
@@ -1,2 +0,0 @@
1
- import { Context } from '@nocobase/actions';
2
- export declare function submit(context: Context, next: any): Promise<never>;
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.submit = submit;
7
-
8
- var _constants = require("../constants");
9
-
10
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
11
-
12
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
-
14
- function submit(_x, _x2) {
15
- return _submit.apply(this, arguments);
16
- }
17
-
18
- function _submit() {
19
- _submit = _asyncToGenerator(function* (context, next) {
20
- const values = context.action.params.values;
21
- const instance = context.body; // NOTE: validate status
22
-
23
- if (instance.status !== _constants.JOB_STATUS.PENDING) {
24
- return context.throw(400);
25
- } // NOTE: validate assignee
26
-
27
-
28
- instance.set({
29
- status: values.status,
30
- result: values.result
31
- });
32
- context.status = 202;
33
- yield next();
34
- const plugin = context.app.pm.get('workflow'); // NOTE: resume the process and no `await` for quick returning
35
-
36
- plugin.resume(instance);
37
- });
38
- return _submit.apply(this, arguments);
39
- }
@@ -1,40 +0,0 @@
1
- import { Registry } from "@nocobase/utils";
2
- import JobModel from '../models/Job';
3
- import Processor from '../Processor';
4
- export declare const calculators: Registry<Function>;
5
- export default calculators;
6
- export declare type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';
7
- export declare type ObjectGetterOptions = {
8
- type?: string;
9
- path?: string;
10
- };
11
- export declare type JobGetterOptions = ObjectGetterOptions & {
12
- nodeId: number;
13
- };
14
- export declare type CalculationOptions = {
15
- calculator: string;
16
- operands: Operand[];
17
- };
18
- export declare type ValueOperand = string | number | boolean | null | Date;
19
- export declare type ConstantOperand = {
20
- type?: 'constant';
21
- value: any;
22
- };
23
- export declare type ContextOperand = {
24
- type: '$context';
25
- options: ObjectGetterOptions;
26
- };
27
- export declare type InputOperand = {
28
- type: '$input';
29
- options: ObjectGetterOptions;
30
- };
31
- export declare type JobOperand = {
32
- type: '$jobsMapByNodeId';
33
- options: JobGetterOptions;
34
- };
35
- export declare type Calculation = {
36
- type: '$calculation';
37
- options: CalculationOptions;
38
- };
39
- export declare type Operand = ValueOperand | ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;
40
- export declare function calculate(operand: any, lastJob: JobModel, processor: Processor): any;
@@ -1,187 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.calculate = calculate;
7
- exports.default = exports.calculators = void 0;
8
-
9
- function _lodash() {
10
- const data = require("lodash");
11
-
12
- _lodash = function _lodash() {
13
- return data;
14
- };
15
-
16
- return data;
17
- }
18
-
19
- function _utils() {
20
- const data = require("@nocobase/utils");
21
-
22
- _utils = function _utils() {
23
- return data;
24
- };
25
-
26
- return data;
27
- }
28
-
29
- const calculators = new (_utils().Registry)();
30
- exports.calculators = calculators;
31
- var _default = calculators; // @deprecated
32
- // HACK: if no path provided, return self
33
- // @see https://github.com/lodash/lodash/pull/1270
34
- // TODO(question): should add default value as lodash?
35
-
36
- exports.default = _default;
37
-
38
- function get(object, path) {
39
- return path == null || !path.length ? object : (0, _lodash().get)(object, path);
40
- } // NOTE:
41
- // this method could only be used in executing nodes.
42
- // because type of 'job' need loaded jobs in runtime execution.
43
- // or the execution should be prepared first.
44
-
45
-
46
- function calculate(operand, lastJob, processor) {
47
- if (typeof operand !== 'object' || operand == null) {
48
- return operand;
49
- } // @Deprecated
50
-
51
-
52
- switch (operand.type) {
53
- // from execution context
54
- case '$context':
55
- return get(processor.execution.context, [operand.options.type, operand.options.path].filter(Boolean).join('.'));
56
- // from last job (or input job)
57
-
58
- case '$input':
59
- return lastJob !== null && lastJob !== void 0 ? lastJob : get(lastJob.result, operand.options.path);
60
- // from job in execution
61
-
62
- case '$jobsMapByNodeId':
63
- // assume jobs have been fetched from execution before
64
- const job = processor.jobsMapByNodeId[operand.options.nodeId];
65
- return job && get(job, operand.options.path);
66
-
67
- case '$calculation':
68
- const fn = calculators.get(operand.options.calculator);
69
-
70
- if (!fn) {
71
- throw new Error(`no calculator function registered for "${operand.options.calculator}"`);
72
- }
73
-
74
- return fn(...operand.options.operands.map(item => calculate(item, lastJob, processor)));
75
- // constant
76
-
77
- default:
78
- return operand.value;
79
- }
80
- } // built-in functions
81
-
82
-
83
- function equal(a, b) {
84
- return a === b;
85
- }
86
-
87
- function notEqual(a, b) {
88
- return a !== b;
89
- }
90
-
91
- function gt(a, b) {
92
- return a > b;
93
- }
94
-
95
- function gte(a, b) {
96
- return a >= b;
97
- }
98
-
99
- function lt(a, b) {
100
- return a < b;
101
- }
102
-
103
- function lte(a, b) {
104
- return a <= b;
105
- }
106
-
107
- calculators.register('equal', equal);
108
- calculators.register('notEqual', notEqual);
109
- calculators.register('gt', gt);
110
- calculators.register('gte', gte);
111
- calculators.register('lt', lt);
112
- calculators.register('lte', lte);
113
- calculators.register('===', equal);
114
- calculators.register('!==', notEqual);
115
- calculators.register('>', gt);
116
- calculators.register('>=', gte);
117
- calculators.register('<', lt);
118
- calculators.register('<=', lte);
119
-
120
- function add(...args) {
121
- return args.reduce((sum, a) => sum + (0, _lodash().toNumber)(a), 0);
122
- }
123
-
124
- function minus(a, b) {
125
- return (0, _lodash().toNumber)(a) - (0, _lodash().toNumber)(b);
126
- }
127
-
128
- function multiple(...args) {
129
- return args.reduce((result, a) => result * (0, _lodash().toNumber)(a), 1);
130
- }
131
-
132
- function divide(a, b) {
133
- return (0, _lodash().toNumber)(a) / (0, _lodash().toNumber)(b);
134
- }
135
-
136
- function mod(a, b) {
137
- return (0, _lodash().toNumber)(a) % (0, _lodash().toNumber)(b);
138
- }
139
-
140
- calculators.register('add', add);
141
- calculators.register('minus', minus);
142
- calculators.register('multiple', multiple);
143
- calculators.register('divide', divide);
144
- calculators.register('mod', mod);
145
- calculators.register('+', add);
146
- calculators.register('-', minus);
147
- calculators.register('*', multiple);
148
- calculators.register('/', divide);
149
- calculators.register('%', mod);
150
-
151
- function includes(a, b) {
152
- return a.includes(b);
153
- }
154
-
155
- function notIncludes(a, b) {
156
- return !a.includes(b);
157
- }
158
-
159
- function startsWith(a, b) {
160
- return a.startsWith(b);
161
- }
162
-
163
- function notStartsWith(a, b) {
164
- return !a.startsWith(b);
165
- }
166
-
167
- function endsWith(a, b) {
168
- return a.endsWith(b);
169
- }
170
-
171
- function notEndsWith(a, b) {
172
- return !a.endsWith(b);
173
- }
174
-
175
- calculators.register('includes', includes);
176
- calculators.register('notIncludes', notIncludes);
177
- calculators.register('startsWith', startsWith);
178
- calculators.register('notStartsWith', notStartsWith);
179
- calculators.register('endsWith', endsWith);
180
- calculators.register('notEndsWith', notEndsWith);
181
-
182
- function concat(a, b) {
183
- return a.concat(b);
184
- }
185
-
186
- calculators.register('concat', concat);
187
- calculators.register('now', () => new Date()); // TODO: add more common calculators
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.submit = submit;
7
-
8
- function _actions() {
9
- const data = require("@nocobase/actions");
10
-
11
- _actions = function _actions() {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- var _constants = require("../../constants");
19
-
20
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
-
22
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
23
-
24
- function submit(_x, _x2) {
25
- return _submit.apply(this, arguments);
26
- }
27
-
28
- function _submit() {
29
- _submit = _asyncToGenerator(function* (context, next) {
30
- const repository = _actions().utils.getRepositoryFromParams(context);
31
-
32
- const _context$action$param = context.action.params,
33
- filterByTk = _context$action$param.filterByTk,
34
- values = _context$action$param.values;
35
- const currentUser = context.state.currentUser;
36
-
37
- if (!currentUser) {
38
- return context.throw(401);
39
- }
40
-
41
- const instance = yield repository.findOne({
42
- filterByTk,
43
- // filter: {
44
- // userId: currentUser?.id
45
- // },
46
- appends: ['job', 'node', 'execution'],
47
- context
48
- });
49
- const _instance$node$config = instance.node.config,
50
- actions = _instance$node$config.actions,
51
- assignees = _instance$node$config.assignees; // NOTE: validate status
52
-
53
- if (instance.status !== _constants.JOB_STATUS.PENDING || instance.job.status !== _constants.JOB_STATUS.PENDING || instance.execution.status !== _constants.EXECUTION_STATUS.STARTED || actions && !actions[values.status]) {
54
- context.throw(400);
55
- }
56
-
57
- if (!assignees.includes(currentUser.id) || instance.userId !== currentUser.id) {
58
- return context.throw(404);
59
- } // NOTE: validate assignee
60
-
61
-
62
- yield instance.update({
63
- status: values.status,
64
- result: values.result
65
- });
66
- context.body = instance;
67
- context.status = 202;
68
- yield next();
69
- instance.job.latestUserJob = instance;
70
- const plugin = context.app.pm.get('workflow'); // NOTE: resume the process and no `await` for quick returning
71
-
72
- plugin.resume(instance.job);
73
- });
74
- return _submit.apply(this, arguments);
75
- }
@@ -1,2 +0,0 @@
1
- import Plugin from '../../Plugin';
2
- export default function (plugin: Plugin): Promise<void>;