2024-09-10 06:16:41 +00:00
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
|
|
export const searchRequestSchema = z.object({
|
|
|
|
|
query: z.string(),
|
2024-09-26 06:31:51 +00:00
|
|
|
maxMatchDisplayCount: z.number(),
|
2024-09-10 19:24:12 +00:00
|
|
|
whole: z.boolean().optional(),
|
2024-09-10 06:16:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2024-09-29 21:39:17 +00:00
|
|
|
// @see : https://github.com/sourcebot-dev/zoekt/blob/main/api.go#L212
|
2024-09-26 03:12:20 +00:00
|
|
|
export const locationSchema = z.object({
|
2024-09-11 04:55:00 +00:00
|
|
|
// 0-based byte offset from the beginning of the file
|
2024-09-10 06:16:41 +00:00
|
|
|
ByteOffset: z.number(),
|
2024-09-11 04:55:00 +00:00
|
|
|
// 1-based line number from the beginning of the file
|
2024-09-10 06:16:41 +00:00
|
|
|
LineNumber: z.number(),
|
2024-09-11 04:55:00 +00:00
|
|
|
// 1-based column number (in runes) from the beginning of line
|
2024-09-10 06:16:41 +00:00
|
|
|
Column: z.number(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-26 03:12:20 +00:00
|
|
|
export const rangeSchema = z.object({
|
2024-09-10 06:16:41 +00:00
|
|
|
Start: locationSchema,
|
|
|
|
|
End: locationSchema,
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-29 21:39:17 +00:00
|
|
|
// @see : https://github.com/sourcebot-dev/zoekt/blob/3780e68cdb537d5a7ed2c84d9b3784f80c7c5d04/api.go#L350
|
2024-09-17 04:37:34 +00:00
|
|
|
export const searchResponseStats = {
|
|
|
|
|
ContentBytesLoaded: z.number(),
|
|
|
|
|
IndexBytesLoaded: z.number(),
|
|
|
|
|
Crashes: z.number(),
|
|
|
|
|
Duration: z.number(),
|
|
|
|
|
FileCount: z.number(),
|
|
|
|
|
ShardFilesConsidered: z.number(),
|
|
|
|
|
FilesConsidered: z.number(),
|
|
|
|
|
FilesLoaded: z.number(),
|
|
|
|
|
FilesSkipped: z.number(),
|
|
|
|
|
ShardsScanned: z.number(),
|
|
|
|
|
ShardsSkipped: z.number(),
|
|
|
|
|
ShardsSkippedFilter: z.number(),
|
|
|
|
|
MatchCount: z.number(),
|
|
|
|
|
NgramMatches: z.number(),
|
|
|
|
|
NgramLookups: z.number(),
|
|
|
|
|
Wait: z.number(),
|
|
|
|
|
MatchTreeConstruction: z.number(),
|
|
|
|
|
MatchTreeSearch: z.number(),
|
|
|
|
|
RegexpsConsidered: z.number(),
|
|
|
|
|
FlushReason: z.number(),
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-28 21:26:27 +00:00
|
|
|
export const symbolSchema = z.object({
|
|
|
|
|
Sym: z.string(),
|
|
|
|
|
Kind: z.string(),
|
|
|
|
|
Parent: z.string(),
|
|
|
|
|
ParentKind: z.string(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-29 21:39:17 +00:00
|
|
|
// @see : https://github.com/sourcebot-dev/zoekt/blob/3780e68cdb537d5a7ed2c84d9b3784f80c7c5d04/api.go#L497
|
2024-11-07 02:28:10 +00:00
|
|
|
export const zoektSearchResponseSchema = z.object({
|
2024-09-10 06:16:41 +00:00
|
|
|
Result: z.object({
|
2024-09-17 04:37:34 +00:00
|
|
|
...searchResponseStats,
|
2024-09-10 06:16:41 +00:00
|
|
|
Files: z.array(z.object({
|
|
|
|
|
FileName: z.string(),
|
|
|
|
|
Repository: z.string(),
|
2024-11-01 17:51:14 +00:00
|
|
|
Version: z.string().optional(),
|
2024-09-10 06:16:41 +00:00
|
|
|
Language: z.string(),
|
2024-11-01 17:51:14 +00:00
|
|
|
Branches: z.array(z.string()).optional(),
|
2024-09-10 06:16:41 +00:00
|
|
|
ChunkMatches: z.array(z.object({
|
|
|
|
|
Content: z.string(),
|
|
|
|
|
Ranges: z.array(rangeSchema),
|
|
|
|
|
FileName: z.boolean(),
|
|
|
|
|
ContentStart: locationSchema,
|
|
|
|
|
Score: z.number(),
|
2024-11-28 21:26:27 +00:00
|
|
|
SymbolInfo: z.array(symbolSchema).nullable(),
|
2024-09-10 06:16:41 +00:00
|
|
|
})),
|
|
|
|
|
Checksum: z.string(),
|
|
|
|
|
Score: z.number(),
|
|
|
|
|
// Set if `whole` is true.
|
2024-09-10 19:24:12 +00:00
|
|
|
Content: z.string().optional(),
|
|
|
|
|
})).nullable(),
|
2024-11-27 05:49:41 +00:00
|
|
|
RepoURLs: z.record(z.string(), z.string()),
|
2024-09-10 06:16:41 +00:00
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
2024-11-07 02:28:10 +00:00
|
|
|
export const searchResponseSchema = z.object({
|
|
|
|
|
...zoektSearchResponseSchema.shape,
|
|
|
|
|
// Flag when a branch filter was used (e.g., `branch:`, `revision:`, etc.).
|
|
|
|
|
isBranchFilteringEnabled: z.boolean(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-10 06:16:41 +00:00
|
|
|
export const fileSourceRequestSchema = z.object({
|
|
|
|
|
fileName: z.string(),
|
2024-11-07 02:28:10 +00:00
|
|
|
repository: z.string(),
|
|
|
|
|
branch: z.string().optional(),
|
2024-09-10 06:16:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const fileSourceResponseSchema = z.object({
|
|
|
|
|
source: z.string(),
|
2025-01-07 18:27:42 +00:00
|
|
|
language: z.string(),
|
2024-09-11 04:55:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2024-09-29 21:39:17 +00:00
|
|
|
// @see : https://github.com/sourcebot-dev/zoekt/blob/3780e68cdb537d5a7ed2c84d9b3784f80c7c5d04/api.go#L728
|
2024-09-17 04:37:34 +00:00
|
|
|
const repoStatsSchema = z.object({
|
2024-09-11 04:55:00 +00:00
|
|
|
Repos: z.number(),
|
|
|
|
|
Shards: z.number(),
|
|
|
|
|
Documents: z.number(),
|
|
|
|
|
IndexBytes: z.number(),
|
|
|
|
|
ContentBytes: z.number(),
|
|
|
|
|
NewLinesCount: z.number(),
|
|
|
|
|
DefaultBranchNewLinesCount: z.number(),
|
|
|
|
|
OtherBranchesNewLinesCount: z.number(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-29 21:39:17 +00:00
|
|
|
// @see : https://github.com/sourcebot-dev/zoekt/blob/3780e68cdb537d5a7ed2c84d9b3784f80c7c5d04/api.go#L716
|
2024-09-17 04:37:34 +00:00
|
|
|
const indexMetadataSchema = z.object({
|
2024-09-11 04:55:00 +00:00
|
|
|
IndexFormatVersion: z.number(),
|
|
|
|
|
IndexFeatureVersion: z.number(),
|
|
|
|
|
IndexMinReaderVersion: z.number(),
|
|
|
|
|
IndexTime: z.string(),
|
|
|
|
|
PlainASCII: z.boolean(),
|
|
|
|
|
LanguageMap: z.record(z.string(), z.number()),
|
|
|
|
|
ZoektVersion: z.string(),
|
|
|
|
|
ID: z.string(),
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-29 21:39:17 +00:00
|
|
|
// @see : https://github.com/sourcebot-dev/zoekt/blob/3780e68cdb537d5a7ed2c84d9b3784f80c7c5d04/api.go#L555
|
2024-09-26 03:12:20 +00:00
|
|
|
export const repositorySchema = z.object({
|
2024-09-11 04:55:00 +00:00
|
|
|
Name: z.string(),
|
|
|
|
|
URL: z.string(),
|
|
|
|
|
Source: z.string(),
|
|
|
|
|
Branches: z.array(z.object({
|
|
|
|
|
Name: z.string(),
|
|
|
|
|
Version: z.string(),
|
2024-11-01 17:51:14 +00:00
|
|
|
})).nullable(),
|
2024-09-11 04:55:00 +00:00
|
|
|
CommitURLTemplate: z.string(),
|
|
|
|
|
FileURLTemplate: z.string(),
|
|
|
|
|
LineFragmentTemplate: z.string(),
|
2024-11-01 17:51:14 +00:00
|
|
|
RawConfig: z.record(z.string(), z.string()).nullable(),
|
2024-09-11 04:55:00 +00:00
|
|
|
Rank: z.number(),
|
|
|
|
|
IndexOptions: z.string(),
|
|
|
|
|
HasSymbols: z.boolean(),
|
|
|
|
|
Tombstone: z.boolean(),
|
|
|
|
|
LatestCommitDate: z.string(),
|
|
|
|
|
FileTombstones: z.string().optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const listRepositoriesResponseSchema = z.object({
|
|
|
|
|
List: z.object({
|
|
|
|
|
Repos: z.array(z.object({
|
|
|
|
|
Repository: repositorySchema,
|
|
|
|
|
IndexMetadata: indexMetadataSchema,
|
2024-09-17 04:37:34 +00:00
|
|
|
Stats: repoStatsSchema,
|
2024-09-11 04:55:00 +00:00
|
|
|
})),
|
2024-09-17 04:37:34 +00:00
|
|
|
Stats: repoStatsSchema,
|
2024-09-11 04:55:00 +00:00
|
|
|
})
|
|
|
|
|
});
|