@pxp-nd/flow 1.0.17 → 1.0.21
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/dist/controllers/Action.js +6 -3
- package/dist/controllers/Flow.d.ts +6 -0
- package/dist/controllers/Flow.js +48 -0
- package/dist/controllers/Node.d.ts +1 -0
- package/dist/controllers/Node.js +43 -20
- package/dist/controllers/NodeInstance.js +5 -2
- package/dist/entity/Action.d.ts +1 -0
- package/dist/entity/Action.js +4 -0
- package/dist/entity/ActionType.d.ts +1 -0
- package/dist/entity/ActionType.js +4 -0
- package/dist/entity/Flow.d.ts +1 -0
- package/dist/entity/Flow.js +4 -0
- package/package.json +1 -1
- package/tsconfig.json +2 -2
|
@@ -48,9 +48,12 @@ let Action = class Action extends core_1.Controller {
|
|
|
48
48
|
);*/
|
|
49
49
|
const actionsFind = await Action_1.default.find({
|
|
50
50
|
relations: ['actionType'],
|
|
51
|
-
where:
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
where: {
|
|
52
|
+
...(actionTypeName ? { actionType: {
|
|
53
|
+
name: actionTypeName
|
|
54
|
+
} } : {}),
|
|
55
|
+
...(actionId ? { actionId: actionId } : {}),
|
|
56
|
+
}
|
|
54
57
|
});
|
|
55
58
|
return { data: actionsFind };
|
|
56
59
|
}
|
|
@@ -11,8 +11,14 @@
|
|
|
11
11
|
* Created at : 2021-07-08 12:55:38
|
|
12
12
|
* Last modified :
|
|
13
13
|
*/
|
|
14
|
+
import { EntityManager } from 'typeorm';
|
|
14
15
|
import { Controller } from '@pxp-nd/core';
|
|
15
16
|
declare class Flow extends Controller {
|
|
16
17
|
get(params: Record<string, any>): Promise<unknown>;
|
|
18
|
+
copyNodeConnections(nodeId: number, newNodeId: number, newFlowId: number, manager: EntityManager): Promise<void>;
|
|
19
|
+
copyNode(node: Record<any, any>, newFlowId: number, manager: EntityManager): Promise<{
|
|
20
|
+
nodeId: any;
|
|
21
|
+
}>;
|
|
22
|
+
createFlowFromFlow(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
17
23
|
}
|
|
18
24
|
export default Flow;
|
package/dist/controllers/Flow.js
CHANGED
|
@@ -25,9 +25,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
const typeorm_1 = require("typeorm");
|
|
28
29
|
const core_1 = require("@pxp-nd/core");
|
|
29
30
|
const Node_1 = __importDefault(require("../entity/Node"));
|
|
30
31
|
const NodeConnection_1 = __importDefault(require("../entity/NodeConnection"));
|
|
32
|
+
const Flow_1 = __importDefault(require("../entity/Flow"));
|
|
31
33
|
let Flow = class Flow extends core_1.Controller {
|
|
32
34
|
async get(params) {
|
|
33
35
|
const nodes = await Node_1.default.find({ flowId: params.flowId });
|
|
@@ -38,6 +40,43 @@ let Flow = class Flow extends core_1.Controller {
|
|
|
38
40
|
}
|
|
39
41
|
return restNodes;
|
|
40
42
|
}
|
|
43
|
+
async copyNodeConnections(nodeId, newNodeId, newFlowId, manager) {
|
|
44
|
+
const connections = await core_1.__(NodeConnection_1.default.find({ nodeIdMaster: nodeId }));
|
|
45
|
+
for (let connection of connections) {
|
|
46
|
+
const newNodeConnection = new NodeConnection_1.default();
|
|
47
|
+
const { nodeConnectionId, nodeIdMaster, nodeIdChild, createdAt, modifiedAt, ...nodeConnectionToCopy } = connection;
|
|
48
|
+
// get node from nodeIdChild
|
|
49
|
+
const dataNodeChild = await Node_1.default.findOne({ nodeId: connection.nodeIdChild });
|
|
50
|
+
const { nodeId: newNodeIdChild } = await this.copyNode(dataNodeChild, newFlowId, manager);
|
|
51
|
+
Object.assign(newNodeConnection, { ...nodeConnectionToCopy, nodeIdMaster: newNodeId, nodeIdChild: newNodeIdChild });
|
|
52
|
+
const insertNewNodeConnection = await core_1.__(manager.save(NodeConnection_1.default, newNodeConnection));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async copyNode(node, newFlowId, manager) {
|
|
56
|
+
// insert new node
|
|
57
|
+
const newNode = new Node_1.default();
|
|
58
|
+
const { nodeId, flowId, createdAt, modifiedAt, actionConfigJson, ...nodeToCopy } = node;
|
|
59
|
+
Object.assign(newNode, { ...nodeToCopy, flowId: newFlowId });
|
|
60
|
+
const insertNewNode = await core_1.__(manager.save(Node_1.default, newNode));
|
|
61
|
+
// insert connection
|
|
62
|
+
await this.copyNodeConnections(node.nodeId, insertNewNode.nodeId, newFlowId, manager);
|
|
63
|
+
return { nodeId: insertNewNode.nodeId };
|
|
64
|
+
}
|
|
65
|
+
async createFlowFromFlow(params, manager) {
|
|
66
|
+
// we need clone the flow selected
|
|
67
|
+
const dataFlow = await core_1.__(Flow_1.default.findOne(params.flowId));
|
|
68
|
+
const { flowId, createdAt, modifiedAt, nodes, ...flowToCopy } = dataFlow;
|
|
69
|
+
const newFlow = new Flow_1.default();
|
|
70
|
+
Object.assign(newFlow, flowToCopy);
|
|
71
|
+
newFlow.name = params.name;
|
|
72
|
+
newFlow.description = params.description;
|
|
73
|
+
const insertNewFlow = await core_1.__(manager.save(Flow_1.default, newFlow));
|
|
74
|
+
// create the nodes
|
|
75
|
+
// get the first node "the trigger node"
|
|
76
|
+
const dataNode = await Node_1.default.findOne({ where: { flowId: params.flowId }, order: { nodeId: "ASC" } });
|
|
77
|
+
dataNode && await this.copyNode(dataNode, insertNewFlow.flowId, manager);
|
|
78
|
+
return { flowId: insertNewFlow.flowId };
|
|
79
|
+
}
|
|
41
80
|
};
|
|
42
81
|
__decorate([
|
|
43
82
|
core_1.Get(),
|
|
@@ -48,6 +87,15 @@ __decorate([
|
|
|
48
87
|
__metadata("design:paramtypes", [Object]),
|
|
49
88
|
__metadata("design:returntype", Promise)
|
|
50
89
|
], Flow.prototype, "get", null);
|
|
90
|
+
__decorate([
|
|
91
|
+
core_1.Post(),
|
|
92
|
+
core_1.DbSettings('Orm'),
|
|
93
|
+
core_1.ReadOnly(false),
|
|
94
|
+
core_1.Log(true),
|
|
95
|
+
__metadata("design:type", Function),
|
|
96
|
+
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
97
|
+
__metadata("design:returntype", Promise)
|
|
98
|
+
], Flow.prototype, "createFlowFromFlow", null);
|
|
51
99
|
Flow = __decorate([
|
|
52
100
|
core_1.Model('flow-nd/Flow')
|
|
53
101
|
], Flow);
|
|
@@ -18,5 +18,6 @@ declare class Node extends Controller {
|
|
|
18
18
|
add(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
19
19
|
AddActionConfigJson(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
20
20
|
getParameterizedNode(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
21
|
+
executeActionJson(params: Record<string, any>, manager: EntityManager): Promise<unknown>;
|
|
21
22
|
}
|
|
22
23
|
export default Node;
|
package/dist/controllers/Node.js
CHANGED
|
@@ -21,17 +21,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
21
21
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
22
22
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
23
23
|
};
|
|
24
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
25
|
-
var t = {};
|
|
26
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
27
|
-
t[p] = s[p];
|
|
28
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
29
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
30
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
31
|
-
t[p[i]] = s[p[i]];
|
|
32
|
-
}
|
|
33
|
-
return t;
|
|
34
|
-
};
|
|
35
24
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
26
|
};
|
|
@@ -40,6 +29,7 @@ const typeorm_1 = require("typeorm");
|
|
|
40
29
|
const Node_1 = __importDefault(require("../entity/Node"));
|
|
41
30
|
const NodeConnection_1 = __importDefault(require("../entity/NodeConnection"));
|
|
42
31
|
const core_1 = require("@pxp-nd/core");
|
|
32
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
43
33
|
const FieldMap_1 = __importDefault(require("../entity/FieldMap"));
|
|
44
34
|
const OriginName_1 = __importDefault(require("../entity/OriginName"));
|
|
45
35
|
let Node = class Node extends core_1.Controller {
|
|
@@ -75,12 +65,10 @@ let Node = class Node extends core_1.Controller {
|
|
|
75
65
|
return nodeData;
|
|
76
66
|
}
|
|
77
67
|
async AddActionConfigJson(params, manager) {
|
|
78
|
-
|
|
79
|
-
let { nodeId: removed, __metadata: removed2 } = params, actionConfigJson = __rest(params, ["nodeId", "__metadata"]);
|
|
68
|
+
let { nodeId: removed, __metadata: removed2, ...actionConfigJson } = params;
|
|
80
69
|
Object.entries(params.__metadata).forEach(([nameKey, values]) => {
|
|
81
70
|
actionConfigJson[nameKey] = `{{ ${values.name} }}`;
|
|
82
71
|
});
|
|
83
|
-
console.log('actionConfigJson', actionConfigJson);
|
|
84
72
|
const upd = await core_1.__(manager.update(Node_1.default, params.nodeId, {
|
|
85
73
|
actionConfigJson: JSON.stringify(actionConfigJson),
|
|
86
74
|
}));
|
|
@@ -92,7 +80,8 @@ let Node = class Node extends core_1.Controller {
|
|
|
92
80
|
};
|
|
93
81
|
}
|
|
94
82
|
async getParameterizedNode(params, manager) {
|
|
95
|
-
|
|
83
|
+
lodash_1.default.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|
84
|
+
const { nodeId, flowId, substitutionsSchemaJson } = params;
|
|
96
85
|
/*const tNodeOrigin = __(NodeModel.find({
|
|
97
86
|
relations: ['action'],
|
|
98
87
|
where: {
|
|
@@ -114,11 +103,16 @@ let Node = class Node extends core_1.Controller {
|
|
|
114
103
|
tNodeData,
|
|
115
104
|
tFieldMapData
|
|
116
105
|
]);*/
|
|
117
|
-
const { actionConfigJson, action: { configJsonTemplate, actionType: { schemaJson } } } = nodeData;
|
|
106
|
+
const { actionConfigJson, action: { schemaJson, configJsonTemplate, actionType: { schemaJson: schemaJsonFromActionType } } } = nodeData;
|
|
118
107
|
const actionConfigJsonObject = actionConfigJson ? JSON.parse(actionConfigJson) : {};
|
|
119
108
|
const configJsonTemplateObject = configJsonTemplate ? JSON.parse(configJsonTemplate) : {};
|
|
120
|
-
let
|
|
121
|
-
|
|
109
|
+
let schemaJsonFromActionTypeObject = schemaJsonFromActionType ? JSON.parse(lodash_1.default.template(schemaJsonFromActionType)(substitutionsSchemaJson)) : {};
|
|
110
|
+
let schemaJsonFromActionObject = schemaJson ? JSON.parse(lodash_1.default.template(schemaJson)(substitutionsSchemaJson)) : {};
|
|
111
|
+
let schemaJsonObject = { ...schemaJsonFromActionTypeObject, ...schemaJsonFromActionObject };
|
|
112
|
+
const mergeValues = {
|
|
113
|
+
...configJsonTemplateObject,
|
|
114
|
+
...actionConfigJsonObject
|
|
115
|
+
};
|
|
122
116
|
const verifyIfValueFromFieldMap = (str) => {
|
|
123
117
|
if (/^{{/.test(str) && /}}$/.test(str)) {
|
|
124
118
|
return true;
|
|
@@ -134,7 +128,11 @@ let Node = class Node extends core_1.Controller {
|
|
|
134
128
|
};
|
|
135
129
|
Object.entries(mergeValues).forEach(([nameKey, value]) => {
|
|
136
130
|
if (schemaJsonObject[nameKey]) {
|
|
137
|
-
schemaJsonObject[nameKey] =
|
|
131
|
+
schemaJsonObject[nameKey] = {
|
|
132
|
+
...schemaJsonObject[nameKey],
|
|
133
|
+
initialValue: value,
|
|
134
|
+
...(verifyIfValueFromFieldMap(value) && { fromFieldMap: true, ...findFieldMapAndMetaData(value) }),
|
|
135
|
+
};
|
|
138
136
|
}
|
|
139
137
|
});
|
|
140
138
|
return {
|
|
@@ -147,6 +145,22 @@ let Node = class Node extends core_1.Controller {
|
|
|
147
145
|
fieldMapData,
|
|
148
146
|
};
|
|
149
147
|
}
|
|
148
|
+
async executeActionJson(params, manager) {
|
|
149
|
+
const { nodeId, originName, originKey, fromValues } = params;
|
|
150
|
+
// we need to get the value from merge values with originKey
|
|
151
|
+
const getParameterizedNodeData = await core_1.__(this.getParameterizedNode({ nodeId: nodeId }, manager));
|
|
152
|
+
const { mergeValues } = getParameterizedNodeData;
|
|
153
|
+
const findOriginValue = Object.entries(mergeValues).find(([nameValue]) => fromValues === nameValue);
|
|
154
|
+
const resValueObject = Object.fromEntries([findOriginValue]);
|
|
155
|
+
const originValue = resValueObject[fromValues];
|
|
156
|
+
const executeViewString = `select * from ${originName} where ${originKey} = ${originValue}`;
|
|
157
|
+
const resExecuteView = await typeorm_1.getManager().query(executeViewString);
|
|
158
|
+
/*const executeView = `select * from ${originName} where ${originKey} = ${newEvent.dataId}`;
|
|
159
|
+
const resExecuteView = await getManager().query(executeView);*/
|
|
160
|
+
return {
|
|
161
|
+
...resExecuteView[0]
|
|
162
|
+
};
|
|
163
|
+
}
|
|
150
164
|
};
|
|
151
165
|
__decorate([
|
|
152
166
|
core_1.Post(),
|
|
@@ -167,7 +181,7 @@ __decorate([
|
|
|
167
181
|
__metadata("design:returntype", Promise)
|
|
168
182
|
], Node.prototype, "AddActionConfigJson", null);
|
|
169
183
|
__decorate([
|
|
170
|
-
core_1.
|
|
184
|
+
core_1.Post(),
|
|
171
185
|
core_1.DbSettings('Orm'),
|
|
172
186
|
core_1.ReadOnly(false),
|
|
173
187
|
core_1.Log(true),
|
|
@@ -175,6 +189,15 @@ __decorate([
|
|
|
175
189
|
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
176
190
|
__metadata("design:returntype", Promise)
|
|
177
191
|
], Node.prototype, "getParameterizedNode", null);
|
|
192
|
+
__decorate([
|
|
193
|
+
core_1.Post(),
|
|
194
|
+
core_1.DbSettings('Orm'),
|
|
195
|
+
core_1.ReadOnly(false),
|
|
196
|
+
core_1.Log(true),
|
|
197
|
+
__metadata("design:type", Function),
|
|
198
|
+
__metadata("design:paramtypes", [Object, typeorm_1.EntityManager]),
|
|
199
|
+
__metadata("design:returntype", Promise)
|
|
200
|
+
], Node.prototype, "executeActionJson", null);
|
|
178
201
|
Node = __decorate([
|
|
179
202
|
core_1.Model('flow-nd/Node')
|
|
180
203
|
], Node);
|
|
@@ -53,7 +53,11 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
53
53
|
if (configJsonTemplate !== '' || actionConfigJson !== '') {
|
|
54
54
|
const actionConfigJsonObject = actionConfigJson && JSON.parse(lodash_1.default.template(actionConfigJson)(resultFromOrigin));
|
|
55
55
|
const configJsonTemplateObject = configJsonTemplate && JSON.parse(lodash_1.default.template(configJsonTemplate)(resultFromOrigin));
|
|
56
|
-
mergeJson =
|
|
56
|
+
mergeJson = {
|
|
57
|
+
...(configJsonTemplateObject || {}),
|
|
58
|
+
...(actionConfigJsonObject || {}),
|
|
59
|
+
__resultFromOrigin: resultFromOrigin
|
|
60
|
+
};
|
|
57
61
|
}
|
|
58
62
|
let nodeInstance = new NodeInstance_1.default();
|
|
59
63
|
nodeInstance.flowInstanceId = flowInstance.flowInstanceId;
|
|
@@ -116,7 +120,6 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
|
|
|
116
120
|
.andWhere("ni.status = 'WAIT' ")
|
|
117
121
|
.limit((maxNodes && maxNodes.value))
|
|
118
122
|
.getMany());
|
|
119
|
-
console.log('nodeInstanceDelayData', nodeInstanceDelayData);
|
|
120
123
|
for (const nodeInstance of nodeInstanceDelayData) {
|
|
121
124
|
//update status from wait to executing
|
|
122
125
|
await core_1.__(manager.update(NodeInstance_1.default, nodeInstance.nodeInstanceId, {
|
package/dist/entity/Action.d.ts
CHANGED
package/dist/entity/Action.js
CHANGED
|
@@ -58,6 +58,10 @@ __decorate([
|
|
|
58
58
|
typeorm_1.Column({ type: 'varchar', nullable: false, length: 1, default: 'N' }),
|
|
59
59
|
__metadata("design:type", String)
|
|
60
60
|
], Action.prototype, "hidden", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
typeorm_1.Column({ name: 'schema_json', type: 'text' }),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], Action.prototype, "schemaJson", void 0);
|
|
61
65
|
__decorate([
|
|
62
66
|
typeorm_1.ManyToOne(() => ActionType_1.default, actionType => actionType.actions, { eager: true }),
|
|
63
67
|
typeorm_1.JoinColumn({ name: 'action_type_id' }),
|
|
@@ -57,6 +57,10 @@ __decorate([
|
|
|
57
57
|
typeorm_1.Column({ name: 'extra_schema_json', type: 'text' }),
|
|
58
58
|
__metadata("design:type", String)
|
|
59
59
|
], ActionType.prototype, "extraSchemaJson", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
typeorm_1.Column({ name: 'actions_json', type: 'text' }),
|
|
62
|
+
__metadata("design:type", String)
|
|
63
|
+
], ActionType.prototype, "actionsJson", void 0);
|
|
60
64
|
__decorate([
|
|
61
65
|
typeorm_1.OneToMany(() => Action_1.default, (action) => action.actionType),
|
|
62
66
|
__metadata("design:type", Array)
|
package/dist/entity/Flow.d.ts
CHANGED
package/dist/entity/Flow.js
CHANGED
|
@@ -34,6 +34,10 @@ __decorate([
|
|
|
34
34
|
typeorm_1.Column({ type: 'varchar', nullable: false, length: 100 }),
|
|
35
35
|
__metadata("design:type", String)
|
|
36
36
|
], Flow.prototype, "name", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
typeorm_1.Column({ type: 'text', nullable: false }),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], Flow.prototype, "description", void 0);
|
|
37
41
|
__decorate([
|
|
38
42
|
typeorm_1.Column({ type: 'varchar', nullable: false, length: 100 }),
|
|
39
43
|
__metadata("design:type", String)
|
package/package.json
CHANGED