CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-io-ts

tessl install tessl/npm-io-ts@2.2.0

TypeScript runtime type system for IO decoding/encoding

Agent Success

Agent success rate when using this tile

72%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.14x

Baseline

Agent success rate without this tile

63%

task.mdevals/scenario-6/

Data Transformation Pipeline

Build a type-safe data transformation pipeline that validates and processes user registration data through multiple sequential validation and transformation steps.

Requirements

Implement a user registration data processor that:

  1. Validates incoming user data structure (username, email, age)
  2. Transforms the validated data by normalizing the email to lowercase
  3. Enriches the data by adding a registration timestamp
  4. Validates business rules (e.g., age must be at least 18)
  5. Composes all steps into a single reusable pipeline function

The pipeline should handle validation errors at each step and propagate them appropriately. All transformations should be type-safe and composable.

Input Format

The input will be an unknown object that should be validated against this structure:

  • username: string (non-empty)
  • email: string (valid email format)
  • age: number (integer)

Output Format

The successful output should have:

  • username: string (unchanged)
  • email: string (normalized to lowercase)
  • age: number (unchanged)
  • registeredAt: Date object (timestamp when processed)

Error Handling

  • Return detailed validation errors for invalid input structures
  • Return specific error messages for business rule violations
  • Maintain type safety throughout the pipeline

Test Cases

  • Valid input { username: "JohnDoe", email: "JOHN@EXAMPLE.COM", age: 25 } returns a successful result with email normalized to lowercase and registeredAt field added @test
  • Invalid input { username: "", email: "invalid", age: 15 } returns validation errors indicating empty username, invalid email format, and age requirement violation @test
  • Input with missing fields { username: "Jane" } returns validation errors for missing email and age fields @test

Implementation

@generates

API

import { Either } from 'fp-ts/Either';

export interface RegistrationInput {
  username: string;
  email: string;
  age: number;
}

export interface ProcessedRegistration {
  username: string;
  email: string;
  age: number;
  registeredAt: Date;
}

export type ValidationError = string[];

export function processRegistration(
  input: unknown
): Either<ValidationError, ProcessedRegistration>;

Dependencies { .dependencies }

io-ts { .dependency }

Provides runtime type validation and monadic composition capabilities for building the validation pipeline.

fp-ts { .dependency }

Provides the Either monad and functional composition utilities.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/io-ts@2.2.x
tile.json