EXAMPLE / Contracts

Write your first contract

Follow user.create from an email schema to a typed handler. Start with the smallest maintained example.

Recorrido del código fuenteBeginner
PATTERN EXPLORER

Follow the pattern. Inspect its limits.

Explore the source walkthrough, its evidence and the choices you would make in your own application.

RECORRIDO DEL CÓDIGO FUENTELeer la operación en el orden redactado
Choose a point to look closer
01 / Recorrido del código fuente

Describe the input

Read UserInput in src/contracts/user.ts. The schema has one required EmailAddress field. The command uses the schema for both input and output.

An exploration of the inspected source; no example is executed here.

1 / 4

The situation.

A small user.create command accepts one required email address. Its current handler returns the same email. This gives you a compact place to understand the contract and handler boundary before adding storage or authentication.

What you will learn

  • Give an operation a stable key and version.
  • Describe the accepted input and returned output in the same contract.
  • Connect a typed handler without assuming the metadata implements the business operation.
LOCAL ILLUSTRATION

Start with a required input.

This form illustrates an email-shaped input and echo result. It does not run ContractSpec’s schema library or create an account.

Enter a synthetic email address to inspect the illustrative result.

Follow the operation.

  1. 01

    Describe the input

    Read UserInput in src/contracts/user.ts. The schema has one required EmailAddress field. The command uses the schema for both input and output.

  2. 02

    Name the operation

    Inspect the user.create key, version 1.0.0, owner, goal, and anonymous authentication policy. These describe the operation and its boundary.

  3. 03

    Follow the handler

    Open src/handlers/user-input.handler.ts. HandlerForOperationSpec derives the handler shape from CreateUser. The implementation returns input.email; it does not create a persisted account.

  4. 04

    Inspect and adapt the starter

    Read the package smoke fixture and validation script. Replace the echo handler with your own behavior, then test that behavior and the contract boundary together.

What the source demonstrates.

  • The maintained source declares user.create with a required email input and a typed output.
  • The handler is typed from the operation specification.
  • A source smoke fixture checks starter metadata and feature registration.

What it does not establish.

  • A database account is created or an email is sent.
  • This example exposes an MCP tool: its manifest disables MCP.
  • This starter implements an approval gate, persistence, or production authentication.

Bring it into your environment.

Use the exact source context and prerequisites below. A source walkthrough is not a verified public-package installation recipe.

  • Access to the inspected source repository and a checkout at the cited revision.
  • The repository's Bun workspace dependencies and required generated package exports. These instructions were inspected; the examples were not executed in this review.

Directorio de trabajo: examples/minimal

PACKAGE-LOCAL COMMANDS
bun run smoke
bun run validate

The smoke fixture checks metadata and feature wiring; validation checks the contract. Neither is an account-creation integration test.

Commands and source inspected; not executed here.

Read the related guide →

Make the pattern your own.

  • Keep the operation key and version intentional as behavior changes.
  • Add persistence in a handler or port with explicit tests.
  • Use the approval fixture or draft-and-send story when learning governed writes.
CONTEXTO DE LA FUENTE

Inspect the evidence.

Reviewed 2026-10-27 · b67c376f

Pinned source links require repository access; publication and anonymous package availability were not checked for this example.

Declared maturity
stable
Catalogue registration
Registered
Inline preview
No generated inline UI preview registered
Execution in this review
Not rerun
Production qualification
Not assessed
Tu vista

Make room for your context.

Shape the presentation around this moment. You can change it whenever you need.

Tu contexto

The different parts of you

Choose a starting point

Una mezcla útil de contexto, imágenes y orientación discreta.

Tune each dimension
Each dimension can change independently. Product permissions and available actions stay unchanged.

Support the way you begin and return

Tune your support

Comodidad de lectura

Elige tu idioma

El idioma de la interfaz solo cambia el texto. Los mercados, precios y flujos de trabajo conservan sus propios ajustes.

Cobertura de traducción

Parte del contenido se muestra en inglés.

Navegación151
Grafo616
Categorías188
Portafolio332
Ejemplos2035
Vista previa de la fuente41

Se añadirán más traducciones a medida que se revise el contenido.

Esta preferencia se guarda en este navegador.

Buscar en el sitio web

Puntos de partida útiles

Sin resultados. Prueba una frase más corta, un nombre de operación u otro ámbito de búsqueda.

UN POCO DE ESPACIO PARA EXPLORAR

Encuentra algo que explorar.

Abre una vista detallada en esta página, prueba otra perspectiva o sigue el detalle a su propia página.

Cómo funcionan las vistas previas y los controles
01

Mirar antes de salir

Pasa el cursor por un enlace o enfócalo con Tab para ver una vista previa. Hacer clic en el enlace original o pulsar Intro siempre abre su destino.

02

Mantener el contexto

Entra en la vista previa para explorar sus secciones. Usa Alt + ↓ desde un enlace enfocado para entrar con el teclado. Escape la cierra.

03

Abrir las posibilidades

Las filas desplegables, las perspectivas y los controles destacados revelan más. Tu vista cambia la comodidad de lectura y el contexto que exploras.

Un botón separado para mirar más de cerca

Muestra pequeños botones de vista previa junto a los enlaces donde haya espacio. Toca el ojo para inspeccionar o el enlace para ir directamente. Esta elección permanece en esta pestaña.

No se recoge historial de navegación. El movimiento reducido sigue tu dispositivo y Tu vista.