@pxp-nd/flow 1.0.18 → 1.0.22

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 CHANGED
@@ -1 +1 @@
1
- # flow-nd
1
+ # flow-nd
@@ -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;
@@ -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);
@@ -29,6 +29,7 @@ const typeorm_1 = require("typeorm");
29
29
  const Node_1 = __importDefault(require("../entity/Node"));
30
30
  const NodeConnection_1 = __importDefault(require("../entity/NodeConnection"));
31
31
  const core_1 = require("@pxp-nd/core");
32
+ const lodash_1 = __importDefault(require("lodash"));
32
33
  const FieldMap_1 = __importDefault(require("../entity/FieldMap"));
33
34
  const OriginName_1 = __importDefault(require("../entity/OriginName"));
34
35
  let Node = class Node extends core_1.Controller {
@@ -64,12 +65,10 @@ let Node = class Node extends core_1.Controller {
64
65
  return nodeData;
65
66
  }
66
67
  async AddActionConfigJson(params, manager) {
67
- console.log('params', params);
68
68
  let { nodeId: removed, __metadata: removed2, ...actionConfigJson } = params;
69
69
  Object.entries(params.__metadata).forEach(([nameKey, values]) => {
70
70
  actionConfigJson[nameKey] = `{{ ${values.name} }}`;
71
71
  });
72
- console.log('actionConfigJson', actionConfigJson);
73
72
  const upd = await core_1.__(manager.update(Node_1.default, params.nodeId, {
74
73
  actionConfigJson: JSON.stringify(actionConfigJson),
75
74
  }));
@@ -81,7 +80,8 @@ let Node = class Node extends core_1.Controller {
81
80
  };
82
81
  }
83
82
  async getParameterizedNode(params, manager) {
84
- const { nodeId, flowId } = params;
83
+ lodash_1.default.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
84
+ const { nodeId, flowId, substitutionsSchemaJson } = params;
85
85
  /*const tNodeOrigin = __(NodeModel.find({
86
86
  relations: ['action'],
87
87
  where: {
@@ -103,10 +103,12 @@ let Node = class Node extends core_1.Controller {
103
103
  tNodeData,
104
104
  tFieldMapData
105
105
  ]);*/
106
- const { actionConfigJson, action: { configJsonTemplate, actionType: { schemaJson } } } = nodeData;
106
+ const { actionConfigJson, action: { schemaJson, configJsonTemplate, actionType: { schemaJson: schemaJsonFromActionType } } } = nodeData;
107
107
  const actionConfigJsonObject = actionConfigJson ? JSON.parse(actionConfigJson) : {};
108
108
  const configJsonTemplateObject = configJsonTemplate ? JSON.parse(configJsonTemplate) : {};
109
- let schemaJsonObject = schemaJson ? JSON.parse(schemaJson) : {};
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 };
110
112
  const mergeValues = {
111
113
  ...configJsonTemplateObject,
112
114
  ...actionConfigJsonObject
@@ -144,7 +146,6 @@ let Node = class Node extends core_1.Controller {
144
146
  };
145
147
  }
146
148
  async executeActionJson(params, manager) {
147
- console.log('params', params);
148
149
  const { nodeId, originName, originKey, fromValues } = params;
149
150
  // we need to get the value from merge values with originKey
150
151
  const getParameterizedNodeData = await core_1.__(this.getParameterizedNode({ nodeId: nodeId }, manager));
@@ -154,9 +155,6 @@ let Node = class Node extends core_1.Controller {
154
155
  const originValue = resValueObject[fromValues];
155
156
  const executeViewString = `select * from ${originName} where ${originKey} = ${originValue}`;
156
157
  const resExecuteView = await typeorm_1.getManager().query(executeViewString);
157
- console.log('mergeValues', mergeValues);
158
- console.log('findOriginValue', findOriginValue);
159
- console.log('executeViewString', executeViewString);
160
158
  /*const executeView = `select * from ${originName} where ${originKey} = ${newEvent.dataId}`;
161
159
  const resExecuteView = await getManager().query(executeView);*/
162
160
  return {
@@ -183,7 +181,7 @@ __decorate([
183
181
  __metadata("design:returntype", Promise)
184
182
  ], Node.prototype, "AddActionConfigJson", null);
185
183
  __decorate([
186
- core_1.Get(),
184
+ core_1.Post(),
187
185
  core_1.DbSettings('Orm'),
188
186
  core_1.ReadOnly(false),
189
187
  core_1.Log(true),
@@ -120,7 +120,6 @@ let NodeInstance = class NodeInstance extends core_1.Controller {
120
120
  .andWhere("ni.status = 'WAIT' ")
121
121
  .limit((maxNodes && maxNodes.value))
122
122
  .getMany());
123
- console.log('nodeInstanceDelayData', nodeInstanceDelayData);
124
123
  for (const nodeInstance of nodeInstanceDelayData) {
125
124
  //update status from wait to executing
126
125
  await core_1.__(manager.update(NodeInstance_1.default, nodeInstance.nodeInstanceId, {
@@ -11,7 +11,9 @@ export default class Action extends PxpEntity {
11
11
  originKey: string;
12
12
  controllerFunction: string;
13
13
  configJsonTemplate: string;
14
+ eventConfig: string;
14
15
  hidden: string;
16
+ schemaJson: string;
15
17
  actionType: ActionType;
16
18
  nodes: Node[];
17
19
  eventNodes: Node[];
@@ -54,10 +54,18 @@ __decorate([
54
54
  typeorm_1.Column({ name: 'config_json_template', type: 'text' }),
55
55
  __metadata("design:type", String)
56
56
  ], Action.prototype, "configJsonTemplate", void 0);
57
+ __decorate([
58
+ typeorm_1.Column({ name: 'event_config', type: 'text' }),
59
+ __metadata("design:type", String)
60
+ ], Action.prototype, "eventConfig", void 0);
57
61
  __decorate([
58
62
  typeorm_1.Column({ type: 'varchar', nullable: false, length: 1, default: 'N' }),
59
63
  __metadata("design:type", String)
60
64
  ], Action.prototype, "hidden", void 0);
65
+ __decorate([
66
+ typeorm_1.Column({ name: 'schema_json', type: 'text' }),
67
+ __metadata("design:type", String)
68
+ ], Action.prototype, "schemaJson", void 0);
61
69
  __decorate([
62
70
  typeorm_1.ManyToOne(() => ActionType_1.default, actionType => actionType.actions, { eager: true }),
63
71
  typeorm_1.JoinColumn({ name: 'action_type_id' }),
@@ -6,6 +6,7 @@ export default class Flow extends PxpEntity {
6
6
  vendorId: number;
7
7
  code: number;
8
8
  name: string;
9
+ description: string;
9
10
  enabled: string;
10
11
  type: string;
11
12
  instances: FlowInstance[];
@@ -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)
@@ -17,4 +17,5 @@ import EventModel from '../entity/Event';
17
17
  export declare class Event implements EntitySubscriberInterface<EventModel> {
18
18
  listenTo(): typeof EventModel;
19
19
  afterInsert(event: InsertEvent<EventModel>): Promise<void>;
20
+ checkConditions(viewData: Record<string, any>, flowId: number, actionId: number): Promise<boolean>;
20
21
  }
@@ -27,6 +27,7 @@ exports.Event = void 0;
27
27
  const typeorm_1 = require("typeorm");
28
28
  const Event_1 = __importDefault(require("../entity/Event"));
29
29
  const Node_1 = __importDefault(require("../entity/Node"));
30
+ const Action_1 = __importDefault(require("../entity/Action"));
30
31
  const Flow_1 = __importDefault(require("../entity/Flow"));
31
32
  const core_1 = require("@pxp-nd/core");
32
33
  const FlowInstance_1 = __importDefault(require("../entity/FlowInstance"));
@@ -45,7 +46,8 @@ let Event = class Event {
45
46
  const executeView = `select * from ${originName} where ${originKey} = ${newEvent.dataId}`;
46
47
  const resExecuteView = await typeorm_1.getManager().query(executeView);
47
48
  const flow = await core_1.__(Flow_1.default.findOne({ where: { flowId: n.flowId } }));
48
- if (flow.vendorId == resExecuteView[0].vendor_id) {
49
+ if (flow.vendorId == resExecuteView[0].vendor_id && this.checkConditions(resExecuteView[0], n.flowId, newEvent.actionId)) {
50
+ //now check all conditions
49
51
  let flowInstance = new FlowInstance_1.default();
50
52
  flowInstance.flowId = n.flowId;
51
53
  flowInstance.dataId = newEvent.dataId;
@@ -57,6 +59,23 @@ let Event = class Event {
57
59
  }
58
60
  }
59
61
  }
62
+ async checkConditions(viewData, flowId, actionId) {
63
+ const action = await Action_1.default.findOne(actionId);
64
+ const node = await Node_1.default.findOne({ where: { actionId, flowId } });
65
+ const actionConfigJson = JSON.parse(node.actionConfigJson);
66
+ let res = true;
67
+ if (action.eventConfig) {
68
+ const eventConfig = JSON.parse(action.eventConfig);
69
+ if (eventConfig.filters) {
70
+ eventConfig.filters.forEach((filter) => {
71
+ if (actionConfigJson[filter.nodeField] && viewData[filter.originField] != actionConfigJson[filter.nodeField]) {
72
+ res = false;
73
+ }
74
+ });
75
+ }
76
+ }
77
+ return res;
78
+ }
60
79
  };
61
80
  Event = __decorate([
62
81
  typeorm_1.EventSubscriber()
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "@pxp-nd/flow",
3
- "version": "1.0.18",
4
- "description": "Workflow module for pxp-nd framework",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "prepublish": "tsc",
8
- "scripts": {
9
- "test": "echo \"Error: no test specified\" && exit 1",
10
- "build": "rimraf ./dist && tsc",
11
- "dev:publish": "yalc publish",
12
- "prod:publish": "npm publish",
13
- "dev": "tsc-watch --target es2017 --outDir ./dist --onSuccess \"node .\"",
14
- "start": "npm run build && node dist/index.js"
15
- },
16
- "repository": {
17
- "type": "git",
18
- "url": "git+https://github.com/kplian/flow-nd.git"
19
- },
20
- "keywords": [
21
- "flow",
22
- "pxp",
23
- "pxp-nd"
24
- ],
25
- "author": "Kplian",
26
- "license": "ISC",
27
- "bugs": {
28
- "url": "https://github.com/kplian/flow-nd/issues"
29
- },
30
- "homepage": "https://github.com/kplian/flow-nd#readme",
31
- "devDependencies": {
32
- "@types/lodash": "^4.14.172",
33
- "@types/node": "^16.4.13",
34
- "rimraf": "^3.0.2",
35
- "tsc-watch": "^4.2.9",
36
- "typescript": "^4.2.4"
37
- },
38
- "dependencies": {
39
- "@pxp-nd/common": "^1.1.4",
40
- "@pxp-nd/core": "^1.1.13",
41
- "axios": "^0.21.1",
42
- "lodash": "^4.17.21",
43
- "typeorm": "^0.2.36"
44
- }
45
- }
1
+ {
2
+ "name": "@pxp-nd/flow",
3
+ "version": "1.0.22",
4
+ "description": "Workflow module for pxp-nd framework",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "prepublish": "tsc",
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "build": "rimraf ./dist && tsc",
11
+ "dev:publish": "yalc publish",
12
+ "prod:publish": "npm publish",
13
+ "dev": "tsc-watch --target es2017 --outDir ./dist --onSuccess \"node .\"",
14
+ "start": "npm run build && node dist/index.js"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/kplian/flow-nd.git"
19
+ },
20
+ "keywords": [
21
+ "flow",
22
+ "pxp",
23
+ "pxp-nd"
24
+ ],
25
+ "author": "Kplian",
26
+ "license": "ISC",
27
+ "bugs": {
28
+ "url": "https://github.com/kplian/flow-nd/issues"
29
+ },
30
+ "homepage": "https://github.com/kplian/flow-nd#readme",
31
+ "devDependencies": {
32
+ "@types/lodash": "^4.14.172",
33
+ "@types/node": "^16.4.13",
34
+ "rimraf": "^3.0.2",
35
+ "tsc-watch": "^4.2.9",
36
+ "typescript": "^4.2.4"
37
+ },
38
+ "dependencies": {
39
+ "@pxp-nd/common": "^1.1.4",
40
+ "@pxp-nd/core": "^1.1.13",
41
+ "axios": "^0.21.1",
42
+ "lodash": "^4.17.21",
43
+ "typeorm": "^0.2.36"
44
+ }
45
+ }
package/tsconfig.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2019",
4
- "module": "commonjs",
5
- "allowJs": false,
6
- "outDir": "dist",
7
- "rootDir": "src",
8
- "strict": false,
9
- "noImplicitAny": true,
10
- "esModuleInterop": true,
11
- "resolveJsonModule": true,
12
- "skipLibCheck": true,
13
- "forceConsistentCasingInFileNames": true,
14
- "emitDecoratorMetadata": true,
15
- "experimentalDecorators": true,
16
- "moduleResolution": "node",
17
- "declaration": true,
18
- "isolatedModules": true,
19
- "strictPropertyInitialization": false,
20
- },
21
- "include": [
22
- "custom.d.ts",
23
- "src/**/*.ts"
24
- ],
25
- "exclude": [
26
- "node_modules",
27
- "dist"
28
- ]
29
- }
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2019",
4
+ "module": "commonjs",
5
+ "allowJs": false,
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strict": false,
9
+ "noImplicitAny": true,
10
+ "esModuleInterop": true,
11
+ "resolveJsonModule": true,
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "emitDecoratorMetadata": true,
15
+ "experimentalDecorators": true,
16
+ "moduleResolution": "node",
17
+ "declaration": true,
18
+ "isolatedModules": true,
19
+ "strictPropertyInitialization": false,
20
+ },
21
+ "include": [
22
+ "custom.d.ts",
23
+ "src/**/*.ts"
24
+ ],
25
+ "exclude": [
26
+ "node_modules",
27
+ "dist"
28
+ ]
29
+ }