import {z} from 'zod' export type GetApiCollectionsCollectionIdItemsArgs = {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', limit?: number | undefined, bbox?: Array | undefined, datetime?: string | undefined, filter?: string | undefined, 'filter-lang'?: ('cql-text' | 'cql-json') | undefined, sortby?: Array | undefined, crs?: string | undefined, 'bbox-crs'?: string | undefined, otherParameters?: {[key: string]: unknown} | undefined}; export type GetApiCollectionsCollectionIdItemsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pointGeoJSON = z.object({type: z.literal("Point"), coordinates: z.array(z.number())}); export const multipointGeoJSON = z.object({type: z.literal("MultiPoint"), coordinates: z.array(z.array(z.number()))}); export const linestringGeoJSON = z.object({type: z.literal("LineString"), coordinates: z.array(z.array(z.number()))}); export const multilinestringGeoJSON = z.object({type: z.literal("MultiLineString"), coordinates: z.array(z.array(z.array(z.number())))}); export const polygonGeoJSON = z.object({type: z.literal("Polygon"), coordinates: z.array(z.array(z.array(z.number())))}); export const multipolygonGeoJSON = z.object({type: z.literal("MultiPolygon"), coordinates: z.array(z.array(z.array(z.array(z.number()))))}); export const geometrycollectionGeoJSON = z.object({type: z.literal("GeometryCollection"), geometries: z.array(z.lazy(() => geometryGeoJSON))}); export const geometryGeoJSON: z.ZodType = z.union([pointGeoJSON, multipointGeoJSON, linestringGeoJSON, multilinestringGeoJSON, polygonGeoJSON, multipolygonGeoJSON, geometrycollectionGeoJSON]); export const link = z.object({href: z.string(), rel: z.string().optional(), type: z.string().optional(), hreflang: z.string().optional(), title: z.string().optional(), length: z.number().int().optional()}); export const featureGeoJSON = z.object({type: z.literal("Feature"), geometry: geometryGeoJSON, properties: z.object({}).nullable(), id: z.union([z.string(), z.number().int()]).optional(), links: z.array(link).optional()}); export const timeStamp = z.string(); export const numberMatched = z.number().int().gte(0); export const numberReturned = z.number().int().gte(0); export const featureCollectionGeoJSON = z.object({type: z.literal("FeatureCollection"), features: z.array(featureGeoJSON), links: z.array(link).optional(), timeStamp: timeStamp.optional(), numberMatched: numberMatched.optional(), numberReturned: numberReturned.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 }; /** * fetch features * * GET /collections/{collectionId}/items */ export const getApiCollectionsCollectionIdItems = async (args: GetApiCollectionsCollectionIdItemsArgs, options?: GetApiCollectionsCollectionIdItemsOptions) => { 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/geo+json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.bbox != null) query.append("bbox", args.bbox.join(',')) if (args.datetime != null) query.append("datetime", String(args.datetime)) if (args.filter != null) query.append("filter", String(args.filter)) if (args['filter-lang'] != null) query.append("filter-lang", String(args['filter-lang'])) if (args.sortby != null) query.append("sortby", args.sortby.join(',')) if (args.crs != null) query.append("crs", String(args.crs)) if (args['bbox-crs'] != null) query.append("bbox-crs", String(args['bbox-crs'])) if (args.otherParameters != null) query.append("otherParameters", JSON.stringify(args.otherParameters)) const url = `${baseUrl.replace(/\/+$/, '')}/collections/${encodeURIComponent(String(args.collectionId))}/items${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(featureCollectionGeoJSON, await res.json()) };