typed-service-contracts

Implements type-safe TypeScript services using Zod schemas and the Spec and Handler pattern.

Updated May 22, 2026
One-click install
npx skills add https://github.com/Asygnuz-S-A-S/one-star --skill typed-service-contracts-asygnuz-s-a-s
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: typed-service-contracts
Source: https://github.com/Asygnuz-S-A-S/one-star/tree/main/.agents/skills/typed-service-contracts
Command: npx skills add https://github.com/Asygnuz-S-A-S/one-star --skill typed-service-contracts-asygnuz-s-a-s

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires zod.

What problem does it solve? Unstructured business logic often mixes validation with side effects and throws unpredictable exceptions, making services hard to test and maintain. This Skill enforces a rigorous contract-first architecture where inputs are parsed, errors are returned as typed values, and handlers never throw. ## Core Features & Use Cases - Spec and Handler Separation: Define contracts (Zod schemas, error unions, interfaces) in spec.ts and impure implementations in handler.ts. - Result Pattern Error Handling: Replace exceptions with discriminated unions of Success and Failure, including error codes, messages, and recoverability flags. - Split Testing Strategy: Write contract tests for schema validation separately from mocked logic tests for handler behavior. - Use Case: When building a CLI command that reads files, define a spec that rejects path traversal input, then implement a handler that returns a typed FILE_NOT_FOUND result instead of crashing. ## Quick Start Ask the AI to scaffold a new service using the typed service contracts pattern with a Zod input schema, error union, and a non-throwing handler.

Frequently Asked Questions about typed-service-contracts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure type-safe services in TypeScript?▼

Use the Spec and Handler pattern: define a spec.ts with Zod input schemas, error code enums, and a Result discriminated union, then implement a handler.ts class that returns typed results. This separates the contract from side-effecting implementation.

How to handle errors in TypeScript without throwing exceptions?▼

Return a Result type as a discriminated union of Success and Failure objects instead of throwing. Each failure carries an error code, message, and recoverable flag, and handlers wrap logic in try-catch to map unexpected exceptions into an UNKNOWN_ERROR result.

What is the difference between parsing and validating with Zod?▼

Parsing transforms and narrows raw input into a trusted type, while validation only checks values. The pattern favors parsing with refinements, such as rejecting path traversal strings, so downstream handlers receive guaranteed-valid DTOs.

How should I test Zod schemas and business logic separately?▼

Write contract tests that feed invalid data tables into the schema's safeParse and assert rejection, then write logic tests that mock dependencies like fs and assert the handler's returned Result object. This isolates validation rules from business flow.

When should I not use the Spec and Handler pattern?▼

Avoid it for trivial scripts or prototypes where the overhead of schemas, error unions, and split files outweighs the benefits. It is designed for CLIs, libraries, and high-reliability logic where exhaustive error handling and testability matter.