-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Create unified Rule types & runtime check helpers
export type Rule =
| string
| IfThenElseRule
| AndRule
| OrRule
| ReturnRule
| TryCatchRule
| Rule[];
type RulesStrings = string | string[];
interface ReturnRule {
return: RulesStrings
}
interface TryCatchRule { try: Rule, catch: Rule }
interface IfThenElseRule {
if: AndRule | OrRule | string
then: Rule
else?: Rule
}const validateRules = {
isString: rule => typeof rule === 'string' && rule.length > 4,
isStringOrStringList: rule => Array.isArray(rule) ? rule.every(validateRules.isString) : validateRules.isString(rule),
isLogicalRule: rule => rule != null && ('and' in rule || 'or' in rule),
isStructuralRule: rule => rule != null && ('if' in rule || 'and' in rule || 'or' in rule || 'map' in rule || 'reduce' in rule || 'filter' in rule || 'return' in rule),
// TODO: add more combined rules to express higher order structures, constraints, etc
}Metadata
Metadata
Assignees
Labels
No labels