import {z} from 'zod' export type Person1Id = string; export type Person1LeagueId = string; export type Person1Season = string; export type Person1SeasonType = string; export type Person2Id = string; export type Person2LeagueId = string; export type Person2Season = string; export type Person2SeasonType = string; export type GetApiBoxscoresimilarityscoreArgs = {Person1Id: Person1Id, Person1LeagueId: Person1LeagueId, Person1Season: Person1Season, Person1SeasonType: Person1SeasonType, Person2Id: Person2Id, Person2LeagueId: Person2LeagueId, Person2Season: Person2Season, Person2SeasonType: Person2SeasonType}; export type GetApiBoxscoresimilarityscoreOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiBoxscoresimilarityscoreResponse = z.object({parameters: z.object({Person1Id: z.literal("$request.query.Person1Id").optional(), Person1LeagueId: z.literal("$request.query.Person1LeagueId").optional(), Person1Season: z.literal("$request.query.Person1Season").optional(), Person1SeasonType: z.literal("$request.query.Person1SeasonType").optional(), Person2Id: z.literal("$request.query.Person2Id").optional(), Person2LeagueId: z.literal("$request.query.Person2LeagueId").optional(), Person2Season: z.literal("$request.query.Person2Season").optional(), Person2SeasonType: z.literal("$request.query.Person2SeasonType").optional()}).optional(), resource: z.literal("boxscoresimilarityscore").optional(), resultSets: z.array(z.unknown()).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 }; /** * BoxScoreSimilarityScore * * GET /boxscoresimilarityscore */ export const getApiBoxscoresimilarityscore = async (args: GetApiBoxscoresimilarityscoreArgs, options?: GetApiBoxscoresimilarityscoreOptions) => { const {baseUrl = "https://stats.nba.com/stats", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Person1Id != null) query.append("Person1Id", String(args.Person1Id)) if (args.Person1LeagueId != null) query.append("Person1LeagueId", String(args.Person1LeagueId)) if (args.Person1Season != null) query.append("Person1Season", String(args.Person1Season)) if (args.Person1SeasonType != null) query.append("Person1SeasonType", String(args.Person1SeasonType)) if (args.Person2Id != null) query.append("Person2Id", String(args.Person2Id)) if (args.Person2LeagueId != null) query.append("Person2LeagueId", String(args.Person2LeagueId)) if (args.Person2Season != null) query.append("Person2Season", String(args.Person2Season)) if (args.Person2SeasonType != null) query.append("Person2SeasonType", String(args.Person2SeasonType)) const url = `${baseUrl.replace(/\/+$/, '')}/boxscoresimilarityscore${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(getApiBoxscoresimilarityscoreResponse, await res.json()) };