-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy pathschemas.ts
More file actions
139 lines (127 loc) · 4.13 KB
/
schemas.ts
File metadata and controls
139 lines (127 loc) · 4.13 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
138
139
// @NOTE : Please keep this file in sync with @sourcebot/web/src/features/search/schemas.ts
// At some point, we should move these to a shared package...
import { z } from "zod";
export const locationSchema = z.object({
// 0-based byte offset from the beginning of the file
byteOffset: z.number(),
// 1-based line number from the beginning of the file
lineNumber: z.number(),
// 1-based column number (in runes) from the beginning of line
column: z.number(),
});
export const rangeSchema = z.object({
start: locationSchema,
end: locationSchema,
});
export const symbolSchema = z.object({
symbol: z.string(),
kind: z.string(),
});
export const searchRequestSchema = z.object({
// The zoekt query to execute.
query: z.string(),
// The number of matches to return.
matches: z.number(),
// The number of context lines to return.
contextLines: z.number().optional(),
// Whether to return the whole file as part of the response.
whole: z.boolean().optional(),
});
export const repositoryInfoSchema = z.object({
id: z.number(),
codeHostType: z.string(),
name: z.string(),
displayName: z.string().optional(),
webUrl: z.string().optional(),
})
export const searchResponseSchema = z.object({
zoektStats: z.object({
// The duration (in nanoseconds) of the search.
duration: z.number(),
fileCount: z.number(),
matchCount: z.number(),
filesSkipped: z.number(),
contentBytesLoaded: z.number(),
indexBytesLoaded: z.number(),
crashes: z.number(),
shardFilesConsidered: z.number(),
filesConsidered: z.number(),
filesLoaded: z.number(),
shardsScanned: z.number(),
shardsSkipped: z.number(),
shardsSkippedFilter: z.number(),
ngramMatches: z.number(),
ngramLookups: z.number(),
wait: z.number(),
matchTreeConstruction: z.number(),
matchTreeSearch: z.number(),
regexpsConsidered: z.number(),
flushReason: z.number(),
}),
files: z.array(z.object({
fileName: z.object({
// The name of the file
text: z.string(),
// Any matching ranges
matchRanges: z.array(rangeSchema),
}),
webUrl: z.string().optional(),
repository: z.string(),
repositoryId: z.number(),
language: z.string(),
chunks: z.array(z.object({
content: z.string(),
matchRanges: z.array(rangeSchema),
contentStart: locationSchema,
symbols: z.array(z.object({
...symbolSchema.shape,
parent: symbolSchema.optional(),
})).optional(),
})),
branches: z.array(z.string()).optional(),
// Set if `whole` is true.
content: z.string().optional(),
})),
repositoryInfo: z.array(repositoryInfoSchema),
isBranchFilteringEnabled: z.boolean(),
});
enum RepoIndexingStatus {
NEW = 'NEW',
IN_INDEX_QUEUE = 'IN_INDEX_QUEUE',
INDEXING = 'INDEXING',
INDEXED = 'INDEXED',
FAILED = 'FAILED',
IN_GC_QUEUE = 'IN_GC_QUEUE',
GARBAGE_COLLECTING = 'GARBAGE_COLLECTING',
GARBAGE_COLLECTION_FAILED = 'GARBAGE_COLLECTION_FAILED'
}
export const repositoryQuerySchema = z.object({
codeHostType: z.string(),
repoId: z.number(),
repoName: z.string(),
repoDisplayName: z.string().optional(),
repoCloneUrl: z.string(),
webUrl: z.string().optional(),
linkedConnections: z.array(z.object({
id: z.number(),
name: z.string(),
})),
imageUrl: z.string().optional(),
indexedAt: z.coerce.date().optional(),
repoIndexingStatus: z.nativeEnum(RepoIndexingStatus),
});
export const listRepositoriesResponseSchema = repositoryQuerySchema.array();
export const fileSourceRequestSchema = z.object({
fileName: z.string(),
repository: z.string(),
branch: z.string().optional(),
});
export const fileSourceResponseSchema = z.object({
source: z.string(),
language: z.string(),
});
export const serviceErrorSchema = z.object({
statusCode: z.number(),
errorCode: z.string(),
message: z.string(),
});