Skip to content

Add TypeScript testing and error handling documentation#31

Merged
amavashev merged 2 commits intomainfrom
claude/review-typescript-client-docs-S4BhT
Mar 15, 2026
Merged

Add TypeScript testing and error handling documentation#31
amavashev merged 2 commits intomainfrom
claude/review-typescript-client-docs-S4BhT

Conversation

@amavashev
Copy link
Contributor

Summary

This PR adds comprehensive TypeScript documentation for testing Cycles-governed code and error handling patterns, bringing TypeScript documentation to feature parity with Python and Java guides.

Key Changes

  • New TypeScript Testing Guide: Added extensive section to testing-with-cycles.md covering:

    • Unit testing withCycles-wrapped functions
    • Mocking CyclesClient with Vitest (vi.fn())
    • Mocking global fetch for integration tests
    • Testing error handling and exception types
    • Testing withCycles full lifecycle with mocked HTTP
    • Testing reserveForStream streaming handle behavior
  • New TypeScript Error Handling Guide: Created error-handling-patterns-in-typescript.md with:

    • Complete exception hierarchy (CyclesProtocolError, CyclesTransportError, and specific subclasses)
    • Detailed property and method reference for error objects
    • Error handling patterns for withCycles and reserveForStream
    • Express middleware error handler example
    • Next.js API route error handling
    • Graceful degradation with caps support
    • Retry-after and exponential backoff patterns
    • Distinguishing retryable vs non-retryable errors
  • Updated Cross-Language Guides:

    • error-handling-patterns-in-cycles-client-code.md: Added TypeScript examples alongside Python and Java for all error handling patterns (DENY decisions, degradation, debt/overdraft, expired reservations, catching all errors, web framework handlers, programmatic client errors)
    • using-the-cycles-client-programmatically.md: Added TypeScript examples for all programmatic client operations (initialization, creating/committing/releasing reservations, preflight decisions, querying balances, listing reservations, recording events)
    • testing-with-cycles.md: Updated tips section to reference TypeScript-specific mocking approaches

Notable Implementation Details

  • TypeScript examples use Vitest as the test framework with vi.fn() for mocking and vi.stubGlobal() for fetch mocking
  • Error handling examples cover both decorator-style (withCycles HOF) and programmatic (CyclesClient) approaches
  • Documentation includes practical patterns for Express and Next.js frameworks
  • All TypeScript examples follow the same structure and patterns as existing Python and Java documentation for consistency

https://claude.ai/code/session_01AioSM8RvRKCXgRsV6m75Mm

claude added 2 commits March 15, 2026 12:02
… doc

Three major how-to guides (programmatic usage, error handling, testing) previously
covered only Python and Java with zero TypeScript content. This adds comprehensive
TypeScript sections to all three, creates a dedicated TypeScript error handling
guide (mirroring the existing Python-specific guide), and adds cross-reference
links throughout.

- Add TypeScript sections to using-the-cycles-client-programmatically.md
- Add TypeScript sections to error-handling-patterns-in-cycles-client-code.md
- Create error-handling-patterns-in-typescript.md (Express, Next.js patterns)
- Add TypeScript section to testing-with-cycles.md (Vitest, mocking patterns)
- Add cross-reference links in quickstart and existing guides

https://claude.ai/code/session_01AioSM8RvRKCXgRsV6m75Mm
- Add 'Error Handling in TypeScript' to VitePress sidebar config
- Add missing isToolAllowed import in TypeScript error handling guide

https://claude.ai/code/session_01AioSM8RvRKCXgRsV6m75Mm
@amavashev amavashev merged commit f79cf2f into main Mar 15, 2026
1 check passed
@amavashev amavashev deleted the claude/review-typescript-client-docs-S4BhT branch March 17, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants