index.d.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // Generated by dts-bundle-generator v9.5.1
  2. import { NextFunction as ExpressNextFunction, Request as ExpressRequest, Response as ExpressResponse } from 'express';
  3. import { WebSocket as WS } from 'ws';
  4. export declare abstract class HttpHandler {
  5. protected abstract route: string | null;
  6. protected abstract action: (...any: any[]) => any;
  7. protected context: any;
  8. constructor(context: Record<string, any>);
  9. setContext(context: Record<string, any>): HttpHandler;
  10. getContext(): Record<string, any>;
  11. getRoute(): string | null;
  12. getAction(): (...any: any[]) => any;
  13. }
  14. export declare enum HttpMethod {
  15. GET = 0,
  16. POST = 1
  17. }
  18. export declare abstract class Middleware extends HttpHandler {
  19. protected abstract order: number;
  20. protected abstract action: (...any: any[]) => any;
  21. getOrder(): number;
  22. }
  23. interface Request$1 extends ExpressRequest {
  24. }
  25. interface Response$1 extends ExpressResponse {
  26. }
  27. export declare abstract class Route extends HttpHandler {
  28. protected abstract method: HttpMethod;
  29. protected abstract action: (req: Request$1, res: Response$1) => any;
  30. protected get documentation(): string;
  31. getMethod(): HttpMethod;
  32. getDocumentation(): string;
  33. }
  34. export declare enum StatusCodes {
  35. CONTINUE = 100,
  36. SWITCHING_PROTOCOLS = 101,
  37. OK = 200,
  38. CREATED = 201,
  39. ACCEPTED = 202,
  40. NON_AUTHORITATIVE_INFORMATION = 203,
  41. NO_CONTENT = 204,
  42. RESET_CONTENT = 205,
  43. PARTIAL_CONTENT = 206,
  44. MULTIPLE_CHOICES = 300,
  45. MOVED_PERMANENTLY = 301,
  46. MOVED_TEMPORARILY = 302,
  47. SEE_OTHER = 303,
  48. NOT_MODIFIED = 304,
  49. USE_PROXY = 305,
  50. TEMPORARY_REDIRECT = 307,
  51. BAD_REQUEST = 400,
  52. UNAUTHORIZED = 401,
  53. PAYMENT_REQUIRED = 402,
  54. FORBIDDEN = 403,
  55. NOT_FOUND = 404,
  56. METHOD_NOT_ALLOWED = 405,
  57. NOT_ACCEPTABLE = 406,
  58. PROXY_AUTHENTICATION_REQUIRED = 407,
  59. REQUEST_TIMEOUT = 408,
  60. CONFLICT = 409,
  61. GONE = 410,
  62. LENGTH_REQUIRED = 411,
  63. PRECONDITION_FAILED = 412,
  64. REQUEST_ENTITY_TOO_LARGE = 413,
  65. REQUEST_URI_TOO_LONG = 414,
  66. UNSUPPORTED_MEDIA_TYPE = 415,
  67. REQUESTED_RANGE_NOT_SATISFIABLE = 416,
  68. EXPECTATION_FAILED = 417,
  69. INTERNAL_SERVER_ERROR = 500,
  70. NOT_IMPLEMENTED = 501,
  71. BAD_GATEWAY = 502,
  72. SERVICE_UNAVAILABLE = 503,
  73. GATEWAY_TIMEOUT = 504,
  74. HTTP_VERSION_NOT_SUPPORTED = 505
  75. }
  76. export interface NextFunction extends ExpressNextFunction {
  77. }
  78. export declare class Logger {
  79. private getTime;
  80. private log;
  81. info(message: string): void;
  82. error(message: string): void;
  83. warn(message: string): void;
  84. }
  85. export type Message = {
  86. type: string;
  87. text: string;
  88. };
  89. export declare abstract class WebSocketHandler {
  90. static Event: {
  91. CONNECTION: string;
  92. MESSAGE: string;
  93. CLOSE: string;
  94. ERROR: string;
  95. };
  96. abstract onConnect: (ws: WS) => any;
  97. abstract onMessage: (message: string) => any;
  98. abstract onError: () => any;
  99. abstract onClose: (code?: number, reason?: string) => any;
  100. }
  101. export type ServerProperties = {
  102. port: number;
  103. host?: string;
  104. middlewaresPath?: string;
  105. sessions?: boolean;
  106. routesPath?: string;
  107. json?: boolean;
  108. urlencoded?: boolean;
  109. locale?: string;
  110. i18nPath?: string;
  111. viewEngine?: string;
  112. viewsPath?: string;
  113. swagger?: {
  114. docsPath?: string;
  115. title?: string;
  116. version?: string;
  117. route?: string;
  118. description?: string;
  119. components?: object;
  120. security?: object;
  121. };
  122. wsHandlers?: {
  123. [url: string]: WebSocketHandler;
  124. };
  125. options?: {
  126. [key: string]: any;
  127. };
  128. };
  129. declare abstract class Registry {
  130. private static httpHandlers;
  131. private server;
  132. protected abstract registerRoutes(): Promise<Registry>;
  133. protected abstract registerMiddlewares(): Promise<Registry>;
  134. registerHttpHandlers(): Promise<Registry>;
  135. protected registerHttpHandler(handler: HttpHandler): Registry;
  136. setServer(server: Server): Registry;
  137. getServer(): Server | null;
  138. static getHttpHandlers(): HttpHandler[];
  139. }
  140. /** @sealed */
  141. export declare class Server {
  142. private instance;
  143. private httpServer;
  144. private readonly port;
  145. private readonly host;
  146. private readonly logger;
  147. private i18n;
  148. private readonly wsHandlers;
  149. private readonly wsServers;
  150. private initialized;
  151. private readonly i18nPath?;
  152. private readonly middlewaresPath?;
  153. private readonly routesPath?;
  154. private readonly viewEngine?;
  155. private readonly viewsPath?;
  156. private readonly options?;
  157. private readonly swaggerComponents?;
  158. private readonly swaggerSecurity?;
  159. private readonly swaggerDocsPath?;
  160. private readonly swaggerTitle?;
  161. private readonly swaggerDescription?;
  162. private readonly swaggerApiVersion?;
  163. private readonly swaggerRoute?;
  164. static registry: Registry;
  165. private readonly systemRegistry;
  166. constructor(properties: ServerProperties);
  167. private init;
  168. private postInit;
  169. private processHttpHandlers;
  170. addMiddleware(middleware: Middleware): Server;
  171. addRoute(route: Route): Server;
  172. private registerRoutesDocumentation;
  173. registerWsServers(): Server;
  174. applyWsHandlers(): Server;
  175. getWsConnections(url: string): Set<WS> | null;
  176. logInfo(message: string): void;
  177. logError(message: string): void;
  178. logWarn(message: string): void;
  179. log(message: Message): void;
  180. private get;
  181. private post;
  182. getLogger(): Logger;
  183. i18nLoad(path: string): Server;
  184. getHost(): string;
  185. getOption(key: string): any;
  186. start(callback?: () => any): Promise<Server>;
  187. }
  188. export declare class IncorrectMethodException extends Error {
  189. constructor();
  190. }
  191. export declare class InvalidMiddlewareException extends Error {
  192. constructor(file: string);
  193. }
  194. export declare class InvalidRouteException extends Error {
  195. constructor(file: string);
  196. }
  197. export declare class RouteNotSetException extends Error {
  198. constructor();
  199. }
  200. export declare class ServerNotInitializedException extends Error {
  201. constructor();
  202. }
  203. export declare class Guid {
  204. static new(): string;
  205. }
  206. export type i18nMap = {
  207. [key: string]: {
  208. [key: string]: string;
  209. };
  210. };
  211. export type KeyParams = {
  212. [key: string]: any;
  213. };
  214. export declare class i18nLoader {
  215. private static instance;
  216. private readonly map;
  217. private locale;
  218. static defaultLocale: string;
  219. constructor(locale: string);
  220. static getInstance(locale?: string): i18nLoader;
  221. setLocale(locale: string): i18nLoader;
  222. load(...paths: string[]): i18nLoader;
  223. loadJson(obj: i18nMap): i18nLoader;
  224. get(key: string): string;
  225. }
  226. export declare const $: (key: string, params?: KeyParams) => string;
  227. export declare enum SwaggerParameterIn {
  228. PATH = "path",
  229. QUERY = "query",
  230. HEADER = "header",
  231. COOKIE = "cookie",
  232. BODY = "body",
  233. REQUEST_BODY = "requestBody"
  234. }
  235. export type SwaggerSchema = {
  236. type: string;
  237. description?: string;
  238. example?: string;
  239. items?: SwaggerSchema[];
  240. properties?: {
  241. [name: string]: SwaggerSchema;
  242. };
  243. };
  244. export type SwaggerParameter = {
  245. in: SwaggerParameterIn;
  246. name: string;
  247. required: boolean;
  248. description: string;
  249. schema?: SwaggerSchema;
  250. };
  251. export type SwaggerRequestBodyContent = {
  252. mediaType: string;
  253. schema: SwaggerSchema;
  254. };
  255. export type SwaggerRequestBody = {
  256. required: boolean;
  257. description: string;
  258. content: SwaggerRequestBodyContent;
  259. };
  260. export type SwaggerResponseContent = {
  261. mediaType: string;
  262. schema: SwaggerSchema;
  263. };
  264. export type SwaggerResponse = {
  265. code: number;
  266. description: string;
  267. content?: SwaggerResponseContent;
  268. };
  269. export declare class SwaggerDoc {
  270. private method;
  271. private route?;
  272. private summary?;
  273. private description?;
  274. private requestBody?;
  275. private parameters;
  276. private responses;
  277. private security;
  278. static get(route: string): SwaggerDoc;
  279. static post(route: string): SwaggerDoc;
  280. private constructor();
  281. private setRoute;
  282. setSummary(summary: string): SwaggerDoc;
  283. setDescription(description: string): SwaggerDoc;
  284. setRequestBody(requestBody: SwaggerRequestBody): SwaggerDoc;
  285. addParameter(param: SwaggerParameter): SwaggerDoc;
  286. addResponse(res: SwaggerResponse): SwaggerDoc;
  287. addSecurityScheme(scheme: string): SwaggerDoc;
  288. toAnnotation(): string;
  289. private getMethod;
  290. private deserializeSchema;
  291. private repeatStr;
  292. }
  293. export {
  294. Request$1 as Request,
  295. Response$1 as Response,
  296. };
  297. export {};