import {z} from 'zod' export type Pageable = {offset?: number | undefined, limit?: number | undefined}; export type GetApiV1SpeciesUsageKeyVernacularNamesArgs = {usageKey: number, arg1: Pageable, limit?: number | undefined, offset?: number | undefined}; export type GetApiV1SpeciesUsageKeyVernacularNamesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const vernacularName = z.object({taxonKey: z.number().int().optional(), vernacularName: z.string().optional(), language: z.enum(["abk", "aar", "afr", "aka", "sqi", "amh", "ara", "arg", "hye", "asm", "ava", "ave", "aym", "aze", "bam", "bak", "eus", "bel", "ben", "bih", "bis", "bos", "bre", "bul", "mya", "cat", "cha", "che", "zho", "chu", "chv", "cor", "cos", "cre", "hrv", "ces", "dan", "div", "nld", "dzo", "eng", "epo", "est", "ewe", "fao", "fij", "fin", "fra", "fry", "ful", "glg", "lug", "kat", "deu", "ell", "kal", "grn", "guj", "hat", "hau", "heb", "her", "hin", "hmo", "hun", "isl", "ido", "ibo", "ind", "ina", "ile", "iku", "ipk", "gle", "ita", "jpn", "jav", "kan", "kau", "kas", "kaz", "khm", "kik", "kin", "kir", "kom", "kon", "kor", "kur", "kua", "lao", "lat", "lav", "lim", "lin", "lit", "lub", "ltz", "mkd", "mlg", "msa", "mal", "mlt", "glv", "mri", "mar", "mah", "mol", "mon", "nau", "nav", "ndo", "nep", "nde", "sme", "nob", "nno", "nor", "nya", "oci", "oji", "ori", "orm", "oss", "pli", "pan", "fas", "pol", "por", "pus", "que", "roh", "ron", "run", "rus", "smo", "sag", "san", "srd", "gla", "srp", "sna", "iii", "snd", "sin", "slk", "slv", "som", "nbl", "sot", "spa", "sun", "swa", "ssw", "swe", "tgl", "tah", "tgk", "tam", "tat", "tel", "tha", "bod", "tir", "ton", "tso", "tsn", "tur", "tuk", "twi", "uig", "ukr", "urd", "uzb", "ven", "vie", "vol", "wln", "cym", "wol", "xho", "yid", "yor", "zha", "zul", ""]).optional(), lifeStage: z.enum(["ZYGOTE", "EMRYO", "LARVA", "JUVENILE", "ADULT", "SPOROPHYTE", "SPORE", "GAMETOPHYTE", "GAMETE", "PUPA"]).optional(), sex: z.enum(["NONE", "MALE", "FEMALE", "HERMAPHRODITE"]).optional(), country: z.enum(["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CD", "CG", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "SS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW", "AA", "XK", "XZ", "ZZ"]).optional(), area: z.string().optional(), source: z.string().optional(), sourceTaxonKey: z.number().int().optional(), preferred: z.boolean().optional(), plural: z.boolean().optional()}); export const pagingResponseVernacularName = z.object({offset: z.number().int().optional(), limit: z.number().int().optional(), endOfRecords: z.boolean().optional(), count: z.number().int().optional(), results: z.array(vernacularName).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 }; /** * Name usage vernacular names by id * * GET /v1/species/{usageKey}/vernacularNames */ export const getApiV1SpeciesUsageKeyVernacularNames = async (args: GetApiV1SpeciesUsageKeyVernacularNamesArgs, options?: GetApiV1SpeciesUsageKeyVernacularNamesOptions) => { const {baseUrl = "https://api.gbif.org", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.arg1 != null) query.append("arg1", JSON.stringify(args.arg1)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/species/${encodeURIComponent(String(args.usageKey))}/vernacularNames${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(pagingResponseVernacularName, await res.json()) };