import {z} from 'zod' export type GetApiSamplingPointPointNotationObservationArgs = {pointNotation: string, skip?: number | undefined, limit?: number | undefined, determinand?: (string | null) | undefined, sampleMaterialType?: (string | null) | undefined, sampleSamplingNotation?: (number | null) | undefined, samplingPurpose?: (string | null) | undefined, date?: (string | null) | undefined, dateFrom?: (string | null) | undefined, dateTo?: (string | null) | undefined, complianceOnly?: boolean | undefined, 'Accept-Crs'?: ('http://www.opengis.net/def/crs/EPSG/0/27700' | 'http://www.opengis.net/def/crs/EPSG/0/4326') | undefined, 'CSV-Header'?: ('present' | 'absent') | undefined, 'API-Version'?: string | undefined}; export type GetApiSamplingPointPointNotationObservationOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSamplingPointPointNotationObservationResponse = z.unknown(); 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 }; /** * List and filter observations for a specific sampling point by its notation * * GET /sampling-point/{pointNotation}/observation */ export const getApiSamplingPointPointNotationObservation = async (args: GetApiSamplingPointPointNotationObservationArgs, options?: GetApiSamplingPointPointNotationObservationOptions) => { const {baseUrl = "https://environment.data.gov.uk/water-quality", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/ld+json") if (args.skip != null) query.append("skip", String(args.skip)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.determinand != null) query.append("determinand", String(args.determinand)) if (args.sampleMaterialType != null) query.append("sampleMaterialType", String(args.sampleMaterialType)) if (args.sampleSamplingNotation != null) query.append("sampleSamplingNotation", String(args.sampleSamplingNotation)) if (args.samplingPurpose != null) query.append("samplingPurpose", String(args.samplingPurpose)) if (args.date != null) query.append("date", String(args.date)) if (args.dateFrom != null) query.append("dateFrom", String(args.dateFrom)) if (args.dateTo != null) query.append("dateTo", String(args.dateTo)) if (args.complianceOnly != null) query.append("complianceOnly", String(args.complianceOnly)) if (args['Accept-Crs'] != null) headers.set("Accept-Crs", String(args['Accept-Crs'])) if (args['CSV-Header'] != null) headers.set("CSV-Header", String(args['CSV-Header'])) if (args['API-Version'] != null) headers.set("API-Version", String(args['API-Version'])) const url = `${baseUrl.replace(/\/+$/, '')}/sampling-point/${encodeURIComponent(String(args.pointNotation))}/observation${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(getApiSamplingPointPointNotationObservationResponse, await res.json()) };