Skip to content

Commit

Permalink
feat: move flow node types to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcarman committed Jun 29, 2024
1 parent 763fbc0 commit 7e75273
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 46 deletions.
56 changes: 56 additions & 0 deletions src/common/experimental/FlowNodeTypes.ts
Original file line number Diff line number Diff line change
@@ -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;
65 changes: 20 additions & 45 deletions src/common/experimental/FlowNodeWrapper.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand Down Expand Up @@ -106,6 +78,7 @@ export class FlowNodeWrapper {
});
}
}

private addRuleConnectors(nodeType: NodeType): void {
if (hasRules(nodeType)) {
nodeType.rules.forEach((rule) => {
Expand All @@ -115,6 +88,7 @@ export class FlowNodeWrapper {
});
}
}

private addScheduledPaths(nodeType: NodeType): void {
if (hasScheduledPaths(nodeType)) {
nodeType.scheduledPaths.forEach((path) => {
Expand All @@ -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;
3 changes: 2 additions & 1 deletion src/common/experimental/FlowWrapper.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 7e75273

Please sign in to comment.