-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathclient.ts
More file actions
40 lines (34 loc) · 1.32 KB
/
client.ts
File metadata and controls
40 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { fileSourceResponseSchema, listRepositoriesResponseSchema, searchResponseSchema } from "@/lib/schemas";
import { FileSourceResponse, ListRepositoriesResponse, SearchRequest, SearchResponse } from "@/lib/types";
export const search = async (body: SearchRequest): Promise<SearchResponse> => {
const result = await fetch(`/api/search`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
}).then(response => response.json());
return searchResponseSchema.parse(result);
}
export const fetchFileSource = async (fileName: string, repository: string): Promise<FileSourceResponse> => {
const result = await fetch(`/api/source`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
fileName,
repository,
}),
}).then(response => response.json());
return fileSourceResponseSchema.parse(result);
}
export const getRepos = async (): Promise<ListRepositoriesResponse> => {
const result = await fetch('/api/repos', {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(response => response.json());
return listRepositoriesResponseSchema.parse(result);
}