Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create unified Rule types & runtime check helpers #48

Open
justsml opened this issue Nov 3, 2022 · 0 comments
Open

Create unified Rule types & runtime check helpers #48

justsml opened this issue Nov 3, 2022 · 0 comments

Comments

@justsml
Copy link
Contributor

justsml commented Nov 3, 2022

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
}

#46 (comment)

#47 (comment)

@justsml justsml changed the title Types: Improve the main Rule type Create unified Rule types & runtime check helpers Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant