Documentation / @facturometro/validator / RuleContext
Interface: RuleContext ​
Defined in: packages/validator/src/engine/context.ts:119
What a rule sees of the document beyond its context node.
Example ​
import type { RuleContext } from '@facturometro/validator';
const isPeppolBilling = (ctx: RuleContext) => ctx.profile === '01';Properties ​
codes ​
readonlycodes:object
Defined in: packages/validator/src/engine/context.ts:121
Code-list membership, against the lists written in the Schematron files.
has() ​
has(
list,value):boolean
Whether a value is in one of the Schematron's code lists.
Parameters ​
list ​
The list, named after the rule or variable that holds it.
value ​
string | undefined
The value, as the rule prepared it (raw or normalized).
Returns ​
boolean
true when the list has it; false for an absent value.
country ​
readonlycountry:CountryContext
Defined in: packages/validator/src/engine/context.ts:132
The parties' countries, in every variant the Schematron derives.
diagnostics ​
readonlydiagnostics: readonlyIssue[]
Defined in: packages/validator/src/engine/context.ts:152
The diagnostics @facturometro/parser reported for the document, as passed to validate(), for rules about what the model cannot hold: PEPPOL-EN16931-R008 reports the EINV-XML-EMPTY ones next to the empty elements it finds in the model. Empty for a built document, or when the caller did not pass them.
documentCurrencyCode ​
readonlydocumentCurrencyCode:string|undefined
Defined in: packages/validator/src/engine/context.ts:154
$documentCurrencyCode: cbc:DocumentCurrencyCode, raw.
ids ​
readonlyids:identifiers
Defined in: packages/validator/src/engine/context.ts:171
The identifier checks (u:gln, u:mod11, ...).
kind ​
readonlykind:"CreditNote"|"Invoice"
Defined in: packages/validator/src/engine/context.ts:173
Which document this is.
profile ​
readonlyprofile:Profile
Defined in: packages/validator/src/engine/context.ts:182
$profile, computed from normalize-space(cbc:ProfileID).
view ​
readonlyview:DocumentView
Defined in: packages/validator/src/engine/context.ts:209
The document view.
Methods ​
dec() ​
dec(
leaf):Decimal|null
Defined in: packages/validator/src/engine/context.ts:145
xs:decimal() of a leaf: an amount, quantity or percentage object ({ value }), or a raw string. Surrounding XML whitespace is collapsed as the XSD cast does. An absent leaf, or a leaf object without a string value, is the empty sequence and yields null; text that is not a lexical decimal throws a LexicalError, which the engine loop turns into a skip of the context node being tested, as the lexical pre-pass has already reported the value. Results are cached per leaf object.
Parameters ​
leaf ​
unknown
The leaf, possibly absent.
Returns ​
Decimal | null
The decimal, or null when absent.
Throws ​
When the text is not in the lexical space of xs:decimal.
fail() ​
fail(
refinement?):Verdict
Defined in: packages/validator/src/engine/context.ts:161
A failing verdict, optionally refined.
Parameters ​
refinement? ​
Where the failure is (relative to the context node) and what explains it.
Returns ​
The verdict.
fractionDigits() ​
fractionDigits(
raw):number
Defined in: packages/validator/src/engine/context.ts:169
string-length(substring-after(., '.')) of a raw value: how many characters follow the decimal point in the document text.
Parameters ​
raw ​
string | undefined
The value as it appears in the document; absent counts as 0.
Returns ​
number
The number of fraction digits.
normSpace() ​
normSpace(
value):string
Defined in: packages/validator/src/engine/context.ts:180
normalize-space() of a value; absent normalizes to the empty string.
Parameters ​
value ​
string | undefined
The value.
Returns ​
string
The normalized text.
round2() ​
round2(
value):Decimal
Defined in: packages/validator/src/engine/context.ts:189
round(x * 10 * 10) div 100: rounds to two decimals, halves toward positive infinity.
Parameters ​
value ​
The decimal.
Returns ​
The rounded decimal.
slack() ​
slack(
expected,actual,slack):boolean
Defined in: packages/validator/src/engine/context.ts:198
u:slack(exp, val, slack): whether val is within slack of exp, both ends included.
Parameters ​
expected ​
The expected value.
actual ​
The actual value.
slack ​
string | number | Decimal
The tolerance, e.g. '0.02'.
Returns ​
boolean
true when expected - slack <= actual <= expected + slack.
sum() ​
sum(
leaves):Decimal
Defined in: packages/validator/src/engine/context.ts:207
XPath's sum() over decimals: absent leaves are skipped, as an empty sequence contributes nothing.
Parameters ​
leaves ​
Iterable<unknown>
Decimals or leaves (see dec).
Returns ​
The sum; zero for nothing.
Throws ​
When a leaf's text is not a lexical decimal (see dec).
within1() ​
within1(
a,b):boolean
Defined in: packages/validator/src/engine/context.ts:217
The strict ± 1 comparison of the BR-*-09 and BR-CO-17 rules: a - 1 < b and a + 1 > b.
Parameters ​
a ​
One side.
b ​
The other side.
Returns ​
boolean
true when the two differ by less than one.
xpath() ​
xpath(
path):string
Defined in: packages/validator/src/engine/context.ts:224
The XPath of a model path in this document.
Parameters ​
path ​
The model path.
Returns ​
string
The XPath, with ubl:, cac: and cbc: prefixes.