Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: publishing AppRouter without hassle #5004

Open
1 task done
Tracked by #3496
olehmisar opened this issue Nov 5, 2023 · 3 comments
Open
1 task done
Tracked by #3496

feat: publishing AppRouter without hassle #5004

olehmisar opened this issue Nov 5, 2023 · 3 comments
Labels
⏭ major bump needed Requires a major version bump

Comments

@olehmisar
Copy link

olehmisar commented Nov 5, 2023

Describe the feature you'd like to request

I am using trpc in bunch of projects that are spread across npm packages. E.g., I have a server my-server and a client my-client. In my-client code I am importing AppRouter like this:

import type { AppRouter } from `my-server`;

I want to be able to publish AppRouter types on NPM without exposing any sensitive information like my server source code or Context of the AppRouter.

Describe the solution you'd like to see

When generating .d.ts files via tsc or vite, .d.ts files contain all imported type definitions. Since AppRouter depends on Context, and Context usually contains all backend services (e.g., UsersService, PaymentService, etc), all the backend type declarations are also included in .d.ts files.

I see at least two solutions:

  • Somehow replace Context object with unknown when generating .d.ts files
  • If appRouter is defined in src/router.ts, only include dist/router.d.ts in package.json files field.

I hope trpc provides a recommended way to publish AppRouter, so developers do not need to think about it themselves.

Describe alternate solutions

Don't provide a recommended way of publishing AppRouter and leave it to devs.

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar
@KATT
Copy link
Member

KATT commented Nov 5, 2023

#4709 does this - implemented in next major (which you can use today)

@olehmisar
Copy link
Author

According to the description of the linked PR, context object is still included in the router type(although context is no longer present in procedure types). Is it possible to remove context from .d.ts altogether?

@KATT
Copy link
Member

KATT commented Nov 5, 2023

Off the top of my head, the @trpc/client needs

  • error formatter
  • transformer (or at least knowing if there is one)

The rest could technically be omitted with regards to the client.

However, in order to call router.createCaller() we'd need the Context.... potentially we could have a way to strip out stuff from routers that'd still work to create clients from.

Feel free to hack on this, know it's quite time consuming though, but you have pretty free reign to challenge how we do things seeing that it's a major change upcoming anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⏭ major bump needed Requires a major version bump
Projects
None yet
Development

No branches or pull requests

2 participants