/** * Created by tacb0ss on 11/07/2018. */ import { ApiException, Logger, TypedMap, ValidatorTypeResolver } from '@nu-art/ts-common'; import { Stream } from 'stream'; import { ExpressRequest, ExpressResponse, ExpressRouter, ServerApi_Middleware } from '../../utils/types.js'; import { MemKey } from '@nu-art/ts-common/mem-storage/MemStorage'; import { ApiDef, BodyApi, HttpMethod_Body, HttpMethod_Query, QueryApi, TypedApi } from '../../../shared/types.js'; export declare const MemKey_ServerApi: MemKey>; export declare abstract class ServerApi> extends Logger { static isDebug: boolean; printResponse: boolean; printRequest: boolean; headersToLog: string[]; private url; private middlewares?; private bodyValidator?; private queryValidator?; readonly apiDef: ApiDef; private postCallActions; protected constructor(apiDef: ApiDef, tag?: string); setMiddlewares(...middlewares: ServerApi_Middleware[]): this; addPostCallAction(sideEffect: () => Promise): this; addMiddlewares(...middlewares: ServerApi_Middleware[]): this; addMiddleware(middleware: ServerApi_Middleware): this; addHeaderToLog(...headersToLog: string[]): void; setBodyValidator(bodyValidator: ValidatorTypeResolver): void; setQueryValidator(queryValidator: ValidatorTypeResolver): void; getUrl(): string; dontPrintResponse(): void; dontPrintRequest(): void; setMaxResponsePrintSize(printResponseMaxSizeBytes: number): void; route(router: ExpressRouter, prefixUrl: string): void; private callWrapper; private performPostCallActions; call: (req: ExpressRequest, res: ExpressResponse) => Promise; protected abstract process(): Promise; } export declare abstract class ServerApi_Get> extends ServerApi { protected constructor(apiDef: ApiDef); } export declare abstract class ServerApi_Post> extends ServerApi { protected constructor(apiDef: ApiDef); } export declare class ServerApi_Redirect> extends ServerApi { private readonly responseCode; private readonly redirectUrl; constructor(apiDef: ApiDef, responseCode: number, redirectUrl: string); protected process(): Promise; } export declare class _ServerQueryApi> extends ServerApi_Get { private readonly action; constructor(apiDef: ApiDef, action: (params: API['P']) => Promise); protected process(): Promise; } export declare class _ServerBodyApi> extends ServerApi_Post { private readonly action; constructor(apiDef: ApiDef, action: (params: API['B']) => Promise); protected process(): Promise; } export declare class ApiResponse { private api; private readonly res; private consumed; private headers?; constructor(api: ServerApi, res: ExpressResponse); setHeader(key: string, value: string): void; addHeader(key: string, value: string): void; isConsumed(): boolean; private consume; stream(responseCode: number, stream: Stream, _headers?: {}): void; private printHeaders; private printResponse; code(responseCode: number, _headers?: any): void; text(responseCode: number, response?: string, _headers?: any): void; html(responseCode: number, response?: string, _headers?: any): void; json(responseCode: number, response?: object | string, _headers?: any): void; private _json; end(responseCode: number, response?: object | string, _headers?: any): void; redirect(responseCode: number, url: string, _headers?: TypedMap): void; exception(exception: ApiException, _headers?: any): void; serverError(error: Error & { cause?: Error; }, _headers?: any): void; }