@metreeca/blue - v0.12.0
    Preparing search index...

    Type Alias UnionShape<B>

    Describes a value drawn from one of several alternatives.

    Admits whatever any of its branches admits, so that a property whose vocabulary ranges over unrelated types (a plain string or any of several structured resources, say) is described by a single shape. A branch is a shape in its own right, a union included, possibly deferred to break definition cycles.

    Matching

    Which branches an operation is carried out against is decided by the input the caller supplies, under the regime that input belongs to:

    • a data value being stored singles out exactly one branch, matched against all its constraints, as it is a legal value of the branch it selects and that branch fixes how it is stored;
    • a relational bound singles out exactly one branch as well, but keys on syntactic traits alone (the value's kind and, where branches share it, their lexical pattern), as a bound filters by order and need not be a legal value of the branch it selects. A localised branch takes a plain string bound, and links and embedded resources take none;
    • a set-matching option singles out exactly one branch as well, but keys on the value's kind alone and ignores any lexical pattern, as an option is tested by equality and an option outside the domain is a legal filter matching nothing. A localised branch takes a plain string option or a map of options keyed by language tag;
    • a retrieval placeholder matches at least one branch and retrieves each branch it fits, as it carries no value of its own and discriminates nothing: the atomic placeholder matches by form alone, ignoring every constraint, and so reaches every branch coming back as a value, an embedded resource excepted, as it names no identifier to come back as; a nested template matches every resource branch admitting at least one of the members it asks for, and may thus span several, each answering the members it admits; a map of tag ranges matches the localised branches alone. A template need not ask for every member a branch declares, but each member it asks for must fit at least one branch, which may declare that member with a shape of its own. A tag range may also be a member name, so an object whose keys each name a member of a resource branch is read as a template, and any other object as a map of tag ranges.

    An input matching no branch is rejected as unsatisfiable, and one required to single out a branch but matching several is rejected as ambiguous. A text search singles out no branch at all: it filters every textual branch at once.

    Important

    Branches are expected to be disjoint: no legal value satisfies two of them at once. Disjointness is a modelling contract rather than a property proved as the shape is built, so overlapping branches are accepted and an offending value is rejected only when it is matched. A union filtered by relational bounds is held to a stricter grade, as a bound is told apart by syntax alone: it admits at most one numeric and one boolean branch, and string branches only under mutually exclusive patterns. One filtered by set-matching options is held to a stricter grade still, as an option is told apart by kind alone: it admits at most one branch of each kind. Under either grade, a plain string over a string branch and a localised one is ambiguous.

    Important

    Branches describing or linking to resources are expected to be coherent: a member name several of them declare denotes the same property throughout the union, agreeing on its kind, its forward and reverse predicates and its captive and foreign flags, while its range, cardinality and value domain may differ. Branches may be deferred, so coherence is checked as the branches are first resolved rather than as the union is built, and an incoherent union is rejected there.

    Inheritance

    Where a resource!ResourceShape extends the shapes it lists as parents, union-valued members are merged according to the following rules. The child is the extending shape; the parent is the inherited one.

    Field Override Rule
    kind Cannot be overridden
    branches Each child branch narrows exactly one parent branch; unpaired parent branches are dropped

    A child narrowing a branch that no parent branch matches, one that several match, or one already taken by another child branch is reported as an error. A child declaring a single non-union shape narrows the one parent branch it matches and collapses the member to that shape, leaving the value no longer polymorphic.

    type UnionShape<B extends UnionBranches = UnionBranches> = {
        kind: "union";
        branches: B;
    }

    Type Parameters

    Index

    Properties

    Properties

    kind: "union"

    Discriminator identifying this as a union shape.

    Inheritance — cannot be overridden.

    branches: B

    The alternatives a value may be drawn from.

    Stated flat: a branch that is itself a union is replaced, as the shape is built, by the alternatives it holds, so that a caller routing a value walks one list however the union was assembled. A branch left deferred is flattened where it is resolved rather than where it is stated.

    Inheritance — each child branch narrows exactly one parent branch; unpaired parent branches are dropped.