feat: support for transformations #102
Open
+78
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to solve the case where a zod schema that includes a transform would be provided
Before the changes
The
res.send
method would expect thez.infer
of the schema (ie. the already transformed type), so the developer has to process the transform before (or there would be a typescript error)The
serializerCompiler
would parse again the data (and thus try to transform again), which can failAfter the change
When you provide a zod transformation, the type provider now asks the data to be the input (non-transformed), so the serializerCompiler is doing the transformation
Example on the provided test:
On the provided test, we reshape a subkey from a Date to string with
toISOString()
. Without the PR,res.send
expectsmyDate
to be a string, which fails at runtime (the transform throws:String.prototype.toISOString()
is not a function).With the change,
res.send
expects a Date, which passes at runtime :)