import {z} from 'zod' export type GetApiDataBatchReadingsViewFlowArgs = {completeness: unknown, date: unknown, dateTime: unknown, measure: unknown, qcode: unknown, quality: unknown, value: unknown, 'min-date'?: string | undefined, 'mineq-date'?: string | undefined, 'max-date'?: string | undefined, 'maxeq-date'?: string | undefined, earliest?: string | undefined, latest?: string | undefined, station?: string | undefined, 'station.RLOIid'?: string | undefined, 'station.wiskiID'?: string | undefined, observationType?: string | undefined, observedProperty?: string | undefined, period?: string | undefined, _projection?: string | undefined, _limit?: number | undefined, _offset?: number | undefined, _sort?: string | undefined}; export type GetApiDataBatchReadingsViewFlowOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const metadataList = z.object({publisher: z.string().optional(), license: z.string().optional(), licenseName: z.string().optional(), documentation: z.string().optional(), version: z.string().optional(), comment: z.string().optional(), hasFormat: z.array(z.string()).optional(), limit: z.number().int().optional(), offset: z.number().int().optional()}); export const item = z.object({"@id": z.string().optional()}); export const dataBatchEndpointFlow = z.object({"@id": z.string().optional(), measure: item.optional(), dateTime: z.string().nullable().optional(), date: z.string().nullable().optional(), value: z.string().nullable().optional(), completeness: z.string().nullable().optional(), quality: z.string().nullable().optional(), qcode: z.string().nullable().optional()}); export const getApiDataBatchReadingsViewFlowResponse = z.object({meta: metadataList.optional(), items: z.array(dataBatchEndpointFlow).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 }; /** * Batch readings for one or more measure time series. * * GET /data/batch-readings?_view=flow */ export const getApiDataBatchReadingsViewFlow = async (args: GetApiDataBatchReadingsViewFlowArgs, options: GetApiDataBatchReadingsViewFlowOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.completeness != null) query.append("completeness", String(args.completeness)) if (args.date != null) query.append("date", String(args.date)) if (args.dateTime != null) query.append("dateTime", String(args.dateTime)) if (args.measure != null) query.append("measure", String(args.measure)) if (args.qcode != null) query.append("qcode", String(args.qcode)) if (args.quality != null) query.append("quality", String(args.quality)) if (args.value != null) query.append("value", String(args.value)) if (args['min-date'] != null) query.append("min-date", String(args['min-date'])) if (args['mineq-date'] != null) query.append("mineq-date", String(args['mineq-date'])) if (args['max-date'] != null) query.append("max-date", String(args['max-date'])) if (args['maxeq-date'] != null) query.append("maxeq-date", String(args['maxeq-date'])) if (args.earliest != null) query.append("earliest", String(args.earliest)) if (args.latest != null) query.append("latest", String(args.latest)) if (args.station != null) query.append("station", String(args.station)) if (args['station.RLOIid'] != null) query.append("station.RLOIid", String(args['station.RLOIid'])) if (args['station.wiskiID'] != null) query.append("station.wiskiID", String(args['station.wiskiID'])) if (args.observationType != null) query.append("observationType", String(args.observationType)) if (args.observedProperty != null) query.append("observedProperty", String(args.observedProperty)) if (args.period != null) query.append("period", String(args.period)) if (args._projection != null) query.append("_projection", String(args._projection)) if (args._limit != null) query.append("_limit", String(args._limit)) if (args._offset != null) query.append("_offset", String(args._offset)) if (args._sort != null) query.append("_sort", String(args._sort)) const url = `${baseUrl.replace(/\/+$/, '')}/data/batch-readings?_view=flow${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(getApiDataBatchReadingsViewFlowResponse, await res.json()) };