You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've just merged the #732 & #718 to main and released a new V9 draft.
Are there any other structural, potentially breaking changes that you would want to get into the next major?
It should be production-ready so feel free to update your deps to 9.0.0-alpha.4, play around with it, and give me feedback.
I have tried slowing down on the major version bumps, so I would ideally not do more breaking changes for a while.
Planning to release 9.0.0 early next week.
There might come a 10.x as well later in a month or so in order to add support for SvelteKit - might require some major changes as their API handlers are a bit different.
If you're happy you can just give a 👍 on this issue.
Summary of changes so far
Middlewares will now have to call a next() function that you have to call.
Great work, @KATT ! I am looking forward to update my app, when I find some time.
You asked about other things which could be changed for the next major and I think we could use the opportunity to improve the transformer syntax. (my favorite topic 😉 ) I am currently on vacation so I here is just a small idea. Feel free to implement, improve or forget... whatever you like.
For transformers currently we have the simple syntax, which is fine, and the combined syntax, which I still feel as a compromise to enable multiple transformers. (My fault, I made that PR back then.... 🙈)
I was thinking about making transformers more generic and stackable. What if we have a stack of transformers, which is applied depending on some flags.
Currently: User -> Input Transformer -> Server -> Output Transformer -> User
Suggestion: User -> Transformer A -> Transformer C -> Server -> Transformer C -> Transformer B -> User
A transformer stack could look like that:
const transformers = [
{
transform: (val) => someFancyOptimization(val),
// if `resolve` is not defined, don't do anything for "deserializing"
apply: OUTPUT,
},
{
transform: (val) => escapeHtmlCharsForSecurityReasons(val),
apply: INPUT,
},
{
transform: (val) => superjson.serialize(val),
resolve: (val) => superjson.deserialize(val),
apply: ALWAYS,
}
]
I have to admit, I don't see a good use case yet which cannot be solved with the current syntax, but I am sure there is one... ;) Looking forward to hear what you think.
I am also on vacation for the next couple of weeks, so can't contribute code but can leave a couple of thoughts I've had here. I don't think any of them would need to be breaking though, necessarily.
Middleware - it'd be really cool to be able to "refine" the context. Example for a router with type Context = { userId: string | null }:
.middleware(async({ ctx, next })=>{const{userId}=ctxif(!userId)thrownew ...
returnnext({ctx: { ...ctx, userId })}).query(...)// userId is non-nullable after this
Mentioned in #271 but an output: z.object({ ... }) prop just like input, would mean we could generate full openapi specs purely from trpc definitions.
Just putting them out there, no reason I'm aware of they'd be breaking, but if you like the ideas and think they would require a breaking change then might be worth looking at.
Only other things I can think of is if #506 could be a technical breaking change for people constricting requests manually (i.e. without @trpc/client). Or if #755 could lead to a breaking change somehow.
Either way, I'm more than happy with v9 as it is and very much looking forward to it being stable!
I was thinking about making transformers more generic and stackable. What if we have a stack of transformers, which is applied depending on some flags. — @simonedelmann
I really don't see the use-case of this and it's still possible to do your own implementation like this using the existing solution.
However, re transformers, one thing I have thought about is that it could be nice in some cases to optionally enable/disable them on a request-basis. Has anyone else been looking for that? Especially useful when once we'll look closer into #755.
Middleware - it'd be really cool to be able to "refine" the context. Example for a router with type Context = { userId: string | null }: — @mmkal
Yes, I agree. I know I play around with this before but reverted it because I got stuck in a generics rabbit hole of generics. I'd sign off on that feature and would be really nice for stuff like authz indeed. Happy to jump on a call or do a deep dive on how the router actually does it TypeScript-magic if someone would like to
Mentioned in #271 but an output: z.object({ ... }) prop just like input, would mean we could generate full openapi specs purely from trpc definitions. — @mmkal
Yep, but should be possible to do later with backwards compat.
Also, there are other considerations with Open API:
Resources are usually /{resource}/{id}?param1=x¶m2=y-style
JSON-RPC based response shape might not be the ideal response shape
An output schema usually have a $ref-schema which would be possible to do automatically / first feature people would request is to make different paths request the same input type
Actually using zod or any other validation on output would slow down API outputs.
It might be better suited as a specific adapter where you define and map the OpenAPI-schema for a router, possibly in combination with something like output
Only other things I can think of is if #506 could be a technical breaking change for people constricting requests manually (i.e. without @trpc/client). Or if #755 could lead to a breaking change somehow. — @mmkal
Batching - safeguard for max url length #506 this is something I've considered to be a thing only in @trpc/client where the dataloader can ask a delegate function "is this too long" in a loop and then split the request into multiple batches.
Refactored some internals and removed some unnecessary exports on adapters - minor breaking changes if someone relied on something they shouldn't have :)
Stricter ErrorFormatter - data has to be a Record<string, unknown>
Minor changes
Expose httpStatus as part of error object as the default error shape
httpStatus will be used to determine the actual HTTP Status code set
Expose TRPCClientError.data as a shortcut to error.shape.data as that's the only one I find myself using
TRPCError we infer in @trpc/react is now TRPCErrorLike and is serialized for SSR in @trpc/next
add new method responseMeta() that is triggered before a request ends - both as part of @trpc/next & @trpc/server
on @trpc/server receives type, paths, errors, and the unserialized data[] that is going out
Activity
simonedelmann commentedon Aug 20, 2021
Great work, @KATT ! I am looking forward to update my app, when I find some time.
You asked about other things which could be changed for the next major and I think we could use the opportunity to improve the transformer syntax. (my favorite topic 😉 ) I am currently on vacation so I here is just a small idea. Feel free to implement, improve or forget... whatever you like.
For transformers currently we have the simple syntax, which is fine, and the combined syntax, which I still feel as a compromise to enable multiple transformers. (My fault, I made that PR back then.... 🙈)
I was thinking about making transformers more generic and stackable. What if we have a stack of transformers, which is applied depending on some flags.
A transformer stack could look like that:
I have to admit, I don't see a good use case yet which cannot be solved with the current syntax, but I am sure there is one... ;) Looking forward to hear what you think.
mmkal commentedon Aug 20, 2021
I am also on vacation for the next couple of weeks, so can't contribute code but can leave a couple of thoughts I've had here. I don't think any of them would need to be breaking though, necessarily.
Middleware - it'd be really cool to be able to "refine" the context. Example for a router with
type Context = { userId: string | null }:Mentioned in #271 but an
output: z.object({ ... })prop just like input, would mean we could generate full openapi specs purely from trpc definitions.Just putting them out there, no reason I'm aware of they'd be breaking, but if you like the ideas and think they would require a breaking change then might be worth looking at.
Only other things I can think of is if #506 could be a technical breaking change for people constricting requests manually (i.e. without @trpc/client). Or if #755 could lead to a breaking change somehow.
Either way, I'm more than happy with v9 as it is and very much looking forward to it being stable!
KATT commentedon Aug 21, 2021
I really don't see the use-case of this and it's still possible to do your own implementation like this using the existing solution.
However, re transformers, one thing I have thought about is that it could be nice in some cases to optionally enable/disable them on a request-basis. Has anyone else been looking for that? Especially useful when once we'll look closer into #755.
Yes, I agree. I know I play around with this before but reverted it because I got stuck in a generics rabbit hole of generics. I'd sign off on that feature and would be really nice for stuff like authz indeed. Happy to jump on a call or do a deep dive on how the router actually does it TypeScript-magic if someone would like to
Yep, but should be possible to do later with backwards compat.
Also, there are other considerations with Open API:
/{resource}/{id}?param1=x¶m2=y-style$ref-schema which would be possible to do automatically / first feature people would request is to make different paths request the same input typeoutputwould slow down API outputs.It might be better suited as a specific adapter where you define and map the OpenAPI-schema for a router, possibly in combination with something like
output@trpc/clientwhere the dataloader can ask a delegate function "is this too long" in a loop and then split the request into multiple batches.KATT commentedon Aug 25, 2021
Release notes
next(): method in server-side middlewares - see docsresponseMeta(): Better support for custom HTTP headers & status code - see caching docs@trpc/nextare now serializedUpgrade guide for the 99% usecase
npx npm-check-updates --filter /@trpc/ -u && yarn.middleware()and addreturn next()at the end. See middleware docsBreaking changes
next()function that you have to call.TRPCErrors -METHOD_NOT_FOUNDremoved &PATH_NOT_FOUNDrenamed toNOT_FOUND(ReduceTRPCError-codes #733)httpErrors-helper?inputto be an array - now assuming aRecord<number, unknown>-style dict (changed with backward compat in fix: batching with zod.optional()input #669)POSTcalls being{ input: x }(originally from flatten post requests'input#671)ErrorFormatter-datahas to be aRecord<string, unknown>Minor changes
httpStatusas part of error object as the default error shapehttpStatuswill be used to determine the actual HTTP Status code setTRPCClientError.dataas a shortcut toerror.shape.dataas that's the only one I find myself usingTRPCErrorwe infer in@trpc/reactis nowTRPCErrorLikeand is serialized for SSR in@trpc/nextresponseMeta()that is triggered before a request ends - both as part of@trpc/next&@trpc/server@trpc/serverreceivestype,paths,errors, and the unserializeddata[]that is going out@trpc/nextit client errorsThanks to @mmkal, @peterp, @anthonyshort, & @simonedelmann for your feedback!
github-actions commentedon Oct 4, 2022
This issue has been locked because it had no new activity for 14 days. If you are running into a similar issue, please create a new issue. Thank you.