import {z} from 'zod' export type GetApiApiV1TopicsTopicIdsOrShortNamesIndicatorsArgs = {topicIdsOrShortNames: string, format?: string | undefined}; export type GetApiApiV1TopicsTopicIdsOrShortNamesIndicatorsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const topicIndicatorDto = z.object({topicId: z.number().int().optional(), topicName: z.string().nullable().optional(), topicShortName: z.string().nullable().optional(), indicatorId: z.number().int().optional(), indicatorName: z.string().nullable().optional(), indicatorDisplayName: z.string().nullable().optional(), indicatorShortName: z.string().nullable().optional(), indicatorDescription: z.string().nullable().optional(), dimAge: z.boolean().optional(), dimSex: z.boolean().optional(), dimVariant: z.boolean().optional(), dimCategory: z.boolean().optional(), defaultAgeId: z.number().int().optional(), defaultSexId: z.number().int().optional(), defaultVariantId: z.number().int().optional(), defaultCategoryId: z.number().int().optional(), unitScaling: z.number().optional(), formatString: z.string().nullable().optional(), unitLongLabel: z.string().nullable().optional(), unitShortLabel: z.string().nullable().optional(), variableType: z.string().nullable().optional(), sourceId: z.number().int().nullable().optional(), sourceName: z.string().nullable().optional(), sourceYear: z.number().int().nullable().optional(), sourceStartYear: z.number().int().nullable().optional(), sourceEndYear: z.number().int().nullable().optional(), sourceCitation: z.string().nullable().optional(), sourceUrl: z.string().nullable().optional()}); export const getApiApiV1TopicsTopicIdsOrShortNamesIndicatorsResponse = z.array(topicIndicatorDto); 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 }; /** * Gets an object Hierarchy of Topics | Indicators | Sources * * GET /api/v1/topics/{topicIdsOrShortNames}/indicators */ export const getApiApiV1TopicsTopicIdsOrShortNamesIndicators = async (args: GetApiApiV1TopicsTopicIdsOrShortNamesIndicatorsArgs, options: GetApiApiV1TopicsTopicIdsOrShortNamesIndicatorsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.format != null) query.append("format", String(args.format)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/topics/${encodeURIComponent(String(args.topicIdsOrShortNames))}/indicators${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(getApiApiV1TopicsTopicIdsOrShortNamesIndicatorsResponse, await res.json()) };