Skip to content

Commit e6af1db

Browse files
authored
fix(serverless): revert breaking change from v3.47.0 (#674)
1 parent 83f6675 commit e6af1db

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

.changeset/serious-fans-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ts-rest/serverless': minor
3+
---
4+
5+
Revert breaking change from v3.47.0. Order of generics on `tsr.router` and `tsr.route` have been reverted. `tsr.routerWithMiddleware` has been introduced so the contract does need to be passed twice.

apps/docs/docs/serverless/routers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ To get around this, you can manually add back the extended part in the generics
3434
import { tsr } from '@ts-rest/serverless/aws';
3535
import { contract } from './contract';
3636

37-
export const postsRouter = tsr.router<
37+
export const postsRouter = tsr.routerWithMiddleware(contract)<
3838
{ userId: string } // <-- Add the extended part here. This will be visible in request.userId
39-
>(contract, { ... });
39+
>({ ... });
4040
```
4141
## Context Object
4242

libs/ts-rest/serverless/src/lib/types.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ export type ServerlessHandlerOptions<
156156

157157
export const createTsr = <TPlatformContext = {}>() => ({
158158
router: <
159+
T extends AppRouter,
159160
TRequestExtension = {},
160-
T extends AppRouter = AppRouter,
161161
TRouter extends RouterImplementation<
162162
T,
163163
TPlatformContext,
@@ -167,12 +167,25 @@ export const createTsr = <TPlatformContext = {}>() => ({
167167
contract: T,
168168
router: TRouter,
169169
) => router,
170-
routerBuilder: <T extends AppRouter = AppRouter>(contract: T) => {
170+
routerWithMiddleware:
171+
<T extends AppRouter>(contract: T) =>
172+
<
173+
TRequestExtension,
174+
TRouter extends RouterImplementation<
175+
T,
176+
TPlatformContext,
177+
TRequestExtension
178+
> = RouterImplementation<T, TPlatformContext, TRequestExtension>,
179+
>(
180+
router: TRouter,
181+
) =>
182+
router,
183+
routerBuilder: <T extends AppRouter>(contract: T) => {
171184
return new RouterBuilder<T, TPlatformContext, {}>(contract);
172185
},
173186
route: <
187+
T extends AppRoute,
174188
TRequestExtension = {},
175-
T extends AppRoute = AppRoute,
176189
TRoute extends AppRouteImplementationOrOptions<
177190
T,
178191
TPlatformContext,

0 commit comments

Comments
 (0)