Event builder
Le builder Event crée une entité Event, 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 { Event } from '@unschema-graph/astro';
// Svelte 5import { Event } from '@unschema-graph/svelte';
// Core / Node.jsimport { Event } from '@unschema-graph/core';import { EventSchema } from '@unschema-graph/core';Le schéma Zod EventSchema est également exporté pour la composition et la validation avancées.
Types TypeScript
Section intitulée « Types TypeScript »import { EventSchema, type SchemaInput, type SchemaOutput,} from '@unschema-graph/core';
type EventInput = SchemaInput<typeof EventSchema>;type EventOutput = SchemaOutput<typeof EventSchema, 'Event'>;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 |
startDate |
string | number | Date | Oui | non-empty |
location |
string | object | Oui | non-empty |
endDate |
string | number | Date | Non | non-empty |
duration |
string | number | DurationObject | Non | non-empty; greater than 0 |
description |
string | Non | — |
image |
string | ImageObject | Array<string | ImageObject> | Non | non-empty |
eventStatus |
string | Non | — |
eventAttendanceMode |
string | Non | — |
organizer |
string | Person | Organization | EntityReference | Array<string | Person | Organization | EntityReference> | Non | non-empty |
performer |
string | Person | Organization | EntityReference | Array<string | Person | Organization | EntityReference> | Non | non-empty |
offers |
Offer | AggregateOffer | Array<Offer | AggregateOffer> | 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 Event.
Exemple minimal
Section intitulée « Exemple minimal »import { Event } from '@unschema-graph/core';
const entity = Event({ "name": "Astro meetup", "startDate": "2026-10-15T18:00:00+02:00", "location": "Paris, France"});{ "@type": "Event", "name": "Astro meetup", "startDate": "2026-10-15T18:00:00+02:00", "location": "Paris, France"}Relations et recettes
Section intitulée « Relations et recettes »- Builders liés :
Article,BlogPosting,NewsArticle,Recipe - Utilisé par : Événements
- Sources externes : Schema.org Event · Google Search Central
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 Event.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.