turkerdev / fastify-type-provider-zod

MIT License
411 stars 25 forks source link

use fast-json-stringify for serialization #62

Closed Uzlopak closed 7 months ago

Uzlopak commented 1 year ago

Could result in some nice perf gains.

kevbook commented 1 year 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 1 year ago

@kevbook Why wasn't it breaking before?

kibertoad commented 7 months ago

@Uzlopak why close?

Uzlopak commented 7 months ago

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

kibertoad commented 7 months ago

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