|
1 | | -import { InjectorService, LocalsContainer } from "@tsed/di"; |
2 | | -import { EndpointMetadata } from "../../mvc/models/EndpointMetadata"; |
3 | | -import { PlatformRequest } from "../services/PlatformRequest"; |
4 | | -import { PlatformResponse } from "../services/PlatformResponse"; |
5 | | -import { RequestLogger } from "./RequestLogger"; |
| 1 | +import {InjectorService, LocalsContainer} from "@tsed/di"; |
| 2 | +import {EndpointMetadata} from "../../mvc/models/EndpointMetadata"; |
| 3 | +import {PlatformRequest} from "../services/PlatformRequest"; |
| 4 | +import {PlatformResponse} from "../services/PlatformResponse"; |
| 5 | +import {RequestLogger} from "./RequestLogger"; |
6 | 6 |
|
7 | 7 | export interface RequestContextOptions { |
8 | | - id: string; |
9 | | - logger: any; |
10 | | - url: string; |
11 | | - ignoreUrlPatterns?: any[]; |
12 | | - level?: "debug" | "info" | "warn" | "error" | "off"; |
13 | | - maxStackSize?: number; |
14 | | - injector?: InjectorService; |
15 | | - response?: PlatformResponse; |
16 | | - request?: PlatformRequest; |
17 | | - endpoint?: EndpointMetadata; |
| 8 | + id: string; |
| 9 | + logger: any; |
| 10 | + url: string; |
| 11 | + ignoreUrlPatterns?: any[]; |
| 12 | + level?: "debug" | "info" | "warn" | "error" | "off"; |
| 13 | + maxStackSize?: number; |
| 14 | + injector?: InjectorService; |
| 15 | + response?: PlatformResponse; |
| 16 | + request?: PlatformRequest; |
| 17 | + endpoint?: EndpointMetadata; |
18 | 18 | } |
19 | 19 | export declare class RequestContext extends Map<any, any> { |
20 | | - /** |
21 | | - * Request id generated by @@contextMiddleware@@. |
22 | | - * |
23 | | - * ::: tip |
24 | | - * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, ""))`. |
25 | | - * Dash are removed to simplify tracking logs in Kibana |
26 | | - * ::: |
27 | | - * |
28 | | - * ::: tip |
29 | | - * Request id can by customized by changing the server configuration. |
30 | | - * |
31 | | - * ```typescript |
32 | | - * @ServerSettings({ |
33 | | - * logger: { |
34 | | - * reqIdBuilder: createUniqId // give your own id generator function |
35 | | - * } |
36 | | - * }) |
37 | | - * class Server { |
38 | | - * |
39 | | - * } |
40 | | - * ``` |
41 | | - * ::: |
42 | | - * |
43 | | - */ |
44 | | - readonly id: string; |
45 | | - /** |
46 | | - * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration. |
47 | | - */ |
48 | | - readonly dateStart: Date; |
49 | | - /** |
50 | | - * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)` |
51 | | - */ |
52 | | - container: LocalsContainer<any>; |
53 | | - /** |
54 | | - * The current @@EndpointMetadata@@ resolved by Ts.ED during the request. |
55 | | - */ |
56 | | - endpoint: EndpointMetadata; |
57 | | - /** |
58 | | - * The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty. |
59 | | - */ |
60 | | - data: any; |
61 | | - /** |
62 | | - * Logger attached to the context request. |
63 | | - */ |
64 | | - logger: RequestLogger; |
65 | | - /** |
66 | | - * The current @@PlatformResponse@@. |
67 | | - */ |
68 | | - response: PlatformResponse; |
69 | | - /** |
70 | | - * The current @@PlatformRequest@@. |
71 | | - */ |
72 | | - request: PlatformRequest; |
73 | | - /** |
74 | | - * |
75 | | - */ |
76 | | - injector: InjectorService; |
77 | | - constructor({ id, injector, logger, response, request, endpoint, ...options }: RequestContextOptions); |
78 | | - destroy(): Promise<void>; |
79 | | - emit(eventName: string, ...args: any[]): Promise<void>; |
| 20 | + /** |
| 21 | + * Request id generated by @@contextMiddleware@@. |
| 22 | + * |
| 23 | + * ::: tip |
| 24 | + * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, ""))`. |
| 25 | + * Dash are removed to simplify tracking logs in Kibana |
| 26 | + * ::: |
| 27 | + * |
| 28 | + * ::: tip |
| 29 | + * Request id can by customized by changing the server configuration. |
| 30 | + * |
| 31 | + * ```typescript |
| 32 | + * @ServerSettings({ |
| 33 | + * logger: { |
| 34 | + * reqIdBuilder: createUniqId // give your own id generator function |
| 35 | + * } |
| 36 | + * }) |
| 37 | + * class Server { |
| 38 | + * |
| 39 | + * } |
| 40 | + * ``` |
| 41 | + * ::: |
| 42 | + * |
| 43 | + */ |
| 44 | + readonly id: string; |
| 45 | + /** |
| 46 | + * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration. |
| 47 | + */ |
| 48 | + readonly dateStart: Date; |
| 49 | + /** |
| 50 | + * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)` |
| 51 | + */ |
| 52 | + container: LocalsContainer<any>; |
| 53 | + /** |
| 54 | + * The current @@EndpointMetadata@@ resolved by Ts.ED during the request. |
| 55 | + */ |
| 56 | + endpoint: EndpointMetadata; |
| 57 | + /** |
| 58 | + * The data return by the previous endpoint if you use multiple handler on the same route. By default data is empty. |
| 59 | + */ |
| 60 | + data: any; |
| 61 | + /** |
| 62 | + * Logger attached to the context request. |
| 63 | + */ |
| 64 | + logger: RequestLogger; |
| 65 | + /** |
| 66 | + * The current @@PlatformResponse@@. |
| 67 | + */ |
| 68 | + response: PlatformResponse; |
| 69 | + /** |
| 70 | + * The current @@PlatformRequest@@. |
| 71 | + */ |
| 72 | + request: PlatformRequest; |
| 73 | + /** |
| 74 | + * |
| 75 | + */ |
| 76 | + injector: InjectorService; |
| 77 | + constructor({id, injector, logger, response, request, endpoint, ...options}: RequestContextOptions); |
| 78 | + destroy(): Promise<void>; |
| 79 | + emit(eventName: string, ...args: any[]): Promise<void>; |
80 | 80 | } |
0 commit comments