import {z} from 'zod' export type GetApiTaxonomyAssetsArgs = {assets?: Array | undefined, class_ids?: Array | undefined, sector_ids?: Array | undefined, subsector_ids?: Array | undefined, version?: string | undefined, classification_start_time?: string | undefined, classification_end_time?: string | undefined, start_inclusive?: boolean | undefined, end_inclusive?: boolean | undefined, page_size?: number | undefined, paging_from?: ('start' | 'end') | undefined, next_page_token?: string | undefined, pretty?: boolean | undefined}; export type GetApiTaxonomyAssetsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const asset = z.string(); export const taxonomyAssetFullName = z.string(); export const taxonomyVersion = z.string(); export const updatedAtTaxonomyVersion = z.string(); export const taxonomyAssetClassificationStartTime = z.string(); export const taxonomyAssetClassificationEndTime = z.string(); export const taxonomyClassId = z.string(); export const taxonomyClass = z.string(); export const taxonomySectorId = z.string(); export const taxonomySector = z.string(); export const taxonomySubsectorId = z.string(); export const taxonomySubsector = z.string(); export const taxonomyAsset = z.object({asset: asset, full_name: taxonomyAssetFullName, taxonomy_version: taxonomyVersion, updated_at_taxonomy_version: updatedAtTaxonomyVersion, classification_start_time: taxonomyAssetClassificationStartTime, classification_end_time: taxonomyAssetClassificationEndTime.optional(), class_id: taxonomyClassId, class: taxonomyClass, sector_id: taxonomySectorId, sector: taxonomySector, subsector_id: taxonomySubsectorId, subsector: taxonomySubsector}); export const nextPageToken = z.string(); export const nextPageUrl = z.string(); export const taxonomyAssetsResponse = z.object({data: z.array(taxonomyAsset), next_page_token: nextPageToken.optional(), next_page_url: nextPageUrl.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 }; /** * Taxonomy for assets * * GET /taxonomy/assets */ export const getApiTaxonomyAssets = async (args: GetApiTaxonomyAssetsArgs, options?: GetApiTaxonomyAssetsOptions) => { const {baseUrl = "https://api.coinmetrics.io/v4", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.assets != null) query.append("assets", args.assets.join(',')) if (args.class_ids != null) query.append("class_ids", args.class_ids.join(',')) if (args.sector_ids != null) query.append("sector_ids", args.sector_ids.join(',')) if (args.subsector_ids != null) query.append("subsector_ids", args.subsector_ids.join(',')) if (args.version != null) query.append("version", String(args.version)) if (args.classification_start_time != null) query.append("classification_start_time", String(args.classification_start_time)) if (args.classification_end_time != null) query.append("classification_end_time", String(args.classification_end_time)) if (args.start_inclusive != null) query.append("start_inclusive", String(args.start_inclusive)) if (args.end_inclusive != null) query.append("end_inclusive", String(args.end_inclusive)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.paging_from != null) query.append("paging_from", String(args.paging_from)) if (args.next_page_token != null) query.append("next_page_token", String(args.next_page_token)) if (args.pretty != null) query.append("pretty", String(args.pretty)) if (apiKey !== undefined) query.set("api_key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/taxonomy/assets${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(taxonomyAssetsResponse, await res.json()) };