Aller au contenu

Organization builder

Le builder Organization crée une entité Organization, injecte son @type, valide les données de manière synchrone et rejette les propriétés inconnues.

// Astro — shown first when Astro is selected
import { Organization } from '@unschema-graph/astro';
// Svelte 5
import { Organization } from '@unschema-graph/svelte';
// Core / Node.js
import { Organization } from '@unschema-graph/core';
import { OrganizationSchema } from '@unschema-graph/core';

Le schéma Zod OrganizationSchema est également exporté pour la composition et la validation avancées.

import {
OrganizationSchema,
type SchemaInput,
type SchemaOutput,
} from '@unschema-graph/core';
type OrganizationInput = SchemaInput<typeof OrganizationSchema>;
type OrganizationOutput = SchemaOutput<typeof OrganizationSchema, 'Organization'>;
Propriété Type d’entrée Obligatoire Valeur par défaut / contraintes
@id string Non —
name string Oui non-empty
legalName string Non —
url string Non —
logo string | ImageObject Non non-empty
image string | ImageObject Non non-empty
description string Non —
sameAs string | Array Non —
address string | PostalAddress | EntityReference Non —
contactPoint ContactPoint | Array<ContactPoint> Non —
email string Non format: email
telephone string Non —
foundingDate string | number | Date 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 Organization.

import { Organization } from '@unschema-graph/core';
const entity = Organization({
"name": "Acme",
"url": "https://example.com"
});
{
"@type": "Organization",
"name": "Acme",
"url": "https://example.com"
}
  • 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.

Utilisez Organization.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.