diff --git a/.github/workflows/publish_npm.yml b/.github/workflows/publish_npm.yml index 88fb657391..e2bc2f8c74 100644 --- a/.github/workflows/publish_npm.yml +++ b/.github/workflows/publish_npm.yml @@ -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 diff --git a/.github/workflows/validate_toml.yml b/.github/workflows/validate_toml.yml index c3e7a18272..668622c34a 100644 --- a/.github/workflows/validate_toml.yml +++ b/.github/workflows/validate_toml.yml @@ -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 diff --git a/api/src/v1/index.ts b/api/src/v1/index.ts index cae6609814..511e656a1c 100644 --- a/api/src/v1/index.ts +++ b/api/src/v1/index.ts @@ -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"; @@ -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); }, ) @@ -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); }, ) @@ -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); }, ) @@ -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; diff --git a/schemas/src/client.ts b/schemas/src/client.ts index 63e1cdb23b..380237ced9 100644 --- a/schemas/src/client.ts +++ b/schemas/src/client.ts @@ -2,5 +2,6 @@ import { hc } from "hono/client"; import type { AppType } from "../../api/src/index"; export const client = hc("https://api.linku.la/"); - +type a = Awaited>["json"]>>; +// ^? export type ApiType = AppType;