import {z} from 'zod' export type GetApiLeaderboardLeaderboardIdRunsArgs = {leaderboardId: string, page?: number | undefined, page_size?: number | undefined, sort?: (Array<'id' | '-id' | 'name' | '-name' | 'created_at' | '-created_at'>) | undefined, id?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, name?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, status?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, created_at?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, owner_mail?: ({eq?: string | undefined, neq?: string | undefined, gt?: string | undefined, gte?: string | undefined, lt?: string | undefined, lte?: string | undefined, contains?: string | undefined, starts_with?: string | undefined, ends_with?: string | undefined, in?: Array | undefined, not_contains?: string | undefined}) | undefined, logic?: ('and' | 'or') | undefined}; export type GetApiLeaderboardLeaderboardIdRunsOptions = {baseUrl?: string | undefined, OpenIdConnect?: string | undefined, fetch?: typeof fetch | undefined}; export const runStatus = z.enum(["Queued", "Running", "Completed", "Failed", "Paused", "Cancelled"]); export const queryLeaderboardRunsEndpointOutput = z.object({id: z.string(), name: z.string(), status: runStatus, createdAt: z.string(), ownerMail: z.string(), organizationId: z.string(), orderId: z.string().nullable(), jobId: z.string().nullable(), audienceId: z.string()}); export const queryLeaderboardRunsEndpointPagedResultOfOutput = z.object({total: z.number().int(), page: z.number().int(), pageSize: z.number().int(), items: z.array(queryLeaderboardRunsEndpointOutput), totalPages: z.number().int().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 }; /** * Queries the runs related to a leaderboard. * * GET /leaderboard/{leaderboardId}/runs * * Also accepts auth: OpenIdConnect */ export const getApiLeaderboardLeaderboardIdRuns = async (args: GetApiLeaderboardLeaderboardIdRunsArgs, options?: GetApiLeaderboardLeaderboardIdRunsOptions) => { const {baseUrl = "https://api.rapidata.ai", fetch: fetchFn = fetch, OpenIdConnect} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) for (const item of args.sort ?? []) query.append("sort", String(item)) if (args.id != null) query.append("id", JSON.stringify(args.id)) if (args.name != null) query.append("name", JSON.stringify(args.name)) if (args.status != null) query.append("status", JSON.stringify(args.status)) if (args.created_at != null) query.append("created_at", JSON.stringify(args.created_at)) if (args.owner_mail != null) query.append("owner_mail", JSON.stringify(args.owner_mail)) if (args.logic != null) query.append("logic", String(args.logic)) if (OpenIdConnect !== undefined) headers.set('authorization', `Bearer ${OpenIdConnect}`) const url = `${baseUrl.replace(/\/+$/, '')}/leaderboard/${encodeURIComponent(String(args.leaderboardId))}/runs${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(queryLeaderboardRunsEndpointPagedResultOfOutput, await res.json()) };