Skip to content

feat: TypeScript memory client#147

Closed
0xpolarzero wants to merge 9 commits into
wevm:mainfrom
0xpolarzero:feature/in-memory-typed-client
Closed

feat: TypeScript memory client#147
0xpolarzero wants to merge 9 commits into
wevm:mainfrom
0xpolarzero:feature/in-memory-typed-client

Conversation

@0xpolarzero
Copy link
Copy Markdown

@0xpolarzero 0xpolarzero commented May 22, 2026

Warning

This PR is part of a stacked PR chain. Review/merge in order:
#144
#145
#143
> #147

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 }>

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, and streaming cleanup across both paths.
  • 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, 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 force-pushed the feature/in-memory-typed-client branch from a6a5a1e to 09adfa9 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/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: TypeScript memory client May 24, 2026
@0xpolarzero
Copy link
Copy Markdown
Author

Will reopen better PRs after playing around and figuring out the best API.

@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