Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

fix(sdk): address TypeScript SDK review findings - #48

Merged
matthew-petty merged 4 commits into
mainfrom
fix/address-typescript-sdk-reviews
Dec 25, 2025
Merged

fix(sdk): address TypeScript SDK review findings#48
matthew-petty merged 4 commits into
mainfrom
fix/address-typescript-sdk-reviews

Conversation

@matthew-petty

Copy link
Copy Markdown
Member

Summary

  • Addresses critical and high-priority review findings from SDK review
  • Adds createKoine() factory pattern for cleaner API
  • Refactors source code into focused modules (~80-250 lines each)
  • Refactors tests into focused test files mirroring source structure

Changes

API Improvements

  • Added createKoine(config) factory that returns a typed client object
  • Made config types readonly to prevent mutation

Code Organization

Split client.ts (703 lines) into focused modules:

File Lines Purpose
src/http.ts 115 HTTP utilities (fetch wrapper, error handling)
src/text.ts 98 generateText() implementation
src/stream/sse.ts 63 SSE parser
src/stream/index.ts 245 streamText() implementation
src/object.ts 136 generateObject() implementation
src/client.ts 95 Factory + re-exports

Split client.test.ts (1042 lines) into focused test files:

File Lines Purpose
__tests__/helpers.ts 98 Shared test utilities
__tests__/text.test.ts 221 generateText tests
__tests__/stream.test.ts 395 streamText tests
__tests__/object.test.ts 222 generateObject tests
__tests__/client.test.ts 146 KoineError + factory tests

Test plan

  • All 42 tests pass
  • Lint passes
  • Build passes
  • Example scripts (hello.ts, stream.ts) work correctly

- Fix KoineError prototype chain for proper instanceof checks
- Add textResolved flag to prevent double promise resolution in streams
- Log warnings for SSE text parse failures instead of silent swallowing
- Add validateConfig() for early config validation with clear errors
- Wrap fetch errors in KoineError (TIMEOUT, NETWORK_ERROR codes)
- Add AbortSignal support for user-controlled cancellation
- Remove internal types from public exports (SSE*, *Response, ErrorResponse)
- Add typed KoineErrorCode union for exhaustive error handling
- Fix README: add missing timeout param, correct type documentation
- Add comprehensive JSDoc to all public functions
API improvements:
- Add createKoine() factory for cleaner API: `const koine = createKoine(config)`
- Config validated once at creation time, not on each method call
- Export KoineClient interface and request/result option types

Type safety:
- Add readonly modifiers to all response type properties
- Add readonly to KoineUsage, KoineStreamResult fields

Dependency cleanup:
- Remove zod from peerDependencies (kept as bundled dependency)

Tests:
- Add 5 new tests for createKoine factory
- Move SSE helper functions to shared scope for reuse
Split the monolithic client.ts (703 lines) into smaller, focused files:
- http.ts: HTTP utilities (safeFetch, error handling)
- text.ts: generateText function
- stream/sse.ts: SSE parser
- stream/index.ts: streamText function
- object.ts: generateObject function
- client.ts: Factory and re-exports
Split the monolithic test file into separate files mirroring the
source code structure:
- helpers.ts: Shared test utilities (mocks, config)
- text.test.ts: generateText tests
- stream.test.ts: streamText tests
- object.test.ts: generateObject tests
- client.test.ts: KoineError and createKoine factory tests

All 42 tests pass. No functionality changed.
@matthew-petty
matthew-petty merged commit a5da0f3 into main Dec 25, 2025
2 checks passed
@codecov

codecov Bot commented Dec 25, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.99052% with 76 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/sdks/typescript/src/stream/index.ts 69.54% 53 Missing ⚠️
packages/sdks/typescript/src/stream/sse.ts 64.44% 16 Missing ⚠️
packages/sdks/typescript/src/http.ts 92.68% 6 Missing ⚠️
packages/sdks/typescript/src/object.ts 98.36% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

This was referenced Dec 25, 2025
@matthew-petty
matthew-petty deleted the fix/address-typescript-sdk-reviews branch December 26, 2025 13:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant