import {z} from 'zod' export type College = string | null; export type Conference = 'null' | 'East' | 'West' | null; export type Country = string | null; export type DateFrom = string | null; export type DateTo = string | null; export type Division = 'null' | 'Atlantic' | 'Central' | 'Northwest' | 'Pacific' | 'Southeast' | 'Southwest' | null; export type DraftPick = string | null; export type DraftYear = string | null; export type GameScope = 'null' | 'Yesterday' | 'Last 10' | null; export type Height = string | null; export type LastNGames = string | null; export type LeagueID = string; export type Location = 'null' | 'Home' | 'Road' | null; export type Month = string | null; export type OpponentTeamID = string | null; export type Outcome = 'null' | 'W' | 'L' | null; export type PORound = string | null; export type PerMode = string; export type PlayerExperience = 'null' | 'Rookie' | 'Sophomore' | 'Veteran' | null; export type PlayerOrTeam = 'Player' | 'Team'; export type PlayerPosition = 'null' | 'F' | 'C' | 'G' | 'C-F' | 'F-C' | 'F-G' | 'G-F' | null; export type PtMeasureType = 'SpeedDistance' | 'Rebounding' | 'Possessions' | 'CatchShoot' | 'PullUpShot' | 'Defense' | 'Drives' | 'Passing' | 'ElbowTouch' | 'PostTouch' | 'PaintTouch' | 'Efficiency'; export type Season = string; export type SeasonSegment = 'null' | 'Post All-Star' | 'Pre All-Star' | null; export type SeasonType = string; export type StarterBench = 'null' | 'Starters' | 'Bench' | null; 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 Weight = string | null; export type GetApiLeaguedashptstatsArgs = {College?: College | undefined, Conference?: Conference | undefined, Country?: Country | undefined, DateFrom?: DateFrom | undefined, DateTo?: DateTo | undefined, Division?: Division | undefined, DraftPick?: DraftPick | undefined, DraftYear?: DraftYear | undefined, GameScope?: GameScope | undefined, Height?: Height | undefined, LastNGames?: LastNGames | undefined, LeagueID: LeagueID, Location?: Location | undefined, Month?: Month | undefined, OpponentTeamID?: OpponentTeamID | undefined, Outcome?: Outcome | undefined, PORound?: PORound | undefined, PerMode: PerMode, PlayerExperience?: PlayerExperience | undefined, PlayerOrTeam: PlayerOrTeam, PlayerPosition?: PlayerPosition | undefined, PtMeasureType: PtMeasureType, Season: Season, SeasonSegment?: SeasonSegment | undefined, SeasonType: SeasonType, StarterBench?: StarterBench | undefined, TeamID?: TeamID | undefined, VsConference?: VsConference | undefined, VsDivision?: VsDivision | undefined, Weight?: Weight | undefined}; export type GetApiLeaguedashptstatsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiLeaguedashptstatsResponse = z.object({parameters: z.object({College: z.literal("$request.query.College").optional(), Conference: z.literal("$request.query.Conference").optional(), Country: z.literal("$request.query.Country").optional(), DateFrom: z.literal("$request.query.DateFrom").optional(), DateTo: z.literal("$request.query.DateTo").optional(), Division: z.literal("$request.query.Division").optional(), DraftPick: z.literal("$request.query.DraftPick").optional(), DraftYear: z.literal("$request.query.DraftYear").optional(), GameScope: z.literal("$request.query.GameScope").optional(), Height: z.literal("$request.query.Height").optional(), LastNGames: z.literal("$request.query.LastNGames").optional(), LeagueID: z.literal("$request.query.LeagueID").optional(), Location: z.literal("$request.query.Location").optional(), Month: z.literal("$request.query.Month").optional(), OpponentTeamID: z.literal("$request.query.OpponentTeamID").optional(), Outcome: z.literal("$request.query.Outcome").optional(), PORound: z.literal("$request.query.PORound").optional(), PerMode: z.literal("$request.query.PerMode").optional(), PlayerExperience: z.literal("$request.query.PlayerExperience").optional(), PlayerOrTeam: z.literal("$request.query.PlayerOrTeam").optional(), PlayerPosition: z.literal("$request.query.PlayerPosition").optional(), PtMeasureType: z.literal("$request.query.PtMeasureType").optional(), Season: z.literal("$request.query.Season").optional(), SeasonSegment: z.literal("$request.query.SeasonSegment").optional(), SeasonType: z.literal("$request.query.SeasonType").optional(), StarterBench: z.literal("$request.query.StarterBench").optional(), TeamID: z.literal("$request.query.TeamID").optional(), VsConference: z.literal("$request.query.VsConference").optional(), VsDivision: z.literal("$request.query.VsDivision").optional(), Weight: z.literal("$request.query.Weight").optional()}).optional(), resource: z.literal("leaguedashptstats").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 }; /** * LeagueDashPtStats * * GET /leaguedashptstats */ export const getApiLeaguedashptstats = async (args: GetApiLeaguedashptstatsArgs, options?: GetApiLeaguedashptstatsOptions) => { 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.College != null) query.append("College", String(args.College)) if (args.Conference != null) query.append("Conference", String(args.Conference)) if (args.Country != null) query.append("Country", String(args.Country)) if (args.DateFrom != null) query.append("DateFrom", String(args.DateFrom)) if (args.DateTo != null) query.append("DateTo", String(args.DateTo)) if (args.Division != null) query.append("Division", String(args.Division)) if (args.DraftPick != null) query.append("DraftPick", String(args.DraftPick)) if (args.DraftYear != null) query.append("DraftYear", String(args.DraftYear)) if (args.GameScope != null) query.append("GameScope", String(args.GameScope)) if (args.Height != null) query.append("Height", String(args.Height)) if (args.LastNGames != null) query.append("LastNGames", String(args.LastNGames)) if (args.LeagueID != null) query.append("LeagueID", String(args.LeagueID)) if (args.Location != null) query.append("Location", String(args.Location)) if (args.Month != null) query.append("Month", String(args.Month)) if (args.OpponentTeamID != null) query.append("OpponentTeamID", String(args.OpponentTeamID)) if (args.Outcome != null) query.append("Outcome", String(args.Outcome)) if (args.PORound != null) query.append("PORound", String(args.PORound)) if (args.PerMode != null) query.append("PerMode", String(args.PerMode)) if (args.PlayerExperience != null) query.append("PlayerExperience", String(args.PlayerExperience)) if (args.PlayerOrTeam != null) query.append("PlayerOrTeam", String(args.PlayerOrTeam)) if (args.PlayerPosition != null) query.append("PlayerPosition", String(args.PlayerPosition)) if (args.PtMeasureType != null) query.append("PtMeasureType", String(args.PtMeasureType)) if (args.Season != null) query.append("Season", String(args.Season)) if (args.SeasonSegment != null) query.append("SeasonSegment", String(args.SeasonSegment)) if (args.SeasonType != null) query.append("SeasonType", String(args.SeasonType)) if (args.StarterBench != null) query.append("StarterBench", String(args.StarterBench)) 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.Weight != null) query.append("Weight", String(args.Weight)) const url = `${baseUrl.replace(/\/+$/, '')}/leaguedashptstats${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(getApiLeaguedashptstatsResponse, await res.json()) };