Skip to content

API surface

This page is a compact map of the APIs you will use most often.

import { DomainValidationError, compose, domain, pipe } from "@xndrjs/domain";
domain.primitive(type, validator);
domain.shape(type, validator);
domain.proof(brand, validator);
domain.capabilities<Props>().methods(factory).attach(shapeKit);
compose.optional(validator);
compose.object(fields);
compose.array(validator);
pipe(value, fn1, fn2, fn3);

Common exported types include:

  • Validator<Input, Output>
  • ValidationResult<T>
  • ValidationFailure
  • ValidationIssue
  • PrimitiveKit
  • ShapeKit
  • KitInstance
  • ProofKit
  • ProofValue

DomainValidationError is thrown by creation and assertion APIs on validation failure.

import { domain, zodFromKit, zodToValidator } from "@xndrjs/domain-zod";
  • zodToValidator(schema): wraps a Zod 4 schema as a domain validator.
  • zodFromKit(kit): validates through a primitive or shape kit, then materializes with create.
import { domain, valibotFromKit, valibotToValidator } from "@xndrjs/domain-valibot";
  • valibotToValidator(schema): wraps a Valibot schema as a domain validator.
  • valibotFromKit(kit): uses a primitive or shape kit as a Valibot field.
import {
createAjvDomainAdapter,
domain,
jsonSchemaToValidator,
openApiComponentToValidator,
} from "@xndrjs/domain-ajv";
  • jsonSchemaToValidator(schema): compiles JSON Schema into a domain validator.
  • openApiComponentToValidator(bundle, componentName): compiles an OpenAPI component schema.
  • createAjvDomainAdapter(options?): creates an adapter with custom AJV options.
import { sleep, task } from "@xndrjs/tasks";
const job = task(async () => fetch("/api/users"))
.retry(
async (error, attempt) => {
await sleep(200 * 2 ** attempt);
return shouldRetry(error);
},
{ maxAttempts: 5 }
)
.inflightDedup(symbolKey);
await job; // lazy until consumed

Use this package in the infrastructure layer to keep async effects explicit.