turkerdev / fastify-type-provider-zod

MIT License
303 stars 19 forks source link

use fast-json-stringify for serialization #62

Closed Uzlopak closed 3 months ago

Uzlopak commented 10 months ago

Could result in some nice perf gains.

kevbook commented 10 months ago

Not sure if this works if you add a preSerialization hook


// This by itself may work
fastify.addHook('preSerialization', async function (_, reply, payload) {
  const status = reply.statusCode;
  return status > 299 ? { status, error: payload } : { status, data: payload };
});

// I think this will break it (which i am kind of debating if it's a good thing to have this)
fastify.addHook('onRoute', function (routeOptions) {
  const responseSchema = routeOptions.schema?.response as Record<string, unknown>;
  if (responseSchema && responseSchema['200']) {
    responseSchema['200'] = z.object({
      status: z.number(),
      data: responseSchema['200'] as AnyZodObject,
    });
  }
});```
kibertoad commented 8 months ago

@kevbook Why wasn't it breaking before?

kibertoad commented 3 months ago

@Uzlopak why close?

Uzlopak commented 3 months ago

@kibertoad Its like open for about 9 months. Should have come to a conclusion in that time.

kibertoad commented 3 months ago

sorry, I didn't get to it in time. I'll do my best to reintroduce it in upcoming weeks