Conversation
There was a problem hiding this comment.
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 namedorpc-*, but they’re actually exercising the newt.router/t.procedureCLI 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
tbuilder insrc/t.ts: providest.procedure/t.routerAPIs producingCLIProcedureLikeand nestedCLIRouterLikerecords. - New CLI compatibility types + guards in
src/trpc-compat.ts:CLIProcedureLike,CLIRouterLikeisCliProcedure(),isCliRouter()AnyRouter/AnyProcedureexpanded to include CLI variants.
- Router parsing extended in
src/index.ts:parseRouter()now dispatches toparseCliRouter()when given a CLI router.createCli()can build a caller map for CLI procedures usingproc.call.- Re-export
tfromindex.ts.
proxify()tightened insrc/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.
commit: |
|
This is included in v0.13.0. |
allow using without trpc or orpc: