Skip to content
Source
Sign inSign up
fuko/trytanstackdb.com
Open History to see the last commit

index.ts

37 lines1012 Bytes

1import todoItemsBatchRoutes from "./api.batch.todo-items";
2import boardRoutes from "./api.boards";
3import projectRoutes from "./api.projects";
4import todoRoutes from "./api.todo-items";
5import { type APIType, deconstructResponseFromHandler } from "./helpers";
6​
7export const API = {
8 "/api/projects": projectRoutes,
9 "/api/boards": boardRoutes,
10 "/api/todo-items": todoRoutes,
11 "/api/batch/todo-items": todoItemsBatchRoutes,
12} satisfies APIType;
13​
14// type APIRoutePath = keyof typeof API;
15​
16// type APIRouteHandler = (typeof API)[APIRoutePath] extends infer T
17// ? T extends object
18// ? keyof T
19// : never
20// : never;
21​
22/**
23 Helper function for calling the local API directly,
24 bypassing fetch.
25​
26 Similar to server functions for apps with remote dbs
27 (the db for this app is local).
28*/
29export async function getDataFromApi<G>(
30 handler: () => Promise<Response>,
31): Promise<G> {
32 const res = await handler();
33​
34 const { body } = await deconstructResponseFromHandler(res);
35​
36 return body as G;