@metreeca/trio - v0.1.1
    Preparing search index...

    Module builder

    Builders for RDF graphs.

    Provides declarative combinators that map domain resources to the RDF graphs representing them.

    Types

    • Mapper — maps a domain value to its RDF rendering

    Combinators

    • resource — builds a resource graph anchored at a chosen subject, threading it into a builder callback and checking every built statement hangs off it
    • description — builds a resource description by concatenating per-property graphs
    • property — links subjects to objects under a predicate, taking objects either as ready terms or as values run through a Mapper and embedded at their own root

    Term encoders

    • link — encodes IRIs as named-resource terms
    • data — encodes scalars as datatype-typed literals
    • text — encodes a language map as language-tagged or plain literals
    • term — applies a per-value encoder across a Some input, one term per value

    Usage

    Every combinator returns a Graph, so a resource and its embedded sub-resources assemble as one nested expression:

    const ex = createNamespace("https://example.org/");

    function encodeVendor(vendor: Vendor): Graph {
    return resource(named(vendor.id), id => description( // anchored at the vendor's own IRI
    property(id, rdf.type, link(vendor.types)), // typing statements
    property(id, ex.name, text(vendor.name)), // language map to tagged/plain literals
    property(id, ex.founded, data(vendor.founded, xsd.gYear)), // scalar to a datatype-typed literal
    property(id, ex.address, vendor.address, encodeAddress), // embed a sub-resource at its own root
    property(link(vendor.products), ex.vendor, id) // inverse: each product links back to it
    ));
    }

    function encodeAddress(address: Address): Graph {
    return resource(blank(), anchor => description( // self-anchored at a fresh blank node
    property(anchor, ex.street, data(address.street)),
    property(anchor, ex.city, data(address.city))
    ));
    }
    Mapper

    Maps a domain value to its RDF rendering: either a single Term or a whole Graph.

    resource

    Builds a resource graph anchored at a chosen subject.

    description

    Builds a resource description by concatenating property graphs into one flat graph.

    property

    Builds direct triples, or maps each object and embeds sub-graphs at their root.

    Encodes IRIs as named resource terms.

    data

    Encodes scalars as datatype-typed literals.

    text

    Encodes a language map as language-tagged or plain literals.

    term

    Maps each value of a Some input through an encoder into RDF terms.