Book builder
Le builder Book crée une entité Book, 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 { Book } from '@unschema-graph/astro';
// Svelte 5import { Book } from '@unschema-graph/svelte';
// Core / Node.jsimport { Book } from '@unschema-graph/core';import { BookSchema } from '@unschema-graph/core';Le schéma Zod BookSchema est également exporté pour la composition et la validation avancées.
Types TypeScript
Section intitulée « Types TypeScript »import { BookSchema, type SchemaInput, type SchemaOutput,} from '@unschema-graph/core';
type BookInput = SchemaInput<typeof BookSchema>;type BookOutput = SchemaOutput<typeof BookSchema, 'Book'>;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 | non-empty |
name |
string | Oui | non-empty |
author |
string | Person | Organization | EntityReference | Array<string | Person | Organization | EntityReference> | Oui | — |
isbn |
string | Non | — |
bookFormat |
string | Non | — |
datePublished |
string | number | Date | Non | non-empty |
publisher |
string | Organization | EntityReference | Non | — |
inLanguage |
string | Non | — |
numberOfPages |
number | Non | integer; greater than 0; maximum: 9007199254740991 |
description |
string | Non | — |
aggregateRating |
AggregateRating | Non | — |
review |
Review | Array<Review> | Non | — |
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 Book.
Exemple minimal
Section intitulée « Exemple minimal »import { Book } from '@unschema-graph/core';
const entity = Book({ "name": "The Astro Handbook", "author": "Ada Lovelace"});{ "@type": "Book", "name": "The Astro Handbook", "author": "Ada Lovelace"}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 Book
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 Book.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.