lightning-flow-scanner-core
Advanced tools
Comparing version 3.20.0 to 3.20.1
@@ -8,3 +8,2 @@ import { Flow } from "../models/Flow"; | ||
private findNextElements; | ||
private recurse; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Compiler = void 0; | ||
const FlowElementConnector_1 = require("../models/FlowElementConnector"); | ||
const FlowNode_1 = require("../models/FlowNode"); | ||
@@ -33,9 +32,9 @@ class Compiler { | ||
findNextElements(flow, currentElement, endElementName) { | ||
var _a; | ||
var _a, _b, _c; | ||
const nextElements = []; | ||
if (currentElement.connectors && currentElement.connectors.length > 0) { | ||
for (const connector of currentElement.connectors) { | ||
const foundConnector = this.recurse(connector); | ||
const targetReference = (_b = (_a = connector === null || connector === void 0 ? void 0 : connector.connectorTargetReference) === null || _a === void 0 ? void 0 : _a.targetReference) !== null && _b !== void 0 ? _b : connector.reference; | ||
// Check if the reference exists in the flow elements | ||
const nextElement = (_a = flow.elements) === null || _a === void 0 ? void 0 : _a.find((element) => element instanceof FlowNode_1.FlowNode && element.name === foundConnector.reference); | ||
const nextElement = (_c = flow.elements) === null || _c === void 0 ? void 0 : _c.find((element) => element instanceof FlowNode_1.FlowNode && element.name === targetReference); | ||
if (nextElement instanceof FlowNode_1.FlowNode && nextElement.name !== endElementName) { | ||
@@ -48,10 +47,4 @@ nextElements.push(nextElement.name); | ||
} | ||
recurse(connector) { | ||
if (connector.reference || !connector.connector) { | ||
return connector; | ||
} | ||
return this.recurse(new FlowElementConnector_1.FlowElementConnector("connector", connector.connector, {})); | ||
} | ||
} | ||
exports.Compiler = Compiler; | ||
//# sourceMappingURL=Compiler.js.map |
@@ -9,4 +9,8 @@ export declare class FlowElementConnector { | ||
childOf: boolean; | ||
connector: FlowElementConnector; | ||
connectorTargetReference: FlowElementConnectorReference; | ||
constructor(type: string, element: object, args: any); | ||
} | ||
declare class FlowElementConnectorReference { | ||
targetReference: string; | ||
} | ||
export {}; |
@@ -12,7 +12,7 @@ "use strict"; | ||
this.childOf = args.childOf ? args.childOf : undefined; | ||
if (element && element["targetReference"]) { | ||
this.reference = element["targetReference"]; | ||
if (element && "targetReference" in element) { | ||
this.reference = element.targetReference; | ||
} | ||
if (element && "connector" in element) { | ||
this.connector = element["connector"]; | ||
this.connectorTargetReference = element.connector; | ||
} | ||
@@ -22,2 +22,4 @@ } | ||
exports.FlowElementConnector = FlowElementConnector; | ||
class FlowElementConnectorReference { | ||
} | ||
//# sourceMappingURL=FlowElementConnector.js.map |
{ | ||
"name": "lightning-flow-scanner-core", | ||
"version": "3.20.0", | ||
"version": "3.20.1", | ||
"main": "out/**", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
import { Flow } from "../models/Flow"; | ||
import { FlowElementConnector } from "../models/FlowElementConnector"; | ||
import { FlowNode } from "../models/FlowNode"; | ||
@@ -55,6 +54,7 @@ | ||
for (const connector of currentElement.connectors) { | ||
const foundConnector = this.recurse(connector); | ||
const targetReference = | ||
connector?.connectorTargetReference?.targetReference ?? connector.reference; | ||
// Check if the reference exists in the flow elements | ||
const nextElement = flow.elements?.find( | ||
(element) => element instanceof FlowNode && element.name === foundConnector.reference | ||
(element) => element instanceof FlowNode && element.name === targetReference | ||
); | ||
@@ -68,9 +68,2 @@ if (nextElement instanceof FlowNode && nextElement.name !== endElementName) { | ||
} | ||
private recurse(connector: FlowElementConnector): FlowElementConnector { | ||
if (connector.reference || !connector.connector) { | ||
return connector; | ||
} | ||
return this.recurse(new FlowElementConnector("connector", connector.connector, {})); | ||
} | ||
} |
@@ -9,3 +9,3 @@ export class FlowElementConnector { | ||
public childOf: boolean; | ||
public connector: FlowElementConnector; | ||
public connectorTargetReference: FlowElementConnectorReference; | ||
@@ -18,9 +18,13 @@ constructor(type: string, element: object, args) { | ||
if (element && element["targetReference"]) { | ||
this.reference = element["targetReference"]; | ||
if (element && "targetReference" in element) { | ||
this.reference = element.targetReference as string; | ||
} | ||
if (element && "connector" in element) { | ||
this.connector = element["connector"] as FlowElementConnector; | ||
this.connectorTargetReference = element.connector as FlowElementConnectorReference; | ||
} | ||
} | ||
} | ||
class FlowElementConnectorReference { | ||
public targetReference: string; | ||
} |
@@ -6,9 +6,22 @@ import { expect } from "chai"; | ||
import { ParseFlows } from "../src/main/libs/ParseFlows"; | ||
import { ParsedFlow } from "../src/main/models/ParsedFlow"; | ||
import { UnconnectedElement } from "../src/main/rules/UnconnectedElement"; | ||
describe("UnconnectedElement", () => { | ||
const unconnectedElementRule: UnconnectedElement = new UnconnectedElement(); | ||
it("there should be checks for unconnected element", async () => { | ||
const example_uri = path.join(__dirname, "./xmlfiles/Unconnected_Element.flow-meta.xml"); | ||
const flows = await core.parse([example_uri]); | ||
const results: core.ScanResult[] = core.scan(flows); | ||
const occurringResults = results[0].ruleResults.filter((rule) => rule.occurs); | ||
expect(occurringResults.find((res) => res.ruleName === "UnconnectedElement")); | ||
const connectedElementTestFile = path.join( | ||
__dirname, | ||
"./xmlfiles/Unconnected_Element.flow-meta.xml" | ||
); | ||
const parsed: ParsedFlow = (await ParseFlows([connectedElementTestFile])).pop() as ParsedFlow; | ||
const ruleResult: core.RuleResult = unconnectedElementRule.execute(parsed.flow as core.Flow); | ||
expect(ruleResult.occurs).to.be.true; | ||
expect(ruleResult.details).to.not.be.empty; | ||
ruleResult.details.forEach((detail) => { | ||
expect(detail.violation.name).to.equal("unused_assignment"); | ||
}); | ||
}); | ||
@@ -21,13 +34,9 @@ | ||
); | ||
const flows = await core.parse([connectedElementTestFile]); | ||
const results: core.ScanResult[] = core.scan(flows); | ||
const occurringResults = results.pop()?.ruleResults.filter((rule) => rule.occurs); | ||
const unconnectedElementResult = occurringResults?.filter( | ||
(res) => res.ruleName === "UnconnectedElement" | ||
); | ||
expect(unconnectedElementResult); | ||
unconnectedElementResult?.forEach((unconnectedElem) => { | ||
expect(unconnectedElem.details.pop()?.name).to.equal("UnconnectedElementTestOnAsync"); | ||
const parsed: ParsedFlow = (await ParseFlows([connectedElementTestFile])).pop() as ParsedFlow; | ||
const ruleResult: core.RuleResult = unconnectedElementRule.execute(parsed.flow as core.Flow); | ||
expect(ruleResult.occurs).to.be.true; | ||
ruleResult.details.forEach((ruleDetail) => { | ||
expect(ruleDetail.name).to.equal("UnconnectedElementTestOnAsync"); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36263
1394828