-
Notifications
You must be signed in to change notification settings - Fork 261
Expand file tree
/
Copy pathclient.ts
More file actions
137 lines (121 loc) · 4.7 KB
/
client.ts
File metadata and controls
137 lines (121 loc) · 4.7 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use client';
import { ServiceError } from "@/lib/serviceError";
import { GetVersionResponse, ListReposQueryParams, ListReposResponse } from "@/lib/types";
import { isServiceError } from "@/lib/utils";
import {
SearchRequest,
SearchResponse,
} from "@/features/search";
import {
FindRelatedSymbolsRequest,
FindRelatedSymbolsResponse,
} from "@/features/codeNav/types";
import {
GetFilesRequest,
GetFilesResponse,
GetTreeRequest,
GetTreeResponse,
FileSourceRequest,
FileSourceResponse,
} from "@/features/git";
import { PermissionSyncStatusResponse } from "../(server)/ee/permissionSyncStatus/route";
export const search = async (body: SearchRequest): Promise<SearchResponse | ServiceError> => {
const result = await fetch("/api/search", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Sourcebot-Client-Source": "sourcebot-web-client",
},
body: JSON.stringify(body),
}).then(response => response.json());
if (isServiceError(result)) {
return result;
}
return result as SearchResponse | ServiceError;
}
export const getFileSource = async (queryParams: FileSourceRequest): Promise<FileSourceResponse | ServiceError> => {
const url = new URL("/api/source", window.location.origin);
for (const [key, value] of Object.entries(queryParams)) {
url.searchParams.set(key, value.toString());
}
const result = await fetch(url, {
method: "GET",
headers: {
"X-Sourcebot-Client-Source": "sourcebot-web-client",
}
}).then(response => response.json());
return result as FileSourceResponse | ServiceError;
}
export const listRepos = async (queryParams: ListReposQueryParams): Promise<ListReposResponse | ServiceError> => {
const url = new URL("/api/repos", window.location.origin);
for (const [key, value] of Object.entries(queryParams)) {
url.searchParams.set(key, value.toString());
}
const result = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-Sourcebot-Client-Source": "sourcebot-web-client",
},
}).then(response => response.json());
return result as ListReposResponse | ServiceError;
}
export const getVersion = async (): Promise<GetVersionResponse> => {
const result = await fetch("/api/version", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-Sourcebot-Client-Source": "sourcebot-web-client",
},
}).then(response => response.json());
return result as GetVersionResponse;
}
export const findSearchBasedSymbolReferences = async (body: FindRelatedSymbolsRequest): Promise<FindRelatedSymbolsResponse | ServiceError> => {
const result = await fetch("/api/find_references", {
method: "POST",
headers: {
"X-Sourcebot-Client-Source": "sourcebot-web-client",
},
body: JSON.stringify(body),
}).then(response => response.json());
return result as FindRelatedSymbolsResponse | ServiceError;
}
export const findSearchBasedSymbolDefinitions = async (body: FindRelatedSymbolsRequest): Promise<FindRelatedSymbolsResponse | ServiceError> => {
const result = await fetch("/api/find_definitions", {
method: "POST",
headers: {
"X-Sourcebot-Client-Source": "sourcebot-web-client",
},
body: JSON.stringify(body),
}).then(response => response.json());
return result as FindRelatedSymbolsResponse | ServiceError;
}
export const getTree = async (body: GetTreeRequest): Promise<GetTreeResponse | ServiceError> => {
const result = await fetch("/api/tree", {
method: "POST",
headers: {
"X-Sourcebot-Client-Source": "sourcebot-web-client",
},
body: JSON.stringify(body),
}).then(response => response.json());
return result as GetTreeResponse | ServiceError;
}
export const getFiles = async (body: GetFilesRequest): Promise<GetFilesResponse | ServiceError> => {
const result = await fetch("/api/files", {
method: "POST",
headers: {
"X-Sourcebot-Client-Source": "sourcebot-web-client",
},
body: JSON.stringify(body),
}).then(response => response.json());
return result as GetFilesResponse | ServiceError;
}
export const getPermissionSyncStatus = async (): Promise<PermissionSyncStatusResponse | ServiceError> => {
const result = await fetch("/api/ee/permissionSyncStatus", {
method: "GET",
headers: {
"X-Sourcebot-Client-Source": "sourcebot-web-client",
},
}).then(response => response.json());
return result as PermissionSyncStatusResponse | ServiceError;
}