Rule Cascade
LearnUse it in your language

Custom operators

Supply x-* custom operators where the runtime supports them, and what happens where it does not.

A ruleset may call an operator whose name starts with x-; your program supplies it. Every runtime that evaluates the ruleset must supply the same operator, so prefer a ruleset function when you can. The manifest lists the operators it needs: check them when your program starts. A missing operator never passes: the rule fails closed.

What to do. Pass the operators as the third argument: useRuleEvaluation(manifest, request, operators). Pass the same object on every render. The browser needs the same operators as the server.

The code.

packages/client/src/react.ts
export function useRuleEvaluation(manifest: Manifest | undefined, request: EvaluationRequest, operators?: Operators): RuleEvaluation {

Run it.

Run it
npm ci && npm run build      # at the repository root, once
node site/learn/languages/typescript-node/tour.mjs

The output.

The hook calls the same evaluate as Node.js; the output of the TypeScript (Node.js) tab is what it does:

Output
needs: x-luhn
registered: ONB-CUS-001 This loyalty number is not valid. Check the digits.
not registered: RULE-EVALUATION-ERROR blocking=true custom operator x-luhn is not registered
Course overview