IF Commons GitHub

logical/constraints

Written to: 4 requirements: 4 proved, 0 partly, 0 failing, 0 with no test recorded. 0006-integrations-exchange FR-004, 0006-integrations-exchange FR-005, 0006-integrations-exchange FR-006, 0006-integrations-exchange FR-007

Schema and Profile as typed constraints over the abstract tree, and validation (commons integrations 0006-integrations-exchange): a schema says which paths a transaction has and how many times, a profile adds constraints to a schema, a terminology says which codes a binding allows, and validation gives findings at the level where each was found (syntax, schema, profile, terminology, business rule).

A finding has a level, a severity, a path, a code and a message made of the code and the path: it never holds a value of the payload, so that findings may be logged (commons integrations 0003-integrations-logical FR-003). A business rule is a function of the tree that returns findings, supplied by an agreement.

Source: commons/integrations/src/logical/constraints.ts

8 of 16 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

FindingLeveltypeno test imports it
type FindingLevel = "syntax" | "schema" | "profile" | "terminology" | "business-rule";

Where a finding was found.

Severitytypeno test imports it
type Severity = "error" | "warning" | "information";

How bad a finding is.

FindingCodetypeno test imports it
type FindingCode =
  | "syntax-error"
  | "unknown-path"
  | "cardinality-min"
  | "cardinality-max"
  | "value-pattern"
  | "value-fixed"
  | "code-not-in-terminology"
  | "terminology-unavailable"
  | "business-rule"
  | "unmapped-source-field"
  | "lossy-mapping"
  | "mapping-target-conflict";

What a finding says.

FINDING_CODESconst
const FINDING_CODES: readonly FindingCode[]

Every finding code, as a closed list of strings a consumer may carry as data; the compiler holds it complete against FindingCode.

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

FINDING_LEVELSconst
const FINDING_LEVELS: readonly FindingLevel[]

Every level of a finding.

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

Findingtypeno test imports it
type Finding = { readonly level: FindingLevel; readonly severity: Severity; readonly code: FindingCode; readonly path: string; readonly message: string };

A finding: never a value of the payload.

findingconst
const finding: (level: FindingLevel, severity: Severity, code: FindingCode, path: string, note?: string) => Finding

A finding from its parts, its message made of the code and the path.

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

Constrainttype
type Constraint = | { readonly kind: "cardinality"; readonly path: string; readonly min: number; readonly max: number … (567 characters)
type Constraint =
  | { readonly kind: "cardinality"; readonly path: string; readonly min: number; readonly max: number | "*" }
  | { readonly kind: "choice"; readonly path: string; readonly alternatives: readonly string[]; readonly min: number; readonly max: number | "*" }
  | { readonly kind: "pattern"; readonly path: string; readonly regex: string }
  | { readonly kind: "fixed"; readonly path: string; readonly value: string }
  | { readonly kind: "binding"; readonly path: string; readonly terminology: Ref<"terminology">; readonly strength: BindingStrength };

What a path of a schema must be.

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

Schematype
type Schema = { readonly id: Ref<"schema">; readonly transaction: string; readonly paths: readonly string[]; readonly constraints: readonly Constraint[] };

A schema: the paths a kind of transaction has, with their constraints. A path with no constraint is allowed; a path not listed (and not below a listed one) is unknown.

Imported by 26 tests of the run (26 passed, 0 failed): the library's results

Profiletypeno test imports it
type Profile = { readonly id: Ref<"profile">; readonly schema: Ref<"schema">; readonly constraints: readonly Constraint[] };

A profile: more constraints on a schema.

Terminologytype
type Terminology = { readonly id: Ref<"terminology">; readonly codes: ReadonlySet<string> };

A code system or value set, as the codes it holds. Loaded from data the user supplies or the issuer publishes; the library embeds none.

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

Terminologiestypeno test imports it
type Terminologies = ReadonlyMap<StandardUrn, Terminology>;

Terminologies by urn.

BusinessRuletypeno test imports it
type BusinessRule = (t: Transaction) => readonly Finding[];

A rule of business: a function of a transaction that gives findings (never of values).

validatefunction
function validate(t: Transaction, schema: Schema, options?: { readonly profile?: Profile | undefined; readonly terminologies?: Terminologies | undefined; readonly rules?: readonly BusinessRule[] | undefined; }): readonly Finding[]

Every finding of a transaction against a schema, a profile where given, the terminologies loaded, and the rules of business supplied, in that order of level. Total and pure.

Imported by 21 tests of the run (21 passed, 0 failed): the library's results

hasErrorsconst
const hasErrors: (fs: readonly Finding[]) => boolean

Whether the findings hold an error.

Imported by 13 tests of the run (13 passed, 0 failed): the library's results

Checkedtypeno test imports it
type Checked<T> = Result<T, readonly Finding[]>;

A result of a step that may give findings: the value, or the findings that stopped it.

Titles, headings, exports, tables, columns and requirements. Esc closes.