Skip to content

feat: TypeScript memory client#2

Closed
0xpolarzero wants to merge 1 commit into
feature/typescript-clientfrom
feature/in-memory-typed-client
Closed

feat: TypeScript memory client#2
0xpolarzero wants to merge 1 commit into
feature/typescript-clientfrom
feature/in-memory-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#147

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

Overview

Adds an in-memory TypeScript client that calls incur commands directly from a Cli instance without running an HTTP server.

API

import { create, createMemoryClient } from 'incur'
import { z } from 'zod'

const cli = create('project')
  .command('deploy', {
    args: z.object({ id: z.string() }),
    options: z.object({ dryRun: z.boolean().default(false) }),
    output: z.object({ id: z.string(), url: z.string() }),
    run: ({ args, options }) => ({
      id: args.id,
      url: options.dryRun ? 'preview://deploy' : 'https://example.com/deploy',
    }),
  })
  .command('logs', {
    args: z.object({ id: z.string() }),
    output: z.object({ line: z.string() }),
    async *run() {
      yield { line: 'deploy started' }
    },
  })

const client = createMemoryClient(cli)

const result = await client('project deploy')({
  args: { id: 'p1' },
  options: { dryRun: true },
})
//    ^? { id: string; url: string }

const stream = await client('project logs')({
  args: { id: 'p1' },
})
//    ^? AsyncIterable<{ line: string }>

Maintainer Notes

  • createMemoryClient(cli, { env }) accepts an optional env source used for CLI-level and command-level env parsing.
  • Cli value stream inference is structural for handlers returning AsyncGenerator; runtime/typegen streaming detection still relies on actual async *run handlers.
  • This PR does not add a changeset because it is part of the still-unreleased TypeScript client stack.

Changes

  • Add createMemoryClient(cli) with the same typed call shape as createClient.
  • Share structured RPC execution between HTTP and in-memory clients.
  • Preserve validation, middleware, errors, CTAs, root commands, aliases/root aliases, env parsing, and streaming cleanup across both paths.
  • Keep raw fetch gateways unsupported by structured RPC.
  • Extend Cli command maps with output metadata and structural stream metadata for local client inference.

Tests

  • Adds memory client runtime coverage for data, validation, errors, middleware, root commands, aliases, env parsing, streams, and cancellation.
  • Adds type tests for createMemoryClient(cli) inference, mounted CLIs, outputs, and streaming calls.
  • Adds RPC coverage for root command execution and stream cancellation.

@0xpolarzero 0xpolarzero changed the title feat: add in-memory typed client feat(5): add in-memory typed client May 22, 2026
@0xpolarzero 0xpolarzero force-pushed the feature/in-memory-typed-client branch from 3d6e575 to 191236e Compare May 22, 2026 19:26
@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/in-memory-typed-client branch 2 times, most recently from a6a5a1e to 09adfa9 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/in-memory-typed-client branch from 09adfa9 to bb53346 Compare May 22, 2026 20:55
@0xpolarzero 0xpolarzero force-pushed the feature/streaming-typed-client branch 2 times, most recently from b247edf to bfc33e6 Compare May 22, 2026 21:53
@0xpolarzero 0xpolarzero force-pushed the feature/in-memory-typed-client branch from bb53346 to 7920352 Compare May 22, 2026 21:57
@0xpolarzero 0xpolarzero changed the title feat(5): add in-memory typed client feat(5): TypeScript memory client May 24, 2026
@0xpolarzero 0xpolarzero changed the title feat(5): TypeScript memory client feat: TypeScript memory client May 24, 2026
@0xpolarzero 0xpolarzero changed the base branch from feature/streaming-typed-client to feature/typescript-client May 24, 2026 23:13
@0xpolarzero 0xpolarzero deleted the feature/in-memory-typed-client branch May 25, 2026 16:35
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