import {z} from 'zod' export type LeagueID = string; export type Location = 'null' | 'Home' | 'Road' | null; export type Outcome = 'null' | 'W' | 'L' | null; export type Season = string; export type SeasonID = string; export type SeasonType = string; export type TeamID = string; export type VsConference = 'null' | 'East' | 'West' | null; export type VsDivision = 'null' | 'Atlantic' | 'Central' | 'Northwest' | 'Pacific' | 'Southeast' | 'Southwest' | 'East' | 'West' | null; export type VsTeamID = string; export type GetApiCumestatsteamgamesArgs = {LeagueID: LeagueID, Location?: Location | undefined, Outcome?: Outcome | undefined, Season: Season, SeasonID?: SeasonID | undefined, SeasonType: SeasonType, TeamID?: TeamID | undefined, VsConference?: VsConference | undefined, VsDivision?: VsDivision | undefined, VsTeamID?: VsTeamID | undefined}; export type GetApiCumestatsteamgamesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCumestatsteamgamesResponse = z.object({parameters: z.object({LeagueID: z.literal("$request.query.LeagueID").optional(), Location: z.literal("$request.query.Location").optional(), Outcome: z.literal("$request.query.Outcome").optional(), Season: z.literal("$request.query.Season").optional(), SeasonID: z.literal("$request.query.SeasonID").optional(), SeasonType: z.literal("$request.query.SeasonType").optional(), TeamID: z.literal("$request.query.TeamID").optional(), VsConference: z.literal("$request.query.VsConference").optional(), VsDivision: z.literal("$request.query.VsDivision").optional(), VsTeamID: z.literal("$request.query.VsTeamID").optional()}).optional(), resource: z.literal("cumestatsteamgames").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 }; /** * CumeStatsTeamGames * * GET /cumestatsteamgames */ export const getApiCumestatsteamgames = async (args: GetApiCumestatsteamgamesArgs, options?: GetApiCumestatsteamgamesOptions) => { 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.LeagueID != null) query.append("LeagueID", String(args.LeagueID)) if (args.Location != null) query.append("Location", String(args.Location)) if (args.Outcome != null) query.append("Outcome", String(args.Outcome)) if (args.Season != null) query.append("Season", String(args.Season)) if (args.SeasonID != null) query.append("SeasonID", String(args.SeasonID)) if (args.SeasonType != null) query.append("SeasonType", String(args.SeasonType)) if (args.TeamID != null) query.append("TeamID", String(args.TeamID)) if (args.VsConference != null) query.append("VsConference", String(args.VsConference)) if (args.VsDivision != null) query.append("VsDivision", String(args.VsDivision)) if (args.VsTeamID != null) query.append("VsTeamID", String(args.VsTeamID)) const url = `${baseUrl.replace(/\/+$/, '')}/cumestatsteamgames${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(getApiCumestatsteamgamesResponse, await res.json()) };