Skip to content

norpc#175

Merged
mmkal merged 17 commits intomainfrom
mmkal/26/01/21/norpc
Feb 26, 2026
Merged

norpc#175
mmkal merged 17 commits intomainfrom
mmkal/26/01/21/norpc

Conversation

@mmkal
Copy link
Owner

@mmkal mmkal commented Jan 21, 2026

allow using without trpc or orpc:

#!/usr/bin/env node
import { z } from 'zod'
import { t, createCli } from 'trpc-cli'

const router = t.router({
  sayHello: t.procedure
    .input(z.object({ name: z.string() })
    .handler(({ input }) => `hello ${input.name}`)
})
node ./my-cli say-hello --name Bob # Hello bob

@charliecreates charliecreates bot requested a review from CharlieHelps January 21, 2026 23:13
Copy link

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core feature looks solid, but a few guards/traversals are currently too permissive or unsafe. In particular, isCliRouter() can throw on null/misclassify arrays and can recurse infinitely on cycles, and parseCliRouter() silently ignores invalid leaves and doesn’t protect against dangerous keys. createCli() also rebuilds the CLI caller map per invocation, which is avoidable overhead. Finally, t.ts emits a suspicious CROUTER-prefixed error that will leak to end users.

Additional notes (1)
  • Maintainability | test/t.test.ts:45-100
    The new tests are consistently named orpc-*, but they’re actually exercising the new t.router/t.procedure CLI router path (no oRPC contract traversal involved). Misnaming makes future debugging harder because failures will send maintainers looking in the wrong subsystem.

This is especially confusing now that the project supports tRPC, oRPC, and “CLI-only” routers.

Summary of changes

What changed

This PR introduces a tRPC-free “CLI router/procedure” mode so consumers can build a CLI without installing @trpc/server (or @orpc/*).

Key additions

  • New t builder in src/t.ts: provides t.procedure / t.router APIs producing CLIProcedureLike and nested CLIRouterLike records.
  • New CLI compatibility types + guards in src/trpc-compat.ts:
    • CLIProcedureLike, CLIRouterLike
    • isCliProcedure(), isCliRouter()
    • AnyRouter / AnyProcedure expanded to include CLI variants.
  • Router parsing extended in src/index.ts:
    • parseRouter() now dispatches to parseCliRouter() when given a CLI router.
    • createCli() can build a caller map for CLI procedures using proc.call.
    • Re-export t from index.ts.
  • proxify() tightened in src/proxify.ts: explicitly rejects proxying CLI/ORPC procedures.
  • New tests in test/t.test.ts: validate CLI mode behavior for Zod + Valibot, nesting, and JSON-input fallbacks.

@charliecreates charliecreates bot removed the request for review from CharlieHelps January 21, 2026 23:23
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 29, 2026

Open in StackBlitz

npm i https://pkg.pr.new/mmkal/trpc-cli@175

commit: 70b3077

@mmkal mmkal merged commit 9a6b5d1 into main Feb 26, 2026
55 checks passed
@github-actions
Copy link
Contributor

This is included in v0.13.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant