@nocobase/plugin-workflow 0.7.0-alpha.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.
- package/LICENSE +201 -0
- package/esm/actions/flow_nodes.d.ts +3 -0
- package/esm/actions/flow_nodes.js +139 -0
- package/esm/actions/flow_nodes.js.map +1 -0
- package/esm/actions/index.d.ts +1 -0
- package/esm/actions/index.js +8 -0
- package/esm/actions/index.js.map +1 -0
- package/esm/calculators/index.d.ts +38 -0
- package/esm/calculators/index.js +128 -0
- package/esm/calculators/index.js.map +1 -0
- package/esm/collections/executions.d.ts +3 -0
- package/esm/collections/executions.js +38 -0
- package/esm/collections/executions.js.map +1 -0
- package/esm/collections/flow_nodes.d.ts +3 -0
- package/esm/collections/flow_nodes.js +72 -0
- package/esm/collections/flow_nodes.js.map +1 -0
- package/esm/collections/jobs.d.ts +3 -0
- package/esm/collections/jobs.js +47 -0
- package/esm/collections/jobs.js.map +1 -0
- package/esm/collections/workflows.d.ts +3 -0
- package/esm/collections/workflows.js +63 -0
- package/esm/collections/workflows.js.map +1 -0
- package/esm/constants.d.ts +17 -0
- package/esm/constants.js +18 -0
- package/esm/constants.js.map +1 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +6 -0
- package/esm/index.js.map +1 -0
- package/esm/instructions/calculation.d.ts +8 -0
- package/esm/instructions/calculation.js +55 -0
- package/esm/instructions/calculation.js.map +1 -0
- package/esm/instructions/condition.d.ts +5 -0
- package/esm/instructions/condition.js +99 -0
- package/esm/instructions/condition.js.map +1 -0
- package/esm/instructions/create.d.ts +8 -0
- package/esm/instructions/create.js +25 -0
- package/esm/instructions/create.js.map +1 -0
- package/esm/instructions/destroy.d.ts +8 -0
- package/esm/instructions/destroy.js +25 -0
- package/esm/instructions/destroy.js.map +1 -0
- package/esm/instructions/index.d.ts +15 -0
- package/esm/instructions/index.js +20 -0
- package/esm/instructions/index.js.map +1 -0
- package/esm/instructions/parallel.d.ts +13 -0
- package/esm/instructions/parallel.js +88 -0
- package/esm/instructions/parallel.js.map +1 -0
- package/esm/instructions/prompt.d.ts +7 -0
- package/esm/instructions/prompt.js +13 -0
- package/esm/instructions/prompt.js.map +1 -0
- package/esm/instructions/query.d.ts +8 -0
- package/esm/instructions/query.js +25 -0
- package/esm/instructions/query.js.map +1 -0
- package/esm/instructions/update.d.ts +8 -0
- package/esm/instructions/update.js +25 -0
- package/esm/instructions/update.js.map +1 -0
- package/esm/models/Execution.d.ts +50 -0
- package/esm/models/Execution.js +250 -0
- package/esm/models/Execution.js.map +1 -0
- package/esm/models/FlowNode.d.ts +17 -0
- package/esm/models/FlowNode.js +4 -0
- package/esm/models/FlowNode.js.map +1 -0
- package/esm/models/Job.d.ts +15 -0
- package/esm/models/Job.js +4 -0
- package/esm/models/Job.js.map +1 -0
- package/esm/models/Workflow.d.ts +27 -0
- package/esm/models/Workflow.js +72 -0
- package/esm/models/Workflow.js.map +1 -0
- package/esm/server.d.ts +5 -0
- package/esm/server.js +62 -0
- package/esm/server.js.map +1 -0
- package/esm/triggers/index.d.ts +9 -0
- package/esm/triggers/index.js +6 -0
- package/esm/triggers/index.js.map +1 -0
- package/esm/triggers/model.d.ts +12 -0
- package/esm/triggers/model.js +47 -0
- package/esm/triggers/model.js.map +1 -0
- package/lib/actions/flow_nodes.d.ts +3 -0
- package/lib/actions/flow_nodes.js +163 -0
- package/lib/actions/flow_nodes.js.map +1 -0
- package/lib/actions/index.d.ts +1 -0
- package/lib/actions/index.js +30 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/calculators/index.d.ts +38 -0
- package/lib/calculators/index.js +132 -0
- package/lib/calculators/index.js.map +1 -0
- package/lib/collections/executions.d.ts +3 -0
- package/lib/collections/executions.js +40 -0
- package/lib/collections/executions.js.map +1 -0
- package/lib/collections/flow_nodes.d.ts +3 -0
- package/lib/collections/flow_nodes.js +74 -0
- package/lib/collections/flow_nodes.js.map +1 -0
- package/lib/collections/jobs.d.ts +3 -0
- package/lib/collections/jobs.js +49 -0
- package/lib/collections/jobs.js.map +1 -0
- package/lib/collections/workflows.d.ts +3 -0
- package/lib/collections/workflows.js +65 -0
- package/lib/collections/workflows.js.map +1 -0
- package/lib/constants.d.ts +17 -0
- package/lib/constants.js +21 -0
- package/lib/constants.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +23 -0
- package/lib/index.js.map +1 -0
- package/lib/instructions/calculation.d.ts +8 -0
- package/lib/instructions/calculation.js +57 -0
- package/lib/instructions/calculation.js.map +1 -0
- package/lib/instructions/condition.d.ts +5 -0
- package/lib/instructions/condition.js +120 -0
- package/lib/instructions/condition.js.map +1 -0
- package/lib/instructions/create.d.ts +8 -0
- package/lib/instructions/create.js +27 -0
- package/lib/instructions/create.js.map +1 -0
- package/lib/instructions/destroy.d.ts +8 -0
- package/lib/instructions/destroy.js +27 -0
- package/lib/instructions/destroy.js.map +1 -0
- package/lib/instructions/index.d.ts +15 -0
- package/lib/instructions/index.js +26 -0
- package/lib/instructions/index.js.map +1 -0
- package/lib/instructions/parallel.d.ts +13 -0
- package/lib/instructions/parallel.js +91 -0
- package/lib/instructions/parallel.js.map +1 -0
- package/lib/instructions/prompt.d.ts +7 -0
- package/lib/instructions/prompt.js +15 -0
- package/lib/instructions/prompt.js.map +1 -0
- package/lib/instructions/query.d.ts +8 -0
- package/lib/instructions/query.js +27 -0
- package/lib/instructions/query.js.map +1 -0
- package/lib/instructions/update.d.ts +8 -0
- package/lib/instructions/update.js +27 -0
- package/lib/instructions/update.js.map +1 -0
- package/lib/models/Execution.d.ts +50 -0
- package/lib/models/Execution.js +256 -0
- package/lib/models/Execution.js.map +1 -0
- package/lib/models/FlowNode.d.ts +17 -0
- package/lib/models/FlowNode.js +7 -0
- package/lib/models/FlowNode.js.map +1 -0
- package/lib/models/Job.d.ts +15 -0
- package/lib/models/Job.js +7 -0
- package/lib/models/Job.js.map +1 -0
- package/lib/models/Workflow.d.ts +27 -0
- package/lib/models/Workflow.js +78 -0
- package/lib/models/Workflow.js.map +1 -0
- package/lib/server.d.ts +5 -0
- package/lib/server.js +68 -0
- package/lib/server.js.map +1 -0
- package/lib/triggers/index.d.ts +9 -0
- package/lib/triggers/index.js +12 -0
- package/lib/triggers/index.js.map +1 -0
- package/lib/triggers/model.d.ts +12 -0
- package/lib/triggers/model.js +49 -0
- package/lib/triggers/model.js.map +1 -0
- package/package.json +28 -0
- package/tsconfig.build.json +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
import { Op } from 'sequelize';
|
|
11
|
+
import actions, { utils } from '@nocobase/actions';
|
|
12
|
+
export function create(context, next) {
|
|
13
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
return actions.create(context, () => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { body: instance, db } = context;
|
|
16
|
+
const repository = utils.getRepositoryFromParams(context);
|
|
17
|
+
if (!instance.upstreamId) {
|
|
18
|
+
const previousHead = yield repository.findOne({
|
|
19
|
+
filter: {
|
|
20
|
+
id: {
|
|
21
|
+
$ne: instance.id
|
|
22
|
+
},
|
|
23
|
+
upstreamId: null
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (previousHead) {
|
|
27
|
+
yield previousHead.setUpstream(instance);
|
|
28
|
+
yield instance.setDownstream(previousHead);
|
|
29
|
+
instance.set('downstream', previousHead);
|
|
30
|
+
}
|
|
31
|
+
return next();
|
|
32
|
+
}
|
|
33
|
+
const upstream = yield instance.getUpstream();
|
|
34
|
+
if (instance.branchIndex == null) {
|
|
35
|
+
const downstream = yield upstream.getDownstream();
|
|
36
|
+
if (downstream) {
|
|
37
|
+
yield downstream.setUpstream(instance);
|
|
38
|
+
yield instance.setDownstream(downstream);
|
|
39
|
+
instance.set('downstream', downstream);
|
|
40
|
+
}
|
|
41
|
+
yield upstream.update({
|
|
42
|
+
downstreamId: instance.id
|
|
43
|
+
});
|
|
44
|
+
upstream.set('downstream', instance);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const [downstream] = yield upstream.getBranches({
|
|
48
|
+
where: {
|
|
49
|
+
id: {
|
|
50
|
+
[Op.ne]: instance.id
|
|
51
|
+
},
|
|
52
|
+
branchIndex: instance.branchIndex
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (downstream) {
|
|
56
|
+
yield downstream.update({
|
|
57
|
+
upstreamId: instance.id,
|
|
58
|
+
branchIndex: null
|
|
59
|
+
});
|
|
60
|
+
yield instance.setDownstream(downstream);
|
|
61
|
+
instance.set('downstream', downstream);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
instance.set('upstream', upstream);
|
|
65
|
+
yield next();
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function searchBranchNodes(nodes, from) {
|
|
70
|
+
const branchHeads = nodes
|
|
71
|
+
.filter((item) => item.upstreamId === from.id && item.branchIndex != null);
|
|
72
|
+
return branchHeads.reduce((flatten, head) => flatten.concat(searchBranchDownstreams(nodes, head)), []);
|
|
73
|
+
}
|
|
74
|
+
function searchBranchDownstreams(nodes, from) {
|
|
75
|
+
let result = [];
|
|
76
|
+
for (let search = from; search; search = search.downstream) {
|
|
77
|
+
result = [...result, search, ...searchBranchNodes(nodes, search)];
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
export function destroy(context, next) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const repository = utils.getRepositoryFromParams(context);
|
|
84
|
+
const { db } = context;
|
|
85
|
+
const { filterByTk } = context.action.params;
|
|
86
|
+
context.body = yield db.sequelize.transaction((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const fields = ['id', 'upstreamId', 'downstreamId', 'branchIndex'];
|
|
88
|
+
const instance = yield repository.findOne({
|
|
89
|
+
filterByTk,
|
|
90
|
+
fields: [...fields, 'workflowId'],
|
|
91
|
+
appends: ['upstream', 'downstream'],
|
|
92
|
+
transaction
|
|
93
|
+
});
|
|
94
|
+
const { upstream, downstream } = instance.get();
|
|
95
|
+
if (upstream && upstream.downstreamId === instance.id) {
|
|
96
|
+
yield upstream.update({
|
|
97
|
+
downstreamId: instance.downstreamId
|
|
98
|
+
}, { transaction });
|
|
99
|
+
}
|
|
100
|
+
if (downstream) {
|
|
101
|
+
yield downstream.update({
|
|
102
|
+
upstreamId: instance.upstreamId,
|
|
103
|
+
branchIndex: instance.branchIndex
|
|
104
|
+
}, { transaction });
|
|
105
|
+
}
|
|
106
|
+
const nodes = yield repository.find({
|
|
107
|
+
filter: {
|
|
108
|
+
workflowId: instance.workflowId
|
|
109
|
+
},
|
|
110
|
+
fields,
|
|
111
|
+
transaction
|
|
112
|
+
});
|
|
113
|
+
const nodesMap = new Map();
|
|
114
|
+
// make map
|
|
115
|
+
nodes.forEach(item => {
|
|
116
|
+
nodesMap.set(item.id, item);
|
|
117
|
+
});
|
|
118
|
+
// overwrite
|
|
119
|
+
nodesMap.set(instance.id, instance);
|
|
120
|
+
// make linked list
|
|
121
|
+
nodes.forEach(item => {
|
|
122
|
+
if (item.upstreamId) {
|
|
123
|
+
item.upstream = nodesMap.get(item.upstreamId);
|
|
124
|
+
}
|
|
125
|
+
if (item.downstreamId) {
|
|
126
|
+
item.downstream = nodesMap.get(item.downstreamId);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
const branchNodes = searchBranchNodes(nodes, instance);
|
|
130
|
+
yield repository.destroy({
|
|
131
|
+
filterByTk: [instance.id, ...branchNodes.map(item => item.id)],
|
|
132
|
+
transaction
|
|
133
|
+
});
|
|
134
|
+
return instance;
|
|
135
|
+
}));
|
|
136
|
+
yield next();
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=flow_nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow_nodes.js","sourceRoot":"","sources":["../../src/actions/flow_nodes.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAC/B,OAAO,OAAO,EAAE,EAAW,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE5D,MAAM,UAAgB,MAAM,CAAC,OAAgB,EAAE,IAAI;;QACjD,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,GAAS,EAAE;YACxC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;YACvC,MAAM,UAAU,GAAG,KAAK,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;YAE1D,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE;gBACxB,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;oBAC5C,MAAM,EAAE;wBACN,EAAE,EAAE;4BACF,GAAG,EAAE,QAAQ,CA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ACH,YAAY;YACZ,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;YACpC,mBAAmB;YACnB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACnB,IAAI,IAAI,CAAC,UAAU,EAAE;oBACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;iBAC/C;gBACD,IAAI,IAAI,CAAC,YAAY,EAAE;oBACrB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACnD;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,WAAW,GAAG,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAEvD,MAAM,UAAU,CAAC,OAAO,CAAC;gBACvB,UAAU,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC9D,WAAW;aACZ,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAA,CAAC,CAAC;QAEH,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA","sourcesContent":["import { Op } from 'sequelize';\nimport actions, { Context, utils } from '@nocobase/actions';\n\nexport async function create(context: Context, next) {\n return actions.create(context, async () => {\n const { body: instance, db } = context;\n const repository = utils.getRepositoryFromParams(context);\n\n if (!instance.upstreamId) {\n const previousHead = await repository.findOne({\n filter: {\n id: {\n $ne: instance.id\n },\n upstreamId: null\n }\n });\n if (previousHead) {\n await previousHead.setUpstream(instance);\n await instance.setDownstream(previousHead);\n instance.set('downstream', previousHead);\n }\n return next();\n }\n\n const upstream = await instance.getUpstream();\n\n if (instance.branchIndex == null) {\n const downstream = await upstream.getDownstream();\n\n if (downstream) {\n await downstream.setUpstream(instance);\n await instance.setDownstream(downstream);\n instance.set('downstream', downstream);\n }\n\n await upstream.update({\n downstreamId: instance.id\n });\n\n upstream.set('downstream', instance);\n } else {\n const [downstream] = await upstream.getBranches({\n where: {\n id: {\n [Op.ne]: instance.id\n },\n branchIndex: instance.branchIndex\n }\n });\n\n if (downstream) {\n await downstream.update({\n upstreamId: instance.id,\n branchIndex: null\n });\n await instance.setDownstream(downstream);\n instance.set('downstream', downstream);\n }\n }\n\n instance.set('upstream', upstream);\n\n await next();\n });\n}\n\nfunction searchBranchNodes(nodes, from): any[] {\n const branchHeads = nodes\n .filter((item: any) => item.upstreamId === from.id && item.branchIndex != null);\n return branchHeads.reduce((flatten: any[], head) => flatten.concat(searchBranchDownstreams(nodes, head)), []) as any[];\n}\n\nfunction searchBranchDownstreams(nodes, from) {\n let result = [];\n for (let search = from; search; search = search.downstream) {\n result = [...result, search, ...searchBranchNodes(nodes, search)];\n }\n return result;\n}\n\nexport async function destroy(context: Context, next) {\n const repository = utils.getRepositoryFromParams(context);\n const { db } = context;\n const { filterByTk } = context.action.params;\n\n context.body = await db.sequelize.transaction(async transaction => {\n const fields = ['id', 'upstreamId', 'downstreamId', 'branchIndex'];\n const instance = await repository.findOne({\n filterByTk,\n fields: [...fields, 'workflowId'],\n appends: ['upstream', 'downstream'],\n transaction\n });\n const { upstream, downstream } = instance.get();\n\n if (upstream && upstream.downstreamId === instance.id) {\n await upstream.update({\n downstreamId: instance.downstreamId\n }, { transaction });\n }\n\n if (downstream) {\n await downstream.update({\n upstreamId: instance.upstreamId,\n branchIndex: instance.branchIndex\n }, { transaction });\n }\n\n const nodes = await repository.find({\n filter: {\n workflowId: instance.workflowId\n },\n fields,\n transaction\n });\n const nodesMap = new Map();\n // make map\n nodes.forEach(item => {\n nodesMap.set(item.id, item);\n });\n // overwrite\n nodesMap.set(instance.id, instance);\n // make linked list\n nodes.forEach(item => {\n if (item.upstreamId) {\n item.upstream = nodesMap.get(item.upstreamId);\n }\n if (item.downstreamId) {\n item.downstream = nodesMap.get(item.downstreamId);\n }\n });\n\n const branchNodes = searchBranchNodes(nodes, instance);\n\n await repository.destroy({\n filterByTk: [instance.id, ...branchNodes.map(item => item.id)],\n transaction\n });\n\n return instance;\n });\n\n await next();\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (app: any): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as flow_nodes from './flow_nodes';
|
|
2
|
+
function make(name, mod) {
|
|
3
|
+
return Object.keys(mod).reduce((result, key) => (Object.assign(Object.assign({}, result), { [`${name}:${key}`]: mod[key] })), {});
|
|
4
|
+
}
|
|
5
|
+
export default function (app) {
|
|
6
|
+
app.actions(Object.assign({}, make('flow_nodes', flow_nodes)));
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAE3C,SAAS,IAAI,CAAC,IAAI,EAAE,GAAG;IACrB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iCAC3C,MAAM,KACT,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IAC5B,EAAE,EAAE,CAAC,CAAA;AACT,CAAC;AAED,MAAM,CAAC,OAAO,WAAU,GAAG;IACzB,GAAG,CAAC,OAAO,mBACN,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,EACjC,CAAC;AACL,CAAC","sourcesContent":["import * as flow_nodes from './flow_nodes';\n\nfunction make(name, mod) {\n return Object.keys(mod).reduce((result, key) => ({\n ...result,\n [`${name}:${key}`]: mod[key]\n }), {})\n}\n\nexport default function(app) {\n app.actions({\n ...make('flow_nodes', flow_nodes)\n });\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Registry } from "@nocobase/utils";
|
|
2
|
+
import ExecutionModel from '../models/Execution';
|
|
3
|
+
import JobModel from '../models/Job';
|
|
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
|
+
path?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare type JobGetterOptions = ObjectGetterOptions & {
|
|
11
|
+
nodeId: number;
|
|
12
|
+
};
|
|
13
|
+
export declare type CalculationOptions = {
|
|
14
|
+
calculator: string;
|
|
15
|
+
operands: Operand[];
|
|
16
|
+
};
|
|
17
|
+
export declare type ConstantOperand = {
|
|
18
|
+
type?: 'constant';
|
|
19
|
+
value: any;
|
|
20
|
+
};
|
|
21
|
+
export declare type ContextOperand = {
|
|
22
|
+
type: '$context';
|
|
23
|
+
options: ObjectGetterOptions;
|
|
24
|
+
};
|
|
25
|
+
export declare type InputOperand = {
|
|
26
|
+
type: '$input';
|
|
27
|
+
options: ObjectGetterOptions;
|
|
28
|
+
};
|
|
29
|
+
export declare type JobOperand = {
|
|
30
|
+
type: '$jobsMapByNodeId';
|
|
31
|
+
options: JobGetterOptions;
|
|
32
|
+
};
|
|
33
|
+
export declare type Calculation = {
|
|
34
|
+
type: '$calculation';
|
|
35
|
+
options: CalculationOptions;
|
|
36
|
+
};
|
|
37
|
+
export declare type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;
|
|
38
|
+
export declare function calculate(operand: Operand, lastJob: JobModel, execution: ExecutionModel): any;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { get as getWithPath } from 'lodash';
|
|
2
|
+
import { Registry } from "@nocobase/utils";
|
|
3
|
+
export const calculators = new Registry();
|
|
4
|
+
export default calculators;
|
|
5
|
+
// @deprecated
|
|
6
|
+
// HACK: if no path provided, return self
|
|
7
|
+
// @see https://github.com/lodash/lodash/pull/1270
|
|
8
|
+
// TODO(question): should add default value as lodash?
|
|
9
|
+
function get(object, path) {
|
|
10
|
+
return path == null || !path.length ? object : getWithPath(object, path);
|
|
11
|
+
}
|
|
12
|
+
// NOTE:
|
|
13
|
+
// this method could only be used in executing nodes.
|
|
14
|
+
// because type of 'job' need loaded jobs in runtime execution.
|
|
15
|
+
// or the execution should be prepared first.
|
|
16
|
+
export function calculate(operand, lastJob, execution) {
|
|
17
|
+
switch (operand.type) {
|
|
18
|
+
// @Deprecated
|
|
19
|
+
// from execution context
|
|
20
|
+
case '$context':
|
|
21
|
+
return get(execution.context, operand.options.path);
|
|
22
|
+
// @Deprecated
|
|
23
|
+
// from last job (or input job)
|
|
24
|
+
case '$input':
|
|
25
|
+
return lastJob !== null && lastJob !== void 0 ? lastJob : get(lastJob.result, operand.options.path);
|
|
26
|
+
// @Deprecated
|
|
27
|
+
// from job in execution
|
|
28
|
+
case '$jobsMapByNodeId':
|
|
29
|
+
// assume jobs have been fetched from execution before
|
|
30
|
+
const job = execution.jobsMapByNodeId[operand.options.nodeId];
|
|
31
|
+
return job && get(job, operand.options.path);
|
|
32
|
+
case '$calculation':
|
|
33
|
+
const fn = calculators.get(operand.options.calculator);
|
|
34
|
+
if (!fn) {
|
|
35
|
+
throw new Error(`no calculator function registered for "${operand.options.calculator}"`);
|
|
36
|
+
}
|
|
37
|
+
return fn(...operand.options.operands.map(item => calculate(item, lastJob, execution)));
|
|
38
|
+
// constant
|
|
39
|
+
default:
|
|
40
|
+
return operand.value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// built-in functions
|
|
44
|
+
function equal(a, b) {
|
|
45
|
+
return a === b;
|
|
46
|
+
}
|
|
47
|
+
function notEqual(a, b) {
|
|
48
|
+
return a !== b;
|
|
49
|
+
}
|
|
50
|
+
function gt(a, b) {
|
|
51
|
+
return a > b;
|
|
52
|
+
}
|
|
53
|
+
function gte(a, b) {
|
|
54
|
+
return a >= b;
|
|
55
|
+
}
|
|
56
|
+
function lt(a, b) {
|
|
57
|
+
return a < b;
|
|
58
|
+
}
|
|
59
|
+
function lte(a, b) {
|
|
60
|
+
return a <= b;
|
|
61
|
+
}
|
|
62
|
+
calculators.register('equal', equal);
|
|
63
|
+
calculators.register('notEqual', notEqual);
|
|
64
|
+
calculators.register('gt', gt);
|
|
65
|
+
calculators.register('gte', gte);
|
|
66
|
+
calculators.register('lt', lt);
|
|
67
|
+
calculators.register('lte', lte);
|
|
68
|
+
calculators.register('===', equal);
|
|
69
|
+
calculators.register('!==', notEqual);
|
|
70
|
+
calculators.register('>', gt);
|
|
71
|
+
calculators.register('>=', gte);
|
|
72
|
+
calculators.register('<', lt);
|
|
73
|
+
calculators.register('<=', lte);
|
|
74
|
+
function add(...args) {
|
|
75
|
+
return args.reduce((sum, a) => sum + a, 0);
|
|
76
|
+
}
|
|
77
|
+
function minus(a, b) {
|
|
78
|
+
return a - b;
|
|
79
|
+
}
|
|
80
|
+
function multipe(...args) {
|
|
81
|
+
return args.reduce((result, a) => result * a, 1);
|
|
82
|
+
}
|
|
83
|
+
function divide(a, b) {
|
|
84
|
+
return a / b;
|
|
85
|
+
}
|
|
86
|
+
function mod(a, b) {
|
|
87
|
+
return a % b;
|
|
88
|
+
}
|
|
89
|
+
calculators.register('add', add);
|
|
90
|
+
calculators.register('minus', minus);
|
|
91
|
+
calculators.register('multipe', multipe);
|
|
92
|
+
calculators.register('divide', divide);
|
|
93
|
+
calculators.register('mod', mod);
|
|
94
|
+
calculators.register('+', add);
|
|
95
|
+
calculators.register('-', minus);
|
|
96
|
+
calculators.register('*', multipe);
|
|
97
|
+
calculators.register('/', divide);
|
|
98
|
+
calculators.register('%', mod);
|
|
99
|
+
function includes(a, b) {
|
|
100
|
+
return a.includes(b);
|
|
101
|
+
}
|
|
102
|
+
function notIncludes(a, b) {
|
|
103
|
+
return !a.includes(b);
|
|
104
|
+
}
|
|
105
|
+
function startsWith(a, b) {
|
|
106
|
+
return a.startsWith(b);
|
|
107
|
+
}
|
|
108
|
+
function notStartsWith(a, b) {
|
|
109
|
+
return !a.startsWith(b);
|
|
110
|
+
}
|
|
111
|
+
function endsWith(a, b) {
|
|
112
|
+
return a.endsWith(b);
|
|
113
|
+
}
|
|
114
|
+
function notEndsWith(a, b) {
|
|
115
|
+
return !a.endsWith(b);
|
|
116
|
+
}
|
|
117
|
+
calculators.register('includes', includes);
|
|
118
|
+
calculators.register('notIncludes', notIncludes);
|
|
119
|
+
calculators.register('startsWith', startsWith);
|
|
120
|
+
calculators.register('notStartsWith', notStartsWith);
|
|
121
|
+
calculators.register('endsWith', endsWith);
|
|
122
|
+
calculators.register('notEndsWith', notEndsWith);
|
|
123
|
+
function before(a, b) {
|
|
124
|
+
return a < b;
|
|
125
|
+
}
|
|
126
|
+
calculators.register('now', () => new Date());
|
|
127
|
+
// TODO: add more common calculators
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/calculators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAK3C,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,QAAQ,EAAY,CAAC;AAEpD,eAAe,WAAW,CAAC;AA8C3B,cAAc;AACd,yCAAyC;AACzC,kDAAkD;AAClD,sDAAsD;AACtD,SAAS,GAAG,CAAC,MAAM,EAAE,IAA6B;IAChD,OAAO,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAC3E,CAAC;AAED,QAAQ;AACR,sDAAsD;AACtD,gEAAgE;AAChE,8CAA8C;AAC9C,MAAM,UAAU,SAAS,CAAC,OAAgB,EAA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AED,SAAS,WAAW,CAAC,CAAC,EAAE,CAAC;IACvB,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,SAAS,UAAU,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,aAAa,CAAC,CAAS,EAAE,CAAS;IACzC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IACpC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,CAAS,EAAE,CAAS;IACvC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AACjD,WAAW,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AAC/C,WAAW,CAAC,QAAQ,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;AACrD,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC3C,WAAW,CAAC,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAEjD,SAAS,MAAM,CAAC,CAAS,EAAE,CAAS;IAClC,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,WAAW,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAE9C,oCAAoC","sourcesContent":["import { get as getWithPath } from 'lodash';\nimport { Registry } from \"@nocobase/utils\";\n\nimport ExecutionModel from '../models/Execution';\nimport JobModel from '../models/Job';\n\nexport const calculators = new Registry<Function>();\n\nexport default calculators;\n\n\nexport type OperandType = '$context' | '$input' | '$jobsMapByNodeId' | '$calculation';\n\nexport type ObjectGetterOptions = {\n path?: string\n};\n\nexport type JobGetterOptions = ObjectGetterOptions & {\n nodeId: number\n};\n\nexport type CalculationOptions = {\n calculator: string,\n operands: Operand[]\n};\n\nexport type ConstantOperand = {\n type?: 'constant';\n value: any\n};\n\nexport type ContextOperand = {\n type: '$context';\n options: ObjectGetterOptions;\n};\n\nexport type InputOperand = {\n type: '$input';\n options: ObjectGetterOptions;\n};\n\nexport type JobOperand = {\n type: '$jobsMapByNodeId';\n options: JobGetterOptions;\n};\n\nexport type Calculation = {\n type: '$calculation';\n options: CalculationOptions\n};\n\n// TODO(type): union type here is wrong\nexport type Operand = ContextOperand | InputOperand | JobOperand | ConstantOperand | Calculation;\n\n// @deprecated\n// HACK: if no path provided, return self\n// @see https://github.com/lodash/lodash/pull/1270\n// TODO(question): should add default value as lodash?\nfunction get(object, path?: string | Array<string>) {\n return path == null || !path.length ? object : getWithPath(object, path);\n}\n\n// NOTE:\n// this method could only be used in executing nodes.\n// because type of 'job' need loaded jobs in runtime execution.\n// or the execution should be prepared first.\nexport function calculate(operand: Operand, lastJob: JobModel, execution: ExecutionModel) {\n switch (operand.type) {\n // @Deprecated\n // from execution context\n case '$context':\n return get(execution.context, operand.options.path);\n\n // @Deprecated\n // from last job (or input job)\n case '$input':\n return lastJob ?? get(lastJob.result, operand.options.path);\n\n // @Deprecated\n // from job in execution\n case '$jobsMapByNodeId':\n // assume jobs have been fetched from execution before\n const job = execution.jobsMapByNodeId[operand.options.nodeId];\n return job && get(job, operand.options.path);\n\n case '$calculation':\n const fn = calculators.get(operand.options.calculator);\n if (!fn) {\n throw new Error(`no calculator function registered for \"${operand.options.calculator}\"`);\n }\n return fn(...operand.options.operands.map(item => calculate(item, lastJob, execution)));\n\n // constant\n default:\n return operand.value;\n }\n}\n\n\n\n// built-in functions\n\nfunction equal(a, b) {\n return a === b;\n}\n\nfunction notEqual(a, b) {\n return a !== b;\n}\n\nfunction gt(a, b) {\n return a > b;\n}\n\nfunction gte(a, b) {\n return a >= b;\n}\n\nfunction lt(a, b) {\n return a < b;\n}\n\nfunction lte(a, b) {\n return a <= b;\n}\n\ncalculators.register('equal', equal);\ncalculators.register('notEqual', notEqual);\ncalculators.register('gt', gt);\ncalculators.register('gte', gte);\ncalculators.register('lt', lt);\ncalculators.register('lte', lte);\n\ncalculators.register('===', equal);\ncalculators.register('!==', notEqual);\ncalculators.register('>', gt);\ncalculators.register('>=', gte);\ncalculators.register('<', lt);\ncalculators.register('<=', lte);\n\n\n\nfunction add(...args) {\n return args.reduce((sum, a) => sum + a, 0);\n}\n\nfunction minus(a, b) {\n return a - b;\n}\n\nfunction multipe(...args) {\n return args.reduce((result, a) => result * a, 1);\n}\n\nfunction divide(a, b) {\n return a / b;\n}\n\nfunction mod(a, b) {\n return a % b;\n}\n\ncalculators.register('add', add);\ncalculators.register('minus', minus);\ncalculators.register('multipe', multipe);\ncalculators.register('divide', divide);\ncalculators.register('mod', mod);\n\ncalculators.register('+', add);\ncalculators.register('-', minus);\ncalculators.register('*', multipe);\ncalculators.register('/', divide);\ncalculators.register('%', mod);\n\nfunction includes(a, b) {\n return a.includes(b);\n}\n\nfunction notIncludes(a, b) {\n return !a.includes(b);\n}\n\nfunction startsWith(a: string, b: string) {\n return a.startsWith(b);\n}\n\nfunction notStartsWith(a: string, b: string) {\n return !a.startsWith(b);\n}\n\nfunction endsWith(a: string, b: string) {\n return a.endsWith(b);\n}\n\nfunction notEndsWith(a: string, b: string) {\n return !a.endsWith(b);\n}\n\ncalculators.register('includes', includes);\ncalculators.register('notIncludes', notIncludes);\ncalculators.register('startsWith', startsWith);\ncalculators.register('notStartsWith', notStartsWith);\ncalculators.register('endsWith', endsWith);\ncalculators.register('notEndsWith', notEndsWith);\n\nfunction before(a: string, b: string) {\n return a < b;\n}\n\ncalculators.register('now', () => new Date());\n\n// TODO: add more common calculators\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
name: 'executions',
|
|
3
|
+
model: 'ExecutionModel',
|
|
4
|
+
title: '执行流程',
|
|
5
|
+
fields: [
|
|
6
|
+
{
|
|
7
|
+
interface: 'linkTo',
|
|
8
|
+
type: 'belongsTo',
|
|
9
|
+
name: 'workflow',
|
|
10
|
+
title: '所属工作流'
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
type: 'boolean',
|
|
14
|
+
name: 'useTransaction',
|
|
15
|
+
title: '使用事务',
|
|
16
|
+
defaultValue: false
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
interface: 'linkTo',
|
|
20
|
+
type: 'hasMany',
|
|
21
|
+
name: 'jobs',
|
|
22
|
+
title: '流程记录'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
interface: 'json',
|
|
26
|
+
type: 'jsonb',
|
|
27
|
+
name: 'context',
|
|
28
|
+
title: '上下文数据'
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
interface: 'select',
|
|
32
|
+
type: 'integer',
|
|
33
|
+
name: 'status',
|
|
34
|
+
title: '状态'
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=executions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executions.js","sourceRoot":"","sources":["../../src/collections/executions.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,gBAAgB;IACvB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE;QACN;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,OAAO;SACf;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,gBAAgB;YACtB,KAAK,EAAE,MAAM;YACb,YAAY,EAAE,KAAK;SACpB;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,MAAM;SACd;QACD;YACE,SAAS,EAAE,MAAM;YACjB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,OAAO;SACf;QACD;YACE,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,IAAI;SACZ;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'executions',\n model: 'ExecutionModel',\n title: '执行流程',\n fields: [\n {\n interface: 'linkTo',\n type: 'belongsTo',\n name: 'workflow',\n title: '所属工作流'\n },\n {\n type: 'boolean',\n name: 'useTransaction',\n title: '使用事务',\n defaultValue: false\n },\n {\n interface: 'linkTo',\n type: 'hasMany',\n name: 'jobs',\n title: '流程记录'\n },\n {\n interface: 'json',\n type: 'jsonb',\n name: 'context',\n title: '上下文数据'\n },\n {\n interface: 'select',\n type: 'integer',\n name: 'status',\n title: '状态'\n }\n ]\n} as CollectionOptions;\n"]}
|