hn-api-sdk
Version:
HackerNews API with TypeScript, generated by tsdk
40 lines (38 loc) • 1.62 kB
TypeScript
import { APIConfig, ObjectLiteral } from './shared/tsdk-helper';
import type { XiorRequestConfig } from './xior';
type RequestConfig<T> = XiorRequestConfig<T>;
declare let handler: (apiConfig: APIConfig, requestData: any, requestConfig?: any | RequestConfig<any> | ObjectLiteral | XiorRequestConfig<any>) => Promise<any>;
export type Handler = typeof handler;
/**
* @example
* ```ts
* setAxiosInstance(axios.create())
setSocketIOInstance(io());
setHandler(axiosHandler);
setHandler(socketIOHandler);
* ```
* @param _handler
*/
export declare function setHandler(_handler: typeof handler): void;
export declare function getHandler(): (apiConfig: APIConfig, requestData: any, requestConfig?: any | RequestConfig<any> | ObjectLiteral | XiorRequestConfig<any>) => Promise<any>;
/**
* Generate API
*
* @param apiConfig - {@link APIConfig}
*
* @example
* ```ts
* const apiDemo = genApi<ApiDemoReqPayload, ApiDemoResData>(ApiDemoConfig);
* ```
*/
export default function genAPICall<ReqPayload, ResData>(apiConfig: APIConfig): {
(data: ReqPayload, requestConfig?: RequestConfig<ReqPayload> | ObjectLiteral, customHandler?: typeof handler): Promise<ResData>;
config: APIConfig;
};
export type Expand<T> = T extends (...args: infer A) => infer R ? (...args: Expand<A>) => Expand<R> : T extends infer O ? {
[K in keyof O]: O[K];
} : never;
export type ExpandRecursively<T> = T extends (...args: infer A) => infer R ? (...args: ExpandRecursively<A>) => ExpandRecursively<R> : T extends object ? T extends infer O ? {
[K in keyof O]: ExpandRecursively<O[K]>;
} : never : T;
export {};