Comment builder
Le builder Comment crée une entité Comment, 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 { Comment } from '@unschema-graph/astro';
// Svelte 5import { Comment } from '@unschema-graph/svelte';
// Core / Node.jsimport { Comment } from '@unschema-graph/core';import { CommentSchema } from '@unschema-graph/core';Le schéma Zod CommentSchema est également exporté pour la composition et la validation avancées.
Types TypeScript
Section intitulée « Types TypeScript »import { CommentSchema, type SchemaInput, type SchemaOutput,} from '@unschema-graph/core';
type CommentInput = SchemaInput<typeof CommentSchema>;type CommentOutput = SchemaOutput<typeof CommentSchema, 'Comment'>;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 | — |
text |
string | Oui | non-empty |
author |
string | Person | Organization | EntityReference | Oui | non-empty |
datePublished |
string | number | Date | Non | non-empty |
upvoteCount |
number | Non | integer; minimum: -9007199254740991; maximum: 9007199254740991 |
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 Comment.
Exemple minimal
Section intitulée « Exemple minimal »import { Comment } from '@unschema-graph/core';
const entity = Comment({ "text": "This pattern works well.", "author": "Grace Hopper"});{ "@type": "Comment", "text": "This pattern works well.", "author": { "@type": "Person", "name": "Grace Hopper" }}Relations et recettes
Section intitulée « Relations et recettes »- Builders liés :
Article,BlogPosting,NewsArticle,Recipe - Utilisé par : aucune recette dédiée
- Sources externes : Schema.org Comment
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 Comment.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.