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

index.ts

35 lines904 Bytes

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