Documentation / @facturometro/einvoice / compileRulesets
Function: compileRulesets() ​
compileRulesets(
composition):CompiledRuleset
Defined in: packages/validator/src/engine/compile.ts:496
Compiles an ordered composition of ruleset constants and caches the result.
Later entries modify earlier ones: a constant may replace, disable or patch only rules that constants before it defined, and when two constants patch the same field of a rule the later one wins. A rule disabled by one constant is gone for every later one: neither an override nor a redefinition of it is allowed.
The structural rule ids (UBL-CR-*, UBL-SR-*, UBL-DT-*) form a base layer before the first constant: disable entries match them as well as earlier rules, and override may change the severity and message of one, resolved into CompiledRuleset.applyStructural. An EINV- id can be named by neither.
Parameters ​
composition ​
The constants, in order; at least one.
Returns ​
The frozen, compiled composition; the same object for the same list.
Throws ​
When the list is empty, a constant is listed twice, two different constants share an id, a required constant is missing or comes later, a rule id is defined twice without an override, a rule id an earlier constant disabled is defined again, a disable or override entry names no rule defined earlier and no structural id that is not disabled, an entry can match an EINV- id, or an override sets test, when or context on a structural id that is not a rule defined earlier.
Example ​
import { compileRulesets, defineRuleset, en16931Ruleset, peppolRuleset } from '@facturometro/validator';
const compiled = compileRulesets([en16931Ruleset, peppolRuleset]);
compiled.info.ids; // ['en16931', 'peppol']
compiled.rules.map((entry) => entry.rule.id);
compileRulesets([peppolRuleset, en16931Ruleset]); // throws: `peppol` must come after `en16931`
const quiet = defineRuleset({ id: 'quiet', version: '1', disable: ['UBL-CR-*'] });
compileRulesets([en16931Ruleset, quiet]).applyStructural(ublCr001Diagnostic); // undefined