Skip to content

Commit

Permalink
feat: Added zod for TS schema validation
Browse files Browse the repository at this point in the history
Makes it possible to parse and exit early if data is malformed or
unexpected as well as generating the types we need.
  • Loading branch information
Venefilyn committed Nov 27, 2024
1 parent 4f1fdcb commit 3cb6316
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
7 changes: 4 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"vite-bundle-visualizer": "^1.2.1",
"vite-plugin-image-optimizer": "^1.1.8",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^5.0.1"
"vite-tsconfig-paths": "^5.0.1",
"zod": "^3.23.8"
},
"proxy": "http://127.0.0.1:5000",
"scripts": {
Expand All @@ -60,10 +61,10 @@
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@vitest/coverage-v8": "^2.1.5",
"babel-plugin-named-exports-order": "^0.0.2",
"prop-types": "^15.8.1",
"vitest": "^2.1.5",
"@vitest/coverage-v8": "^2.1.5"
"vitest": "^2.1.5"
},
"engines": {
"node": ">=20",
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/apiDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// Copyright Contributors to the Packit project.
// SPDX-License-Identifier: MIT

import { z } from "zod";

/**
* This is a list of items from the Packit API
*/

// /api/projects/$forge/$namespace/$repo
export interface Project {
namespace: string;
repo_name: string;
project_url: string;
prs_handled: number;
branches_handled: number;
releases_handled: number;
issues_handled: number;
}

export const Project = z.object({
namespace: z.string(),
repo_name: z.string(),
project_url: z.string(),
prs_handled: z.number(),
branches_handled: z.number(),
releases_handled: z.number(),
issues_handled: z.number(),
});

export type Project = z.infer<typeof Project>;

// /api/projects/$forge/$namespace/$repo/issues
export type ProjectIssue = number;
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3cb6316

Please sign in to comment.