import {z} from 'zod' export type GetApiInternalV1SpansProjectIdQuantilesArgs = {project_id: number, time_start: string, time_end: string, query?: string | undefined, where?: string | undefined, search?: string | undefined, search_attrs?: Array | undefined, system?: Array | undefined, duration_gte?: number | undefined, duration_lt?: number | undefined, limit?: number | undefined}; export type GetApiInternalV1SpansProjectIdQuantilesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const timeseries = z.object({name: z.string(), value: z.array(z.number()), time: z.array(z.number())}); export const getApiInternalV1SpansProjectIdQuantilesResponse = z.object({timeseries: z.array(timeseries)}); 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 }; /** * Quantiles * * GET /internal/v1/spans/{project_id}/quantiles * * Also accepts auth: authTokenQuery */ export const getApiInternalV1SpansProjectIdQuantiles = async (args: GetApiInternalV1SpansProjectIdQuantilesArgs, options?: GetApiInternalV1SpansProjectIdQuantilesOptions) => { const {baseUrl = "https://api.uptrace.dev", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.time_start != null) query.append("time_start", String(args.time_start)) if (args.time_end != null) query.append("time_end", String(args.time_end)) if (args.query != null) query.append("query", String(args.query)) if (args.where != null) query.append("where", String(args.where)) if (args.search != null) query.append("search", String(args.search)) for (const item of args.search_attrs ?? []) query.append("search_attrs", String(item)) for (const item of args.system ?? []) query.append("system", String(item)) if (args.duration_gte != null) query.append("duration_gte", String(args.duration_gte)) if (args.duration_lt != null) query.append("duration_lt", String(args.duration_lt)) if (args.limit != null) query.append("limit", String(args.limit)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/internal/v1/spans/${encodeURIComponent(String(args.project_id))}/quantiles${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(getApiInternalV1SpansProjectIdQuantilesResponse, await res.json()) };