import {z} from 'zod' export type GetApiTransformationschemeAgencyIDResourceIDVersionArgs = {agencyID: string, resourceID: string, version: string, references?: ('none' | 'parents' | 'parentsandsiblings' | 'children' | 'descendants' | 'all' | 'datastructure' | 'metadatastructure' | 'categoryscheme' | 'conceptscheme' | 'codelist' | 'hierarchicalcodelist' | 'organisationscheme' | 'agencyscheme' | 'dataproviderscheme' | 'dataconsumerscheme' | 'organisationunitscheme' | 'dataflow' | 'metadataflow' | 'reportingtaxonomy' | 'provisionagreement' | 'structureset' | 'process' | 'categorisation' | 'contentconstraint' | 'actualconstraint' | 'allowedconstraint' | 'attachmentconstraint' | 'transformationscheme' | 'rulesetscheme' | 'userdefinedoperatorscheme' | 'customtypescheme' | 'namepersonalisationscheme' | 'namealiasscheme') | undefined, detail?: ('allstubs' | 'referencestubs' | 'referencepartial' | 'allcompletestubs' | 'referencecompletestubs' | 'full') | undefined, 'Accept-Encoding'?: ('br' | 'compress' | 'deflate' | 'exi' | 'gzip' | 'identity' | 'pack200-gzip' | 'zstd') | undefined, 'Accept-Language'?: string | undefined, 'If-Modified-Since'?: string | undefined}; export type GetApiTransformationschemeAgencyIDResourceIDVersionOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiTransformationschemeAgencyIDResourceIDVersionResponse = 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 transformation schemes * * GET /transformationscheme/{agencyID}/{resourceID}/{version} */ export const getApiTransformationschemeAgencyIDResourceIDVersion = async (args: GetApiTransformationschemeAgencyIDResourceIDVersionArgs, options?: GetApiTransformationschemeAgencyIDResourceIDVersionOptions) => { 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.references != null) query.append("references", String(args.references)) if (args.detail != null) query.append("detail", String(args.detail)) 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(/\/+$/, '')}/transformationscheme/${encodeURIComponent(String(args.agencyID))}/${encodeURIComponent(String(args.resourceID))}/${encodeURIComponent(String(args.version))}${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(getApiTransformationschemeAgencyIDResourceIDVersionResponse, await res.json()) };