Skip to content

Documentation / @einvoice-ts/validator / Rule

Interface: Rule<N> ​

Defined in: packages/validator/src/engine/rule.ts:81

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 ​

ts
import type { Rule } from '@einvoice-ts/validator';

const ids = (rules: readonly Rule[]) => rules.map((rule) => rule.id);

Type Parameters ​

N ​

N = unknown

Properties ​

bt ​

readonly bt: readonly string[]

Defined in: packages/validator/src/engine/rule.ts:83

Business terms (BT-*) the rule is about.


docsUrl? ​

readonly optional docsUrl?: string

Defined in: packages/validator/src/engine/rule.ts:93

Documentation page of the rule, when it has one.


family ​

readonly family: string

Defined in: packages/validator/src/engine/rule.ts:95

Rule family, e.g. BR-CO, PEPPOL-EN16931-R or national:DK; custom by default.


id ​

readonly id: string

Defined in: packages/validator/src/engine/rule.ts:97

Rule id, e.g. BR-CO-10.


message ​

readonly message: string

Defined in: packages/validator/src/engine/rule.ts:99

Message reported on failure, verbatim from the specification for spec rules.


severity ​

readonly severity: Severity

Defined in: packages/validator/src/engine/rule.ts:101

Whether a failure makes the document invalid.


when? ​

readonly optional when?: (ctx) => boolean

Defined in: packages/validator/src/engine/rule.ts:117

Document-level gate, evaluated once: when it returns false the rule is skipped.

Parameters ​

ctx ​

RuleContext

The rule context.

Returns ​

boolean

Whether the rule applies to the document.

Methods ​

context() ​

context(view, ctx): readonly Hit<N, unknown>[]

Defined in: packages/validator/src/engine/rule.ts:91

The nodes the rule applies to, with their model paths.

Parameters ​

view ​

DocumentView

The document view, whose selectors are memoized.

ctx ​

RuleContext

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:110

Judges one selected node.

Parameters ​

node ​

N

The node.

ctx ​

RuleContext

The rule context.

hit ​

Hit<N>

The node together with its path and parent.

Returns ​

Verdict

The verdict.

MIT licensed. Specification material belongs to OpenPeppol, CEN and OASIS (see NOTICE). Peppol is a trademark of OpenPeppol AISBL; this project is not affiliated with it.