import {z} from 'zod' export type GetApiV3NhlProjectionsFormatStartingGoaltendersByDateDateArgs = {format: 'JSON' | 'XML', date: string}; export type GetApiV3NhlProjectionsFormatStartingGoaltendersByDateDateOptions = {baseUrl?: string | undefined, apiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const goaltender = z.object({PlayerID: z.number().int().optional(), TeamID: z.number().int().optional(), Team: z.string().nullable().optional(), FirstName: z.string().nullable().optional(), LastName: z.string().nullable().optional(), Jersey: z.number().int().nullable().optional(), Confirmed: z.boolean().optional()}); export const startingGoaltenders = z.object({GameID: z.number().int().optional(), Season: z.number().int().optional(), SeasonType: z.number().int().optional(), Day: z.string().nullable().optional(), DateTime: z.string().nullable().optional(), Status: z.string().nullable().optional(), HomeTeamID: z.number().int().nullable().optional(), HomeTeam: z.string().nullable().optional(), AwayTeamID: z.number().int().nullable().optional(), AwayTeam: z.string().nullable().optional(), HomeGoaltender: goaltender.optional(), AwayGoaltender: goaltender.optional()}); export const getApiV3NhlProjectionsFormatStartingGoaltendersByDateDateResponse = z.array(startingGoaltenders); 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 }; /** * Starting Goaltenders - by Date * * GET /v3/nhl/projections/{format}/StartingGoaltendersByDate/{date} * * Also accepts auth: apiKeyQuery */ export const getApiV3NhlProjectionsFormatStartingGoaltendersByDateDate = async (args: GetApiV3NhlProjectionsFormatStartingGoaltendersByDateDateArgs, options?: GetApiV3NhlProjectionsFormatStartingGoaltendersByDateDateOptions) => { const {baseUrl = "https://api.sportsdata.io", fetch: fetchFn = fetch, apiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKeyHeader !== undefined) headers.set("Ocp-Apim-Subscription-Key", apiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v3/nhl/projections/${encodeURIComponent(String(args.format))}/StartingGoaltendersByDate/${encodeURIComponent(String(args.date))}${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(getApiV3NhlProjectionsFormatStartingGoaltendersByDateDateResponse, await res.json()) };