@outfitter/contracts
v0.1.0
Published
Result/Error patterns, error taxonomy, and handler contracts for Outfitter
Maintainers
Readme
@outfitter/contracts
Result/Error patterns, error taxonomy, handler contracts, and shared interfaces for the Outfitter ecosystem.
Status
Scaffold - Types and interfaces defined, implementations pending.
Installation
bun add @outfitter/contractsOverview
This package provides the foundational contracts that all Outfitter packages depend on:
- Error taxonomy - 10 concrete error classes with category-based exit/status codes
- Handler contract - Transport-agnostic domain logic interface
- Validation - Zod-based input validation returning Results
- Serialization - Safe JSON handling with redaction
- Adapters - Pluggable interfaces for indexing, caching, auth, and storage
Usage
import {
Result,
NotFoundError,
Handler,
HandlerContext,
createContext,
} from "@outfitter/contracts";
// Define a handler
const getNote: Handler<{ id: string }, Note, NotFoundError> = async (input, ctx) => {
const note = await db.notes.find(input.id);
if (!note) return Result.err(new NotFoundError("note", input.id));
return Result.ok(note);
};
// Create context and invoke
const ctx = createContext({ logger, config });
const result = await getNote({ id: "abc123" }, ctx);License
MIT
