dbos-inc / dbos-transact

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

simplify user database declarations #461

Closed demetris-manikas closed 1 month ago

demetris-manikas commented 1 month ago

Resolves #459 Unfortunately this PR introduces a breaking change since the httpServer/middleware had to be adjusted as well.

devhawk commented 1 month ago

Can we do the unbreaking part of this work now and save the breaking part for a future 2.0 release?

demetris-manikas commented 1 month ago

I removed the breaking changes.

demetris-manikas commented 1 month ago

Sorry about this. I got carried away because all tests and linting were passing; This must be dropped and the changes in a previous PR about reducing any usage that changed <T extends any[]> func ( ...args T> to func (...args: unknown[]) and <C extends UserDatabaseClient> func (TransactionContext<C>) to func (TransactionContext<UserDatabaseClient>) were a mistake and have to be reverted.

This declaration

type Func<T extends unknown[]> = (a: string, ...args: T) => void;

allows to define an implementation like the following which declares more than it should

const FuncImpl: Func<[number]> = (a: string, b: number) =>{}

BUT

type Func2 = (a:string ...args: unknown[]) => void;

does not allow do declare

const Func2Impl: Func2 = (a: string, b: number) => {}

BUT only

const Func2Impl: Func2 = (a: string, b: unknown) => {}

which is terrible.

As I realize now the proper way to define a function that takes any number of arguments is

type Func = (a: string ...any[]) => void

and it is safe since as it only declares that this is a function that must have a string argument and can take any number of additional arguments.

I will prepare a PR later that reverts all the affected code by #448.

Sorry again. Typescript is a pain sometimes ....