forked from nucypher/taco-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for if-then-else condition.
- Loading branch information
1 parent
dbf54b2
commit b9ad459
Showing
5 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Condition } from './condition'; | ||
import { | ||
IfThenElseConditionProps, | ||
ifThenElseConditionSchema, | ||
IfThenElseConditionType, | ||
} from './schemas/if-then-else'; | ||
import { OmitConditionType } from './shared'; | ||
|
||
export { | ||
IfThenElseConditionProps, | ||
ifThenElseConditionSchema, | ||
IfThenElseConditionType, | ||
} from './schemas/if-then-else'; | ||
|
||
export class IfThenElseCondition extends Condition { | ||
constructor(value: OmitConditionType<IfThenElseConditionProps>) { | ||
super(ifThenElseConditionSchema, { | ||
conditionType: IfThenElseConditionType, | ||
...value, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { z } from 'zod'; | ||
|
||
import { maxNestedDepth } from '../multi-condition'; | ||
|
||
import { baseConditionSchema } from './common'; | ||
import { anyConditionSchema } from './utils'; | ||
|
||
export const IfThenElseConditionType = 'if-then-else'; | ||
|
||
export const ifThenElseConditionSchema: z.ZodSchema = z.lazy(() => | ||
baseConditionSchema | ||
.extend({ | ||
conditionType: z | ||
.literal(IfThenElseConditionType) | ||
.default(IfThenElseConditionType), | ||
ifCondition: anyConditionSchema, | ||
thenCondition: anyConditionSchema, | ||
elseCondition: z.union([anyConditionSchema, z.boolean()]), | ||
}) | ||
.refine( | ||
(condition) => maxNestedDepth(2)(condition), | ||
{ | ||
message: 'Exceeded max nested depth of 2 for multi-condition type', | ||
}, // Max nested depth of 2 | ||
), | ||
); | ||
|
||
export type IfThenElseConditionProps = z.infer< | ||
typeof ifThenElseConditionSchema | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters