dbos-inc / dbos-transact-ts

The TypeScript framework for backends that scale
https://docs.dbos.dev
MIT License
366 stars 27 forks source link

Add context stacking #592

Closed GarrisonBates closed 2 months ago

GarrisonBates commented 2 months ago

Right now, a method like this: @Transaction({ readOnly: true }) @GetApi("/get-properties") static async getProperties(ctx: TransactionContext<any> & HandlerContext, clubId: number) {

Will throw type errors because @Transaction expects ctx to be TransactionContext. The way HandlerContext was written avoids this issue, so I changed @Transaction to be typed the same way as generateApiDec: https://github.com/dbos-inc/dbos-transact/blob/60bd51f77ccbd283a36868beb5002825f68fd27f/src/httpServer/handler.ts#L252

This would be a huge QOL upgrade, since it would save the trouble of creating separate @Transaction methods for API endpoints.