Skip to content

feat(4): support streaming typed clients#6

Merged
0xpolarzero merged 1 commit into
feature/typescript-clientfrom
feature/streaming-typed-client
May 24, 2026
Merged

feat(4): support streaming typed clients#6
0xpolarzero merged 1 commit into
feature/typescript-clientfrom
feature/streaming-typed-client

Conversation

@0xpolarzero
Copy link
Copy Markdown
Owner

@0xpolarzero 0xpolarzero commented May 22, 2026

Warning

This PR is part of a stacked PR chain.

Upstream merge PRs:
wevm/incur#144 ->
wevm/incur#145 ->
wevm/incur#143 ->
wevm/incur#146 ->
wevm/incur#147

Correctly based review stack in this fork:
#3 ->
#4 ->
#5 ->
#6 ->
#2

Overview

Adds async-generator streaming support to generated TypeScript clients and the existing structured RPC route.

API

// Commands declared with `async *run` return typed async iterables.
const stream = await client('project logs')({
  args: { id: 'p1' },
})
//    ^? AsyncIterable<{ line: string }>

for await (const chunk of stream) {
  //             ^? { line: string }
  console.log(chunk.line)
}

// Non-streaming commands keep returning regular promise results.
const result = await client('project deploy')({
  args: { id: 'p1' },
})
//    ^? project deploy output

Maintainer Note: Stream Detection

Streaming typegen detection is based on actual async *run handlers. A wrapper like run() { return stream() } is not emitted as stream: true.

Changes

  • Detect async generator command handlers and emit stream: true metadata in typegen.
  • Type streaming client calls as async iterables while preserving existing non-streaming call types.
  • Add application/x-ndjson handling for RPC stream responses.
  • Preserve returned CTA/error records from async generator RPC streams.
  • Cancel the response body when consumers stop reading a stream early.

Tests

  • Adds client tests for NDJSON chunks, stream errors, malformed streams, missing completion records, and cancellation.
  • Adds type tests for streaming command return inference.
  • Adds typegen snapshot coverage for generated stream metadata.
  • Adds RPC route coverage for async generator streams preserving returned CTA/error records.

@0xpolarzero 0xpolarzero force-pushed the feature/typescript-client branch from 3b1b7f1 to 87299d9 Compare May 22, 2026 19:38
@0xpolarzero 0xpolarzero force-pushed the feature/streaming-typed-client branch from 05db286 to 8441d5d Compare May 22, 2026 19:43
@0xpolarzero 0xpolarzero force-pushed the feature/typescript-client branch from 87299d9 to 2bd19e0 Compare May 22, 2026 20:49
@0xpolarzero 0xpolarzero force-pushed the feature/streaming-typed-client branch from 8441d5d to b1b1f53 Compare May 22, 2026 20:49
@0xpolarzero 0xpolarzero force-pushed the feature/typescript-client branch from 2bd19e0 to 80462ea Compare May 22, 2026 20:55
@0xpolarzero 0xpolarzero force-pushed the feature/streaming-typed-client branch from b1b1f53 to b247edf Compare May 22, 2026 20:55
@0xpolarzero 0xpolarzero force-pushed the feature/streaming-typed-client branch from b247edf to bfc33e6 Compare May 22, 2026 21:53
@0xpolarzero 0xpolarzero merged commit bfc33e6 into feature/typescript-client May 24, 2026
@0xpolarzero 0xpolarzero deleted the feature/streaming-typed-client branch May 24, 2026 23:16
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.

1 participant