mmkal / trpc-cli

Turn a tRPC router into a type-safe, fully-functional, documented CLI
Other
74 stars 1 forks source link

Feature request: Support for `@trpc/server@11` #37

Closed david-arteaga closed 7 hours ago

david-arteaga commented 1 week ago

Currently the trpc docs quickstart instructs developers to install @trpc/server@next when setting up. This currently installs @trpc/server@11, which doesn't seem to be compatible with this library.

I tried running it with v11 and got a pretty useless stack trace:

node:internal/process/promises:389
      new UnhandledPromiseRejection(reason);
      ^

UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".
    at throwUnhandledRejectionsMode (node:internal/process/promises:389:7)
    at processPromiseRejections (node:internal/process/promises:470:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:32) {
  code: 'ERR_UNHANDLED_REJECTION'
}

Node.js v22.3.0

Dug around for a bit and it seems the main issue is with how procedures are called, specifically this line in index.ts:

const result: unknown = await caller[procedureInfo.type as 'mutation'](procedureInfo.name, input)

I fixed it by changing it (in the build dist/index.js) from:

const result = await caller[procedureInfo.type](procedureInfo.name, input);

to

const result = await caller[procedureInfo.name](input);

And that seems to fix it for v11 (I'm using 11.0.0-rc.498 exactly). It still works with nested sub-routers and the dot separation convention.

There are still several type errors since several types have been deprecated/changed in v11, but that doesn't prevent the code from running, which was my immediate goal in fixing this.

So just leaving this here to document what I found and hopefully make it easier to implement support for @trpc/server@11.

mmkal commented 1 week ago

Thanks for looking into this. I would like to be able to switch between them. If you have half working changes, want to open a draft PR? If not I can just apply what you described here.

david-arteaga commented 1 week ago

Yeah switching would be great.

I don't have any other changes, just what I described above, but I'm thinking that won't even get past typescript compilation.