Skip to content

Documentation / @facturometro/validator / RuleFactory

Interface: RuleFactory() ​

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

The two rule constructors: rule(id, definition) for specification rules and rule.custom(id, definition) for rules with inline metadata.

Example ​

ts
import type { RuleFactory } from '@facturometro/validator';

const build = (factory: RuleFactory) => factory('BR-02', { at: 'document', test: (d) => d.id !== undefined });

Call Signature ​

RuleFactory<K>(id, definition): Rule<DocumentPaths[K]>

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

Builds a specification rule anchored at a DocumentPaths key.

Type Parameters ​

K ​

K extends keyof DocumentPaths

Parameters ​

id ​

SpecRuleId

A rule id of the pinned specification.

definition ​

AtRuleDefinition<K>

The gate, anchor and test.

Returns ​

Rule<DocumentPaths[K]>

The rule.

Call Signature ​

RuleFactory<N>(id, definition): Rule<N>

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

Builds a specification rule with a selector function as context.

Type Parameters ​

N ​

N

Parameters ​

id ​

SpecRuleId

A rule id of the pinned specification.

definition ​

ContextRuleDefinition<N>

The gate, selector and test.

Returns ​

Rule<N>

The rule.

Properties ​

custom ​

readonly custom: {<K>(id, definition): Rule<DocumentPaths[K]>; <N>(id, definition): Rule<N>; }

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

Builds a rule with inline metadata; the id must not belong to the specification.

Call Signature ​

<K>(id, definition): Rule<DocumentPaths[K]>

Builds a custom rule anchored at a DocumentPaths key.

Type Parameters ​
K ​

K extends keyof DocumentPaths

Parameters ​
id ​

string

The rule id.

definition ​

AtRuleDefinition<K> & CustomRuleMetadata

The metadata, gate, anchor and test.

Returns ​

Rule<DocumentPaths[K]>

The rule.

Call Signature ​

<N>(id, definition): Rule<N>

Builds a custom rule with a selector function as context.

Type Parameters ​
N ​

N

Parameters ​
id ​

string

The rule id.

definition ​

ContextRuleDefinition<N> & CustomRuleMetadata

The metadata, gate, selector and test.

Returns ​

Rule<N>

The rule.

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