Review builder
Le builder Review crée une entité Review, injecte son @type,
valide les données de manière synchrone et rejette les propriétés inconnues.
// Astro — shown first when Astro is selectedimport { Review } from '@unschema-graph/astro';
// Svelte 5import { Review } from '@unschema-graph/svelte';
// Core / Node.jsimport { Review } from '@unschema-graph/core';import { ReviewSchema } from '@unschema-graph/core';Le schéma Zod ReviewSchema est également exporté pour la composition et la validation avancées.
Types TypeScript
Section intitulée « Types TypeScript »import { ReviewSchema, type SchemaInput, type SchemaOutput,} from '@unschema-graph/core';
type ReviewInput = SchemaInput<typeof ReviewSchema>;type ReviewOutput = SchemaOutput<typeof ReviewSchema, 'Review'>;Propriétés d’entrée
Section intitulée « Propriétés d’entrée »| Propriété | Type d’entrée | Obligatoire | Valeur par défaut / contraintes |
|---|---|---|---|
@id |
string | Non | — |
author |
string | Person | Organization | EntityReference | Oui | non-empty |
reviewRating |
Rating | Oui | — |
datePublished |
string | number | Date | Non | non-empty |
reviewBody |
string | Non | — |
name |
string | Non | — |
itemReviewed |
string | SchemaOrgEntity | EntityReference | Non | non-empty |
Les alias ci-dessus restent la référence exacte, notamment pour les objets imbriqués. Le builder
accepte aussi une configuration de validation en second argument et possède une sortie dont le
@type vaut toujours Review.
Exemple minimal
Section intitulée « Exemple minimal »import { Review } from '@unschema-graph/core';
const entity = Review({ "author": "Ada Lovelace", "reviewRating": { "ratingValue": 5 }, "reviewBody": "Clear and reliable."});{ "@type": "Review", "author": { "@type": "Person", "name": "Ada Lovelace" }, "reviewRating": { "@type": "Rating", "ratingValue": 5, "bestRating": 5, "worstRating": 1 }, "reviewBody": "Clear and reliable."}Relations et recettes
Section intitulée « Relations et recettes »- Builders liés :
Product,Offer,AggregateOffer,Service - Utilisé par : E-commerce
- Sources externes : Schema.org Review
Erreurs fréquentes
Section intitulée « Erreurs fréquentes »- Passer une propriété inconnue au builder strict.
- Utiliser une donnée source privée d’une propriété obligatoire.
- Supposer qu’un Schema.org valide garantit un affichage dans la recherche.
Validation
Section intitulée « Validation »Utilisez Review.safeParse(input) pour les données externes. Pour une extension
Schema.org non encore modélisée, validez d’abord l’entité puis utilisez
withAdditionalProperties(). N’ajoutez jamais une propriété inventée au builder.