import { Translations } from "./components/LajiForm"; import { Lang } from "./types"; import type { paths } from "./generated/api"; export declare class LajiApiError extends Error { statusCode: number; constructor(message: string, statusCode: number); } interface Query { [param: string]: any; } export interface ApiClientImplementation { fetch: (path: string, query: Query, options: any) => Promise; } type RelaxQuery = P extends { query: infer Q; } ? Omit & (Record extends Omit> ? { query?: Omit> & Partial>>; } : { query: Omit> & Partial>>; }) : P; type MiddlewareInjectedKeys = "collectionID" | "formID"; type Parameters = "parameters" extends keyof T ? T["parameters"] : never; type ExtractContentIfExists = R extends { content: infer C; } ? C[keyof C] : null; type ExtractRequestBodyIfExists = R extends { requestBody: { content: infer C; }; } | { requestBody?: { content: infer C; }; } ? C[keyof C] : never; type HttpSuccessCodes = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226; type IntersectUnionTypes = A extends B ? A : never; type WithResponses = T & { responses: unknown; }; type Path = keyof paths & string; type PathWithMethod = keyof { [P in keyof paths as paths[P] extends Record ? P : never]: paths[P]; }; type Method

= Exclude; type Responses

> = WithResponses["responses"]; type CacheNode = { branches: Map; queries: Map>; path: string; }; /** * ApiClient with automatically generated typings for laji-api. An `ApiClientImplementation` must be provided, that will * perform the actual requests. The implementation acts as a middleware for injecting access token and person token. * * Get requests are automatically cached, and they will flush if the resource receives a POST/PUT/DELETE request. */ export default class ApiClient { apiClient: ApiClientImplementation; lang: Lang; translations: Translations; cacheTree: CacheNode; on: { [path: string]: (() => void)[]; }; constructor(apiClient: ApiClientImplementation, lang: Lang | undefined, translations: Translations); private flush; private getCacheNode; /** The response is cached until the resource receives a POST/PUT/DELETE request. */ get

, R extends Responses ? "get" : never>>(path: P, params?: RelaxQuery, MiddlewareInjectedKeys>, /** Defaults to true */ useCache?: boolean): Promise]>>; /** Subscribe to a GET request. It re-emits when the resource receives a POST/PUT/DELETE request. */ subscribe

, R extends Responses ? "get" : never>>(path: P, params: RelaxQuery, MiddlewareInjectedKeys> | undefined, onFulfilled: (response: ExtractContentIfExists]>) => void, onError?: () => void, /** * Store doesn't sync it's search indices right away after data is changed, so delaying the request can be useful */ delay?: number): () => void; put

, R extends Responses ? "put" : never>>(path: P, params?: RelaxQuery, MiddlewareInjectedKeys>, body?: ExtractRequestBodyIfExists): Promise]>>; post

, R extends Responses ? "post" : never>>(path: P, params?: RelaxQuery, MiddlewareInjectedKeys>, body?: ExtractRequestBodyIfExists): Promise]>>; delete

, R extends Responses ? "delete" : never>>(path: P, params?: RelaxQuery, MiddlewareInjectedKeys>): Promise]>>; /** * Implementing apiClient must return a promise that passes the raw response as 1st arg. * @param path URL for GET. * @param query Object, where keys are param names and values are param values. * @returns a Promise. */ fetch

, R extends Responses>(path: P, method: M, params?: Parameters, body?: ExtractRequestBodyIfExists, options?: any): Promise]>>; setLang(lang: Lang): void; } export {};