typizator-client
Version:
Client library for a generic server API creator with typizator and cdk-typescript-lib
43 lines (42 loc) • 1.92 kB
TypeScript
import { ApiDefinition, ApiImplementationWithVisibility, ApiMetadata } from "typizator";
export declare const API_URL_PARAM = "ApiUrl";
export type SubApiUrls<T extends ApiDefinition> = {
[K in keyof T as T[K] extends ApiDefinition ? K : never]?: T[K] extends ApiDefinition ? Partial<BaseUrlInformation<T[K]>> : never;
};
/**
* Information about the connection to the server HTTP/JSON API
*/
export type BaseUrlInformation<T extends ApiDefinition> = {
/**
* Base URL for the API
*/
url: string;
/**
* You usually don't have to use it directly, it is used to track URLs in sub-APIs
*/
path?: string;
/**
* URL information for the child APIs. You can override the URLs for some of them
*/
children?: SubApiUrls<T>;
/**
* Freezer function that is called when the server call is started. Allows to freeze the interface if needed
*/
freeze?: () => void;
/**
* Unfreezer function that is called when the server call is finishied (whatever is the result). Allows to unfreeze the interface if needed
*/
unfreeze?: () => void;
/**
* If true, configure API to ignore CORS restrictions
*/
wildcardCors?: boolean;
};
/**
* Connects to the server API defined by a typizator API schema
* @param metadata API schema definition allowing strict typing of parameters and return types of the methods
* @param connectivity Information on how to connect to the backend server. See `BaseUrlInformation` for details
* @param securityProvider Optional function returning a security token that will be sent to the server as X-Security-Token header
* @returns Callable API with every method implemented as `async` function
*/
export declare const connectTsApi: <T extends ApiDefinition>(metadata: ApiMetadata<T>, connectivity: BaseUrlInformation<T>, securityProvider?: () => string) => ApiImplementationWithVisibility<T>;