refactor: Better types #17

Merged
timharek merged 11 commits from feature-better-type-safety into main 2024-04-02 12:57:30 +00:00
2 changed files with 28 additions and 2 deletions
Showing only changes of commit cdd424e6ca - Show all commits

View File

@ -2,7 +2,8 @@
"lock": false,
"tasks": {
"start": "deno run -A --watch=static/,routes/ dev.ts",
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx"
"check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx",
"types:nrk": "deno run -A generate-types.ts && deno fmt ./lib"
},
"imports": {
"$fresh/": "https://deno.land/x/fresh@1.6.8/",
@ -13,7 +14,8 @@
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.5.1",
"twind": "https://esm.sh/twind@0.16.17",
"twind/": "https://esm.sh/twind@0.16.17/",
"zod": "https://deno.land/x/zod@v3.22.4/mod.ts"
"zod": "https://deno.land/x/zod@v3.22.4/mod.ts",
"openapi-typescript": "npm:openapi-typescript@6.7.5"
},
"compilerOptions": {
"jsx": "react-jsx",

24
generate-types.ts Normal file
View File

@ -0,0 +1,24 @@
import openapiTS from "openapi-typescript";
const nrkTypes: { filename: string; url: URL }[] = [
{
filename: "./lib/nrk-search.ts",
url: new URL("https://psapi.nrk.no/documentation/openapi/search-radio/v1/openapi.yml"),
},
{
filename: "./lib/nrk-catalog.ts",
url: new URL("https://psapi.nrk.no/documentation/openapi/programsider-radio/openapi.yml"),
},
] as const;
async function generateTypes() {
for (const type of nrkTypes) {
const contents = await openapiTS(type.url);
await Deno.writeTextFile(new URL(type.filename, import.meta.url), contents);
}
}
if (import.meta.main) {
await generateTypes();
}