export type GetApiApiSearchArgs = {q: string, offset?: number | undefined, size?: (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10) | undefined, type?: Array | undefined}; export type GetApiApiSearchOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Search for anything. * * GET /api/search */ export const getApiApiSearch = async (args: GetApiApiSearchArgs, options: GetApiApiSearchOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.q != null) query.append("q", String(args.q)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.size != null) query.append("size", String(args.size)) for (const item of args.type ?? []) query.append("type", String(item)) const url = `${baseUrl.replace(/\/+$/, '')}/api/search${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 undefined };