import {z} from 'zod' export type GetApiAvailableconstraintFlowKeyProviderComponentIDArgs = {flow: string, key: string, provider: string, componentID: string, mode?: ('exact' | 'available') | undefined, references?: ('none' | 'all' | 'datastructure' | 'conceptscheme' | 'codelist' | 'dataproviderscheme' | 'dataflow') | undefined, startPeriod?: string | undefined, endPeriod?: string | undefined, updatedAfter?: string | undefined, 'Accept-Encoding'?: ('br' | 'compress' | 'deflate' | 'exi' | 'gzip' | 'identity' | 'pack200-gzip' | 'zstd') | undefined, 'Accept-Language'?: string | undefined, 'If-Modified-Since'?: string | undefined}; export type GetApiAvailableconstraintFlowKeyProviderComponentIDOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAvailableconstraintFlowKeyProviderComponentIDResponse = z.string(); 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 }; /** * Get information about data availability * * GET /availableconstraint/{flow}/{key}/{provider}/{componentID} */ export const getApiAvailableconstraintFlowKeyProviderComponentID = async (args: GetApiAvailableconstraintFlowKeyProviderComponentIDArgs, options?: GetApiAvailableconstraintFlowKeyProviderComponentIDOptions) => { const {baseUrl = "https://sdw-wsrest.ecb.europa.eu/service", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/vnd.sdmx.structure+json;version=1.0.0") if (args.mode != null) query.append("mode", String(args.mode)) if (args.references != null) query.append("references", String(args.references)) if (args.startPeriod != null) query.append("startPeriod", String(args.startPeriod)) if (args.endPeriod != null) query.append("endPeriod", String(args.endPeriod)) if (args.updatedAfter != null) query.append("updatedAfter", String(args.updatedAfter)) if (args['Accept-Encoding'] != null) headers.set("Accept-Encoding", String(args['Accept-Encoding'])) if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args['If-Modified-Since'] != null) headers.set("If-Modified-Since", String(args['If-Modified-Since'])) const url = `${baseUrl.replace(/\/+$/, '')}/availableconstraint/${encodeURIComponent(String(args.flow))}/${encodeURIComponent(String(args.key))}/${encodeURIComponent(String(args.provider))}/${encodeURIComponent(String(args.componentID))}${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(getApiAvailableconstraintFlowKeyProviderComponentIDResponse, await res.json()) };