@deepkit/http 1.0.1-alpha.16 → 1.0.1-alpha.160

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +236 -0
  2. package/dist/cjs/index.d.ts +14 -10
  3. package/dist/cjs/index.js +19 -11
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/src/controllers.d.ts +10 -3
  6. package/dist/cjs/src/controllers.js +7 -3
  7. package/dist/cjs/src/controllers.js.map +1 -1
  8. package/dist/cjs/src/decorator.d.ts +144 -70
  9. package/dist/cjs/src/decorator.js +277 -102
  10. package/dist/cjs/src/decorator.js.map +1 -1
  11. package/dist/cjs/src/filter.d.ts +49 -0
  12. package/dist/cjs/src/filter.js +215 -0
  13. package/dist/cjs/src/filter.js.map +1 -0
  14. package/dist/cjs/src/http-app.d.ts +8 -0
  15. package/dist/cjs/src/http-app.js +16 -0
  16. package/dist/cjs/src/http-app.js.map +1 -0
  17. package/dist/cjs/src/http.d.ts +131 -32
  18. package/dist/cjs/src/http.js +523 -122
  19. package/dist/cjs/src/http.js.map +1 -1
  20. package/dist/cjs/src/kernel.d.ts +50 -9
  21. package/dist/cjs/src/kernel.js +109 -98
  22. package/dist/cjs/src/kernel.js.map +1 -1
  23. package/dist/cjs/src/logger.d.ts +3 -3
  24. package/dist/cjs/src/logger.js +9 -12
  25. package/dist/cjs/src/logger.js.map +1 -1
  26. package/dist/cjs/src/middleware.d.ts +61 -0
  27. package/dist/cjs/src/middleware.js +95 -0
  28. package/dist/cjs/src/middleware.js.map +1 -0
  29. package/dist/cjs/src/model.d.ts +270 -4
  30. package/dist/cjs/src/model.js +401 -3
  31. package/dist/cjs/src/model.js.map +1 -1
  32. package/dist/cjs/src/module.config.d.ts +149 -4
  33. package/dist/cjs/src/module.config.js +11 -6
  34. package/dist/cjs/src/module.config.js.map +1 -1
  35. package/dist/cjs/src/module.d.ts +14 -32
  36. package/dist/cjs/src/module.js +122 -7
  37. package/dist/cjs/src/module.js.map +1 -1
  38. package/dist/cjs/src/request-parser.d.ts +37 -0
  39. package/dist/cjs/src/request-parser.js +382 -0
  40. package/dist/cjs/src/request-parser.js.map +1 -0
  41. package/dist/cjs/src/router.d.ts +174 -75
  42. package/dist/cjs/src/router.js +469 -288
  43. package/dist/cjs/src/router.js.map +1 -1
  44. package/dist/cjs/src/static-serving.d.ts +32 -4
  45. package/dist/cjs/src/static-serving.js +115 -71
  46. package/dist/cjs/src/static-serving.js.map +1 -1
  47. package/dist/cjs/src/utils.js +2 -2
  48. package/dist/cjs/src/utils.js.map +1 -1
  49. package/dist/cjs/tsconfig.tsbuildinfo +1 -2916
  50. package/dist/esm/index.d.ts +14 -10
  51. package/dist/esm/index.js +14 -10
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/src/controllers.d.ts +10 -3
  54. package/dist/esm/src/controllers.js +7 -3
  55. package/dist/esm/src/controllers.js.map +1 -1
  56. package/dist/esm/src/decorator.d.ts +144 -70
  57. package/dist/esm/src/decorator.js +272 -99
  58. package/dist/esm/src/decorator.js.map +1 -1
  59. package/dist/esm/src/filter.d.ts +49 -0
  60. package/dist/esm/src/filter.js +209 -0
  61. package/dist/esm/src/filter.js.map +1 -0
  62. package/dist/esm/src/http-app.d.ts +8 -0
  63. package/dist/esm/src/http-app.js +12 -0
  64. package/dist/esm/src/http-app.js.map +1 -0
  65. package/dist/esm/src/http.d.ts +131 -32
  66. package/dist/esm/src/http.js +504 -121
  67. package/dist/esm/src/http.js.map +1 -1
  68. package/dist/esm/src/kernel.d.ts +50 -9
  69. package/dist/esm/src/kernel.js +110 -100
  70. package/dist/esm/src/kernel.js.map +1 -1
  71. package/dist/esm/src/logger.d.ts +3 -3
  72. package/dist/esm/src/logger.js +7 -11
  73. package/dist/esm/src/logger.js.map +1 -1
  74. package/dist/esm/src/middleware.d.ts +61 -0
  75. package/dist/esm/src/middleware.js +90 -0
  76. package/dist/esm/src/middleware.js.map +1 -0
  77. package/dist/esm/src/model.d.ts +270 -4
  78. package/dist/esm/src/model.js +357 -1
  79. package/dist/esm/src/model.js.map +1 -1
  80. package/dist/esm/src/module.config.d.ts +149 -4
  81. package/dist/esm/src/module.config.js +9 -5
  82. package/dist/esm/src/module.config.js.map +1 -1
  83. package/dist/esm/src/module.d.ts +14 -32
  84. package/dist/esm/src/module.js +121 -7
  85. package/dist/esm/src/module.js.map +1 -1
  86. package/dist/esm/src/request-parser.d.ts +37 -0
  87. package/dist/esm/src/request-parser.js +372 -0
  88. package/dist/esm/src/request-parser.js.map +1 -0
  89. package/dist/esm/src/router.d.ts +174 -75
  90. package/dist/esm/src/router.js +463 -285
  91. package/dist/esm/src/router.js.map +1 -1
  92. package/dist/esm/src/static-serving.d.ts +32 -4
  93. package/dist/esm/src/static-serving.js +107 -65
  94. package/dist/esm/src/static-serving.js.map +1 -1
  95. package/dist/esm/src/utils.js +1 -0
  96. package/dist/esm/src/utils.js.map +1 -1
  97. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -2916
  98. package/index.ts +14 -10
  99. package/package.json +30 -19
  100. package/src/controllers.ts +4 -3
  101. package/src/decorator.ts +242 -104
  102. package/src/filter.ts +224 -0
  103. package/src/http-app.ts +11 -0
  104. package/src/http.ts +501 -100
  105. package/src/kernel.ts +128 -80
  106. package/src/logger.ts +4 -6
  107. package/src/middleware.ts +116 -0
  108. package/src/model.ts +516 -5
  109. package/src/module.config.ts +168 -5
  110. package/src/module.ts +120 -7
  111. package/src/request-parser.ts +430 -0
  112. package/src/router.ts +546 -317
  113. package/src/static-serving.ts +120 -50
  114. package/src/utils.ts +0 -2
  115. package/tsconfig.esm.json +7 -7
  116. package/tsconfig.json +18 -11
  117. package/tsconfig.spec.json +8 -0
  118. package/dist/cjs/tests/router.spec.d.ts +0 -1
  119. package/dist/cjs/tests/router.spec.js +0 -481
  120. package/dist/cjs/tests/router.spec.js.map +0 -1
  121. package/dist/esm/tests/router.spec.d.ts +0 -1
  122. package/dist/esm/tests/router.spec.js +0 -479
  123. package/dist/esm/tests/router.spec.js.map +0 -1
  124. package/tests/router.spec.ts +0 -347
@@ -0,0 +1,209 @@
1
+ /*@ts-ignore*/
2
+ import { __ΩClassType } from '@deepkit/core';
3
+ import { AppModule } from '@deepkit/app';
4
+ import { RouteConfig, HttpRouter } from './router.js';
5
+ const __ΩHttpRouteFilterRoute = ['path', 'pathRegExp', "GET", "HEAD", "POST", "PATCH", "PUT", "DELETE", "OPTIONS", "TRACE", 'httpMethod', 'category', 'group', 'HttpRouteFilterRoute', 'P&4!8A4"8P.#.$.%.&.\'.(.).*J4+8&4,8&4-8Mw.y'];
6
+ export { __ΩHttpRouteFilterRoute as __ΩHttpRouteFilterRoute };
7
+ export class HttpRouteFilterModel {
8
+ constructor() {
9
+ this.controllers = [];
10
+ this.excludeControllers = [];
11
+ this.routes = [];
12
+ this.excludeRoutes = [];
13
+ this.routeNames = [];
14
+ this.excludeRouteNames = [];
15
+ this.modules = [];
16
+ this.excludeModules = [];
17
+ this.moduleClasses = [];
18
+ this.excludeModuleClasses = [];
19
+ }
20
+ reset() {
21
+ this.controllers = [];
22
+ this.excludeControllers = [];
23
+ this.routes = [];
24
+ this.excludeRoutes = [];
25
+ this.routeNames = [];
26
+ this.excludeRouteNames = [];
27
+ this.modules = [];
28
+ this.moduleClasses = [];
29
+ }
30
+ }
31
+ HttpRouteFilterModel.__type = [() => __ΩClassType, 'controllers', function () { return []; }, () => __ΩClassType, 'excludeControllers', function () { return []; }, () => __ΩHttpRouteFilterRoute, 'routes', function () { return []; }, () => __ΩHttpRouteFilterRoute, 'excludeRoutes', function () { return []; }, 'routeNames', function () { return []; }, 'excludeRouteNames', function () { return []; }, () => AppModule, 'modules', function () { return []; }, () => AppModule, 'excludeModules', function () { return []; }, () => __ΩClassType, () => AppModule, 'moduleClasses', function () { return []; }, () => __ΩClassType, () => AppModule, 'excludeModuleClasses', function () { return []; }, 'reset', 'HttpRouteFilterModel', 'n!F3">#n$F3%>&n\'F3(>)n*F3+>,&F3->.&F3/>0P"71F32>3P"74F35>6P"78o7"F39>:P"7<o;"F3=>>P"0?5w@'];
32
+ function match(routeConfig, route) {
33
+ if (route.httpMethod && routeConfig.httpMethods.includes(route.httpMethod))
34
+ return true;
35
+ if (route.category && route.category !== routeConfig.category)
36
+ return true;
37
+ if (route.group && routeConfig.groups.includes(route.group))
38
+ return true;
39
+ if (route.path || route.pathRegExp) {
40
+ if (!route.pathRegExp && route.path)
41
+ route.pathRegExp = new RegExp('^' + route.path.replace(/\*/g, '.*') + '$');
42
+ if (route.pathRegExp && route.pathRegExp.test(routeConfig.getFullPath()))
43
+ return true;
44
+ }
45
+ return false;
46
+ }
47
+ match.__type = [() => RouteConfig, 'routeConfig', () => __ΩHttpRouteFilterRoute, 'route', 'match', 'PP7!2"n#2$)/%'];
48
+ export class HttpRouterFilterResolver {
49
+ constructor(router) {
50
+ this.router = router;
51
+ }
52
+ /**
53
+ * Resolves
54
+ */
55
+ resolve(filter) {
56
+ const result = [];
57
+ outer: for (const routeConfig of this.router.getRoutes()) {
58
+ if (filter.controllers.length && routeConfig.action.type === 'controller' && !filter.controllers.includes(routeConfig.action.controller))
59
+ continue;
60
+ if (filter.excludeControllers.length && routeConfig.action.type === 'controller' && filter.excludeControllers.includes(routeConfig.action.controller))
61
+ continue;
62
+ if (filter.modules.length) {
63
+ if (!routeConfig.module)
64
+ continue;
65
+ let found = false;
66
+ for (const module of filter.modules) {
67
+ //modules get cloned everywhere, but id is sticky. So we compare that.
68
+ if (routeConfig.module.id === module.id) {
69
+ found = true;
70
+ break;
71
+ }
72
+ }
73
+ if (!found)
74
+ continue;
75
+ }
76
+ if (filter.excludeModules.length) {
77
+ if (!routeConfig.module)
78
+ continue;
79
+ for (const module of filter.excludeModules) {
80
+ //modules get cloned everywhere, but id is sticky. So we compare that.
81
+ if (routeConfig.module.id === module.id)
82
+ continue outer;
83
+ }
84
+ }
85
+ if (filter.moduleClasses.length) {
86
+ if (!routeConfig.module)
87
+ continue;
88
+ let found = false;
89
+ for (const module of filter.moduleClasses) {
90
+ if (routeConfig.module instanceof module) {
91
+ found = true;
92
+ break;
93
+ }
94
+ }
95
+ if (!found)
96
+ continue;
97
+ }
98
+ if (filter.excludeModuleClasses.length) {
99
+ if (!routeConfig.module)
100
+ continue;
101
+ for (const module of filter.excludeModuleClasses) {
102
+ if (routeConfig.module instanceof module)
103
+ continue outer;
104
+ }
105
+ }
106
+ if (filter.routeNames.length) {
107
+ let found = false;
108
+ for (const name of filter.routeNames) {
109
+ if (name.includes('*')) {
110
+ const regex = new RegExp('^' + name.replace(/\*/g, '.*') + '$');
111
+ if (regex.test(routeConfig.name)) {
112
+ found = true;
113
+ break;
114
+ }
115
+ }
116
+ else if (name === routeConfig.name) {
117
+ found = true;
118
+ break;
119
+ }
120
+ }
121
+ if (!found)
122
+ continue;
123
+ }
124
+ if (filter.excludeRouteNames.length) {
125
+ for (const name of filter.excludeRouteNames) {
126
+ if (name.includes('*')) {
127
+ const regex = new RegExp('^' + name.replace(/\*/g, '.*') + '$');
128
+ if (regex.test(routeConfig.name))
129
+ continue outer;
130
+ }
131
+ else if (name == routeConfig.name) {
132
+ continue outer;
133
+ }
134
+ }
135
+ }
136
+ if (filter.routes.length) {
137
+ let found = false;
138
+ for (const route of filter.routes) {
139
+ if (match(routeConfig, route)) {
140
+ found = true;
141
+ }
142
+ }
143
+ if (!found)
144
+ continue;
145
+ }
146
+ for (const route of filter.excludeRoutes) {
147
+ if (match(routeConfig, route))
148
+ continue outer;
149
+ }
150
+ result.push(routeConfig);
151
+ }
152
+ return result;
153
+ }
154
+ }
155
+ HttpRouterFilterResolver.__type = [() => HttpRouter, 'router', 'constructor', () => HttpRouteFilterModel, 'filter', () => RouteConfig, 'resolve', 'HttpRouterFilterResolver', 'PP7!2"<"0#PP7$2%P7&F0\'5w('];
156
+ /**
157
+ * A class to describe a filter for routes.
158
+ */
159
+ export class HttpRouteFilter {
160
+ constructor() {
161
+ this.model = new HttpRouteFilterModel();
162
+ }
163
+ reset() {
164
+ this.model.reset();
165
+ return this;
166
+ }
167
+ forControllers(...controllers) {
168
+ this.model.controllers.push(...controllers);
169
+ return this;
170
+ }
171
+ excludeControllers(...controllers) {
172
+ this.model.excludeControllers.push(...controllers);
173
+ return this;
174
+ }
175
+ forRoutes(...routes) {
176
+ this.model.routes.push(...routes);
177
+ return this;
178
+ }
179
+ excludeRoutes(...routes) {
180
+ this.model.excludeRoutes.push(...routes);
181
+ return this;
182
+ }
183
+ forRouteNames(...names) {
184
+ this.model.routeNames.push(...names);
185
+ return this;
186
+ }
187
+ excludeRouteNames(...names) {
188
+ this.model.excludeRouteNames.push(...names);
189
+ return this;
190
+ }
191
+ forModules(...modules) {
192
+ this.model.modules.push(...modules);
193
+ return this;
194
+ }
195
+ excludeModules(...modules) {
196
+ this.model.excludeModules.push(...modules);
197
+ return this;
198
+ }
199
+ forModuleClasses(...moduleClasses) {
200
+ this.model.moduleClasses.push(...moduleClasses);
201
+ return this;
202
+ }
203
+ excludeModuleClasses(...moduleClasses) {
204
+ this.model.excludeModuleClasses.push(...moduleClasses);
205
+ return this;
206
+ }
207
+ }
208
+ HttpRouteFilter.__type = ['model', function () { return new HttpRouteFilterModel(); }, 'reset', () => __ΩClassType, 'controllers', 'forControllers', () => __ΩClassType, 'excludeControllers', () => __ΩHttpRouteFilterRoute, 'routes', 'forRoutes', () => __ΩHttpRouteFilterRoute, 'excludeRoutes', 'names', 'forRouteNames', 'excludeRouteNames', () => AppModule, 'modules', 'forModules', () => AppModule, 'excludeModules', () => __ΩClassType, () => AppModule, 'moduleClasses', 'forModuleClasses', () => __ΩClassType, () => AppModule, 'excludeModuleClasses', 'HttpRouteFilter', '!3!>"P!0#Pn$@2%!0&Pn\'@2%!0(Pn)@2*!0+Pn,@2*!0-P&@2.!0/P&@2.!00PP"71@22!03PP"74@22!05PP"77o6"@28!09PP"7;o:"@28!0<5w='];
209
+ //# sourceMappingURL=filter.js.map
@@ -0,0 +1 @@
1
+ {"version":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ttpRouterRegistry } from './router.js';
3
+ /**
4
+ * Same as App, but with easily accessible router to make the most common use case easier.
5
+ */
6
+ export declare class HttpApp<T extends RootModuleDefinition> extends App<T> {
7
+ get router(): HttpRouterRegistry;
8
+ }
@@ -0,0 +1,12 @@
1
+ import { App } from '@deepkit/app';
2
+ import { HttpRouterRegistry } from './router.js';
3
+ /**
4
+ * Same as App, but with easily accessible router to make the most common use case easier.
5
+ */
6
+ export class HttpApp extends App {
7
+ get router() {
8
+ return super.get(HttpRouterRegistry);
9
+ }
10
+ }
11
+ HttpApp.__type = ['T', () => App, 'HttpApp', 'b!Pe"!7"!5e!!6"w#'];
12
+ //# sourceMappingURL=http-app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-app.js","sourceRoot":"","sources":["../../../src/http-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAwB,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,OAAwC,SAAQ,GAAM;IAC/D,IAAI,MAAM;QACN,OAAO,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACzC,CAAC"}
@@ -1,8 +1,15 @@
1
- import { HttpRequest, HttpResponse } from './model';
1
+ import { ClassType, CustomError } from '@deepkit/core';
2
+ import { OutgoingHttpHeaders, ServerResponse } from 'http';
3
+ import { HttpRequest, HttpRequestPositionedParameters, HttpResponse } from './model.js';
2
4
  import { InjectorContext } from '@deepkit/injector';
3
- import { Logger } from '@deepkit/logger';
4
- import { RouteConfig, RouteParameterResolverForInjector, Router } from './router';
5
+ import { LoggerInterface } from '@deepkit/logger';
6
+ import { HttpRouter, RouteConfig, RouteParameterResolverForInjector } from './router.js';
5
7
  import { WorkflowEvent } from '@deepkit/workflow';
8
+ import type { ElementStruct } from '@deepkit/template';
9
+ import { Stopwatch } from '@deepkit/stopwatch';
10
+ import { Type } from '@deepkit/type';
11
+ import stream from 'stream';
12
+ export declare function isElementStruct(v: any): v is ElementStruct;
6
13
  export declare class Redirect {
7
14
  statusCode: number;
8
15
  routeName?: string;
@@ -16,27 +23,55 @@ export declare class Redirect {
16
23
  }, statusCode?: number): Redirect;
17
24
  static toUrl(url: string, statusCode?: number): Redirect;
18
25
  }
19
- export interface HttpError<T> {
20
- new (...args: any[]): Error;
21
- getHttpCode(): T;
26
+ export declare class HttpError<T extends number> extends CustomError {
27
+ message: string;
28
+ httpCode: T;
29
+ constructor(message: string, httpCode: T);
22
30
  }
23
- export declare function HttpError<T extends number>(code: T, defaultMessage?: string): HttpError<T>;
24
- declare const HttpNotFoundError_base: HttpError<404>;
25
- export declare class HttpNotFoundError extends HttpNotFoundError_base {
26
- }
27
- declare const HttpBadRequestError_base: HttpError<400>;
31
+ export declare function createHttpError<T extends number>(code: T, defaultMessage?: string): ClassType<HttpError<T>>;
32
+ declare const HttpBadRequestError_base: ClassType<HttpError<400>>;
28
33
  export declare class HttpBadRequestError extends HttpBadRequestError_base {
29
34
  }
30
- declare const HttpAccessDeniedError_base: HttpError<403>;
35
+ declare const HttpUnauthorizedError_base: ClassType<HttpError<401>>;
36
+ export declare class HttpUnauthorizedError extends HttpUnauthorizedError_base {
37
+ }
38
+ declare const HttpAccessDeniedError_base: ClassType<HttpError<403>>;
31
39
  export declare class HttpAccessDeniedError extends HttpAccessDeniedError_base {
32
40
  }
41
+ declare const HttpNotFoundError_base: ClassType<HttpError<404>>;
42
+ export declare class HttpNotFoundError extends HttpNotFoundError_base {
43
+ }
44
+ declare const HttpMethodNotAllowedError_base: ClassType<HttpError<405>>;
45
+ export declare class HttpMethodNotAllowedError extends HttpMethodNotAllowedError_base {
46
+ }
47
+ declare const HttpNotAcceptableError_base: ClassType<HttpError<406>>;
48
+ export declare class HttpNotAcceptableError extends HttpNotAcceptableError_base {
49
+ }
50
+ declare const HttpTimeoutError_base: ClassType<HttpError<408>>;
51
+ export declare class HttpTimeoutError extends HttpTimeoutError_base {
52
+ }
53
+ declare const HttpConflictError_base: ClassType<HttpError<409>>;
54
+ export declare class HttpConflictError extends HttpConflictError_base {
55
+ }
56
+ declare const HttpGoneError_base: ClassType<HttpError<410>>;
57
+ export declare class HttpGoneError extends HttpGoneError_base {
58
+ }
59
+ declare const HttpTooManyRequestsError_base: ClassType<HttpError<429>>;
60
+ export declare class HttpTooManyRequestsError extends HttpTooManyRequestsError_base {
61
+ }
62
+ declare const HttpInternalServerError_base: ClassType<HttpError<500>>;
63
+ export declare class HttpInternalServerError extends HttpInternalServerError_base {
64
+ }
65
+ declare const HttpNotImplementedError_base: ClassType<HttpError<501>>;
66
+ export declare class HttpNotImplementedError extends HttpNotImplementedError_base {
67
+ }
33
68
  export declare class HttpWorkflowEvent {
34
69
  injectorContext: InjectorContext;
35
70
  request: HttpRequest;
36
71
  response: HttpResponse;
37
- stopped: boolean;
72
+ propagationStopped: boolean;
38
73
  stopPropagation(): void;
39
- isStopped(): boolean;
74
+ isPropagationStopped(): boolean;
40
75
  nextState?: any;
41
76
  nextStateEvent?: any;
42
77
  clearNext(): void;
@@ -44,6 +79,9 @@ export declare class HttpWorkflowEvent {
44
79
  * @see WorkflowNextEvent.next
45
80
  */
46
81
  next(nextState: string, event?: any): void;
82
+ /**
83
+ * Whether already a next workflow state has been scheduled.
84
+ */
47
85
  hasNext(): boolean;
48
86
  constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse);
49
87
  get url(): string;
@@ -62,6 +100,7 @@ export declare class HttpWorkflowEventWithRoute extends HttpWorkflowEvent {
62
100
  route: RouteConfig;
63
101
  constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig);
64
102
  send(response: any): void;
103
+ accessDenied(error?: Error): void;
65
104
  }
66
105
  export declare class HttpRouteEvent extends HttpWorkflowEvent {
67
106
  injectorContext: InjectorContext;
@@ -81,31 +120,32 @@ export declare class HttpAuthEvent extends HttpWorkflowEventWithRoute {
81
120
  parameterResolver: RouteParameterResolverForInjector;
82
121
  constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig, parameterResolver: RouteParameterResolverForInjector);
83
122
  success(): void;
84
- accessDenied(): void;
85
123
  }
86
124
  export declare class HttpAccessDeniedEvent extends HttpWorkflowEvent {
87
125
  injectorContext: InjectorContext;
88
126
  request: HttpRequest;
89
127
  response: HttpResponse;
90
128
  route: RouteConfig;
91
- constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig);
129
+ error?: Error | undefined;
130
+ constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig, error?: Error | undefined);
92
131
  }
93
- export declare class HttpResolveParametersEvent extends HttpWorkflowEvent {
132
+ export declare class HttpResolveParametersEvent extends HttpWorkflowEventWithRoute {
94
133
  injectorContext: InjectorContext;
95
134
  request: HttpRequest;
96
135
  response: HttpResponse;
97
136
  parameterResolver: RouteParameterResolverForInjector;
98
137
  route: RouteConfig;
99
- parameters: any[];
138
+ parameters: HttpRequestPositionedParameters;
100
139
  constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, parameterResolver: RouteParameterResolverForInjector, route: RouteConfig);
140
+ accessDenied(): void;
101
141
  }
102
- export declare class HttpControllerEvent extends HttpWorkflowEvent {
142
+ export declare class HttpControllerEvent extends HttpWorkflowEventWithRoute {
103
143
  injectorContext: InjectorContext;
104
144
  request: HttpRequest;
105
145
  response: HttpResponse;
106
- parameters: any[];
146
+ parameters: HttpRequestPositionedParameters;
107
147
  route: RouteConfig;
108
- constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, parameters: any[], route: RouteConfig);
148
+ constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, parameters: HttpRequestPositionedParameters | undefined, route: RouteConfig);
109
149
  }
110
150
  export declare class HttpResponseEvent extends WorkflowEvent {
111
151
  injectorContext: InjectorContext;
@@ -113,14 +153,22 @@ export declare class HttpResponseEvent extends WorkflowEvent {
113
153
  response: HttpResponse;
114
154
  result: any;
115
155
  route?: RouteConfig | undefined;
156
+ /**
157
+ * The time it took to call the controller action in milliseconds.
158
+ */
159
+ controllerActionTime: number;
116
160
  constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, result: any, route?: RouteConfig | undefined);
117
161
  }
118
- export declare class HttpControllerErrorEvent extends HttpWorkflowEvent {
162
+ export declare class HttpControllerErrorEvent extends HttpWorkflowEventWithRoute {
119
163
  injectorContext: InjectorContext;
120
164
  request: HttpRequest;
121
165
  response: HttpResponse;
122
166
  route: RouteConfig;
123
167
  error: Error;
168
+ /**
169
+ * The time it took to call the controller action in milliseconds.
170
+ */
171
+ controllerActionTime: number;
124
172
  constructor(injectorContext: InjectorContext, request: HttpRequest, response: HttpResponse, route: RouteConfig, error: Error);
125
173
  }
126
174
  export declare const httpWorkflow: import("@deepkit/workflow").WorkflowDefinition<{
@@ -148,22 +196,67 @@ export declare const httpWorkflow: import("@deepkit/workflow").WorkflowDefinitio
148
196
  parametersFailed: typeof HttpControllerErrorEvent;
149
197
  response: typeof HttpResponseEvent;
150
198
  }>;
151
- export declare class HtmlResponse {
199
+ export declare class BaseResponse {
200
+ _statusCode?: number | undefined;
201
+ _headers: OutgoingHttpHeaders;
202
+ autoSerializing: boolean;
203
+ constructor(_statusCode?: number | undefined, _headers?: OutgoingHttpHeaders);
204
+ status(code: number): this;
205
+ /**
206
+ * Per default a JSONResponse is serialized using the return type specified at the route.
207
+ * This disables that behaviour so that JSON.stringify is run on the result directly.
208
+ */
209
+ disableAutoSerializing(): this;
210
+ header(name: string, value: string | number): this;
211
+ headers(headers: OutgoingHttpHeaders): this;
212
+ contentType(type: string): this;
213
+ }
214
+ export declare class Response extends BaseResponse {
215
+ content: string | Uint8Array;
216
+ constructor(content: string | Uint8Array, contentType: string, statusCode?: number);
217
+ }
218
+ export declare class HtmlResponse extends BaseResponse {
152
219
  html: string;
153
- statusCode?: number | undefined;
154
- constructor(html: string, statusCode?: number | undefined);
220
+ constructor(html: string, statusCode?: number);
155
221
  }
156
- export declare class JSONResponse {
222
+ export declare class JSONResponse extends BaseResponse {
157
223
  json: any;
158
- statusCode?: number | undefined;
159
- constructor(json: any, statusCode?: number | undefined);
224
+ constructor(json: any, statusCode?: number);
225
+ }
226
+ export type SupportedHttpResult = undefined | null | number | string | Response | JSONResponse | HtmlResponse | HttpResponse | ServerResponse | stream.Readable | Redirect | Uint8Array | Error;
227
+ export interface HttpResultFormatterContext {
228
+ request: HttpRequest;
229
+ response: HttpResponse;
230
+ route?: RouteConfig;
231
+ }
232
+ export declare class HttpResultFormatter {
233
+ protected router: HttpRouter;
234
+ protected jsonContentType: string;
235
+ protected htmlContentType: string;
236
+ constructor(router: HttpRouter);
237
+ protected setContentTypeIfNotSetAlready(response: HttpResponse, contentType: string): void;
238
+ handleError(error: Error, context: HttpResultFormatterContext): void;
239
+ handleUndefined(result: undefined | null, context: HttpResultFormatterContext): void;
240
+ handleRedirect(result: Redirect, context: HttpResultFormatterContext): void;
241
+ handleUnknown(result: any, context: HttpResultFormatterContext): void;
242
+ handleHtmlResponse(result: HtmlResponse, context: HttpResultFormatterContext): void;
243
+ handleGenericResponse(result: Response, context: HttpResultFormatterContext): void;
244
+ handleJSONResponse(result: JSONResponse, context: HttpResultFormatterContext): void;
245
+ handleTypeEntity<T>(classType: ClassType<T>, instance: T, context: HttpResultFormatterContext, route?: RouteConfig): void;
246
+ handleType<T>(type: Type, instance: T, context: HttpResultFormatterContext, route?: RouteConfig): void;
247
+ handleStream(stream: stream.Readable, context: HttpResultFormatterContext): void;
248
+ handleBinary(result: Uint8Array, context: HttpResultFormatterContext): void;
249
+ handleResponse(context: HttpResultFormatterContext): void;
250
+ handle(result: SupportedHttpResult, context: HttpResultFormatterContext): void;
160
251
  }
161
252
  export declare class HttpListener {
162
- protected router: Router;
163
- protected logger: Logger;
164
- constructor(router: Router, logger: Logger);
253
+ protected router: HttpRouter;
254
+ protected logger: LoggerInterface;
255
+ protected resultFormatter: HttpResultFormatter;
256
+ protected stopwatch?: Stopwatch | undefined;
257
+ constructor(router: HttpRouter, logger: LoggerInterface, resultFormatter: HttpResultFormatter, stopwatch?: Stopwatch | undefined);
165
258
  onRequest(event: typeof httpWorkflow.onRequest.event): void;
166
- onRoute(event: typeof httpWorkflow.onRoute.event): void;
259
+ onRoute(event: typeof httpWorkflow.onRoute.event): Promise<void>;
167
260
  onRouteForward(event: typeof httpWorkflow.onRoute.event): void;
168
261
  routeNotFound(event: typeof httpWorkflow.onRouteNotFound.event): Promise<void>;
169
262
  onAuth(event: typeof httpWorkflow.onAuth.event): void;
@@ -172,6 +265,12 @@ export declare class HttpListener {
172
265
  onController(event: typeof httpWorkflow.onController.event): Promise<void>;
173
266
  onParametersFailed(event: typeof httpWorkflow.onParametersFailed.event): void;
174
267
  onControllerError(event: typeof httpWorkflow.onControllerError.event): void;
268
+ /**
269
+ * This happens before the result is sent.
270
+ */
271
+ onResultSerialization(event: typeof httpWorkflow.onResponse.event): Promise<void>;
175
272
  onResponse(event: typeof httpWorkflow.onResponse.event): Promise<void>;
176
273
  }
177
274
  export {};
275
+ export declare type __ΩSupportedHttpResult = any[];
276
+ export declare type __ΩHttpResultFormatterContext = any[];