concrete/relations/mirror-type
A slot mirroring another slot is not its upstream's kind: a value of another value kind, a row of another `from` table, or a list of another element.
A slot mirroring another slot is not its upstream's kind: a value of another value kind, a row of another from table, or a list of another element.
Graded by the relations stage of concrete check, in the probe venue. A violation reports this id and the file it failed at — see every rule and concrete check.
Reason
A slot whose source: is another slot is a MIRROR: it holds exactly its upstream's value,
resolved wherever the content is read. Nothing converts the value on the way. So the
two slots must hold the same kind of value — a text slot can mirror a text, select, url, date,
email or phone slot (each holds a string), an image slot an image slot. A row mirrors a row
from the same table, and a list mirrors a list of the same element: a list of contact
rows mirrors a list of contact rows, whatever fields of its own each item adds around the
row.
This rule grades a mirror of another section's slot. A mirror of a slot in its own section is refused by the section's own contracts, with the same reasoning.
The slot builders already refuse a mismatched mirror where it is written. This rule asks the same question of what the build actually carries, because a cast, or an upstream whose kind changed after the mirror was written, reaches the artifact without that error — and a mirror handed a value of the wrong kind renders nothing, or renders it wrong.
Fix
Declare the mirror at its upstream's kind. If the slot really wants something derived
from the upstream — an image's caption, a list's first item, its length — that is a projection, and a
projection is a compute() that reads the upstream and returns the slot's own kind.
Before and after
// A text slot mirroring an image: the compiler rejects it, as the rule does.
// @noErrors
import { fact, fill, image, Section, section, Slot, text } from "@homepages/concrete";
const Hero = section(
{
key: "hero",
label: "Hero",
slots: {
photo: image({ label: "Photo", from: fact.property.property_media, source: fill.pick({ brief: "The most striking exterior." }) }),
},
},
({ slot }) => (
<Section>
<Slot.Image slot={slot.photo} />
</Section>
),
);
export const Card = section(
{
key: "card",
label: "Card",
slots: { caption: text.short({ label: "Caption", cap: 60, source: Hero.slots.photo }) },
},
({ slot }) => (
<Section>
<Slot.Text slot={slot.caption} as="p" />
</Section>
),
);import { compute, fact, fill, image, Section, section, Slot, text } from "@homepages/concrete";
const Hero = section(
{
key: "hero",
label: "Hero",
slots: {
photo: image({ label: "Photo", from: fact.property.property_media, source: fill.pick({ brief: "The most striking exterior." }) }),
},
},
({ slot }) => (
<Section>
<Slot.Image slot={slot.photo} />
</Section>
),
);
export const Card = section(
{
key: "card",
label: "Card",
slots: {
// The same image, mirrored whole. A mirror holds what its upstream holds, so it states no `from`.
photo: image({ label: "Photo", source: Hero.slots.photo }),
// A projection of it is a compute, returning this slot's own kind.
caption: text.short({
label: "Caption",
cap: 60,
source: compute({ reads: [Hero.slots.photo] }, (photo) => photo?.name ?? ""),
}),
},
},
({ slot }) => (
<Section>
<Slot.Image slot={slot.photo} />
<Slot.Text slot={slot.caption} as="p" />
</Section>
),
);