Skip to content

Commit 3810262

Browse files
committed
chore: update to zod v4
1 parent 911945a commit 3810262

26 files changed

+1293
-1249
lines changed

apps/api/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,39 @@
1616
},
1717
"dependencies": {
1818
"@fastify/cookie": "^11.0.2",
19-
"@fastify/cors": "^10.0.2",
19+
"@fastify/cors": "^11.1.0",
2020
"@fastify/env": "^5.0.2",
21-
"@fastify/jwt": "^9.0.4",
21+
"@fastify/jwt": "^10.0.0",
2222
"@fastify/sensible": "^6.0.2",
2323
"@fastify/swagger": "^9.4.2",
2424
"@fastify/swagger-ui": "^5.2.1",
2525
"@orama/cuid2": "^2.2.3",
2626
"@taskcord/database": "workspace:*",
27-
"dotenv": "^16.4.7",
28-
"drizzle-orm": "^0.39.3",
29-
"fastify": "^5.2.1",
27+
"dotenv": "^17.2.3",
28+
"drizzle-orm": "^0.44.7",
29+
"fastify": "^5.6.1",
3030
"fastify-plugin": "^5.0.1",
3131
"fastify-zod": "^1.4.0",
3232
"ioredis": "^5.5.0",
3333
"jsonwebtoken": "^9.0.2",
3434
"pg": "^8.13.2",
3535
"uuidv7": "^1.0.2",
36-
"zod": "^3.24.1"
36+
"zod": "^4.1.12"
3737
},
3838
"devDependencies": {
39-
"@faker-js/faker": "^9.8.0",
39+
"@faker-js/faker": "^10.1.0",
4040
"@repo/eslint-config": "workspace:*",
4141
"@repo/typescript-config": "workspace:*",
4242
"@types/jsonwebtoken": "^9.0.8",
4343
"@types/node": "^20.11.24",
4444
"@types/pg": "^8.11.11",
4545
"@types/supertest": "^6.0.2",
46-
"drizzle-kit": "^0.30.4",
46+
"drizzle-kit": "^0.31.5",
4747
"pino-pretty": "^13.0.0",
4848
"supertest": "^7.0.0",
4949
"tsdown": "^0.15.6",
5050
"tsup": "^8.2.4",
51-
"typescript": "5.5.4",
52-
"vitest": "^3.0.5"
51+
"typescript": "5.9.3",
52+
"vitest": "^4.0.2"
5353
}
5454
}
Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,34 @@
1-
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
1+
import type { FastifyInstance } from "fastify";
22
import AuthController from "./auth.controller";
33
import AuthService from "./auth.service";
4-
import { authSchemaRef, authSchemas } from "./auth.schema";
54

65
export default function AuthRoute(fastify: FastifyInstance) {
7-
// Register schemas
8-
for (const schema of authSchemas) {
9-
fastify.addSchema(schema);
10-
}
6+
const authController = new AuthController(new AuthService());
117

12-
const authController = new AuthController(new AuthService());
13-
14-
fastify.get(
15-
"/discord/init",
16-
{
17-
schema: {
18-
tags: ["Auth"],
19-
querystring: authSchemaRef("authInitQueryParams"),
20-
description: "Initialize the Discord auth flow",
21-
},
22-
},
23-
authController.initializeDiscordAuthFlowHandler.bind(authController),
24-
);
8+
fastify.get(
9+
"/discord/init",
10+
{
11+
schema: {
12+
tags: ["Auth"],
13+
querystring: { $ref: "authInitQueryParams" },
14+
description: "Initialize the Discord auth flow",
15+
},
16+
},
17+
authController.initializeDiscordAuthFlowHandler.bind(authController)
18+
);
2519

26-
fastify.get(
27-
"/discord/oauth-callback",
28-
{
29-
schema: {
30-
tags: ["Auth"],
31-
description: "Callback for the Discord auth flow",
32-
querystring: authSchemaRef("queryParams"),
33-
response: {
34-
200: authSchemaRef("200"),
20+
fastify.get(
21+
"/discord/oauth-callback",
22+
{
23+
schema: {
24+
tags: ["Auth"],
25+
description: "Callback for the Discord auth flow",
26+
querystring: { $ref: "queryParams" },
27+
response: {
28+
200: { $ref: "200" },
29+
},
30+
},
3531
},
36-
},
37-
},
38-
authController.handleDiscordOAuthCallback.bind(authController),
39-
);
32+
authController.handleDiscordOAuthCallback.bind(authController)
33+
);
4034
}
Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
import { z } from "zod";
2-
import { buildJsonSchemas } from "fastify-zod";
1+
import { zodSchemasToJSONSchema } from "@/utils/schemaHelper";
2+
import { z } from "zod/v4";
33

4-
export const DiscordAuthCallbackSchema = {
5-
request: {
6-
queryParams: z.object({
7-
code: z.string().nonempty(),
8-
state: z.string().min(5),
9-
}),
10-
},
11-
response: {
12-
200: z.object({
13-
access_token: z.string(),
14-
token_type: z.string(),
15-
expires_in: z.number(),
16-
refresh_token: z.string(),
17-
scope: z.string(),
18-
}),
19-
},
20-
};
4+
const queryParamsSchema = z
5+
.object({
6+
code: z.string().nonempty(),
7+
state: z.string().min(5),
8+
})
9+
.meta({ $id: "queryParams" });
2110

22-
const DiscordAuthInitRequestSchema = {
23-
request: z.object({
24-
redirect_url: z.enum(["http://localhost:5173", "https://p005.netlify.app"]),
25-
}),
26-
};
11+
const auth200ResponseSchema = z
12+
.object({
13+
access_token: z.string(),
14+
token_type: z.string(),
15+
expires_in: z.number(),
16+
refresh_token: z.string(),
17+
scope: z.string(),
18+
})
19+
.meta({ $id: "200" });
2720

28-
export const { schemas: authSchemas, $ref: authSchemaRef } = buildJsonSchemas(
29-
{
30-
...DiscordAuthCallbackSchema.request,
31-
...DiscordAuthCallbackSchema.response,
32-
authInitQueryParams: DiscordAuthInitRequestSchema.request,
33-
} as const,
34-
{ $id: "authSchema" },
35-
);
21+
const authInitQueryParamsSchema = z
22+
.object({
23+
redirect_url: z.enum([
24+
"http://localhost:5173",
25+
"https://p005.netlify.app",
26+
]),
27+
})
28+
.meta({ $id: "authInitQueryParams" });
29+
30+
export type QueryParams = z.infer<typeof queryParamsSchema>;
31+
export type Auth200Response = z.infer<typeof auth200ResponseSchema>;
32+
export type AuthInitQueryParams = z.infer<typeof authInitQueryParamsSchema>;
33+
34+
export const zodAuthSchemas = zodSchemasToJSONSchema([
35+
queryParamsSchema,
36+
auth200ResponseSchema,
37+
authInitQueryParamsSchema,
38+
]);

apps/api/src/modules/auth/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import type { FastifyInstance, FastifyPluginOptions } from "fastify";
22
import { fastifyPlugin } from "fastify-plugin";
33
import AuthRoute from "./auth.route";
4+
import { zodAuthSchemas } from "./auth.schema";
45

56
export default fastifyPlugin(
6-
async (fastify: FastifyInstance, options: FastifyPluginOptions) => {
7-
await fastify.register(AuthRoute, options);
8-
},
7+
async (fastify: FastifyInstance, options: FastifyPluginOptions) => {
8+
zodAuthSchemas.map((schema) => {
9+
fastify.addSchema(schema);
10+
});
11+
12+
await fastify.register(AuthRoute, options);
13+
}
914
);
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import type { FastifyInstance, FastifyPluginOptions } from "fastify";
22
import { fastifyPlugin } from "fastify-plugin";
33
import LabelRoute from "./label.route";
4+
import { zodLabelSchemas } from "./label.schema";
45

56
export default fastifyPlugin(
6-
async (fastify: FastifyInstance, options: FastifyPluginOptions) => {
7-
await fastify.register(LabelRoute, options);
8-
},
7+
async (fastify: FastifyInstance, options: FastifyPluginOptions) => {
8+
zodLabelSchemas.map((schema) => {
9+
fastify.addSchema(schema);
10+
});
11+
12+
await fastify.register(LabelRoute, options);
13+
}
914
);
Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1-
import type { FastifyReply, FastifyRequest } from "fastify";
21
import type { DbNewLabel } from "@taskcord/database";
2+
import type { FastifyReply, FastifyRequest } from "fastify";
33
import type LabelService from "./label.service";
44

55
export default class LabelController {
6-
private labelService: LabelService;
7-
8-
constructor(labelService: LabelService) {
9-
this.labelService = labelService;
10-
}
11-
12-
// Create a new label
13-
public async createLabel(
14-
request: FastifyRequest<{ Body: DbNewLabel }>,
15-
reply: FastifyReply,
16-
) {
17-
const labelData = request.body;
18-
19-
const label = await this.labelService.createLabel(labelData);
20-
21-
return reply.code(201).send({ taskLabel: label });
22-
}
23-
24-
public async getAllProjectLabels(
25-
request: FastifyRequest<{ Params: { projectId: string } }>,
26-
reply: FastifyReply,
27-
) {
28-
const labels = await this.labelService.getAllLabelsByProjectId(
29-
request.params.projectId,
30-
);
31-
return reply.send({ taskLabels: labels });
32-
}
33-
34-
public async updateLabel(
35-
request: FastifyRequest<{
36-
Params: { labelId: string };
37-
Body: DbNewLabel;
38-
}>,
39-
reply: FastifyReply,
40-
) {
41-
const labelData = request.body;
42-
const label = await this.labelService.updateLabel(
43-
request.params.labelId,
44-
labelData,
45-
);
46-
return reply.send({ taskLabel: label });
47-
}
48-
49-
public async deleteLabel(
50-
request: FastifyRequest<{ Params: { labelId: string } }>,
51-
reply: FastifyReply,
52-
) {
53-
const label = await this.labelService.deleteLabel(request.params.labelId);
54-
return reply.send({ taskLabel: label });
55-
}
6+
private labelService: LabelService;
7+
8+
constructor(labelService: LabelService) {
9+
this.labelService = labelService;
10+
}
11+
12+
// Create a new label
13+
public async createLabel(
14+
request: FastifyRequest<{ Body: DbNewLabel }>,
15+
reply: FastifyReply
16+
) {
17+
const labelData = request.body;
18+
19+
const label = await this.labelService.createLabel(labelData);
20+
21+
return reply.code(201).send({ taskLabel: label });
22+
}
23+
24+
public async getAllProjectLabels(
25+
request: FastifyRequest<{ Params: { projectId: string } }>,
26+
reply: FastifyReply
27+
) {
28+
const labels = await this.labelService.getAllLabelsByProjectId(
29+
request.params.projectId
30+
);
31+
return reply.send({ taskLabels: labels });
32+
}
33+
34+
public async updateLabel(
35+
request: FastifyRequest<{
36+
Params: { labelId: string };
37+
Body: DbNewLabel;
38+
}>,
39+
reply: FastifyReply
40+
) {
41+
const labelData = request.body;
42+
const label = await this.labelService.updateLabel(
43+
request.params.labelId,
44+
labelData
45+
);
46+
return reply.send({ taskLabel: label });
47+
}
48+
49+
public async deleteLabel(
50+
request: FastifyRequest<{ Params: { labelId: string } }>,
51+
reply: FastifyReply
52+
) {
53+
const label = await this.labelService.deleteLabel(
54+
request.params.labelId
55+
);
56+
return reply.send({ taskLabel: label });
57+
}
5658
}

0 commit comments

Comments
 (0)