From 7e752732f3d526d48df8a56a157485ad677a3439 Mon Sep 17 00:00:00 2001 From: Tom Carman Date: Sat, 29 Jun 2024 01:12:20 +0100 Subject: [PATCH] feat: move flow node types to own file --- src/common/experimental/FlowNodeTypes.ts | 56 +++++++++++++++++++ src/common/experimental/FlowNodeWrapper.ts | 65 +++++++--------------- src/common/experimental/FlowWrapper.ts | 3 +- 3 files changed, 78 insertions(+), 46 deletions(-) create mode 100644 src/common/experimental/FlowNodeTypes.ts diff --git a/src/common/experimental/FlowNodeTypes.ts b/src/common/experimental/FlowNodeTypes.ts new file mode 100644 index 0000000..5d39525 --- /dev/null +++ b/src/common/experimental/FlowNodeTypes.ts @@ -0,0 +1,56 @@ +import { + FlowAssignment, + FlowCollectionProcessor, + FlowCustomError, + FlowRecordRollback, + FlowScreen, + FlowSubflow, + FlowTransform, + FlowActionCall, + FlowApexPluginCall, + FlowOrchestratedStage, + FlowRecordCreate, + FlowRecordDelete, + FlowRecordLookup, + FlowRecordUpdate, + FlowWait, + FlowDecision, + FlowLoop, + FlowStep, + FlowStart, +} from '@salesforce/types/metadata'; + +export type NodeType = NodeWithConnector | NodeWithFaultConnector | FlowWait | FlowDecision | FlowLoop | FlowStep; + +export type NodeWithConnector = + | FlowAssignment + | FlowCollectionProcessor + | FlowCustomError + | FlowRecordRollback + | FlowScreen + | FlowSubflow + | FlowTransform + | FlowStart + | FlowActionCall + | FlowApexPluginCall + | FlowOrchestratedStage + | FlowRecordCreate + | FlowRecordDelete + | FlowRecordLookup + | FlowRecordUpdate; + +export type NodeWithFaultConnector = + | FlowActionCall + | FlowApexPluginCall + | FlowOrchestratedStage + | FlowRecordCreate + | FlowRecordDelete + | FlowRecordLookup + | FlowRecordUpdate; + +export type NodeWithDefaultConnector = FlowWait | FlowDecision; +export type NodeWithNextValueConnector = FlowLoop; +export type NodeWithNoMoreValuesConnector = FlowLoop; +export type NodeWithWaitEvents = FlowWait; +export type NodeWithRules = FlowDecision; +export type NodeWithScheduledPaths = FlowStart; diff --git a/src/common/experimental/FlowNodeWrapper.ts b/src/common/experimental/FlowNodeWrapper.ts index 0509fc1..55bf1e9 100644 --- a/src/common/experimental/FlowNodeWrapper.ts +++ b/src/common/experimental/FlowNodeWrapper.ts @@ -1,44 +1,16 @@ +import { FlowConnector } from '@salesforce/types/metadata'; import { - FlowAssignment, - FlowCollectionProcessor, - FlowCustomError, - FlowRecordRollback, - FlowScreen, - FlowSubflow, - FlowTransform, - FlowConnector, - FlowActionCall, - FlowApexPluginCall, - FlowOrchestratedStage, - FlowRecordCreate, - FlowRecordDelete, - FlowRecordLookup, - FlowRecordUpdate, - FlowWait, - FlowDecision, - FlowLoop, - FlowStep, - FlowStart, -} from '@salesforce/types/metadata'; + NodeType, + NodeWithConnector, + NodeWithFaultConnector, + NodeWithDefaultConnector, + NodeWithNextValueConnector, + NodeWithNoMoreValuesConnector, + NodeWithWaitEvents, + NodeWithRules, + NodeWithScheduledPaths, +} from './FlowNodeTypes.js'; -export type NodeType = NodeWithConnector | NodeWithFaultConnector | FlowWait | FlowDecision | FlowLoop | FlowStep; -type NodeWithConnector = - | FlowAssignment - | FlowCollectionProcessor - | FlowCustomError - | FlowRecordRollback - | FlowScreen - | FlowSubflow - | FlowTransform - | FlowStart; -type NodeWithFaultConnector = - | FlowActionCall - | FlowApexPluginCall - | FlowOrchestratedStage - | FlowRecordCreate - | FlowRecordDelete - | FlowRecordLookup - | FlowRecordUpdate; type Connector = FlowConnector & { type: string; }; @@ -106,6 +78,7 @@ export class FlowNodeWrapper { }); } } + private addRuleConnectors(nodeType: NodeType): void { if (hasRules(nodeType)) { nodeType.rules.forEach((rule) => { @@ -115,6 +88,7 @@ export class FlowNodeWrapper { }); } } + private addScheduledPaths(nodeType: NodeType): void { if (hasScheduledPaths(nodeType)) { nodeType.scheduledPaths.forEach((path) => { @@ -128,9 +102,10 @@ export class FlowNodeWrapper { const hasConnector = (node: NodeType): node is NodeWithConnector => 'connector' in node; const hasFaultConnector = (node: NodeWithConnector): node is NodeWithFaultConnector => 'faultConnector' in node; -const hasDefaultConnector = (node: NodeType): node is FlowWait | FlowDecision => 'defaultConnector' in node; -const hasNextValueConnector = (node: NodeType): node is FlowLoop => 'nextValueConnector' in node; -const hasNoMoreValuesConnector = (node: NodeType): node is FlowLoop => 'noMoreValuesConnector' in node; -const hasWaitEvents = (node: NodeType): node is FlowWait => 'waitEvents' in node; -const hasRules = (node: NodeType): node is FlowDecision => 'rules' in node; -const hasScheduledPaths = (node: NodeType): node is FlowStart => 'scheduledPaths' in node; +const hasDefaultConnector = (node: NodeType): node is NodeWithDefaultConnector => 'defaultConnector' in node; +const hasNextValueConnector = (node: NodeType): node is NodeWithNextValueConnector => 'nextValueConnector' in node; +const hasNoMoreValuesConnector = (node: NodeType): node is NodeWithNoMoreValuesConnector => + 'noMoreValuesConnector' in node; +const hasWaitEvents = (node: NodeType): node is NodeWithWaitEvents => 'waitEvents' in node; +const hasRules = (node: NodeType): node is NodeWithRules => 'rules' in node; +const hasScheduledPaths = (node: NodeType): node is NodeWithScheduledPaths => 'scheduledPaths' in node; diff --git a/src/common/experimental/FlowWrapper.ts b/src/common/experimental/FlowWrapper.ts index 7ff1b2b..c24537b 100644 --- a/src/common/experimental/FlowWrapper.ts +++ b/src/common/experimental/FlowWrapper.ts @@ -1,5 +1,6 @@ import { Flow } from '@salesforce/types/metadata'; -import { NodeType, FlowNodeWrapper } from './FlowNodeWrapper.js'; +import { FlowNodeWrapper } from './FlowNodeWrapper.js'; +import { NodeType } from './FlowNodeTypes.js'; export class FlowWrapper { public flowName: string;