index.d.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. json?: boolean;
  105. urlencoded?: boolean;
  106. locale?: string;
  107. i18nPath?: string;
  108. middlewaresPath?: string;
  109. routesPath?: string;
  110. viewEngine?: string;
  111. viewsPath?: string;
  112. swagger?: {
  113. docsPath?: string;
  114. title?: string;
  115. version?: string;
  116. route?: string;
  117. description?: string;
  118. components?: object;
  119. security?: object;
  120. };
  121. wsHandlers?: {
  122. [url: string]: WebSocketHandler;
  123. };
  124. options?: {
  125. [key: string]: any;
  126. };
  127. };
  128. /** @sealed */
  129. export declare class Server {
  130. private instance;
  131. private httpServer;
  132. private readonly port;
  133. private readonly host;
  134. private readonly logger;
  135. private i18n;
  136. private readonly httpHandlers;
  137. private readonly wsHandlers;
  138. private readonly wsServers;
  139. private initialized;
  140. private readonly i18nPath?;
  141. private readonly middlewaresPath?;
  142. private readonly routesPath?;
  143. private readonly viewEngine?;
  144. private readonly viewsPath?;
  145. private readonly options?;
  146. private readonly swaggerComponents?;
  147. private readonly swaggerSecurity?;
  148. private readonly swaggerDocsPath?;
  149. private readonly swaggerTitle?;
  150. private readonly swaggerDescription?;
  151. private readonly swaggerApiVersion?;
  152. private readonly swaggerRoute?;
  153. private swagger;
  154. private json;
  155. private urlencoded;
  156. constructor(properties: ServerProperties);
  157. init(): Promise<Server>;
  158. private postInit;
  159. private processHttpHandlers;
  160. addMiddleware(middleware: Middleware): Server;
  161. addRoute(route: Route): Server;
  162. private registerRoutesDocumentation;
  163. registerWsServers(): Server;
  164. applyWsHandlers(): Server;
  165. getWsConnections(url: string): Set<WS> | null;
  166. logInfo(message: string): void;
  167. logError(message: string): void;
  168. logWarn(message: string): void;
  169. log(message: Message): void;
  170. private get;
  171. private post;
  172. private registerSystemMiddlewares;
  173. private appendHttpHandler;
  174. registerRoutes(dir: string): Promise<Server>;
  175. registerMiddlewares(dir: string): Promise<Server>;
  176. getLogger(): Logger;
  177. i18nLoad(path: string): Server;
  178. getHost(): string;
  179. getOption(key: string): any;
  180. start(callback?: () => any): void;
  181. }
  182. export declare class IncorrectMethodException extends Error {
  183. constructor();
  184. }
  185. export declare class InvalidMiddlewareException extends Error {
  186. constructor(file: string);
  187. }
  188. export declare class InvalidRouteException extends Error {
  189. constructor(file: string);
  190. }
  191. export declare class RouteNotSetException extends Error {
  192. constructor();
  193. }
  194. export declare class ServerNotInitializedException extends Error {
  195. constructor();
  196. }
  197. export declare class Guid {
  198. static new(): string;
  199. }
  200. export type i18nMap = {
  201. [key: string]: {
  202. [key: string]: string;
  203. };
  204. };
  205. export type KeyParams = {
  206. [key: string]: any;
  207. };
  208. export declare class i18nLoader {
  209. private static instance;
  210. private readonly map;
  211. private locale;
  212. static defaultLocale: string;
  213. constructor(locale: string);
  214. static getInstance(locale?: string): i18nLoader;
  215. setLocale(locale: string): i18nLoader;
  216. load(...paths: string[]): i18nLoader;
  217. loadJson(obj: i18nMap): i18nLoader;
  218. get(key: string): string;
  219. }
  220. export declare const $$: (key: string, params?: KeyParams) => string;
  221. export declare enum SwaggerParameterIn {
  222. PATH = "path",
  223. QUERY = "query",
  224. HEADER = "header",
  225. COOKIE = "cookie",
  226. BODY = "body",
  227. REQUEST_BODY = "requestBody"
  228. }
  229. export type SwaggerSchema = {
  230. type: string;
  231. description?: string;
  232. example?: string;
  233. items?: SwaggerSchema[];
  234. properties?: {
  235. [name: string]: SwaggerSchema;
  236. };
  237. };
  238. export type SwaggerParameter = {
  239. in: SwaggerParameterIn;
  240. name: string;
  241. required: boolean;
  242. description: string;
  243. schema?: SwaggerSchema;
  244. };
  245. export type SwaggerRequestBodyContent = {
  246. mediaType: string;
  247. schema: SwaggerSchema;
  248. };
  249. export type SwaggerRequestBody = {
  250. required: boolean;
  251. description: string;
  252. content: SwaggerRequestBodyContent;
  253. };
  254. export type SwaggerResponseContent = {
  255. mediaType: string;
  256. schema: SwaggerSchema;
  257. };
  258. export type SwaggerResponse = {
  259. code: number;
  260. description: string;
  261. content?: SwaggerResponseContent;
  262. };
  263. export declare class SwaggerDoc {
  264. private method;
  265. private route?;
  266. private summary?;
  267. private description?;
  268. private requestBody?;
  269. private parameters;
  270. private responses;
  271. private security;
  272. static get(route: string): SwaggerDoc;
  273. static post(route: string): SwaggerDoc;
  274. private constructor();
  275. private setRoute;
  276. setSummary(summary: string): SwaggerDoc;
  277. setDescription(description: string): SwaggerDoc;
  278. setRequestBody(requestBody: SwaggerRequestBody): SwaggerDoc;
  279. addParameter(param: SwaggerParameter): SwaggerDoc;
  280. addResponse(res: SwaggerResponse): SwaggerDoc;
  281. addSecurityScheme(scheme: string): SwaggerDoc;
  282. toAnnotation(): string;
  283. private getMethod;
  284. private deserializeSchema;
  285. private repeatStr;
  286. }
  287. export {
  288. Request$1 as Request,
  289. Response$1 as Response,
  290. };
  291. export {};