import { HttpMethod } from 'openapi-typescript-helpers'; import { RequiredKeys } from 'ts-essentials'; import { paths as projectPaths } from './openapi/project-api'; /** * Optional parameter that can be passed to the client methods. It allows * overriding the access token or project ID, and setting various headers, * such as 'Content-Type'. */ export interface ZapEHRClientRequest { /** * The access token to use for the request. If not provided, the access token from `zapehr.init()` will be used. */ accessToken?: string; /** * The project ID to use for the request. If not provided, the project ID from `zapehr.init()` will be used. */ projectId?: string; /** * The value of the 'Content-Type' header to use for the request. */ contentType?: string; } export interface InternalClientRequest extends ZapEHRClientRequest { ifMatch?: string; } export declare function projectClient>(path: Path): Client; type FetcherResponse = any; export declare function fetcher(baseUrlThunk: () => string, path: string, methodParam: string): (params?: Record | [any], request?: InternalClientRequest) => Promise; /** * Adds params to a URLSearchParams object in such a way as to preserve array values. * @param params params * @param search URLSearchParams object */ export declare function addParamsToSearch(params: Record, search: URLSearchParams): void; /** Helper Types **/ type AllPaths = projectPaths; type Client> = { [M in Method]: ClientMethod; }; type ClientMethod> = BodyParams extends never ? PathParams extends never ? (request?: ZapEHRClientRequest) => Promise> : RequiredPathParams extends never ? (params?: PathParams, request?: ZapEHRClientRequest) => Promise> : (params: PathParams, request?: ZapEHRClientRequest) => Promise> : PathParams extends never ? (params: BodyParams, request?: ZapEHRClientRequest) => Promise> : (params: Flatten & PathParams>, request?: ZapEHRClientRequest) => Promise>; type PathParams = AllPaths[Path] extends { [M in Method]: { parameters: { path?: infer P; query?: infer Q; }; }; } ? P & Q : never; type RequiredPathParams = RequiredKeys> extends never ? never : PathParams; type BodyParams = AllPaths[Path] extends { [M in Method]: any; } ? AllPaths[Path][Method] extends { requestBody?: { content: { 'application/json': infer B; }; }; } ? B : never : never; type PathResponseType = M extends { responses: infer Responses; } ? { [Response in keyof Responses]: Responses[Response] extends { content: { 'application/json': infer Content; }; } ? Content : Response extends 'default' ? Responses[Response] : never; } : never; type PathResponse> = AllPaths[Path] extends { [M in Method]: { responses: { 200: Record; }; }; } ? PathResponseType[200] : never; type Flatten = { [K in keyof T]: T[K]; } & {}; export {};