Documentation / @facturometro/validator / Rule
Interface: Rule<N> ​
Defined in: packages/validator/src/engine/rule.ts:74
A compiled validation rule: the specification's metadata and the logic that evaluates it.
when is a document-level gate evaluated once per document; context selects the nodes; test judges each one. The engine catches anything they throw and reports it as a fatal EINV-RULE-ERROR issue, so a rule can never abort a validation run.
Example ​
import type { Rule } from '@facturometro/validator';
const ids = (rules: readonly Rule[]) => rules.map((rule) => rule.id);Type Parameters ​
N ​
N = unknown
Properties ​
bt ​
readonlybt: readonlystring[]
Defined in: packages/validator/src/engine/rule.ts:76
Business terms (BT-*) the rule is about.
docsUrl? ​
readonlyoptionaldocsUrl?:string
Defined in: packages/validator/src/engine/rule.ts:86
Documentation page of the rule, when it has one.
family ​
readonlyfamily:string
Defined in: packages/validator/src/engine/rule.ts:88
Rule family, e.g. BR-CO, PEPPOL-EN16931-R or national:DK; custom by default.
id ​
readonlyid:string
Defined in: packages/validator/src/engine/rule.ts:90
Rule id, e.g. BR-CO-10.
message ​
readonlymessage:string
Defined in: packages/validator/src/engine/rule.ts:92
Message reported on failure, verbatim from the specification for spec rules.
severity ​
readonlyseverity:Severity
Defined in: packages/validator/src/engine/rule.ts:94
Whether a failure makes the document invalid.
when? ​
readonlyoptionalwhen?: (ctx) =>boolean
Defined in: packages/validator/src/engine/rule.ts:110
Document-level gate, evaluated once: when it returns false the rule is skipped.
Parameters ​
ctx ​
The rule context.
Returns ​
boolean
Whether the rule applies to the document.
Methods ​
context() ​
context(
view,ctx): readonlyHit<N,unknown>[]
Defined in: packages/validator/src/engine/rule.ts:84
The nodes the rule applies to, with their model paths.
Parameters ​
view ​
The document view, whose selectors are memoized.
ctx ​
The rule context.
Returns ​
readonly Hit<N, unknown>[]
The hits, in document order.
test() ​
test(
node,ctx,hit):Verdict
Defined in: packages/validator/src/engine/rule.ts:103
Judges one selected node.
Parameters ​
node ​
N
The node.
ctx ​
The rule context.
hit ​
Hit<N>
The node together with its path and parent.
Returns ​
The verdict.