import {z} from 'zod' export type GetApiSnapshotsSnapshotIdSymbolsArgs = {snapshot_id: string, file_path?: (string | null) | undefined, q?: (string | null) | undefined, kind?: (string | null) | undefined, language?: (string | null) | undefined, visibility?: (string | null) | undefined, in_hot_files?: boolean | undefined, in_entry_points?: boolean | undefined, bug_fixed?: boolean | undefined, sort?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiSnapshotsSnapshotIdSymbolsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const symbolImportanceComponents = z.object({file_pagerank: z.number().optional(), visibility_factor: z.number().optional(), complexity_norm: z.number().optional(), kind_boost: z.number().optional(), is_entry_point: z.boolean().optional()}); export const symbolEntry = z.object({id: z.string(), file_path: z.string(), name: z.string(), qualified_name: z.string(), kind: z.string(), signature: z.string().optional(), start_line: z.number().int().optional(), end_line: z.number().int().optional(), docstring: z.string().nullable().optional(), visibility: z.string().optional(), is_async: z.boolean().optional(), complexity_estimate: z.number().optional(), language: z.string().optional(), parent_name: z.string().nullable().optional(), importance_score: z.number().nullable().optional(), importance_components: symbolImportanceComponents.nullable().optional(), file_pagerank: z.number().nullable().optional(), is_entry_point: z.boolean().nullable().optional(), file_churn_percentile: z.number().nullable().optional(), file_is_hotspot: z.boolean().nullable().optional(), fix_count: z.number().int().nullable().optional()}); export const paginatedSymbolEntry = z.object({items: z.array(symbolEntry), total: z.number().int(), has_more: z.boolean(), next_offset: z.number().int().nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Symbols * * GET /snapshots/{snapshot_id}/symbols */ export const getApiSnapshotsSnapshotIdSymbols = async (args: GetApiSnapshotsSnapshotIdSymbolsArgs, options: GetApiSnapshotsSnapshotIdSymbolsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.file_path != null) query.append("file_path", String(args.file_path)) if (args.q != null) query.append("q", String(args.q)) if (args.kind != null) query.append("kind", String(args.kind)) if (args.language != null) query.append("language", String(args.language)) if (args.visibility != null) query.append("visibility", String(args.visibility)) if (args.in_hot_files != null) query.append("in_hot_files", String(args.in_hot_files)) if (args.in_entry_points != null) query.append("in_entry_points", String(args.in_entry_points)) if (args.bug_fixed != null) query.append("bug_fixed", String(args.bug_fixed)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/snapshots/${encodeURIComponent(String(args.snapshot_id))}/symbols${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paginatedSymbolEntry, await res.json()) };