When the projection Template is not bonded to the shape (typically at API boundaries where shape defines
the admissible surface and the projection arrives per request), pass model as a separate argument. The return
value is narrowed to Instance<T> where T is inferred from model:
constmodel = { id:"", name:"" }; // projection requested by the caller
validate(response, { shape:Product, model })({ value:product=>console.log(product.name), // typed as { readonly id: Reference; readonly name: string } trace:trace=>console.error(trace) });
The model option answers "are we validating a model, or validating against one?" and selects between the three
modes shown above:
omitted or false — validate value as an instance against the shape's bonded model
a projection Template value — validate value as an instance against that explicit projection; narrows
the
return to Instance<T> where T is inferred from model
true — validate value as a retrieval template (the model itself, not an instance of it)
Caution
By default, templates support the full query language, including aggregate transforms and nested expansion.
When exposing endpoints to untrusted clients, restrict query complexity as required by setting plain
to true, depth to 0 or a positive value, and/or limit to a maximum result set size.
Linked data validation API.
Provides validation for linked data resources, retrieval templates, and individual values against SHACL-derived shapes.
Defining Shapes
Define resource shapes with property constraints and cardinality ranges from the value module:
Validating Resources
Validate resources using validate, pattern matching on the Relay result:
Validating Projections
When the projection Template is not bonded to the shape (typically at API boundaries where
shapedefines the admissible surface and the projection arrives per request), passmodelas a separate argument. The return value is narrowed toInstance<T>whereTis inferred frommodel:Validating Templates
Validate a retrieval template using validate with
model: true:The
modeloption answers "are we validating a model, or validating against one?" and selects between the three modes shown above:false— validatevalueas an instance against the shape's bonded modelvalueas an instance against that explicit projection; narrows the return toInstance<T>whereTis inferred frommodeltrue— validatevalueas a retrieval template (the model itself, not an instance of it)By default, templates support the full query language, including aggregate transforms and nested expansion. When exposing endpoints to untrusted clients, restrict query complexity as required by setting
plaintotrue,depthto0or a positive value, and/orlimitto a maximum result set size.See
SHACL - Shapes Constraint Language