Skip to content

Documentation / @facturometro/einvoice / 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 ​

ts
import type { Rule } from '@facturometro/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:76

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


docsUrl? ​

readonly optional docsUrl?: string

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

Documentation page of the rule, when it has one.


family ​

readonly family: 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 ​

readonly id: string

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

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


message ​

readonly message: string

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

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


severity ​

readonly severity: Severity

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

Whether a failure makes the document invalid.


when? ​

readonly optional when?: (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 ​

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

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

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 artefacts belong to OpenPEPPOL, CEN and OASIS.