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

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 (135) 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 +7 -2
  5. package/lib/client/Branch.d.ts +1 -1
  6. package/lib/client/ExecutionCanvas.js +5 -10
  7. package/lib/client/WorkflowCanvas.js +11 -40
  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 +21 -25
  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 +40 -6
  29. package/lib/client/nodes/calculation.js +171 -19
  30. package/lib/client/nodes/condition.d.ts +67 -0
  31. package/lib/client/nodes/condition.js +287 -27
  32. package/lib/client/nodes/create.d.ts +8 -6
  33. package/lib/client/nodes/create.js +27 -33
  34. package/lib/client/nodes/delay.d.ts +2 -0
  35. package/lib/client/nodes/delay.js +8 -4
  36. package/lib/client/nodes/destroy.d.ts +2 -2
  37. package/lib/client/nodes/destroy.js +2 -2
  38. package/lib/client/nodes/index.d.ts +10 -2
  39. package/lib/client/nodes/index.js +73 -27
  40. package/lib/client/nodes/manual/AssigneesSelect.d.ts +6 -0
  41. package/lib/client/nodes/manual/AssigneesSelect.js +64 -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 +64 -0
  51. package/lib/client/nodes/manual/index.js +146 -0
  52. package/lib/client/nodes/parallel.d.ts +11 -5
  53. package/lib/client/nodes/parallel.js +22 -34
  54. package/lib/client/nodes/query.d.ts +9 -14
  55. package/lib/client/nodes/query.js +38 -44
  56. package/lib/client/nodes/request.d.ts +75 -33
  57. package/lib/client/nodes/request.js +124 -63
  58. package/lib/client/nodes/update.d.ts +2 -2
  59. package/lib/client/nodes/update.js +2 -2
  60. package/lib/client/schemas/collection.js +1 -1
  61. package/lib/client/schemas/executions.js +1 -1
  62. package/lib/client/schemas/workflows.js +1 -1
  63. package/lib/client/style.js +0 -4
  64. package/lib/client/triggers/collection.d.ts +7 -3
  65. package/lib/client/triggers/collection.js +39 -48
  66. package/lib/client/triggers/index.d.ts +5 -2
  67. package/lib/client/triggers/index.js +34 -12
  68. package/lib/client/triggers/schedule/index.d.ts +7 -5
  69. package/lib/client/triggers/schedule/index.js +38 -79
  70. package/lib/client/utils.d.ts +1 -0
  71. package/lib/client/utils.js +38 -0
  72. package/lib/client/variable.d.ts +21 -0
  73. package/lib/client/variable.js +147 -0
  74. package/lib/server/Plugin.d.ts +3 -3
  75. package/lib/server/Plugin.js +12 -21
  76. package/lib/server/Processor.d.ts +9 -2
  77. package/lib/server/Processor.js +33 -33
  78. package/lib/server/actions/index.js +2 -4
  79. package/lib/server/actions/workflows.d.ts +1 -0
  80. package/lib/server/actions/workflows.js +80 -23
  81. package/lib/server/collections/executions.js +5 -7
  82. package/lib/server/collections/flow_nodes.js +6 -18
  83. package/lib/server/collections/jobs.js +3 -1
  84. package/lib/server/collections/workflows.js +8 -4
  85. package/lib/server/constants.d.ts +9 -3
  86. package/lib/server/constants.js +11 -5
  87. package/lib/server/functions/index.d.ts +4 -0
  88. package/lib/server/functions/index.js +38 -0
  89. package/lib/server/index.d.ts +0 -1
  90. package/lib/server/index.js +0 -14
  91. package/lib/server/instructions/calculation.d.ts +2 -7
  92. package/lib/server/instructions/calculation.js +32 -37
  93. package/lib/server/instructions/condition.d.ts +4 -4
  94. package/lib/server/instructions/condition.js +126 -54
  95. package/lib/server/instructions/index.js +1 -1
  96. package/lib/server/instructions/manual/actions.js +101 -0
  97. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts +2 -0
  98. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.js +2 -1
  99. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js +10 -10
  100. package/lib/server/instructions/manual/index.d.ts +25 -0
  101. package/lib/server/instructions/manual/index.js +200 -0
  102. package/lib/server/instructions/parallel.js +11 -7
  103. package/lib/server/instructions/request.d.ts +5 -4
  104. package/lib/server/instructions/request.js +60 -79
  105. package/lib/server/migrations/20230221032941-change-request-body-type.d.ts +5 -0
  106. package/lib/server/migrations/20230221032941-change-request-body-type.js +113 -0
  107. package/lib/server/migrations/20230221071831-calculation-expression.d.ts +4 -0
  108. package/lib/server/migrations/20230221071831-calculation-expression.js +143 -0
  109. package/lib/server/migrations/20230221121203-condition-calculation.d.ts +4 -0
  110. package/lib/server/migrations/20230221121203-condition-calculation.js +126 -0
  111. package/lib/server/migrations/20230221162902-jsonb-to-json.d.ts +4 -0
  112. package/lib/server/migrations/20230221162902-jsonb-to-json.js +81 -0
  113. package/lib/server/triggers/schedule.js +11 -3
  114. package/package.json +10 -10
  115. package/lib/client/calculators.d.ts +0 -89
  116. package/lib/client/calculators.js +0 -668
  117. package/lib/client/components/CollectionFieldSelect.d.ts +0 -2
  118. package/lib/client/components/CollectionFieldSelect.js +0 -106
  119. package/lib/client/components/EjsTextArea.d.ts +0 -2
  120. package/lib/client/components/EjsTextArea.js +0 -232
  121. package/lib/server/actions/jobs.d.ts +0 -2
  122. package/lib/server/actions/jobs.js +0 -39
  123. package/lib/server/calculators/index.d.ts +0 -40
  124. package/lib/server/calculators/index.js +0 -187
  125. package/lib/server/extensions/assignees/actions.js +0 -75
  126. package/lib/server/extensions/assignees/index.d.ts +0 -2
  127. package/lib/server/extensions/assignees/index.js +0 -273
  128. package/lib/server/extensions/index.d.ts +0 -3
  129. package/lib/server/extensions/index.js +0 -13
  130. package/lib/server/instructions/prompt.d.ts +0 -19
  131. package/lib/server/instructions/prompt.js +0 -131
  132. /package/lib/server/{extensions/assignees → instructions/manual}/actions.d.ts +0 -0
  133. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.d.ts +0 -0
  134. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.js +0 -0
  135. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.d.ts +0 -0
@@ -25,12 +25,56 @@ function _css() {
25
25
  return data;
26
26
  }
27
27
 
28
- var _calculators = require("../calculators");
28
+ function _jsonTemplates() {
29
+ const data = _interopRequireDefault(require("json-templates"));
30
+
31
+ _jsonTemplates = function _jsonTemplates() {
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 _client2() {
49
+ const data = _interopRequireWildcard(require("@nocobase/evaluators/client"));
50
+
51
+ _client2 = function _client2() {
52
+ return data;
53
+ };
54
+
55
+ return data;
56
+ }
57
+
58
+ var _FlowContext = require("../FlowContext");
29
59
 
30
60
  var _locale = require("../locale");
31
61
 
62
+ var _variable = require("../variable");
63
+
64
+ var _RadioWithTooltip = require("../components/RadioWithTooltip");
65
+
66
+ const _excluded = ["node", "insert"];
67
+
68
+ 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); }
69
+
70
+ 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; }
71
+
32
72
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
73
 
74
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
75
+
76
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
77
+
34
78
  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; }
35
79
 
36
80
  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; }
@@ -42,36 +86,144 @@ var _default = {
42
86
  type: 'calculation',
43
87
  group: 'control',
44
88
  fieldset: {
45
- 'config.calculation': {
46
- type: 'object',
47
- title: `{{t("Configure calculation", { ns: "${_locale.NAMESPACE}" })}}`,
48
- name: 'config.calculation',
89
+ 'config.engine': {
90
+ type: 'string',
91
+ title: `{{t("Calculation engine", { ns: "${_locale.NAMESPACE}" })}}`,
92
+ name: 'config.engine',
93
+ 'x-decorator': 'FormItem',
94
+ 'x-component': 'RadioWithTooltip',
95
+ 'x-component-props': {
96
+ options: Array.from(_client2().default.getEntities()).reduce((result, [value, options]) => result.concat(_objectSpread({
97
+ value
98
+ }, options)), [])
99
+ },
49
100
  required: true,
101
+ default: 'math.js'
102
+ },
103
+ 'config.expression': {
104
+ type: 'string',
105
+ title: `{{t("Calculation expression", { ns: "${_locale.NAMESPACE}" })}}`,
106
+ name: 'config.expression',
50
107
  'x-decorator': 'FormItem',
51
- 'x-component': 'CalculationConfig'
108
+ 'x-component': 'Variable.TextArea',
109
+ 'x-component-props': {
110
+ scope: '{{useWorkflowVariableOptions}}'
111
+ },
112
+
113
+ ['x-validator'](value, rules, {
114
+ form
115
+ }) {
116
+ const values = form.values;
117
+
118
+ const _evaluators$get = _client2().default.get(values.config.engine),
119
+ evaluate = _evaluators$get.evaluate;
120
+
121
+ const exp = value.trim().replace(/{{([^{}]+)}}/g, '1');
122
+
123
+ try {
124
+ evaluate(exp);
125
+ return '';
126
+ } catch (e) {
127
+ return (0, _locale.lang)('Expression syntax error');
128
+ }
129
+ },
130
+
131
+ 'x-reactions': {
132
+ dependencies: ['config.engine'],
133
+ fulfill: {
134
+ schema: {
135
+ description: '{{renderReference($deps[0])}}'
136
+ }
137
+ }
138
+ },
139
+ required: true
52
140
  }
53
141
  },
54
142
  view: {},
143
+ scope: {
144
+ useWorkflowVariableOptions: _variable.useWorkflowVariableOptions,
145
+ renderReference: _client2().renderReference
146
+ },
55
147
  components: {
56
- CalculationConfig({
57
- value,
58
- onChange
148
+ CalculationResult({
149
+ dataSource
59
150
  }) {
60
- return _react().default.createElement(_calculators.Calculation, _objectSpread(_objectSpread({}, value), {}, {
61
- onChange: onChange
62
- }));
151
+ var _execution$jobs;
152
+
153
+ const _useFlowContext = (0, _FlowContext.useFlowContext)(),
154
+ execution = _useFlowContext.execution;
155
+
156
+ if (!execution) {
157
+ return (0, _locale.lang)('Calculation result');
158
+ }
159
+
160
+ const result = (0, _jsonTemplates().default)(dataSource)({
161
+ $jobsMapByNodeId: ((_execution$jobs = execution.jobs) !== null && _execution$jobs !== void 0 ? _execution$jobs : []).reduce((map, job) => Object.assign(map, {
162
+ [job.nodeId]: job.result
163
+ }), {})
164
+ });
165
+ return _react().default.createElement("pre", {
166
+ className: (0, _css().css)`
167
+ margin: 0;
168
+ `
169
+ }, JSON.stringify(result, null, 2));
170
+ },
171
+
172
+ RadioWithTooltip: _RadioWithTooltip.RadioWithTooltip
173
+ },
174
+
175
+ getOptions(config, types) {
176
+ if (types && !types.some(type => type in _variable.TypeSets || Object.values(_variable.TypeSets).some(set => set.has(type)))) {
177
+ return null;
63
178
  }
64
179
 
180
+ return [// { key: '', value: '', label: lang('Calculation result') }
181
+ ];
65
182
  },
66
183
 
67
- getter() {
68
- const _useWorkflowTranslati = (0, _locale.useWorkflowTranslation)(),
69
- t = _useWorkflowTranslati.t;
184
+ useInitializers(node) {
185
+ var _node$title;
70
186
 
71
- return _react().default.createElement("div", {
72
- className: (0, _css().css)`flex-shrink: 0`
73
- }, t('Calculation result'));
187
+ return {
188
+ type: 'item',
189
+ title: (_node$title = node.title) !== null && _node$title !== void 0 ? _node$title : `#${node.id}`,
190
+ component: CalculationInitializer,
191
+ node
192
+ };
74
193
  }
75
194
 
76
195
  };
77
- exports.default = _default;
196
+ exports.default = _default;
197
+
198
+ function CalculationInitializer(_ref) {
199
+ let node = _ref.node,
200
+ insert = _ref.insert,
201
+ props = _objectWithoutProperties(_ref, _excluded);
202
+
203
+ return _react().default.createElement(_client().SchemaInitializer.Item, _objectSpread(_objectSpread({}, props), {}, {
204
+ onClick: () => {
205
+ var _node$title2;
206
+
207
+ insert({
208
+ type: 'void',
209
+ name: node.id,
210
+ title: node.title,
211
+ 'x-component': 'CardItem',
212
+ 'x-component-props': {
213
+ title: (_node$title2 = node.title) !== null && _node$title2 !== void 0 ? _node$title2 : `#${node.id}`
214
+ },
215
+ 'x-designer': 'SimpleDesigner',
216
+ properties: {
217
+ result: {
218
+ type: 'void',
219
+ 'x-component': 'CalculationResult',
220
+ 'x-component-props': {
221
+ // NOTE: as same format as other reference for migration of revision
222
+ dataSource: `{{$jobsMapByNodeId.${node.id}}}`
223
+ }
224
+ }
225
+ }
226
+ });
227
+ }
228
+ }));
229
+ }
@@ -1,4 +1,18 @@
1
1
  /// <reference types="react" />
2
+ import { Registry } from "@nocobase/utils/client";
3
+ import { useWorkflowVariableOptions } from "../variable";
4
+ import { RadioWithTooltip } from "../components/RadioWithTooltip";
5
+ interface Calculator {
6
+ name: string;
7
+ type: 'boolean' | 'number' | 'string' | 'date' | 'unknown' | 'null' | 'array';
8
+ group: string;
9
+ }
10
+ export declare const calculators: Registry<Calculator>;
11
+ export declare function Calculation({ calculator, operands, onChange }: {
12
+ calculator: any;
13
+ operands?: any[];
14
+ onChange: any;
15
+ }): JSX.Element;
2
16
  declare function CalculationConfig({ value, onChange }: {
3
17
  value: any;
4
18
  onChange: any;
@@ -22,12 +36,60 @@ declare const _default: {
22
36
  label: string;
23
37
  }[];
24
38
  };
39
+ 'config.engine': {
40
+ type: string;
41
+ title: string;
42
+ name: string;
43
+ 'x-decorator': string;
44
+ 'x-component': string;
45
+ 'x-component-props': {
46
+ options: [string, import("@nocobase/evaluators/client").Evaluator] | (string | {
47
+ label: string;
48
+ })[];
49
+ };
50
+ required: boolean;
51
+ default: string;
52
+ };
25
53
  'config.calculation': {
26
54
  type: string;
27
55
  name: string;
28
56
  title: string;
29
57
  'x-decorator': string;
30
58
  'x-component': string;
59
+ 'x-reactions': {
60
+ dependencies: string[];
61
+ fulfill: {
62
+ state: {
63
+ visible: string;
64
+ };
65
+ };
66
+ };
67
+ required: boolean;
68
+ };
69
+ 'config.expression': {
70
+ type: string;
71
+ title: string;
72
+ name: string;
73
+ 'x-decorator': string;
74
+ 'x-component': string;
75
+ 'x-component-props': {
76
+ scope: string;
77
+ };
78
+ "x-validator"(value: any, rules: any, { form }: {
79
+ form: any;
80
+ }): string;
81
+ 'x-reactions': {
82
+ dependencies: string[];
83
+ fulfill: {
84
+ state: {
85
+ visible: string;
86
+ };
87
+ schema: {
88
+ description: string;
89
+ };
90
+ };
91
+ };
92
+ required: boolean;
31
93
  };
32
94
  };
33
95
  view: {};
@@ -39,8 +101,13 @@ declare const _default: {
39
101
  };
40
102
  }[];
41
103
  render(data: any): JSX.Element;
104
+ scope: {
105
+ renderReference: (key: string) => JSX.Element;
106
+ useWorkflowVariableOptions: typeof useWorkflowVariableOptions;
107
+ };
42
108
  components: {
43
109
  CalculationConfig: typeof CalculationConfig;
110
+ RadioWithTooltip: typeof RadioWithTooltip;
44
111
  };
45
112
  };
46
113
  export default _default;