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

    Interface ResourceShape

    Shape definition for linked data resources.

    Validates linked data resources with structural constraints including inheritance, property definitions, and SHACL-aligned validation rules. Resource shapes define the expected structure of linked data resources and support type inference for property values.

    Important

    Resource shapes are closed: validated resources may only contain entries explicitly defined in the shape. Any additional entries will cause validation to fail.

    Inheritance

    When a resource shape extends a parent via extends, fields are merged according to the following rules. The child is the extending shape; the parent is the inherited shape.

    Field Override Rule
    kind Cannot be overridden
    model Computed from entries, not user-defined
    virtual Inherited; conflicting parents without child override are reported as an error
    name Always from child; not inherited
    description Always from child; not inherited
    namespace Inherited; conflicting parents without child override are reported as an error
    extends Structural; outside inheritance scope
    class Shape-specific target class; outside inheritance scope
    classes Union of parent class and child/parent classes
    pattern Child may replace trailing /* wildcard with more specific segments
    in Intersection of parent and child sets; empty result is reported as an error
    hasValue Union of parent and child required values; child must require all parent values
    validators Union of parent and child validators; all apply
    entries Union; clashing keys merged per property rules; kind mismatch is reported as an error

    Cross-Field Validation

    • all merged hasValue entries must be members of the merged in set (if defined)
    • forward predicate IRIs must be unique across all entries
    • reverse predicate IRIs must be unique across all entries
    • forward and reverse are independent sets: the same IRI may appear in both
    interface ResourceShape {
        kind: "resource";
        model: Template;
        validators?: readonly [Validator<Resource>, Validator<Resource>];
        entries: { readonly [entry: string]: Entry };
        virtual?: boolean;
        name?: Dictionary;
        description?: Dictionary;
        namespace?: { "": string; readonly [term: string]: string };
        extends?: Lazy<ResourceShape> | readonly Lazy<ResourceShape>[];
        class?: string;
        classes?: readonly string[];
        pattern?: string;
        in?: readonly string[];
        hasValue?: readonly string[];
    }

    Hierarchy (View Summary)

    Index

    Properties

    kind: "resource"

    Discriminator identifying this as a resource shape.

    Inheritance — cannot be overridden.

    model: Template

    Prototype value for runtime model assembly.

    Provides an immutable retrieval template matching this shape. When a shape extends parent shapes, inherited entries are merged into the template; local definitions override inherited ones. Entries whose cardinality admits absence are carried as optional keys, so a matching literal spells out only the entries it supplies. The runtime state type may be recovered via Instance.

    Inheritance — computed from entries, not user-defined.

    validators?: readonly [Validator<Resource>, Validator<Resource>]

    Custom resource validators.

    When specified, all validators are applied during validation. Must be non-empty. Each validator reports violations as a Trace, returning undefined if the resource passes.

    Inheritance — parent and child validators are merged; all apply.

    SHACL defines custom constraints via SPARQL; this library uses programmatic validators.

    entries: { readonly [entry: string]: Entry }

    The entries constraining the resource.

    Each entry constrains one field of the JSON-LD node object the shape describes: its @id (an Id), its @type (a Type), or a data or object Property keyed by a predicate IRI. At most one Id and one Type entry are allowed, counted after inheritance merging: declarations sharing a property name collapse into a single entry, so a marker reaching the shape through several parents or redeclared by the shape counts once, while markers of the same kind under distinct names are rejected.

    Inheritance — parent and child entries are merged; clashing keys are merged per property rules.

    virtual?: boolean

    Marks the resource as dynamically generated.

    When true, indicates the resource is at least partially computed rather than stored.

    Inheritance — inherited from parent; conflicting parents without child override are reported as an error.

    undefined (false)

    name?: Dictionary

    Human-readable name for the shape.

    Inheritance — always from child; not inherited.

    SHACL defines sh:name only for property shapes; extended here to node shapes.

    description?: Dictionary

    Human-readable description of the shape.

    Inheritance — always from child; not inherited.

    SHACL defines sh:description only for property shapes; extended here to node shapes.

    namespace?: { "": string; readonly [term: string]: string }

    Default namespace for converting property names to IRIs.

    Property names without explicit IRI mappings are resolved relative to this namespace.

    Inheritance — inherited from parent; conflicting parents without child override are reported as an error.

    defaultNamespace

    extends?: Lazy<ResourceShape> | readonly Lazy<ResourceShape>[]

    Parent shape(s) this shape inherits from.

    Inherited entries and constraints are merged into the derived shape. When a child overrides an inherited property, constraints are enforced conjunctively: values must satisfy both the child's and all inherited constraints. This ensures overrides can only restrict, never relax, inherited definitions.

    Warning

    When inheriting from multiple shapes with different namespace values, an overriding namespace must be declared in this shape.

    Inheritance — structural; outside inheritance scope.

    class?: string

    Target class for resource instances.

    The absolute IRI identifying the primary class that resource instances must belong to. Shape-specific and not inherited. If defined, this value is exposed through the property mapped to @type using type.

    Inheritance — shape-specific target class; outside inheritance scope.

    classes?: readonly string[]

    Ancillary class constraints for resource instances.

    Additional class IRIs that resource instances must conform to. Empty arrays are ignored.

    Inheritance — union of parent class and child/parent classes.

    pattern?: string

    IRI path pattern that resource identifiers must match.

    Patterns are IRI-like templates using {name} placeholders for single path segments and /* for trailing wildcards. Patterns may be absolute or root-relative; root-relative patterns match absolute IRIs, ignoring the origin.

    Inheritance — only the trailing /* wildcard admits narrowing: a child may replace /* with more specific segments (for example, /products/* to /products/{id}/reviews/{rid}), provided the fixed prefix matches. All other cases require exact equality; a mismatch is reported as an error.

    undefined (no pattern constraint)

    https://example.org/products/{sku}  → https://example.org/products/ABC-456
    https://example.org/categories/* → https://example.org/categories/electronics/phones

    /employees/{id} → https://example.org/employees/123
    /departments/* → https://example.org/departments/sales/emea
    in?: readonly string[]

    Allowed resource identifiers (closed enumeration).

    When specified, resource identifiers must be members of this list. IRIs must be absolute. Empty arrays are ignored.

    Inheritance — intersection of parent and child sets; empty result is reported as an error.

    undefined (no enumeration constraint)

    hasValue?: readonly string[]

    Required resource identifiers that must be present.

    When specified, all listed resource identifiers must appear. IRIs must be absolute. Empty arrays are ignored.

    Inheritance — union of parent and child required values; child must require all parent values.

    undefined (no required values)