Skip to content

Commit

Permalink
try to fix client types again
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnlyTails committed Jan 29, 2024
1 parent 706125f commit 7635b81
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish_npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ jobs:
with:
message: Bumps version of @kulupu-linku/sona to ${{ github.event.release.tag_name }}
add: schemas/package.json
pull: --commit
7 changes: 2 additions & 5 deletions .github/workflows/validate_toml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,9 @@ jobs:
npx ajv-cli -s "./schemas/generated/${file:6}" -c ajv-formats --errors=text -d $file;
done
- name: Pull before pushing again
if: contains(steps.changes.outputs.changes, 'data')
run: git pull

- name: Commit packaged files
uses: EndBug/add-and-commit@v9
if: contains(steps.changes.outputs.changes, 'data') && !github.event.pull_request.head.repo.fork
with:
message: "Generated raw JSON files for ${{ github.sha }}"
message: Generated raw JSON files for ${{ github.sha }}
pull: --commit
24 changes: 12 additions & 12 deletions api/src/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { zValidator } from "@hono/zod-validator";
import { Hono } from "hono";
import { HTTPException } from "hono/http-exception";
import { z } from "zod";
import { fetchWithZod } from "..";
import { languagesFilter } from "../utils";
Expand Down Expand Up @@ -32,9 +31,10 @@ const app = new Hono()
async (c) => {
const data = await fetchWithZod(versions.v1.schemas.words, rawFile("v1", "words.json"));
const word = data[c.req.param("word")];
if (!word) throw new HTTPException(404, { message: `Could not find a word named ${word}` });

return c.json(word);
return word
? c.json({ ok: true as const, data: word })
: c.json({ ok: false as const, message: `Could not find a word named ${word}` }, 404);
},
)

Expand All @@ -56,9 +56,10 @@ const app = new Hono()
rawFile("v1", "fingerspelling.json"),
);
const sign = data[c.req.param("sign")];
if (!sign) throw new HTTPException(404, { message: `Could not find a sign named ${sign}` });

return c.json(sign);
return sign
? c.json({ ok: true as const, data: sign })
: c.json({ ok: false as const, message: `Could not find a sign named ${sign}` }, 404);
},
)

Expand All @@ -75,9 +76,10 @@ const app = new Hono()
async (c) => {
const data = await fetchWithZod(versions.v1.schemas.signs, rawFile("v1", "signs.json"));
const sign = data[c.req.param("sign")];
if (!sign) throw new HTTPException(404, { message: `Could not find a sign named ${sign}` });

return c.json(sign);
return sign
? c.json({ ok: true as const, data: sign })
: c.json({ ok: false as const, message: `Could not find a sign named ${sign}` }, 404);
},
)

Expand All @@ -88,12 +90,10 @@ const app = new Hono()
.get("/fonts/:font", zValidator("param", z.object({ font: z.string() })), async (c) => {
const data = await fetchWithZod(versions.v1.schemas.fonts, rawFile("v1", "fonts.json"));
const font = data[c.req.param("font")];
if (!font)
throw new HTTPException(404, {
message: `Could not find a font named ${font}`,
});

return c.json(font);
return font
? c.json({ ok: true as const, data: font })
: c.json({ ok: false as const, message: `Could not find a font named ${font}` }, 404);
});

export default app;
3 changes: 2 additions & 1 deletion schemas/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { hc } from "hono/client";
import type { AppType } from "../../api/src/index";

export const client = hc<AppType>("https://api.linku.la/");

type a = Awaited<ReturnType<Awaited<ReturnType<(typeof client)["v1"]["fonts"][":font"]["$get"]>>["json"]>>;
// ^?
export type ApiType = AppType;

0 comments on commit 7635b81

Please sign in to comment.