Person builder
Le builder Person crée une entité Person, 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 { Person } from '@unschema-graph/astro';
// Svelte 5import { Person } from '@unschema-graph/svelte';
// Core / Node.jsimport { Person } from '@unschema-graph/core';import { PersonSchema } from '@unschema-graph/core';Le schéma Zod PersonSchema est également exporté pour la composition et la validation avancées.
Types TypeScript
Section intitulée « Types TypeScript »import { PersonSchema, type SchemaInput, type SchemaOutput,} from '@unschema-graph/core';
type PersonInput = SchemaInput<typeof PersonSchema>;type PersonOutput = SchemaOutput<typeof PersonSchema, 'Person'>;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 | — |
name |
string | Oui | non-empty |
givenName |
string | Non | — |
familyName |
string | Non | — |
additionalName |
string | Non | — |
url |
string | Non | — |
image |
string | ImageObject | Non | non-empty |
jobTitle |
string | Non | — |
worksFor |
string | object | Non | — |
sameAs |
string | Array |
Non | — |
email |
string | Non | format: email |
telephone |
string | Non | — |
description |
string | Non | — |
address |
string | PostalAddress | EntityReference | 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 Person.
Exemple minimal
Section intitulée « Exemple minimal »import { Person } from '@unschema-graph/core';
const entity = Person({ "name": "Ada Lovelace", "jobTitle": "Engineer"});{ "@type": "Person", "name": "Ada Lovelace", "jobTitle": "Engineer"}Relations et recettes
Section intitulée « Relations et recettes »- Builders liés :
Organization,LocalBusiness,Restaurant,Store - Utilisé par : Blog et média
- Sources externes : Schema.org Person
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 Person.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.