Now that codecs were introduced, it's only logical to support the bidi decode <-> encode semantics. The serializer compiler implementation should rather look like this:
app.setSerializerCompiler(({ schema, method, url }) => (data) => {
if (!(schema instanceof z.ZodType)) {
throw new Error(`${method} ${url} has no zod schema: ${JSON.stringify(schema)}`);
}
const encoded = schema.encode(data);
return JSON.stringify(encoded);
});
Except .transform calls will throw with this approach, since transform is a decode-only operation.
Now that codecs were introduced, it's only logical to support the bidi decode <-> encode semantics. The serializer compiler implementation should rather look like this:
Except
.transformcalls will throw with this approach, since transform is a decode-only operation.