Skip to content

Commit 7828f33

Browse files
authored
Merge pull request #437 from ucdjs/feat/rename-schemas-and-improve
2 parents 0261e07 + f1e82e6 commit 7828f33

File tree

30 files changed

+1867
-558
lines changed

30 files changed

+1867
-558
lines changed

apps/api/src/routes/v1_versions/$version.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { OpenAPIHono } from "@hono/zod-openapi";
2+
import type { UnicodeFileTree } from "@ucdjs/schemas";
23
import type { HonoEnv } from "../../types";
34
import { createRoute } from "@hono/zod-openapi";
45
import { dedent } from "@luxass/utils";
5-
import { UnicodeTreeSchema, UnicodeVersionDetailsSchema } from "@ucdjs/schemas";
6+
import { UnicodeFileTreeNodeSchema, UnicodeFileTreeSchema, UnicodeVersionDetailsSchema } from "@ucdjs/schemas";
67
import {
78
hasUCDFolderPath,
89
resolveUCDVersion,
@@ -108,7 +109,7 @@ export const GET_VERSION_FILE_TREE_ROUTE = createRoute({
108109
200: {
109110
content: {
110111
"application/json": {
111-
schema: UnicodeTreeSchema,
112+
schema: UnicodeFileTreeSchema,
112113
examples: {
113114
default: {
114115
summary: "File tree for a Unicode version",
@@ -208,19 +209,32 @@ export function registerGetVersionRoute(router: OpenAPIHono<HonoEnv>) {
208209

209210
// Try to get statistics from bucket if available
210211
const bucket = c.env.UCD_BUCKET;
211-
let statistics = null;
212+
let statistics = {
213+
newBlocks: 0,
214+
newCharacters: 0,
215+
newScripts: 0,
216+
totalBlocks: 0,
217+
totalCharacters: 0,
218+
totalScripts: 0,
219+
};
220+
221+
// This is so bad.... but we have to do it for now.
212222
if (bucket) {
213-
statistics = await calculateStatistics(bucket, version);
223+
const tmp = await calculateStatistics(bucket, version);
224+
if (tmp) {
225+
statistics = tmp;
226+
}
214227
}
215228

216229
return c.json({
217230
...versionInfo,
218-
statistics: statistics ?? undefined,
231+
statistics,
219232
}, 200);
220233
});
221234
}
222235

223236
export function registerVersionFileTreeRoute(router: OpenAPIHono<HonoEnv>) {
237+
router.openAPIRegistry.register("UnicodeFileTreeNode", UnicodeFileTreeNodeSchema);
224238
router.openapi(GET_VERSION_FILE_TREE_ROUTE, async (c) => {
225239
try {
226240
let version = c.req.param("version");
@@ -243,7 +257,11 @@ export function registerVersionFileTreeRoute(router: OpenAPIHono<HonoEnv>) {
243257
format: "F2",
244258
});
245259

246-
return c.json(result, 200);
260+
// We cast the result to UnicodeFileTree because the traverse function
261+
// returns entries that uses lastModified as `number | undefined`.
262+
// But we can't use the `number | undefined` type in the API schema.
263+
// So we need to return lastModified as `number | null` always.
264+
return c.json(result as UnicodeFileTree, 200);
247265
} catch (error) {
248266
console.error("Error processing directory:", error);
249267
return internalServerError(c, {

0 commit comments

Comments
 (0)