@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.
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/lib/client/AddButton.d.ts +1 -1
- package/lib/client/AddButton.js +7 -2
- package/lib/client/Branch.d.ts +1 -1
- package/lib/client/ExecutionCanvas.js +5 -10
- package/lib/client/WorkflowCanvas.js +11 -40
- package/lib/client/WorkflowProvider.js +10 -1
- package/lib/client/components/CollectionBlockInitializer.d.ts +7 -0
- package/lib/client/components/CollectionBlockInitializer.js +81 -0
- package/lib/client/components/CollectionFieldInitializers.d.ts +2 -0
- package/lib/client/components/CollectionFieldInitializers.js +89 -0
- package/lib/client/components/CollectionFieldset.js +21 -25
- package/lib/client/components/FilterDynamicComponent.d.ts +6 -0
- package/lib/client/components/FilterDynamicComponent.js +43 -0
- package/lib/client/components/NullRender.d.ts +1 -0
- package/lib/client/components/NullRender.js +10 -0
- package/lib/client/components/RadioWithTooltip.d.ts +7 -0
- package/lib/client/components/RadioWithTooltip.js +94 -0
- package/lib/client/constants.d.ts +10 -8
- package/lib/client/constants.js +52 -14
- package/lib/client/index.d.ts +0 -1
- package/lib/client/index.js +1 -10
- package/lib/client/locale/en-US.d.ts +18 -18
- package/lib/client/locale/en-US.js +19 -19
- package/lib/client/locale/zh-CN.d.ts +47 -20
- package/lib/client/locale/zh-CN.js +48 -21
- package/lib/client/nodes/calculation.d.ts +40 -6
- package/lib/client/nodes/calculation.js +171 -19
- package/lib/client/nodes/condition.d.ts +67 -0
- package/lib/client/nodes/condition.js +287 -27
- package/lib/client/nodes/create.d.ts +8 -6
- package/lib/client/nodes/create.js +27 -33
- package/lib/client/nodes/delay.d.ts +2 -0
- package/lib/client/nodes/delay.js +8 -4
- package/lib/client/nodes/destroy.d.ts +2 -2
- package/lib/client/nodes/destroy.js +2 -2
- package/lib/client/nodes/index.d.ts +10 -2
- package/lib/client/nodes/index.js +73 -27
- package/lib/client/nodes/manual/AssigneesSelect.d.ts +6 -0
- package/lib/client/nodes/manual/AssigneesSelect.js +64 -0
- package/lib/client/nodes/manual/ModeConfig.d.ts +5 -0
- package/lib/client/nodes/manual/ModeConfig.js +160 -0
- package/lib/client/nodes/manual/SchemaConfig.d.ts +6 -0
- package/lib/client/nodes/manual/SchemaConfig.js +715 -0
- package/lib/client/nodes/manual/WorkflowTodo.d.ts +8 -0
- package/lib/client/nodes/manual/WorkflowTodo.js +691 -0
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +5 -0
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +75 -0
- package/lib/client/nodes/manual/index.d.ts +64 -0
- package/lib/client/nodes/manual/index.js +146 -0
- package/lib/client/nodes/parallel.d.ts +11 -5
- package/lib/client/nodes/parallel.js +22 -34
- package/lib/client/nodes/query.d.ts +9 -14
- package/lib/client/nodes/query.js +38 -44
- package/lib/client/nodes/request.d.ts +75 -33
- package/lib/client/nodes/request.js +124 -63
- package/lib/client/nodes/update.d.ts +2 -2
- package/lib/client/nodes/update.js +2 -2
- package/lib/client/schemas/collection.js +1 -1
- package/lib/client/schemas/executions.js +1 -1
- package/lib/client/schemas/workflows.js +1 -1
- package/lib/client/style.js +0 -4
- package/lib/client/triggers/collection.d.ts +7 -3
- package/lib/client/triggers/collection.js +39 -48
- package/lib/client/triggers/index.d.ts +5 -2
- package/lib/client/triggers/index.js +34 -12
- package/lib/client/triggers/schedule/index.d.ts +7 -5
- package/lib/client/triggers/schedule/index.js +38 -79
- package/lib/client/utils.d.ts +1 -0
- package/lib/client/utils.js +38 -0
- package/lib/client/variable.d.ts +21 -0
- package/lib/client/variable.js +147 -0
- package/lib/server/Plugin.d.ts +3 -3
- package/lib/server/Plugin.js +12 -21
- package/lib/server/Processor.d.ts +9 -2
- package/lib/server/Processor.js +33 -33
- package/lib/server/actions/index.js +2 -4
- package/lib/server/actions/workflows.d.ts +1 -0
- package/lib/server/actions/workflows.js +80 -23
- package/lib/server/collections/executions.js +5 -7
- package/lib/server/collections/flow_nodes.js +6 -18
- package/lib/server/collections/jobs.js +3 -1
- package/lib/server/collections/workflows.js +8 -4
- package/lib/server/constants.d.ts +9 -3
- package/lib/server/constants.js +11 -5
- package/lib/server/functions/index.d.ts +4 -0
- package/lib/server/functions/index.js +38 -0
- package/lib/server/index.d.ts +0 -1
- package/lib/server/index.js +0 -14
- package/lib/server/instructions/calculation.d.ts +2 -7
- package/lib/server/instructions/calculation.js +32 -37
- package/lib/server/instructions/condition.d.ts +4 -4
- package/lib/server/instructions/condition.js +126 -54
- package/lib/server/instructions/index.js +1 -1
- package/lib/server/instructions/manual/actions.js +101 -0
- package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts +2 -0
- package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.js +2 -1
- package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js +10 -10
- package/lib/server/instructions/manual/index.d.ts +25 -0
- package/lib/server/instructions/manual/index.js +200 -0
- package/lib/server/instructions/parallel.js +11 -7
- package/lib/server/instructions/request.d.ts +5 -4
- package/lib/server/instructions/request.js +60 -79
- package/lib/server/migrations/20230221032941-change-request-body-type.d.ts +5 -0
- package/lib/server/migrations/20230221032941-change-request-body-type.js +113 -0
- package/lib/server/migrations/20230221071831-calculation-expression.d.ts +4 -0
- package/lib/server/migrations/20230221071831-calculation-expression.js +143 -0
- package/lib/server/migrations/20230221121203-condition-calculation.d.ts +4 -0
- package/lib/server/migrations/20230221121203-condition-calculation.js +126 -0
- package/lib/server/migrations/20230221162902-jsonb-to-json.d.ts +4 -0
- package/lib/server/migrations/20230221162902-jsonb-to-json.js +81 -0
- package/lib/server/triggers/schedule.js +11 -3
- package/package.json +10 -10
- package/lib/client/calculators.d.ts +0 -89
- package/lib/client/calculators.js +0 -668
- package/lib/client/components/CollectionFieldSelect.d.ts +0 -2
- package/lib/client/components/CollectionFieldSelect.js +0 -106
- package/lib/client/components/EjsTextArea.d.ts +0 -2
- package/lib/client/components/EjsTextArea.js +0 -232
- package/lib/server/actions/jobs.d.ts +0 -2
- package/lib/server/actions/jobs.js +0 -39
- package/lib/server/calculators/index.d.ts +0 -40
- package/lib/server/calculators/index.js +0 -187
- package/lib/server/extensions/assignees/actions.js +0 -75
- package/lib/server/extensions/assignees/index.d.ts +0 -2
- package/lib/server/extensions/assignees/index.js +0 -273
- package/lib/server/extensions/index.d.ts +0 -3
- package/lib/server/extensions/index.js +0 -13
- package/lib/server/instructions/prompt.d.ts +0 -19
- package/lib/server/instructions/prompt.js +0 -131
- /package/lib/server/{extensions/assignees → instructions/manual}/actions.d.ts +0 -0
- /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.d.ts +0 -0
- /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.js +0 -0
- /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.d.ts +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ISchema } from "@formily/react";
|
|
2
2
|
import { Registry } from "@nocobase/utils/client";
|
|
3
3
|
import React from "react";
|
|
4
|
+
import { SchemaInitializerItemOptions } from '@nocobase/client';
|
|
4
5
|
export interface Trigger {
|
|
5
6
|
title: string;
|
|
6
7
|
type: string;
|
|
7
|
-
getOptions?(config: any): {
|
|
8
|
+
getOptions?(config: any, types: any[]): {
|
|
8
9
|
label: string;
|
|
9
10
|
value: any;
|
|
10
11
|
key: string;
|
|
@@ -20,7 +21,9 @@ export interface Trigger {
|
|
|
20
21
|
[key: string]: any;
|
|
21
22
|
};
|
|
22
23
|
render?(props: any): React.ReactNode;
|
|
23
|
-
|
|
24
|
+
useInitializers?(config: any): SchemaInitializerItemOptions | null;
|
|
25
|
+
initializers?: any;
|
|
24
26
|
}
|
|
25
27
|
export declare const triggers: Registry<Trigger>;
|
|
26
28
|
export declare const TriggerConfig: () => JSX.Element;
|
|
29
|
+
export declare function useTrigger(): Trigger;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.triggers = exports.TriggerConfig = void 0;
|
|
7
|
+
exports.useTrigger = useTrigger;
|
|
7
8
|
|
|
8
9
|
function _css() {
|
|
9
10
|
const data = require("@emotion/css");
|
|
@@ -97,6 +98,12 @@ var _locale = require("../locale");
|
|
|
97
98
|
|
|
98
99
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
99
100
|
|
|
101
|
+
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; }
|
|
102
|
+
|
|
103
|
+
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; }
|
|
104
|
+
|
|
105
|
+
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; }
|
|
106
|
+
|
|
100
107
|
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); } }
|
|
101
108
|
|
|
102
109
|
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); }); }; }
|
|
@@ -262,6 +269,8 @@ const TriggerConfig = () => {
|
|
|
262
269
|
'x-component': 'Action.Drawer',
|
|
263
270
|
'x-decorator': 'Form',
|
|
264
271
|
'x-decorator-props': {
|
|
272
|
+
disabled: workflow.executed,
|
|
273
|
+
|
|
265
274
|
useValues(options) {
|
|
266
275
|
return (0, _client2().useRequest)(() => Promise.resolve({
|
|
267
276
|
data: {
|
|
@@ -284,20 +293,26 @@ const TriggerConfig = () => {
|
|
|
284
293
|
}
|
|
285
294
|
`
|
|
286
295
|
},
|
|
287
|
-
properties:
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
type: 'void',
|
|
291
|
-
'x-component': 'Action.Drawer.Footer',
|
|
292
|
-
properties: executed ? {
|
|
293
|
-
close: {
|
|
294
|
-
title: '{{t("Close")}}',
|
|
295
|
-
'x-component': 'Action',
|
|
296
|
+
properties: _objectSpread(_objectSpread({}, executed ? {
|
|
297
|
+
alert: {
|
|
298
|
+
'x-component': _antd().Alert,
|
|
296
299
|
'x-component-props': {
|
|
297
|
-
|
|
300
|
+
type: 'warning',
|
|
301
|
+
showIcon: true,
|
|
302
|
+
message: `{{t("Trigger in executed workflow cannot be modified", { ns: "${_locale.NAMESPACE}" })}}`,
|
|
303
|
+
className: (0, _css().css)`
|
|
304
|
+
width: 100%;
|
|
305
|
+
font-size: 85%;
|
|
306
|
+
margin-bottom: 2em;
|
|
307
|
+
`
|
|
298
308
|
}
|
|
299
309
|
}
|
|
300
|
-
} : {
|
|
310
|
+
} : {}), fieldset)
|
|
311
|
+
},
|
|
312
|
+
actions: executed ? null : {
|
|
313
|
+
type: 'void',
|
|
314
|
+
'x-component': 'Action.Drawer.Footer',
|
|
315
|
+
properties: {
|
|
301
316
|
cancel: {
|
|
302
317
|
title: '{{t("Cancel")}}',
|
|
303
318
|
'x-component': 'Action',
|
|
@@ -324,4 +339,11 @@ const TriggerConfig = () => {
|
|
|
324
339
|
}));
|
|
325
340
|
};
|
|
326
341
|
|
|
327
|
-
exports.TriggerConfig = TriggerConfig;
|
|
342
|
+
exports.TriggerConfig = TriggerConfig;
|
|
343
|
+
|
|
344
|
+
function useTrigger() {
|
|
345
|
+
const _useFlowContext4 = (0, _FlowContext.useFlowContext)(),
|
|
346
|
+
workflow = _useFlowContext4.workflow;
|
|
347
|
+
|
|
348
|
+
return triggers.get(workflow.type);
|
|
349
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { useCollectionDataSource } from '@nocobase/client';
|
|
1
|
+
import { useCollectionDataSource, SchemaInitializerItemOptions } from '@nocobase/client';
|
|
2
|
+
import { CollectionFieldInitializers } from '../../components/CollectionFieldInitializers';
|
|
2
3
|
declare const _default: {
|
|
3
4
|
title: string;
|
|
4
5
|
type: string;
|
|
@@ -16,9 +17,10 @@ declare const _default: {
|
|
|
16
17
|
components: {
|
|
17
18
|
ScheduleConfig: () => JSX.Element;
|
|
18
19
|
};
|
|
19
|
-
getOptions(config: any): any[];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
getOptions(config: any, types: any): any[];
|
|
21
|
+
useInitializers(config: any): SchemaInitializerItemOptions | null;
|
|
22
|
+
initializers: {
|
|
23
|
+
CollectionFieldInitializers: typeof CollectionFieldInitializers;
|
|
24
|
+
};
|
|
23
25
|
};
|
|
24
26
|
export default _default;
|
|
@@ -5,26 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
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
8
|
function _client() {
|
|
29
9
|
const data = require("@nocobase/client");
|
|
30
10
|
|
|
@@ -37,15 +17,15 @@ function _client() {
|
|
|
37
17
|
|
|
38
18
|
var _ScheduleConfig = require("./ScheduleConfig");
|
|
39
19
|
|
|
40
|
-
var _FlowContext = require("../../FlowContext");
|
|
41
|
-
|
|
42
|
-
var _calculators = require("../../calculators");
|
|
43
|
-
|
|
44
20
|
var _constants = require("./constants");
|
|
45
21
|
|
|
46
22
|
var _locale = require("../../locale");
|
|
47
23
|
|
|
48
|
-
|
|
24
|
+
var _CollectionFieldInitializers = require("../../components/CollectionFieldInitializers");
|
|
25
|
+
|
|
26
|
+
var _CollectionBlockInitializer = require("../../components/CollectionBlockInitializer");
|
|
27
|
+
|
|
28
|
+
var _variable = require("../../variable");
|
|
49
29
|
|
|
50
30
|
var _default = {
|
|
51
31
|
title: `{{t("Schedule event", { ns: "${_locale.NAMESPACE}" })}}`,
|
|
@@ -65,75 +45,54 @@ var _default = {
|
|
|
65
45
|
ScheduleConfig: _ScheduleConfig.ScheduleConfig
|
|
66
46
|
},
|
|
67
47
|
|
|
68
|
-
getOptions(config) {
|
|
48
|
+
getOptions(config, types) {
|
|
69
49
|
const _useWorkflowTranslati = (0, _locale.useWorkflowTranslation)(),
|
|
70
50
|
t = _useWorkflowTranslati.t;
|
|
71
51
|
|
|
72
|
-
const options = [
|
|
73
|
-
value: 'date',
|
|
74
|
-
label: t('Trigger time')
|
|
75
|
-
}];
|
|
52
|
+
const options = [];
|
|
76
53
|
|
|
77
|
-
if (
|
|
54
|
+
if (!types || types.includes('date')) {
|
|
78
55
|
options.push({
|
|
79
|
-
|
|
80
|
-
|
|
56
|
+
key: 'date',
|
|
57
|
+
value: 'date',
|
|
58
|
+
label: t('Trigger time')
|
|
81
59
|
});
|
|
82
60
|
}
|
|
83
61
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
onChange: _onChange
|
|
89
|
-
}) {
|
|
90
|
-
var _collections$find;
|
|
91
|
-
|
|
92
|
-
const _useWorkflowTranslati2 = (0, _locale.useWorkflowTranslation)(),
|
|
93
|
-
t = _useWorkflowTranslati2.t;
|
|
94
|
-
|
|
95
|
-
const compile = (0, _client().useCompile)();
|
|
96
|
-
|
|
97
|
-
const _useCollectionManager = (0, _client().useCollectionManager)(),
|
|
98
|
-
_useCollectionManager2 = _useCollectionManager.collections,
|
|
99
|
-
collections = _useCollectionManager2 === void 0 ? [] : _useCollectionManager2;
|
|
100
|
-
|
|
101
|
-
const _useFlowContext = (0, _FlowContext.useFlowContext)(),
|
|
102
|
-
workflow = _useFlowContext.workflow;
|
|
62
|
+
if (config.mode === _constants.SCHEDULE_MODE.COLLECTION_FIELD) {
|
|
63
|
+
const fieldOptions = (0, _variable.useCollectionFieldOptions)({
|
|
64
|
+
collection: config.collection
|
|
65
|
+
});
|
|
103
66
|
|
|
104
|
-
|
|
105
|
-
|
|
67
|
+
if (fieldOptions.length) {
|
|
68
|
+
options.push({
|
|
69
|
+
key: 'data',
|
|
70
|
+
value: 'data',
|
|
71
|
+
label: t('Trigger data'),
|
|
72
|
+
children: fieldOptions
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
106
76
|
|
|
107
|
-
|
|
77
|
+
return options;
|
|
78
|
+
},
|
|
108
79
|
|
|
109
|
-
|
|
80
|
+
useInitializers(config) {
|
|
81
|
+
if (!config.collection) {
|
|
110
82
|
return null;
|
|
111
83
|
}
|
|
112
84
|
|
|
113
|
-
|
|
114
|
-
|
|
85
|
+
return {
|
|
86
|
+
type: 'item',
|
|
87
|
+
title: `{{t("Trigger data", { ns: "${_locale.NAMESPACE}" })}}`,
|
|
88
|
+
component: _CollectionBlockInitializer.CollectionBlockInitializer,
|
|
89
|
+
collection: config.collection,
|
|
90
|
+
dataSource: '{{$context.data}}'
|
|
115
91
|
};
|
|
116
|
-
|
|
117
|
-
placeholder: t('Trigger data'),
|
|
118
|
-
value: path,
|
|
119
|
-
options: collection.fields.filter(field => {
|
|
120
|
-
var _field$uiSchema;
|
|
121
|
-
|
|
122
|
-
return _calculators.BaseTypeSet.has(field === null || field === void 0 ? void 0 : (_field$uiSchema = field.uiSchema) === null || _field$uiSchema === void 0 ? void 0 : _field$uiSchema.type);
|
|
123
|
-
}).map(field => {
|
|
124
|
-
var _field$uiSchema2;
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
value: field.name,
|
|
128
|
-
label: compile((_field$uiSchema2 = field.uiSchema) === null || _field$uiSchema2 === void 0 ? void 0 : _field$uiSchema2.title)
|
|
129
|
-
};
|
|
130
|
-
}),
|
|
131
|
-
onChange: next => {
|
|
132
|
-
_onChange(`{{$context.${next.join('.')}}}`);
|
|
133
|
-
},
|
|
134
|
-
allowClear: false
|
|
135
|
-
});
|
|
136
|
-
}
|
|
92
|
+
},
|
|
137
93
|
|
|
94
|
+
initializers: {
|
|
95
|
+
CollectionFieldInitializers: _CollectionFieldInitializers.CollectionFieldInitializers
|
|
96
|
+
}
|
|
138
97
|
};
|
|
139
98
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function linkNodes(nodes: any): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.linkNodes = linkNodes;
|
|
7
|
+
|
|
8
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
9
|
+
|
|
10
|
+
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); }
|
|
11
|
+
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
function linkNodes(nodes) {
|
|
15
|
+
const nodesMap = new Map();
|
|
16
|
+
nodes.forEach(item => nodesMap.set(item.id, item));
|
|
17
|
+
|
|
18
|
+
var _iterator = _createForOfIteratorHelper(nodesMap.values()),
|
|
19
|
+
_step;
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
23
|
+
let node = _step.value;
|
|
24
|
+
|
|
25
|
+
if (node.upstreamId) {
|
|
26
|
+
node.upstream = nodesMap.get(node.upstreamId);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (node.downstreamId) {
|
|
30
|
+
node.downstream = nodesMap.get(node.downstreamId);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
_iterator.e(err);
|
|
35
|
+
} finally {
|
|
36
|
+
_iterator.f();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare type VariableOption = {
|
|
2
|
+
key: string;
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
children?: VariableOption[];
|
|
6
|
+
};
|
|
7
|
+
export declare const TypeSets: {
|
|
8
|
+
boolean: Set<string>;
|
|
9
|
+
number: Set<string>;
|
|
10
|
+
string: Set<string>;
|
|
11
|
+
date: Set<string>;
|
|
12
|
+
};
|
|
13
|
+
export declare function filterTypedFields(fields: any, types: any): any;
|
|
14
|
+
export declare function useWorkflowVariableOptions(): {
|
|
15
|
+
label: any;
|
|
16
|
+
value: any;
|
|
17
|
+
key: any;
|
|
18
|
+
children: any;
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
}[];
|
|
21
|
+
export declare function useCollectionFieldOptions(props: any): any;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TypeSets = void 0;
|
|
7
|
+
exports.filterTypedFields = filterTypedFields;
|
|
8
|
+
exports.useCollectionFieldOptions = useCollectionFieldOptions;
|
|
9
|
+
exports.useWorkflowVariableOptions = useWorkflowVariableOptions;
|
|
10
|
+
|
|
11
|
+
function _client() {
|
|
12
|
+
const data = require("@nocobase/client");
|
|
13
|
+
|
|
14
|
+
_client = function _client() {
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var _nodes = require("./nodes");
|
|
22
|
+
|
|
23
|
+
var _FlowContext = require("./FlowContext");
|
|
24
|
+
|
|
25
|
+
var _triggers = require("./triggers");
|
|
26
|
+
|
|
27
|
+
var _locale = require("./locale");
|
|
28
|
+
|
|
29
|
+
const VariableTypes = [{
|
|
30
|
+
title: `{{t("Node result", { ns: "${_locale.NAMESPACE}" })}}`,
|
|
31
|
+
value: '$jobsMapByNodeId',
|
|
32
|
+
|
|
33
|
+
options(types) {
|
|
34
|
+
const current = (0, _nodes.useNodeContext)();
|
|
35
|
+
const upstreams = (0, _nodes.useAvailableUpstreams)(current);
|
|
36
|
+
const options = [];
|
|
37
|
+
upstreams.forEach(node => {
|
|
38
|
+
var _instruction$getOptio;
|
|
39
|
+
|
|
40
|
+
const instruction = _nodes.instructions.get(node.type);
|
|
41
|
+
|
|
42
|
+
const subOptions = (_instruction$getOptio = instruction.getOptions) === null || _instruction$getOptio === void 0 ? void 0 : _instruction$getOptio.call(instruction, node.config, types);
|
|
43
|
+
|
|
44
|
+
if (subOptions) {
|
|
45
|
+
var _node$title;
|
|
46
|
+
|
|
47
|
+
options.push({
|
|
48
|
+
key: node.id.toString(),
|
|
49
|
+
value: node.id.toString(),
|
|
50
|
+
label: (_node$title = node.title) !== null && _node$title !== void 0 ? _node$title : `#${node.id}`,
|
|
51
|
+
children: subOptions
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return options;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
}, {
|
|
59
|
+
title: `{{t("Trigger variables", { ns: "${_locale.NAMESPACE}" })}}`,
|
|
60
|
+
value: '$context',
|
|
61
|
+
|
|
62
|
+
options(types) {
|
|
63
|
+
var _trigger$getOptions, _trigger$getOptions2;
|
|
64
|
+
|
|
65
|
+
const _useFlowContext = (0, _FlowContext.useFlowContext)(),
|
|
66
|
+
workflow = _useFlowContext.workflow;
|
|
67
|
+
|
|
68
|
+
const trigger = _triggers.triggers.get(workflow.type);
|
|
69
|
+
|
|
70
|
+
return (_trigger$getOptions = trigger === null || trigger === void 0 ? void 0 : (_trigger$getOptions2 = trigger.getOptions) === null || _trigger$getOptions2 === void 0 ? void 0 : _trigger$getOptions2.call(trigger, workflow.config, types)) !== null && _trigger$getOptions !== void 0 ? _trigger$getOptions : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}, {
|
|
74
|
+
title: `{{t("System variables", { ns: "${_locale.NAMESPACE}" })}}`,
|
|
75
|
+
value: '$system',
|
|
76
|
+
options: [{
|
|
77
|
+
key: 'now',
|
|
78
|
+
value: 'now',
|
|
79
|
+
label: `{{t("Current time", { ns: "${_locale.NAMESPACE}" })}}`
|
|
80
|
+
}]
|
|
81
|
+
}];
|
|
82
|
+
const TypeSets = {
|
|
83
|
+
boolean: new Set(['boolean']),
|
|
84
|
+
number: new Set(['integer', 'bigInt', 'float', 'double', 'real', 'decimal']),
|
|
85
|
+
string: new Set(['string', 'text', 'password']),
|
|
86
|
+
date: new Set(['date', 'time'])
|
|
87
|
+
};
|
|
88
|
+
exports.TypeSets = TypeSets;
|
|
89
|
+
|
|
90
|
+
function matchFieldType(field, type) {
|
|
91
|
+
if (typeof type === 'string') {
|
|
92
|
+
var _TypeSets$type;
|
|
93
|
+
|
|
94
|
+
return Boolean((_TypeSets$type = TypeSets[type]) === null || _TypeSets$type === void 0 ? void 0 : _TypeSets$type.has(field.type));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (typeof type === 'object' && type.type === 'reference') {
|
|
98
|
+
var _type$options, _type$options2;
|
|
99
|
+
|
|
100
|
+
return field.collectionName === ((_type$options = type.options) === null || _type$options === void 0 ? void 0 : _type$options.collection) && field.name === 'id' || field.type === 'belongsTo' && field.target === ((_type$options2 = type.options) === null || _type$options2 === void 0 ? void 0 : _type$options2.collection);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function filterTypedFields(fields, types) {
|
|
107
|
+
return types ? fields.filter(field => types.some(type => matchFieldType(field, type))) : fields;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function useWorkflowVariableOptions() {
|
|
111
|
+
const compile = (0, _client().useCompile)();
|
|
112
|
+
const options = VariableTypes.map(item => {
|
|
113
|
+
const options = typeof item.options === 'function' ? item.options().filter(Boolean) : item.options;
|
|
114
|
+
return {
|
|
115
|
+
label: compile(item.title),
|
|
116
|
+
value: item.value,
|
|
117
|
+
key: item.value,
|
|
118
|
+
children: compile(options),
|
|
119
|
+
disabled: options && !options.length
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
return options;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function useCollectionFieldOptions(props) {
|
|
126
|
+
const fields = props.fields,
|
|
127
|
+
collection = props.collection,
|
|
128
|
+
types = props.types;
|
|
129
|
+
const compile = (0, _client().useCompile)();
|
|
130
|
+
|
|
131
|
+
const _useCollectionManager = (0, _client().useCollectionManager)(),
|
|
132
|
+
getCollectionFields = _useCollectionManager.getCollectionFields;
|
|
133
|
+
|
|
134
|
+
return filterTypedFields(fields !== null && fields !== void 0 ? fields : getCollectionFields(collection), types).filter(field => field.interface && (!field.target || field.type === 'belongsTo')).map(field => {
|
|
135
|
+
var _field$uiSchema, _field$uiSchema2;
|
|
136
|
+
|
|
137
|
+
return field.type === 'belongsTo' ? {
|
|
138
|
+
label: `${compile(((_field$uiSchema = field.uiSchema) === null || _field$uiSchema === void 0 ? void 0 : _field$uiSchema.title) || field.name)} ID`,
|
|
139
|
+
key: field.foreignKey,
|
|
140
|
+
value: field.foreignKey
|
|
141
|
+
} : {
|
|
142
|
+
label: compile(((_field$uiSchema2 = field.uiSchema) === null || _field$uiSchema2 === void 0 ? void 0 : _field$uiSchema2.title) || field.name),
|
|
143
|
+
key: field.name,
|
|
144
|
+
value: field.name
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
}
|
package/lib/server/Plugin.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import { Instruction } from './instructions';
|
|
|
4
4
|
import ExecutionModel from './models/Execution';
|
|
5
5
|
import JobModel from './models/Job';
|
|
6
6
|
import WorkflowModel from './models/Workflow';
|
|
7
|
+
import Processor from './Processor';
|
|
7
8
|
import { Trigger } from './triggers';
|
|
8
9
|
declare type Pending = [ExecutionModel, JobModel?];
|
|
9
10
|
export default class WorkflowPlugin extends Plugin {
|
|
10
11
|
instructions: Registry<Instruction>;
|
|
11
12
|
triggers: Registry<Trigger>;
|
|
12
|
-
|
|
13
|
-
extensions: typeof import("./extensions/assignees").default[];
|
|
13
|
+
functions: Registry<Function>;
|
|
14
14
|
executing: ExecutionModel | null;
|
|
15
15
|
pending: Pending[];
|
|
16
16
|
events: [WorkflowModel, any, {
|
|
@@ -26,6 +26,6 @@ export default class WorkflowPlugin extends Plugin {
|
|
|
26
26
|
resume(job: any): Promise<void>;
|
|
27
27
|
private dispatch;
|
|
28
28
|
private process;
|
|
29
|
-
|
|
29
|
+
createProcessor(execution: ExecutionModel, options?: {}): Processor;
|
|
30
30
|
}
|
|
31
31
|
export {};
|
package/lib/server/Plugin.js
CHANGED
|
@@ -47,18 +47,16 @@ function _utils() {
|
|
|
47
47
|
|
|
48
48
|
var _actions = _interopRequireDefault(require("./actions"));
|
|
49
49
|
|
|
50
|
-
var _calculators = _interopRequireDefault(require("./calculators"));
|
|
51
|
-
|
|
52
50
|
var _constants = require("./constants");
|
|
53
51
|
|
|
54
|
-
var _extensions = _interopRequireDefault(require("./extensions"));
|
|
55
|
-
|
|
56
52
|
var _instructions = _interopRequireDefault(require("./instructions"));
|
|
57
53
|
|
|
58
54
|
var _Processor = _interopRequireDefault(require("./Processor"));
|
|
59
55
|
|
|
60
56
|
var _triggers = _interopRequireDefault(require("./triggers"));
|
|
61
57
|
|
|
58
|
+
var _functions = _interopRequireDefault(require("./functions"));
|
|
59
|
+
|
|
62
60
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
63
61
|
|
|
64
62
|
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; }
|
|
@@ -91,8 +89,7 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
91
89
|
_this = this;
|
|
92
90
|
this.instructions = new (_utils().Registry)();
|
|
93
91
|
this.triggers = new (_utils().Registry)();
|
|
94
|
-
this.
|
|
95
|
-
this.extensions = _extensions.default;
|
|
92
|
+
this.functions = new (_utils().Registry)();
|
|
96
93
|
this.executing = null;
|
|
97
94
|
this.pending = [];
|
|
98
95
|
this.events = [];
|
|
@@ -187,7 +184,7 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
187
184
|
const execution = yield workflow.createExecution({
|
|
188
185
|
context,
|
|
189
186
|
key: workflow.key,
|
|
190
|
-
status: _constants.EXECUTION_STATUS.
|
|
187
|
+
status: _constants.EXECUTION_STATUS.QUEUEING,
|
|
191
188
|
useTransaction: workflow.useTransaction
|
|
192
189
|
}, {
|
|
193
190
|
transaction
|
|
@@ -248,6 +245,10 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
248
245
|
return _asyncToGenerator(function* () {
|
|
249
246
|
const db = _this2.db,
|
|
250
247
|
options = _this2.options;
|
|
248
|
+
(0, _actions.default)(_this2);
|
|
249
|
+
(0, _triggers.default)(_this2, options.triggers);
|
|
250
|
+
(0, _instructions.default)(_this2, options.instructions);
|
|
251
|
+
(0, _functions.default)(_this2, options.functions);
|
|
251
252
|
|
|
252
253
|
_this2.app.acl.registerSnippet({
|
|
253
254
|
name: `pm.${_this2.name}.workflows`,
|
|
@@ -268,21 +269,13 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
268
269
|
}
|
|
269
270
|
});
|
|
270
271
|
|
|
271
|
-
(0, _actions.default)(_this2);
|
|
272
|
-
(0, _triggers.default)(_this2, options.triggers);
|
|
273
|
-
(0, _instructions.default)(_this2, options.instructions);
|
|
274
272
|
db.on('workflows.beforeSave', _this2.onBeforeSave);
|
|
275
273
|
db.on('workflows.afterSave', model => _this2.toggle(model));
|
|
276
|
-
db.on('workflows.afterDestroy', model => _this2.toggle(model, false));
|
|
277
|
-
|
|
278
|
-
_this2.app.on('afterLoad', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
279
|
-
_this2.extensions.reduce((promise, extend) => promise.then(() => extend(_this2)), Promise.resolve());
|
|
280
|
-
})); // [Life Cycle]:
|
|
274
|
+
db.on('workflows.afterDestroy', model => _this2.toggle(model, false)); // [Life Cycle]:
|
|
281
275
|
// * load all workflows in db
|
|
282
276
|
// * add all hooks for enabled workflows
|
|
283
277
|
// * add hooks for create/update[enabled]/delete workflow to add/remove specific hooks
|
|
284
278
|
|
|
285
|
-
|
|
286
279
|
_this2.app.on('beforeStart', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
287
280
|
const collection = db.getCollection('workflows');
|
|
288
281
|
const workflows = yield collection.repository.find({
|
|
@@ -375,7 +368,7 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
375
368
|
} else {
|
|
376
369
|
const execution = yield _this4.db.getRepository('executions').findOne({
|
|
377
370
|
filter: {
|
|
378
|
-
status: _constants.EXECUTION_STATUS.
|
|
371
|
+
status: _constants.EXECUTION_STATUS.QUEUEING
|
|
379
372
|
},
|
|
380
373
|
sort: 'createdAt'
|
|
381
374
|
});
|
|
@@ -385,8 +378,6 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
385
378
|
}
|
|
386
379
|
}
|
|
387
380
|
|
|
388
|
-
;
|
|
389
|
-
|
|
390
381
|
if (next) {
|
|
391
382
|
_this4.process(...next);
|
|
392
383
|
}
|
|
@@ -399,7 +390,7 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
399
390
|
return _asyncToGenerator(function* () {
|
|
400
391
|
_this5.executing = execution;
|
|
401
392
|
|
|
402
|
-
if (execution.status === _constants.EXECUTION_STATUS.
|
|
393
|
+
if (execution.status === _constants.EXECUTION_STATUS.QUEUEING) {
|
|
403
394
|
yield execution.update({
|
|
404
395
|
status: _constants.EXECUTION_STATUS.STARTED
|
|
405
396
|
});
|
|
@@ -407,7 +398,7 @@ class WorkflowPlugin extends _server().Plugin {
|
|
|
407
398
|
|
|
408
399
|
const processor = _this5.createProcessor(execution);
|
|
409
400
|
|
|
410
|
-
_this5.app.logger.info(`[Workflow] execution ${execution.id} ${job ? 'resuming' : 'starting'}
|
|
401
|
+
_this5.app.logger.info(`[Workflow] execution ${execution.id} ${job ? 'resuming' : 'starting'}...`);
|
|
411
402
|
|
|
412
403
|
try {
|
|
413
404
|
yield job ? processor.resume(job) : processor.start();
|
|
@@ -12,7 +12,7 @@ export default class Processor {
|
|
|
12
12
|
static StatusMap: {
|
|
13
13
|
[x: number]: number;
|
|
14
14
|
};
|
|
15
|
-
transaction
|
|
15
|
+
transaction?: Transaction;
|
|
16
16
|
nodes: FlowNodeModel[];
|
|
17
17
|
nodesMap: Map<number, FlowNodeModel>;
|
|
18
18
|
jobsMap: Map<number, JobModel>;
|
|
@@ -23,7 +23,7 @@ export default class Processor {
|
|
|
23
23
|
private makeNodes;
|
|
24
24
|
private makeJobs;
|
|
25
25
|
private getTransaction;
|
|
26
|
-
|
|
26
|
+
prepare(): Promise<void>;
|
|
27
27
|
start(): Promise<void>;
|
|
28
28
|
resume(job: JobModel): Promise<void>;
|
|
29
29
|
private commit;
|
|
@@ -37,5 +37,12 @@ export default class Processor {
|
|
|
37
37
|
findBranchStartNode(node: FlowNodeModel, parent?: FlowNodeModel): FlowNodeModel | null;
|
|
38
38
|
findBranchParentNode(node: FlowNodeModel): FlowNodeModel | null;
|
|
39
39
|
findBranchParentJob(job: JobModel, node: FlowNodeModel): JobModel | null;
|
|
40
|
+
getScope(node?: any): {
|
|
41
|
+
$context: any;
|
|
42
|
+
$jobsMapByNodeId: {
|
|
43
|
+
[key: number]: any;
|
|
44
|
+
};
|
|
45
|
+
$system: {};
|
|
46
|
+
};
|
|
40
47
|
getParsedValue(value: any, node?: any): any;
|
|
41
48
|
}
|