seasonedcc / composable-functions

Types and functions to make composition easy and safe
MIT License
666 stars 14 forks source link

Nested errors for schema - take 2 #31

Closed diogob closed 2 years ago

diogob commented 2 years ago

Purpose

When a domain function received nested input data, errorMessagesForSchema should mirror that structure so we do not lose nested error information. This should address #24

Technical details

This approach seems simpler than the one on #26 since it does not require any info from the schema (other than its type). Using this code we could keep backwards compatibility or break it just to drop the schema parameter (since we can use just the generic type parameter).

jansedlon commented 2 years ago

Hi, is there possibility to support zod's discriminated unions? Discriminated unions does not extend the AnyZodObject so it's not possible to use it.

diogob commented 2 years ago

Hi @jansedlon could you open a separate issue with an example schema?

diogob commented 2 years ago

We could probably simplify the code quite a bit, but I want to validate the approach before investing more time.