Skip to content

Documentation / @facturometro/einvoice / rule

Variable: rule ​

const rule: RuleFactory

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

Builds a validation rule.

rule(id, definition) looks the id up in the generated spec table and takes severity, message, family, business terms and documentation URL from there; an unknown id throws when the module defining the rule loads, never at validation time. rule.custom(id, definition) takes the metadata inline and refuses ids of the specification.

The at form anchors the rule at a DocumentPaths key; the context form takes a selector over the document view.

Example ​

ts
import { rule } from '@facturometro/validator';

const br01 = rule('BR-01', {
  at: 'document',
  test: (document, ctx) =>
    ctx.normSpace(document.customizationId) !== '' || { at: ['customizationId'] },
});

const poNumber = rule.custom('ACME-R-001', {
  at: 'document',
  message: 'A purchase order reference is required.',
  severity: 'fatal',
  test: (document) => document.orderReference?.id !== undefined,
});

Throws ​

rule() when the id is not in the spec table; rule.custom() when it is.

MIT licensed. Specification artefacts belong to OpenPEPPOL, CEN and OASIS.