Skip to content

Commit

Permalink
refactor: support strict-boolean-expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Aug 12, 2023
1 parent e83d68a commit a41c191
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions servers/all/$server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ const validatorCompiler: FastifySchemaCompiler<FastifySchema> = ({ schema }) =>
};

const validatorsToSchema = ({ query, ...validators }: { query?: unknown; body?: unknown; headers?: unknown }): FastifySchema => ({
...(query ? { querystring: query } : {}),
...(query !== undefined ? { querystring: query } : {}),
...validators,
});

Expand All @@ -246,7 +246,7 @@ const methodToHandler = (
): RouteHandlerMethod => (req, reply) => {
const data = methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand All @@ -256,7 +256,7 @@ const asyncMethodToHandler = (
): RouteHandlerMethod => async (req, reply) => {
const data = await methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand Down
2 changes: 1 addition & 1 deletion servers/minimum/$server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const methodToHandler = (
): RouteHandlerMethod => (req, reply) => {
const data = methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand Down
4 changes: 2 additions & 2 deletions servers/noMulter/$server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const methodToHandler = (
): RouteHandlerMethod => (req, reply) => {
const data = methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand All @@ -123,7 +123,7 @@ const asyncMethodToHandler = (
): RouteHandlerMethod => async (req, reply) => {
const data = await methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand Down
4 changes: 2 additions & 2 deletions servers/noTypedParams/$server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const methodToHandler = (
): RouteHandlerMethod => (req, reply) => {
const data = methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand All @@ -139,7 +139,7 @@ const asyncMethodToHandler = (
): RouteHandlerMethod => async (req, reply) => {
const data = await methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand Down
6 changes: 3 additions & 3 deletions servers/noValidator/$server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const validatorCompiler: FastifySchemaCompiler<FastifySchema> = ({ schema }) =>
};

const validatorsToSchema = ({ query, ...validators }: { query?: unknown; body?: unknown; headers?: unknown }): FastifySchema => ({
...(query ? { querystring: query } : {}),
...(query !== undefined ? { querystring: query } : {}),
...validators,
});

Expand All @@ -145,7 +145,7 @@ const methodToHandler = (
): RouteHandlerMethod => (req, reply) => {
const data = methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand All @@ -155,7 +155,7 @@ const asyncMethodToHandler = (
): RouteHandlerMethod => async (req, reply) => {
const data = await methodCallback(req as any) as any;

if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);

reply.code(data.status).send(data.body);
};
Expand Down
4 changes: 2 additions & 2 deletions src/buildServerFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ${isAsync ? 'asyncM' : 'm'}ethodToHandler = (
): RouteHandlerMethod => ${isAsync ? 'async ' : ''}(req, reply) => {
const data = ${isAsync ? 'await ' : ''}methodCallback(req as any) as any;
if (data.headers) reply.headers(data.headers);
if (data.headers !== undefined) reply.headers(data.headers);
reply.code(data.status).send(data.body);
};
Expand Down Expand Up @@ -330,7 +330,7 @@ const validatorCompiler: FastifySchemaCompiler<FastifySchema> = ({ schema }) =>
? `
const validatorsToSchema = ({ query, ...validators }: { query?: unknown; body?: unknown; headers?: unknown }): FastifySchema => ({
...(query ? { querystring: query } : {}),
...(query !== undefined ? { querystring: query } : {}),
...validators,
});`
: ''
Expand Down

0 comments on commit a41c191

Please sign in to comment.