effect-app / libs

The core libraries to build apps with Effect
44 stars 6 forks source link

Expose missing services closer to their dependent definitions #107

Closed patroza closed 3 days ago

patroza commented 3 days ago

Right now, if you miss specifying a dependency, you get an error at the root main function, which is far away from the Service or Controller that uses the dependency. Depending how many changes you did, or what package got updated, you might have a hard time tracking where you are missing the dependency.

e.g

We could also leverage satisfies somehow. Like satisfies Layer<any,any,never>

enricopolanski commented 3 days ago

Sounds reasonable.

patroza commented 3 days ago

Will apply these for now, but instead of a strict true/false, for the near future, I would consider a whitelist of dependencies you want to omit, it will still provide meaningful protection, instead of completely opt out.

patroza commented 3 days ago

Implemented in https://github.com/effect-app/libs/commit/565d6783d2e491636d0f356bd32bd61ab6d728c4

I think we should also consider the request level dependencies like UserProfile, though they are more obvious anyway.

Right now the DX is:

Screenshot 2024-11-03 at 13 01 56 Screenshot 2024-11-03 at 13 02 08

(we should look at upgrading the controller one too to show the specifically missing dependencies)

patroza commented 3 days ago

I think we can make things nicer for the controller, if we would use an option object like in Service instead of positional args, but it would cause an extra indent for all the action handlers which I’m not really willing to pay. But if I can shave off one, maybe I’ll consider it. Maybe we can use the o_O hack now too though

patroza commented 3 days ago

Got an updated API for controllers, which makes it even more similar to Effect.Service, and has the same benefits of the dependencies error reporting, without adding additional indentation level, with only minor adjustments: https://github.com/effect-app/sample/compare/29762037f9ae03099cf1082f099afce508948f30..2d3da5d50d9c3aa1b1d5faae956618f456656ac0

Screenshot 2024-11-03 at 21 27 07

Playing with a fluent api so we can further condense, and get rid of some of the extra stuff in https://github.com/effect-app/libs/issues/110

patroza commented 3 days ago

Implemented in 565d678

Finalised in https://github.com/effect-app/libs/commit/01f531e80354be77cbc917ff82557e30cbe981b5