Skip to content

Commit

Permalink
Ensure that all condition types are accounted for in ConditionFactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekpierre committed Oct 15, 2024
1 parent 92f76b8 commit 8819889
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/taco/src/conditions/condition-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,39 @@ import {
CompoundConditionType,
} from './compound-condition';
import { Condition, ConditionProps } from './condition';
import {
IfThenElseCondition,
IfThenElseConditionProps,
IfThenElseConditionType,
} from './if-then-else-condition';
import {
SequentialCondition,
SequentialConditionProps,
SequentialConditionType,
} from './sequential';

const ERR_INVALID_CONDITION_TYPE = (type: string) =>
`Invalid condition type: ${type}`;

export class ConditionFactory {
public static conditionFromProps(props: ConditionProps): Condition {
switch (props.conditionType) {
// Base Conditions
case RpcConditionType:
return new RpcCondition(props as RpcConditionProps);
case TimeConditionType:
return new TimeCondition(props as TimeConditionProps);
case ContractConditionType:
return new ContractCondition(props as ContractConditionProps);
case CompoundConditionType:
return new CompoundCondition(props as CompoundConditionProps);
case JsonApiConditionType:
return new JsonApiCondition(props as JsonApiConditionProps);
// Logical Conditions
case CompoundConditionType:
return new CompoundCondition(props as CompoundConditionProps);
case SequentialConditionType:
return new SequentialCondition(props as SequentialConditionProps);
case IfThenElseConditionType:
return new IfThenElseCondition(props as IfThenElseConditionProps);
default:
throw new Error(ERR_INVALID_CONDITION_TYPE(props.conditionType));
}
Expand Down

0 comments on commit 8819889

Please sign in to comment.