Form limits
Read the SHACL limits of an action shape, so a form blocks a value the plan would refuse.
What it is
Manta validates every plan against the SHACL shapes of its actions before it runs. If one value breaks a limit, such as a list with too many items or a text that is too long, Manta refuses the whole plan. The person sees the error only after they submit.
useShaclPropertyConstraints reads the same limits from the datastore, so your form can block the value first. It
gives the limits of each property of a shape, keyed by property path.
Do not copy a limit into your code as a number. Manta changes a limit when the platform changes it, for example when a live test shows that Meta accepts more titles than its documents say. A copied number then blocks values that Manta accepts, or lets through values that Manta refuses.
Import
import { useShaclPropertyConstraints, type ShaclPropertyConstraints } from "@manta-eu/react/ldo-ui";
The hook reads through the connection that SparqlOptionsProvider sets up. Outside React,
fetchShaclPropertyConstraints(engine, options, { shapeIri, propertyIri }) does the same read.
Example
A carousel editor that stops at the number of cards Meta accepts:
import { useShaclPropertyConstraints } from "@manta-eu/react/ldo-ui";
import { expandPrefix } from "@manta-eu/rdf-lib/namespaces";
const cards = expandPrefix("meta:childAttachments");
export function AddCardButton(props: { cardCount: number; onAdd: () => void }) {
const { cardCount, onAdd } = props;
const { data } = useShaclPropertyConstraints({ shapeIri: expandPrefix("meta:CarouselShape"), propertyIri: cards });
const maxCount = data?.get(cards)?.maxCount;
return (
<button type="button" disabled={maxCount !== undefined && cardCount >= maxCount} onClick={onAdd}>
Add card
</button>
);
}
A property whose value is a node of its own lists that node’s shape in nodes. Read that shape for the value’s own
limits. A Meta title, for example, takes its length limit from meta:TitleShape:
const text = expandPrefix("meta:text");
const { data } = useShaclPropertyConstraints({ shapeIri: expandPrefix("meta:TitleShape"), propertyIri: text });
return <input maxLength={data?.get(text)?.maxLength} />;
Request
useShaclPropertyConstraints({
shapeIri, // string: the shape, such as the action shape of the entity the form edits
propertyIri, // string, optional: one property path; leave it out to read every property of the shape
enabled, // boolean, optional, defaults to true
});
Response
The hook returns TanStack Query’s UseQueryResult<Map<string, ShaclPropertyConstraints>, Error>. The map’s key is the
property path. Each value has these fields:
| Field | Type | Meaning |
|---|---|---|
path |
string |
The property path. |
minCount, maxCount |
number, optional |
The fewest and the most values the property takes. |
minLength, maxLength |
number, optional |
The shortest and the longest text, in characters. |
minInclusive, maxInclusive |
number, optional |
The smallest and the largest number, included. |
minExclusive, maxExclusive |
number, optional |
The smallest and the largest number, not included. |
patterns |
string[] |
Regular expressions that a text value must match, every one. |
allowedValues |
string[], optional |
The only values the property takes, from sh:in. |
nodes |
string[] |
The shapes that a node value must satisfy. |
qualified |
ShaclQualifiedLimit[] |
Counts that apply only to the values that meet conditions. |
A field is missing when the shape sets no such limit. When two parts of a shape name the same property, the value must satisfy both, so the response keeps the tighter limit.
A qualified limit counts only some of the values. For example, a Google Performance Max asset group takes 3 to 15
headlines in schema:hasPart: that limit has minCount: 3, maxCount: 15 and the condition
{ path: google:assetGroupAssetFieldType, value: "HEADLINE" }, with the full IRI as path.
The hook reads a qualified limit only when sh:hasValue selects its values. It leaves out a qualified limit that
selects values in another way, such as by length.
The hook reads only the property shapes that the shape names with sh:property, and each one needs an IRI as its
sh:path. A property path such as sh:inversePath makes the read fail. It does not read a limit that
the shape adds through sh:and, sh:or, sh:xone, or an sh:node on the shape itself.
A Datalog guard rule can also refuse a plan, and the hook does not show its limit. For example, a Meta flexible feed with no carousel and no placement rules takes at most 10 headlines, 10 primary texts and 5 descriptions. A guard rule applies that limit, so the shape carries no count for it. The run of the plan reports the guard’s message.