Skip to content

Commit

Permalink
Added early web API code
Browse files Browse the repository at this point in the history
unknown coined_era values are now allowed
fixed schema path in word files
  • Loading branch information
TheOnlyTails committed Dec 5, 2023
1 parent 6bc0abd commit 05d2804
Show file tree
Hide file tree
Showing 267 changed files with 388 additions and 270 deletions.
2 changes: 1 addition & 1 deletion .scripts/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def main():
# or crowdin will solve this for us
for word, worddata in WORDS.items():
worddata["representations"] = REPRESENTATIONS[word]
worddata["$schema"] = "../../schemas/generated/word.json"
worddata["$schema"] = "../schemas/generated/word.json"
with open(f"../words/{word}.toml", "w") as f:
tomlified = tomlkit.dumps(worddata, sort_keys=True)
f.write(tomlified)
Expand Down
20 changes: 14 additions & 6 deletions schemas/generated/word.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@
"description": "Which official Toki Pona book was this word featured in, if any."
},
"coined_era": {
"type": "string",
"enum": [
"pre-pu",
"post-pu",
"post-ku"
"anyOf": [
{
"type": "string",
"enum": [
"pre-pu",
"post-pu",
"post-ku"
]
},
{
"type": "string",
"const": ""
}
],
"description": "When this word was coined (relative to the publication dates of the official Toki Pona books)"
"description": "When this word was coined (relative to the publication dates of the official Toki Pona books, if known)"
},
"coined_year": {
"type": "string",
Expand Down
11 changes: 9 additions & 2 deletions schemas/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@linku/sona",
"version": "0.1.0",
"description": "A library providing TypeScript types for the sona API",
"description": "A library providing TypeScript types and Zod schemas for the sona API",
"homepage": "https://linku.la/",
"bugs": {
"url": "https://github.com/lipu-linku/sona/issues/"
Expand All @@ -26,9 +26,15 @@
},
"scripts": {
"generate:schemas": "tsx ./generateSchemas.ts",
"build": "tsup src/**/*.ts --dts --format esm"
"dev": "tsx ./src/server/router.ts --watch-path ./src/**/*.ts",
"build:server": "",
"build:lib": "tsup src/types/**/*.ts --dts --format esm"
},
"dependencies": {
"@hono/node-server": "^1.3.1",
"@taplo/lib": "0.4.0-alpha.2",
"hono": "^3.11.1",
"semver": "^7.5.4",
"zod": "^3.22.4"
},
"devDependencies": {
Expand All @@ -37,6 +43,7 @@
"ts-json-schema-generator": "^1.4.1",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"typescript": "^5.3.2",
"zod-to-json-schema": "^3.22.1"
},
"engines": {
Expand Down
59 changes: 57 additions & 2 deletions schemas/pnpm-lock.yaml

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

3 changes: 3 additions & 0 deletions schemas/src/server/branches.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const branches = {
v1: "main",
} as const satisfies Record<`v${number}`, string>;
13 changes: 13 additions & 0 deletions schemas/src/server/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { serve } from "@hono/node-server";
import { Hono } from "hono";
import { prettyJSON } from "hono/pretty-json";
import v1 from "./v1/routes";

const app = new Hono();

app.use("*", prettyJSON());
app.notFound((c) => c.json({ message: "Not found", ok: false }, 404));

app.route("/v1", v1);

serve(app);
11 changes: 11 additions & 0 deletions schemas/src/server/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Taplo } from "@taplo/lib";
import { MiddlewareHandler } from "hono";

export const tomlMiddleware: MiddlewareHandler<{
Variables: {
toml: Taplo;
};
}> = async (c, next) => {
c.set("toml", await Taplo.initialize());
await next();
};
21 changes: 21 additions & 0 deletions schemas/src/server/v1/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Hono } from "hono";
import { branches } from "../branches";
import { tomlMiddleware } from "../utils";

export const API_URL = `https://raw.githubusercontent.com/lipu-linku/sona/${branches.v1}`;

const app = new Hono().options();

app.get("/about", (c) =>
c.json({
api_url: API_URL,
version: 1,
}),
);

app.get("/word/:word", tomlMiddleware, async (c) => {
const data = await fetch(`${API_URL}/words/${c.req.param("word")}.toml`)
.then((r) => r.text())
});

export default app;
2 changes: 1 addition & 1 deletion words/Pingo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "ku lili"
Expand Down
2 changes: 1 addition & 1 deletion words/a.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/aka.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "none"
Expand Down
2 changes: 1 addition & 1 deletion words/akesi.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/ako.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "none"
Expand Down
2 changes: 1 addition & 1 deletion words/ala.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/alasa.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/ale.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/alente.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "none"
Expand Down
2 changes: 1 addition & 1 deletion words/ali.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/alu.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "none"
Expand Down
2 changes: 1 addition & 1 deletion words/anpa.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/ante.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/anu.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/apeja.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "ku lili"
Expand Down
2 changes: 1 addition & 1 deletion words/awase.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "none"
Expand Down
2 changes: 1 addition & 1 deletion words/awen.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/e.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/eki.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "none"
Expand Down
2 changes: 1 addition & 1 deletion words/eliki.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = "distress, affliction, adversity, pain"
author_verbatim_source = "https://discord.com/channels/301377942062366741/375591429608570881/1072666397626335242"
book = "none"
Expand Down
2 changes: 1 addition & 1 deletion words/en.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
2 changes: 1 addition & 1 deletion words/enko.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "none"
Expand Down
2 changes: 1 addition & 1 deletion words/epiku.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "ku suli"
Expand Down
2 changes: 1 addition & 1 deletion words/esun.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"$schema" = "../../schemas/generated/word.json"
"$schema" = "../schemas/generated/word.json"
author_verbatim = ""
author_verbatim_source = ""
book = "pu"
Expand Down
Loading

0 comments on commit 05d2804

Please sign in to comment.