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

    Module union

    Union shape types and operations.

    Defines the shape describing a value drawn from one of several alternatives and its branch types, and provides the union factory stating them and the accessors reading the branches, so that a member whose vocabulary ranges over unrelated types is described by a single shape. Alternatives are stated positionally, and a value is stored as it stands under the one branch it belongs to.

    Defining polymorphic members

    State the alternatives positionally; cardinality belongs to the enclosing member rather than to a branch:

    import { optional, resource } from '@metreeca/blue/resource';
    import { reference } from '@metreeca/blue/reference';
    import { string } from '@metreeca/blue/string';
    import { union } from '@metreeca/blue/union';

    const Contact = resource({
    address: optional(union(
    string(),
    reference(PostalAddress)
    ))
    });

    Either alternative is accepted at the same position, stored as it stands with no wrapping:

    { "address": "123 Main St" }

    { "address": "https://data.example.com/addresses/456" }

    Reading the alternatives off a shape

    The accessors list the alternatives a shape admits values from, treating a shape that is not a union as a single branch, so a caller handles polymorphic and plain shapes alike. They also pick the branches an input is matched against: the one branch a stored value, a relational bound or a set-matching option singles out, and every branch a retrieval placeholder may draw from.

    Type Aliases

    UnionShape

    Describes a value drawn from one of several alternatives.

    UnionBranches

    The alternatives a union admits.

    Documents

    Unions — Design

    Driving CRUD from union shapes, matched as sh:xone on write and sh:or on read

    Functions

    getShapeBranches

    Resolves the branches a shape admits values from.

    getStateBranch

    Picks the single branch a data value belongs to.

    getBoundBranch

    Picks the single branch a relational bound filters against.

    getOptionBranch

    Picks the single branch a set-matching option is tested against.

    getModelBranches

    Picks every branch a retrieval placeholder fits.

    union

    Creates a union shape.