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-8/

Data Transformation Pipeline with Round-Trip Validation

Build a data transformation system that converts between internal and external representations while ensuring data integrity through round-trip validation. The system should handle configuration data that needs to be transformed for storage or transmission, then reliably reconstructed.

Requirements

You need to implement a bidirectional transformation system with the following capabilities:

Data Model

Create transformations for a user configuration object with these properties:

  • A timestamp (stored as ISO string externally, Date object internally)
  • A status flag (stored as "active"/"inactive" string externally, boolean internally)
  • Numeric settings that must remain unchanged during transformation

Transformation Requirements

  1. Bidirectional Conversion: Implement both encoding (internal → external) and decoding (external → internal) with a single unified definition
  2. Type Safety: Ensure compile-time type checking for both input and output types
  3. Round-Trip Guarantee: Verify that encoding then decoding returns the original value (decode(encode(x)) === x)
  4. Validation: External data should be validated during decoding to ensure it meets expected format requirements

Functional Requirements

  • Transform Date objects to/from ISO 8601 strings
  • Convert boolean status to/from "active"/"inactive" string literals
  • Preserve numeric values without transformation
  • Provide clear error messages when validation fails

Test Cases

Implement the following test cases:

  • Given a valid internal configuration with a Date, boolean status true, and numeric values, encoding produces an object with ISO string, "active" status, and preserved numbers @test
  • Given a valid external configuration with ISO string, "active" status, and numeric values, decoding produces an object with Date, boolean true, and preserved numbers @test
  • Round-trip: encoding then decoding an internal configuration returns an equivalent object (dates equal, values preserved) @test
  • Decoding an external config with invalid ISO date string returns a validation error @test
  • Decoding an external config with invalid status value (not "active" or "inactive") returns a validation error @test

Implementation

@generates

API

/**
 * Internal representation of configuration
 */
export interface InternalConfig {
  timestamp: Date;
  isActive: boolean;
  maxRetries: number;
  timeout: number;
}

/**
 * External representation of configuration
 */
export interface ExternalConfig {
  timestamp: string;
  status: "active" | "inactive";
  maxRetries: number;
  timeout: number;
}

/**
 * Codec for bidirectional transformation between internal and external config
 */
export const ConfigCodec: any; // Type should support both encode and decode operations

Dependencies { .dependencies }

io-ts { .dependency }

Provides runtime type validation and bidirectional transformation capabilities.

fp-ts { .dependency }

Provides functional programming utilities including Either for error handling.

Version

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