import {z} from 'zod' export type GetApiBeachBeachRankingsArgs = {ts?: number | undefined, all?: boolean | undefined, season?: string | undefined, person_id?: number | undefined, ranking_list_type_id?: number | undefined}; export type GetApiBeachBeachRankingsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiBeachBeachRankingsResponse = z.array(z.object({id: z.number().int().optional(), season_id: z.string().optional(), person_id: z.number().int().optional(), ranking_list_type_id: z.number().int().optional(), ranking_list_type_name: z.string().optional(), sex: z.string().optional(), rank: z.number().int().optional(), all_points: z.number().int().optional(), player_name: z.string().optional(), club: z.string().optional(), slug: z.string().optional(), code: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), deleted_at: z.string().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 }; /** * BeachRankingPerson Updates (full or delta) * * GET /beach/beach-rankings */ export const getApiBeachBeachRankings = async (args: GetApiBeachBeachRankingsArgs, options?: GetApiBeachBeachRankingsOptions) => { const {baseUrl = "https://api.volleynet.cc", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ts != null) query.append("ts", String(args.ts)) if (args.all != null) query.append("all", String(args.all)) if (args.season != null) query.append("season", String(args.season)) if (args.person_id != null) query.append("person_id", String(args.person_id)) if (args.ranking_list_type_id != null) query.append("ranking_list_type_id", String(args.ranking_list_type_id)) const url = `${baseUrl.replace(/\/+$/, '')}/beach/beach-rankings${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(getApiBeachBeachRankingsResponse, await res.json()) };