Skip to content

Create unified Rule types & runtime check helpersΒ #48

@justsml

Description

@justsml

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions