import {z} from 'zod' export type GetApiCollectionsCollectionIdQueryablesArgs = {collectionId: 'CROPTYPES_DE_P1Y' | 'D4H' | 'DESIS_HSI_L2A' | 'DatKI_LBMDE_2021' | 'ENMAP_HSI_L0_QL' | 'ENMAP_HSI_L1B' | 'ENMAP_HSI_L1C' | 'ENMAP_HSI_L2A' | 'EO4CAM_URBANISIERUNGSGRAD' | 'FCCL_DE_P1M' | 'FOREST_STRUCTURE_DE_AGBD_P1Y' | 'FOREST_STRUCTURE_DE_COVER_P1Y' | 'FOREST_STRUCTURE_DE_RH95_P1Y' | 'GL_MOW_DE_P1Y_FC' | 'GL_MOW_DE_P1Y_FREQ' | 'GSP_SCDE_MEAN' | 'GSP_SCDE_P1Y' | 'GSP_SCDL_MEAN' | 'GSP_SCDL_P1Y' | 'GSP_SCD_MEAN' | 'GSP_SCD_P1Y' | 'GSP_SCE_P1D' | 'GWP_P1D' | 'GWP_P1M' | 'GWP_P1Y' | 'LST_Germany' | 'METOP_GOME2_L3_P1D_BRO' | 'METOP_GOME2_L3_P1D_CF' | 'METOP_GOME2_L3_P1D_H2O' | 'METOP_GOME2_L3_P1D_HCHO' | 'METOP_GOME2_L3_P1D_NO2' | 'METOP_GOME2_L3_P1D_NO2TROPO' | 'METOP_GOME2_L3_P1D_O3' | 'METOP_GOME2_L3_P1D_SO2' | 'N2N_NOISE_AI_DE_2017' | 'N2N_NOISE_DE_2017' | 'S2-soilsuite-africa-2018-2021-P4Y' | 'S2-soilsuite-europe-2018-2022-P5Y' | 'S2_L2A_MAJA' | 'S2_L2A_MAJA_v2' | 'S2_L3A_WASP' | 'S2_L3A_WASP_V2' | 'S5P_TROPOMI_L3_P1D_AI_v2' | 'S5P_TROPOMI_L3_P1D_ALH_v2' | 'S5P_TROPOMI_L3_P1D_AOD_v2' | 'S5P_TROPOMI_L3_P1D_ASSA_v2' | 'S5P_TROPOMI_L3_P1D_CF_v2' | 'S5P_TROPOMI_L3_P1D_COT_v2' | 'S5P_TROPOMI_L3_P1D_CTH_v2' | 'S5P_TROPOMI_L3_P1D_H2O_v2' | 'S5P_TROPOMI_L3_P1D_HCHO_v2' | 'S5P_TROPOMI_L3_P1D_O3_v2' | 'S5P_TROPOMI_L3_P1D_SO2LH_v2' | 'S5P_TROPOMI_L3_P1D_SO2_v2' | 'S5P_TROPOMI_L3_P1D_UVI_v2' | 'S5P_TROPOMI_L4_P1D_NO2surf' | 'SAR4TEC_ASCE' | 'SAR4TEC_DESC' | 'SUPERSITES' | 'SWIM_WE' | 'TDM_DEM_90' | 'TDM_FNF_50' | 'TIMELINE_AVHRR_P1M_LSTD' | 'TIMELINE_AVHRR_P1M_SST' | 'URBAN_DEGREE_DE' | 'WSF3D_MATSTOCK' | 'WSF_2015' | 'WSF_2019' | 'WSF_Evolution' | 'WSF_TRACKER', otherParameters?: {[key: string]: unknown} | undefined}; export type GetApiCollectionsCollectionIdQueryablesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const queryable = z.object({id: z.string().optional(), type: z.enum(["string", "uri", "number", "integer", "date", "dateTime", "boolean", "geometry"])}); export const queryables = z.object({queryables: z.array(queryable)}); 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 }; /** * lists the queryable attributes for the feature collection with id `collectionId` * * GET /collections/{collectionId}/queryables */ export const getApiCollectionsCollectionIdQueryables = async (args: GetApiCollectionsCollectionIdQueryablesArgs, options?: GetApiCollectionsCollectionIdQueryablesOptions) => { const {baseUrl = "https://geoservice.dlr.de/eoc/ogc/stac/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.otherParameters != null) query.append("otherParameters", JSON.stringify(args.otherParameters)) const url = `${baseUrl.replace(/\/+$/, '')}/collections/${encodeURIComponent(String(args.collectionId))}/queryables${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(queryables, await res.json()) };