@deepkit/http 1.0.1-alpha.98 → 1.0.2

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 (101) hide show
  1. package/CHANGELOG.md +244 -0
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/index.js +1 -0
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/src/controllers.js +1 -1
  6. package/dist/cjs/src/decorator.d.ts +7 -6
  7. package/dist/cjs/src/decorator.js +55 -42
  8. package/dist/cjs/src/decorator.js.map +1 -1
  9. package/dist/cjs/src/filter.js +4 -4
  10. package/dist/cjs/src/filter.js.map +1 -1
  11. package/dist/cjs/src/http-app.d.ts +8 -0
  12. package/dist/cjs/src/http-app.js +16 -0
  13. package/dist/cjs/src/http-app.js.map +1 -0
  14. package/dist/cjs/src/http.d.ts +2 -4
  15. package/dist/cjs/src/http.js +63 -51
  16. package/dist/cjs/src/http.js.map +1 -1
  17. package/dist/cjs/src/kernel.d.ts +43 -3
  18. package/dist/cjs/src/kernel.js +58 -8
  19. package/dist/cjs/src/kernel.js.map +1 -1
  20. package/dist/cjs/src/logger.js +2 -2
  21. package/dist/cjs/src/logger.js.map +1 -1
  22. package/dist/cjs/src/middleware.d.ts +2 -2
  23. package/dist/cjs/src/middleware.js +5 -6
  24. package/dist/cjs/src/middleware.js.map +1 -1
  25. package/dist/cjs/src/model.d.ts +154 -31
  26. package/dist/cjs/src/model.js +81 -41
  27. package/dist/cjs/src/model.js.map +1 -1
  28. package/dist/cjs/src/module.config.d.ts +67 -2
  29. package/dist/cjs/src/module.config.js +2 -2
  30. package/dist/cjs/src/module.config.js.map +1 -1
  31. package/dist/cjs/src/module.js +18 -13
  32. package/dist/cjs/src/module.js.map +1 -1
  33. package/dist/cjs/src/request-parser.d.ts +2 -1
  34. package/dist/cjs/src/request-parser.js +138 -60
  35. package/dist/cjs/src/request-parser.js.map +1 -1
  36. package/dist/cjs/src/router.d.ts +12 -6
  37. package/dist/cjs/src/router.js +40 -28
  38. package/dist/cjs/src/router.js.map +1 -1
  39. package/dist/cjs/src/static-serving.d.ts +4 -0
  40. package/dist/cjs/src/static-serving.js +44 -40
  41. package/dist/cjs/src/static-serving.js.map +1 -1
  42. package/dist/cjs/src/utils.js +1 -2
  43. package/dist/cjs/src/utils.js.map +1 -1
  44. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  45. package/dist/esm/index.d.ts +1 -0
  46. package/dist/esm/index.js +1 -0
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/src/controllers.js +2 -2
  49. package/dist/esm/src/controllers.js.map +1 -1
  50. package/dist/esm/src/decorator.d.ts +7 -6
  51. package/dist/esm/src/decorator.js +66 -54
  52. package/dist/esm/src/decorator.js.map +1 -1
  53. package/dist/esm/src/filter.js +5 -5
  54. package/dist/esm/src/filter.js.map +1 -1
  55. package/dist/esm/src/http-app.d.ts +8 -0
  56. package/dist/esm/src/http-app.js +12 -0
  57. package/dist/esm/src/http-app.js.map +1 -0
  58. package/dist/esm/src/http.d.ts +2 -4
  59. package/dist/esm/src/http.js +65 -53
  60. package/dist/esm/src/http.js.map +1 -1
  61. package/dist/esm/src/kernel.d.ts +43 -3
  62. package/dist/esm/src/kernel.js +60 -10
  63. package/dist/esm/src/kernel.js.map +1 -1
  64. package/dist/esm/src/logger.js +2 -2
  65. package/dist/esm/src/logger.js.map +1 -1
  66. package/dist/esm/src/middleware.d.ts +2 -2
  67. package/dist/esm/src/middleware.js +6 -7
  68. package/dist/esm/src/middleware.js.map +1 -1
  69. package/dist/esm/src/model.d.ts +154 -31
  70. package/dist/esm/src/model.js +59 -31
  71. package/dist/esm/src/model.js.map +1 -1
  72. package/dist/esm/src/module.config.d.ts +67 -2
  73. package/dist/esm/src/module.config.js +2 -2
  74. package/dist/esm/src/module.config.js.map +1 -1
  75. package/dist/esm/src/module.js +20 -15
  76. package/dist/esm/src/module.js.map +1 -1
  77. package/dist/esm/src/request-parser.d.ts +2 -1
  78. package/dist/esm/src/request-parser.js +139 -61
  79. package/dist/esm/src/request-parser.js.map +1 -1
  80. package/dist/esm/src/router.d.ts +12 -6
  81. package/dist/esm/src/router.js +46 -36
  82. package/dist/esm/src/router.js.map +1 -1
  83. package/dist/esm/src/static-serving.d.ts +4 -0
  84. package/dist/esm/src/static-serving.js +41 -39
  85. package/dist/esm/src/static-serving.js.map +1 -1
  86. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  87. package/index.ts +1 -0
  88. package/package.json +23 -16
  89. package/src/decorator.ts +20 -2
  90. package/src/http-app.ts +11 -0
  91. package/src/http.ts +30 -10
  92. package/src/kernel.ts +81 -9
  93. package/src/middleware.ts +1 -1
  94. package/src/model.ts +175 -16
  95. package/src/module.config.ts +75 -1
  96. package/src/module.ts +20 -12
  97. package/src/request-parser.ts +147 -62
  98. package/src/router.ts +36 -10
  99. package/src/static-serving.ts +49 -38
  100. package/tsconfig.json +9 -3
  101. package/tsconfig.spec.json +8 -0
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpKernel = void 0;
4
4
  /*@ts-ignore*/
5
5
  const { __ΩLoggerInterface } = require('@deepkit/logger');
6
+ function __assignType(fn, args) {
7
+ fn.__type = args;
8
+ return fn;
9
+ }
6
10
  const injector_1 = require("@deepkit/injector");
7
11
  const router_js_1 = require("./router.js");
8
12
  const event_1 = require("@deepkit/event");
@@ -11,6 +15,8 @@ const http_js_1 = require("./http.js");
11
15
  const stopwatch_1 = require("@deepkit/stopwatch");
12
16
  const fs_1 = require("fs");
13
17
  const type_1 = require("@deepkit/type");
18
+ const __ΩHttpKernelHandleOptions = ['throwOnNotFound', 'HttpKernelHandleOptions', 'P)4!8Mw"y'];
19
+ const __ΩHttpKernelMiddlewareOptions = [() => __ΩHttpKernelHandleOptions, 'fallThroughOnNotFound', 'HttpKernelMiddlewareOptions', 'Pn!)4"8Mw#y'];
14
20
  class HttpKernel {
15
21
  constructor(router, eventDispatcher, injectorContext, logger, stopwatch) {
16
22
  this.router = router;
@@ -19,24 +25,65 @@ class HttpKernel {
19
25
  this.logger = logger;
20
26
  this.stopwatch = stopwatch;
21
27
  }
22
- async request(requestBuilder) {
28
+ /**
29
+ * Creates a request handler function that can be used with http.createServer
30
+ * or any other http server library based on the node.js http module.
31
+ *
32
+ * When `fallThroughOnNotFound` is set to true, the handler will call `next()`
33
+ * when the route is not found, allowing the request to fall through to the next
34
+ * middleware in the chain.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import { createServer } from 'http';
39
+ *
40
+ * const app = new App({
41
+ * imports: [new HttpModule({})],
42
+ * });
43
+ *
44
+ * const handler = app.get(HttpKernel).createMiddleware({ fallThroughOnNotFound: true });
45
+ * const server = createServer(handler);
46
+ *
47
+ * server.listen(3000);
48
+ * ```
49
+ */
50
+ createMiddleware(options = {}) {
51
+ if (options.fallThroughOnNotFound && 'undefined' === typeof options.throwOnNotFound) {
52
+ options.throwOnNotFound = true;
53
+ }
54
+ return __assignType((req, res, next) => {
55
+ return this.handleRequest(req, res, options).then(() => {
56
+ next();
57
+ }).catch(__assignType((error) => {
58
+ if (options.fallThroughOnNotFound && error instanceof http_js_1.HttpError && error.httpCode === 404) {
59
+ next();
60
+ return;
61
+ }
62
+ next(error);
63
+ }, ['error', '', 'P"2!"/"']));
64
+ }, ['req', 'res', 'error', '', 'next', 'P!2!!2"P"2#8$/$2%"/$']);
65
+ }
66
+ async request(requestBuilder, options = {}) {
23
67
  const request = requestBuilder.build();
24
68
  const response = new model_js_1.MemoryHttpResponse(request);
25
69
  response.assignSocket(request.socket);
26
- await this.handleRequest(request, response);
70
+ await this.handleRequest(request, response, options);
27
71
  return response;
28
72
  }
29
- async handleRequest(req, res) {
73
+ async handleRequest(_req, _res, options = {}) {
30
74
  const httpInjectorContext = this.injectorContext.createChildScope('http');
75
+ const req = (0, model_js_1.incomingMessageToHttpRequest)(_req);
76
+ const res = (0, model_js_1.serverResponseToHttpResponse)(_res);
31
77
  httpInjectorContext.set(model_js_1.HttpRequest, req);
32
78
  httpInjectorContext.set(model_js_1.HttpResponse, res);
33
79
  httpInjectorContext.set(injector_1.InjectorContext, httpInjectorContext);
80
+ req.throwErrorOnNotFound = options.throwOnNotFound || false;
34
81
  const frame = this.stopwatch ? this.stopwatch.start(req.method + ' ' + req.getUrl(), stopwatch_1.FrameCategory.http, true) : undefined;
35
82
  const workflow = http_js_1.httpWorkflow.create('start', this.eventDispatcher, httpInjectorContext, this.stopwatch);
36
83
  try {
37
84
  if (frame) {
38
85
  frame.data({ url: req.getUrl(), method: req.getMethod(), clientIp: req.getRemoteAddress() });
39
- await frame.run({}, () => workflow.apply('request', new http_js_1.HttpRequestEvent(httpInjectorContext, req, res)));
86
+ await frame.run(() => workflow.apply('request', new http_js_1.HttpRequestEvent(httpInjectorContext, req, res)));
40
87
  }
41
88
  else {
42
89
  await workflow.apply('request', new http_js_1.HttpRequestEvent(httpInjectorContext, req, res));
@@ -48,13 +95,16 @@ class HttpKernel {
48
95
  if (error instanceof type_1.ValidationError) {
49
96
  resultFormatter.handle(new http_js_1.JSONResponse({
50
97
  message: error.message,
51
- errors: error.errors
98
+ errors: error.errors,
52
99
  }, 400).disableAutoSerializing(), { request: req, response: res });
53
100
  return;
54
101
  }
55
102
  else if (error instanceof http_js_1.HttpError) {
103
+ if (req.throwErrorOnNotFound && error.httpCode === 404) {
104
+ throw error;
105
+ }
56
106
  resultFormatter.handle(new http_js_1.JSONResponse({
57
- message: error.message
107
+ message: error.message,
58
108
  }, error.httpCode).disableAutoSerializing(), { request: req, response: res });
59
109
  return;
60
110
  }
@@ -63,7 +113,7 @@ class HttpKernel {
63
113
  this.logger.error('HTTP kernel request failed', error);
64
114
  }
65
115
  finally {
66
- for (const file of Object.values(req.uploadedFiles)) {
116
+ for (const file of Object.values(req.uploadedFiles || [])) {
67
117
  (0, fs_1.unlink)(file.path, () => {
68
118
  });
69
119
  }
@@ -75,5 +125,5 @@ class HttpKernel {
75
125
  }
76
126
  }
77
127
  exports.HttpKernel = HttpKernel;
78
- HttpKernel.__type = [() => router_js_1.HttpRouter, 'router', () => event_1.EventDispatcher, 'eventDispatcher', () => injector_1.InjectorContext, 'injectorContext', () => __ΩLoggerInterface, 'logger', () => stopwatch_1.Stopwatch, 'stopwatch', 'constructor', () => model_js_1.RequestBuilder, 'requestBuilder', () => model_js_1.MemoryHttpResponse, 'request', () => model_js_1.HttpRequest, 'req', () => model_js_1.HttpResponse, 'res', 'handleRequest', 'PP7!2"<P7#2$<P7%2&<n\'2(<P7)2*8<"0+PP7,2-P7.`0/PP7021P7223"045'];
128
+ HttpKernel.__type = [() => router_js_1.HttpRouter, 'router', () => event_1.EventDispatcher, 'eventDispatcher', () => injector_1.InjectorContext, 'injectorContext', () => __ΩLoggerInterface, 'logger', () => stopwatch_1.Stopwatch, 'stopwatch', 'constructor', () => __ΩHttpKernelMiddlewareOptions, 'options', () => ({}), 'createMiddleware', () => model_js_1.RequestBuilder, 'requestBuilder', () => __ΩHttpKernelHandleOptions, () => ({}), () => model_js_1.MemoryHttpResponse, 'request', '_req', '_res', () => __ΩHttpKernelHandleOptions, () => ({}), 'handleRequest', 'HttpKernel', 'PP7!2"<P7#2$<P7%2&<n\'2(<P7)2*8<"0+Pn,2->."0/PP7021n22->3P74`05P!26!27n82->9$`0:5w;'];
79
129
  //# sourceMappingURL=kernel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kernel.js","sourceRoot":"","sources":["../../../src/kernel.ts"],"names":[],"mappings":";;;;uCAGgC,iBAAiB;AAHjD,gDAAoD;AACpD,2CAAyC;AACzC,0CAAiD;AAEjD,yCAA2F;AAC3F,uCAAyG;AACzG,kDAA8D;AAC9D,2BAA4B;AAC5B,wCAAgD;AAEhD,MAAa,UAAU;IACnB,YACc,MAAkB,EAClB,eAAgC,EAChC,eAAgC,EAChC,MAAuB,EACvB,SAAqB;QAJrB,WAAM,GAAN,MAAM,CAAY;QAClB,oBAAe,GAAf,eAAe,CAAiB;QAChC,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remoteAddress || '0.0.0.0', '-', event.request.method, `"${event.request.url}"`, event.response.statusCode, `"${event.request.headers.referer || ''}"`);
23
23
  }
24
24
  }
25
- HttpLogger.__type = [() => __ΩLoggerInterface, 'logger', 'constructor', () => http_js_1.httpWorkflow.onResponse.event, 'event', 'onHttpRequest', 'Pn!2";"0#Pi$2%"0&5'];
25
+ exports.HttpLogger = HttpLogger;
26
+ HttpLogger.__type = [() => __ΩLoggerInterface, 'logger', 'constructor', () => http_js_1.httpWorkflow.onResponse.event, 'event', 'onHttpRequest', 'HttpLogger', 'Pn!2";"0#Pi$2%"0&5w\''];
26
27
  __decorate([
27
28
  event_1.eventDispatcher.listen(http_js_1.httpWorkflow.onResponse, 101) //101 is right after 100 default listener
28
29
  ,
@@ -30,5 +31,4 @@ __decorate([
30
31
  __metadata("design:paramtypes", [Object]),
31
32
  __metadata("design:returntype", void 0)
32
33
  ], HttpLogger.prototype, "onHttpRequest", null);
33
- exports.HttpLogger = HttpLogger;
34
34
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;uCAAgC,iBAAiB;AACjD,0CAAiD;AACjD,uCAAyC;AAEzC,MAAa,UAAU;IACnB,YAAoB,MAAuB;QAAvB,WAAM,GAAN,MAAM,CAAiB;IAC3C,CAAC;IAGD,aAAa,CAAC,KAA2C;QACrD,IAAI,CAAC,MAAM,CAAC,GAAG,CACX,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,IAAI,SAAS,EAAE,GAAG,EACxD,KAAK,CAAC,OAAO,CAAC,MAAM,EACpB,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,GAAG,EACxB,KAAK,CAAC,QAAQ,CAAC,UAAU,EACzB,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,GAAG,CAE7C,CAAC;IACN,CAAC;;qGATwC,UAAU,CAAC,KAAK;AADzD;IAAC,uBAAe,CAAC,MAAM,CAAC,sBAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,yCAAyC;;;;;+CAU9F;AAdL,gCAeC"}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;uCAAgC,iBAAiB;AACjD,0CAAiD;AACjD,uCAAyC;AAEzC,MAAa,UAAU;IACnB,YAAoB,MAAuB;QAAvB,WAAM,GAAN,MAAM,CAAiB;IAC3C,CAAC;IAGD,aAAa,CAAC,KAA2C;QACrD,IAAI,CAAC,MAAM,CAAC,GAAG,CACX,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,aAAa,IAAI,SAAS,EAAE,GAAG,EACxD,KAAK,CAAC,OAAO,CAAC,MAAM,EACpB,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,GAAG,EACxB,KAAK,CAAC,QAAQ,CAAC,UAAU,EACzB,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,GAAG,CAE7C,CAAC;IACN,CAAC;;AAdL,gCAeC;qGAV4C,UAAU,CAAC,KAAK;AAAzD;IADC,uBAAe,CAAC,MAAM,CAAC,sBAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,yCAAyC;;;;;+CAU9F"}
@@ -2,7 +2,7 @@ import { ClassType } from '@deepkit/core';
2
2
  import { AppModule } from '@deepkit/app';
3
3
  import { HttpRequest, HttpResponse } from './model.js';
4
4
  import { InjectorModule } from '@deepkit/injector';
5
- export declare type HttpMiddlewareFn = (req: HttpRequest, res: HttpResponse, next: (err?: any) => void) => void | Promise<void>;
5
+ export type HttpMiddlewareFn = (req: HttpRequest, res: HttpResponse, next: (err?: any) => void) => void | Promise<void>;
6
6
  export interface HttpMiddleware {
7
7
  execute: HttpMiddlewareFn;
8
8
  }
@@ -25,7 +25,7 @@ export declare class HttpMiddlewareConfig {
25
25
  excludeControllers: ClassType[];
26
26
  routeNames: string[];
27
27
  excludeRouteNames: string[];
28
- timeout: number;
28
+ timeout?: number;
29
29
  modules: InjectorModule<any>[];
30
30
  selfModule: boolean;
31
31
  getClassTypes(): ClassType[];
@@ -8,11 +8,11 @@ const app_1 = require("@deepkit/app");
8
8
  const type_1 = require("@deepkit/type");
9
9
  const model_js_1 = require("./model.js");
10
10
  const injector_1 = require("@deepkit/injector");
11
- const __ΩHttpMiddlewareFn = [() => model_js_1.HttpRequest, 'req', () => model_js_1.HttpResponse, 'res', 'err', '', 'next', 'PP7!2"P7#2$P"2%8$/&2\'P$$`J/&'];
11
+ const __ΩHttpMiddlewareFn = [() => model_js_1.HttpRequest, 'req', () => model_js_1.HttpResponse, 'res', 'err', '', 'next', 'HttpMiddlewareFn', 'PP7!2"P7#2$P"2%8$/&2\'P$$`J/&w(y'];
12
12
  exports.__ΩHttpMiddlewareFn = __ΩHttpMiddlewareFn;
13
- const __ΩHttpMiddleware = [() => __ΩHttpMiddlewareFn, 'execute', 'Pn!4"M'];
13
+ const __ΩHttpMiddleware = [() => __ΩHttpMiddlewareFn, 'execute', 'HttpMiddleware', 'Pn!4"Mw#y'];
14
14
  exports.__ΩHttpMiddleware = __ΩHttpMiddleware;
15
- const __ΩHttpMiddlewareRoute = ['path', 'pathRegExp', "GET", "HEAD", "POST", "PATCH", "PUT", "DELETE", "OPTIONS", "TRACE", 'httpMethod', 'category', 'excludeCategory', 'group', 'excludeGroup', 'P&4!8A4"8P.#.$.%.&.\'.(.).*J4+8&4,8&4-8&4.8&4/8M'];
15
+ const __ΩHttpMiddlewareRoute = ['path', 'pathRegExp', "GET", "HEAD", "POST", "PATCH", "PUT", "DELETE", "OPTIONS", "TRACE", 'httpMethod', 'category', 'excludeCategory', 'group', 'excludeGroup', 'HttpMiddlewareRoute', 'P&4!8A4"8P.#.$.%.&.\'.(.).*J4+8&4,8&4-8&4.8&4/8Mw0y'];
16
16
  exports.__ΩHttpMiddlewareRoute = __ΩHttpMiddlewareRoute;
17
17
  class HttpMiddlewareConfig {
18
18
  constructor() {
@@ -24,7 +24,6 @@ class HttpMiddlewareConfig {
24
24
  this.excludeControllers = [];
25
25
  this.routeNames = [];
26
26
  this.excludeRouteNames = [];
27
- this.timeout = 4000;
28
27
  this.modules = [];
29
28
  this.selfModule = false;
30
29
  }
@@ -38,7 +37,7 @@ class HttpMiddlewareConfig {
38
37
  }
39
38
  }
40
39
  exports.HttpMiddlewareConfig = HttpMiddlewareConfig;
41
- HttpMiddlewareConfig.__type = ['name', () => __ΩHttpMiddlewareFn, () => __ΩClassType, () => __ΩHttpMiddleware, 'middlewares', function () { return []; }, () => __ΩHttpMiddlewareRoute, 'routes', function () { return []; }, () => __ΩHttpMiddlewareRoute, 'excludeRoutes', function () { return []; }, 'order', function () { return 0; }, () => __ΩClassType, 'controllers', function () { return []; }, () => __ΩClassType, 'excludeControllers', function () { return []; }, 'routeNames', function () { return []; }, 'excludeRouteNames', function () { return []; }, 'timeout', function () { return 4000; }, () => injector_1.InjectorModule, 'modules', function () { return []; }, 'selfModule', function () { return false; }, () => __ΩClassType, 'getClassTypes', '&3!8Pn"n$o#"JF3%>&n\'F3(>)n*F3+>,\'3->.n/F30>1n2F33>4&F35>6&F37>8\'39>:P"7;F3<>=)3>>?Pn@F0A5'];
40
+ HttpMiddlewareConfig.__type = ['name', () => __ΩHttpMiddlewareFn, () => __ΩClassType, () => __ΩHttpMiddleware, 'middlewares', function () { return []; }, () => __ΩHttpMiddlewareRoute, 'routes', function () { return []; }, () => __ΩHttpMiddlewareRoute, 'excludeRoutes', function () { return []; }, 'order', function () { return 0; }, () => __ΩClassType, 'controllers', function () { return []; }, () => __ΩClassType, 'excludeControllers', function () { return []; }, 'routeNames', function () { return []; }, 'excludeRouteNames', function () { return []; }, 'timeout', () => injector_1.InjectorModule, 'modules', function () { return []; }, 'selfModule', function () { return false; }, () => __ΩClassType, 'getClassTypes', 'HttpMiddlewareConfig', '&3!8Pn"n$o#"JF3%>&n\'F3(>)n*F3+>,\'3->.n/F30>1n2F33>4&F35>6&F37>8\'398P"7:F3;><)3=>>Pn?F0@5wA'];
42
41
  class HttpMiddlewareApi {
43
42
  constructor() {
44
43
  this.t = new HttpMiddlewareConfig;
@@ -91,6 +90,6 @@ class HttpMiddlewareApi {
91
90
  }
92
91
  }
93
92
  exports.HttpMiddlewareApi = HttpMiddlewareApi;
94
- HttpMiddlewareApi.__type = ['name', () => __ΩHttpMiddlewareFn, () => __ΩClassType, () => __ΩHttpMiddleware, 'middlewares', 'for', () => __ΩHttpMiddlewareRoute, 'routes', 'forRoutes', () => __ΩHttpMiddlewareRoute, 'excludeRoutes', 'names', 'forRouteNames', 'excludeRouteNames', 'timeout', () => __ΩClassType, 'controllers', 'forControllers', () => __ΩClassType, 'excludeControllers', 'order', () => app_1.AppModule, 'modules', 'forModules', 'forSelfModules', 'P&2!"0!PPn"n$o#"J@2%"0&Pn\'@2("0)Pn*@2("0+P&@2,"0-P&@2,"0.P\'2/"0/Pn0@21"02Pn3@21"04P\'25"05PP"76@27"08P"095'];
93
+ HttpMiddlewareApi.__type = ['t', function () { return new HttpMiddlewareConfig; }, 'name', () => __ΩHttpMiddlewareFn, () => __ΩClassType, () => __ΩHttpMiddleware, 'middlewares', 'for', () => __ΩHttpMiddlewareRoute, 'routes', 'forRoutes', () => __ΩHttpMiddlewareRoute, 'excludeRoutes', 'names', 'forRouteNames', 'excludeRouteNames', 'timeout', () => __ΩClassType, 'controllers', 'forControllers', () => __ΩClassType, 'excludeControllers', 'order', () => app_1.AppModule, 'modules', 'forModules', 'forSelfModules', 'HttpMiddlewareApi', '!3!>"P&2#"0#PPn$n&o%"J@2\'"0(Pn)@2*"0+Pn,@2*"0-P&@2."0/P&@2."00P\'21"01Pn2@23"04Pn5@23"06P\'27"07PP"78@29"0:P"0;5w<'];
95
94
  exports.httpMiddleware = (0, type_1.createFreeDecoratorContext)(HttpMiddlewareApi);
96
95
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"midd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AC,CAAC,UAAU,GAAG,KAAK,CAAC;IAC9B,CAAC;IAED,iBAAiB,CAAC,GAAG,KAAe;QAChC,IAAI,CAAC,CAAC,CAAC,iBAAiB,GAAG,KAAK,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,OAAe;QACnB,IAAI,CAAC,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC;IAC7B,CAAC;IAED,cAAc,CAAC,GAAG,WAAwB;QACtC,IAAI,CAAC,CAAC,CAAC,WAAW,GAAG,WAAW,CAAC;IACrC,CAAC;IAED,kBAAkB,CAAC,GAAG,WAAwB;QAC1C,IAAI,CAAC,CAAC,CAAC,kBAAkB,GAAG,WAAW,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAa;QACf,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;IACzB,CAAC;IAED,UAAU,CAAC,GAAG,OAAyB;QACnC,IAAI,CAAC,CAAC,CAAC,OAAO,GAAG,OAAO,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,cAAc;QACV,IAAI,CAAC,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;IAC7B,CAAC;;AA3DL,8CA4DC;sDA3DO,IAAI,oBAAoB;AA6DnB,QAAA,cAAc,GAAG,IAAA,iCAA0B,EAAC,iBAAiB,CAAC,CAAC"}
@@ -1,8 +1,7 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { IncomingMessage, OutgoingHttpHeader, OutgoingHttpHeaders, ServerResponse } from 'http';
4
2
  import { UploadedFile } from './router.js';
5
3
  import { Type, ValidationErrorItem } from '@deepkit/type';
4
+ import { TypeAnnotation } from '@deepkit/core';
6
5
  export declare class HttpResponse extends ServerResponse {
7
6
  status(code: number): void;
8
7
  }
@@ -14,13 +13,13 @@ export declare class HttpResponse extends ServerResponse {
14
13
  */
15
14
  export declare function readBody(request: IncomingMessage): Promise<Buffer>;
16
15
  export declare function createRequestWithCachedBody(request: Partial<IncomingMessage>, body: Buffer): HttpRequest;
17
- export declare type HttpRequestQuery = {
16
+ export type HttpRequestQuery = {
18
17
  [name: string]: string;
19
18
  };
20
- export declare type HttpRequestResolvedParameters = {
19
+ export type HttpRequestResolvedParameters = {
21
20
  [name: string]: any;
22
21
  };
23
- export declare type HttpRequestPositionedParameters = {
22
+ export type HttpRequestPositionedParameters = {
24
23
  arguments: any[];
25
24
  parameters: HttpRequestResolvedParameters;
26
25
  };
@@ -40,32 +39,153 @@ export declare class ValidatedBody<T> {
40
39
  value: T;
41
40
  };
42
41
  }
43
- export declare type HttpBody<T> = T & {
44
- __meta?: ['httpBody'];
45
- };
46
- export declare type HttpBodyValidation<T> = ValidatedBody<T> & {
47
- __meta?: ['httpBodyValidation'];
48
- };
49
- export declare type HttpPath<T, Options extends {
42
+ /**
43
+ * Marks a parameter as HTTP body and reads the value from the request body.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * class Controller {
48
+ * @http.GET('/api')
49
+ * route(body: HttpBody<{username: string}>) {
50
+ * //body is {username: string} and required
51
+ * //could also reference an interface or type alias via `HttpBody<MyInterface>`
52
+ * }
53
+ * }
54
+ *
55
+ * // curl /api -d '{"username":"Peter"}'
56
+ */
57
+ export type HttpBody<T> = T & TypeAnnotation<'httpBody'>;
58
+ export type HttpBodyValidation<T> = ValidatedBody<T> & TypeAnnotation<'httpBodyValidation'>;
59
+ export interface HttpRequestParserOptions {
60
+ withPath?: boolean;
61
+ withBody?: boolean;
62
+ withQuery?: boolean;
63
+ withHeader?: boolean;
64
+ }
65
+ /**
66
+ * Delays the parsing of the path/body/query/header to the very last moment, when the parameter is actually used.
67
+ *
68
+ * If no options are provided, the parser will receive data from path, header, body, and query, in this order.
69
+ * This basically allows to fetch data from all possible HTTP sources in one go.
70
+ *
71
+ * You can disable various sources by providing the options, e.g. `{withBody: false}` to disable body parsing.
72
+ * Or `{withQuery: false}` to disable query parsing. Or `{withHeader: false}` to disable header parsing.
73
+ * To only parse the body, use `{withQuery: false, withHeader: false}`.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * async route(parser: HttpRequestParser<{authorization: string}>) {
78
+ * const data = await parser();
79
+ * console.log(data.authorization);
80
+ * }
81
+ * ```
82
+ *
83
+ * Note that the parsers is based on all defined parameters (e.g. `userId: HttpQuery<string>` => {userId: string}),
84
+ * and then starts from there applying header, body, and then query values.
85
+ * This means you also get access to defined path parameters, like:
86
+ *
87
+ * ```typescript
88
+ * @http.GET('teams/:teamId')
89
+ * async route(teamId: string) {
90
+ * //teamId is string
91
+ * }
92
+ *
93
+ * httpWorkflow.onController.listen((event, parser: HttpRequestParser<{teamId: string}>) => {
94
+ * const data = await parser();
95
+ * console.log(data.teamId);
96
+ * });
97
+ * ```
98
+ *
99
+ * HttpRequestParser is necessary in event listeners, since they are instantiated synchronously,
100
+ * but body is parsed asynchronously. So use in event listeners HttpRequestParser instead of HttpBody.
101
+ */
102
+ export type HttpRequestParser<T> = ((options?: HttpRequestParserOptions) => Promise<T>) & TypeAnnotation<'httpRequestParser', T>;
103
+ /**
104
+ * Marks a parameter as HTTP path and reads the value from the request path.
105
+ * This is normally not requires since the parameter name automatically maps to the path parameter,
106
+ * but in case of requesting the path parameter in for example listeners, this is required.
107
+ * The name option can be used to change the parameter name.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * app.listen(httpWorkflow.onController, (event, request: HttpRequest, groupId: HttpPath<number>) => {
112
+ * console.log(groupId); //123
113
+ * });
114
+ *
115
+ * class Controller {
116
+ * @http.GET('/api/:groupId')
117
+ * route(groupId: number) {
118
+ * //groupId is number and required
119
+ * //same as `groupId: HttpPath<number>`
120
+ * }
121
+ * }
122
+ * ```
123
+ */
124
+ export type HttpPath<T, Options extends {
50
125
  name?: string;
51
- } = {}> = T & {
52
- __meta?: ['httpPath', Options];
53
- };
54
- export declare type HttpHeader<T, Options extends {
126
+ } = {}> = T & TypeAnnotation<'httpPath', Options>;
127
+ /**
128
+ * Marks a parameter as HTTP header and reads the value from the request header.
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * class Controller {
133
+ * @http.GET('/api')
134
+ * route(authorization: HttpHeader<string>) {
135
+ * //authorization is string and required
136
+ * //use `authorization?: HttpHeader<string>` to make it optional
137
+ * }
138
+ * }
139
+ *
140
+ * // curl /api -H 'Authorization: 123'
141
+ * ```
142
+ *
143
+ * To change the header name, use `param: HttpHeader<string, {name: 'X-My-Header'}>`.
144
+ */
145
+ export type HttpHeader<T, Options extends {
55
146
  name?: string;
56
- } = {}> = T & {
57
- __meta?: ['httpHeader', Options];
58
- };
59
- export declare type HttpQuery<T, Options extends {
147
+ } = {}> = T & TypeAnnotation<'httpHeader', Options>;
148
+ /**
149
+ * Marks a parameter as HTTP query and reads the value from the request query string.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * class Controller {
154
+ * @http.GET('/api')
155
+ * route(limit: HttpQuery<number>) {
156
+ * //limit is number and required
157
+ * //use `limit?: HttpQuery<number>` to make it optional
158
+ * }
159
+ * }
160
+ *
161
+ * // curl /api?limit=10
162
+ * ```
163
+ */
164
+ export type HttpQuery<T, Options extends {
60
165
  name?: string;
61
- } = {}> = T & {
62
- __meta?: ['httpQuery', Options];
63
- };
64
- export declare type HttpQueries<T, Options extends {
166
+ } = {}> = T & TypeAnnotation<'httpQuery', Options>;
167
+ /**
168
+ * Marks a parameter as HTTP query objects and reads multiple values from the request query string into an object.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * interface Query {
173
+ * limit?: number;
174
+ * offset?: number;
175
+ * sort?: 'asc' | 'desc';
176
+ * }
177
+ *
178
+ * class Controller {
179
+ * @http.GET('/api')
180
+ * route(query: HttpQueries<Query>) {
181
+ * //query is an object containing limit, offset, and sort
182
+ * }
183
+ *
184
+ * // curl /api?limit=10&offset=20&sort=asc
185
+ */
186
+ export type HttpQueries<T, Options extends {
65
187
  name?: string;
66
- } = {}> = T & {
67
- __meta?: ['httpQueries', Options];
68
- };
188
+ } = {}> = T & TypeAnnotation<'httpQueries', Options>;
69
189
  /**
70
190
  * For all parameters used in the URL path, a regular expression of /[^/]+/ is used. To change that, use getRegExp.
71
191
  *
@@ -80,9 +200,7 @@ export declare type HttpQueries<T, Options extends {
80
200
  * }
81
201
  * ```
82
202
  */
83
- export declare type HttpRegExp<T, Pattern extends string | RegExp> = T & {
84
- __meta?: ['httpRegExp', Pattern];
85
- };
203
+ export type HttpRegExp<T, Pattern extends string | RegExp> = T & TypeAnnotation<'httpRegExp', Pattern>;
86
204
  export declare function getRegExp(type: Type): string | RegExp | undefined;
87
205
  export declare class RequestBuilder {
88
206
  protected path: string;
@@ -107,7 +225,7 @@ export declare class RequestBuilder {
107
225
  json?: any;
108
226
  }[]): this;
109
227
  body(body: string | Buffer): this;
110
- query(query: any): this;
228
+ query(query: any | string): this;
111
229
  }
112
230
  export declare class HttpRequest extends IncomingMessage {
113
231
  /**
@@ -119,6 +237,7 @@ export declare class HttpRequest extends IncomingMessage {
119
237
  uploadedFiles: {
120
238
  [name: string]: UploadedFile;
121
239
  };
240
+ throwErrorOnNotFound: boolean;
122
241
  /**
123
242
  * The router sets the body when it was read.
124
243
  */
@@ -137,6 +256,8 @@ export declare class HttpRequest extends IncomingMessage {
137
256
  getMethod(): string;
138
257
  getRemoteAddress(): string;
139
258
  }
259
+ export declare function incomingMessageToHttpRequest(request: IncomingMessage): HttpRequest;
260
+ export declare function serverResponseToHttpResponse(response: ServerResponse): HttpResponse;
140
261
  export declare class MemoryHttpResponse extends HttpResponse {
141
262
  body: Buffer;
142
263
  headers: {
@@ -158,6 +279,8 @@ export declare type __ΩHttpRequestResolvedParameters = any[];
158
279
  export declare type __ΩHttpRequestPositionedParameters = any[];
159
280
  export declare type __ΩHttpBody = any[];
160
281
  export declare type __ΩHttpBodyValidation = any[];
282
+ export declare type __ΩHttpRequestParserOptions = any[];
283
+ export declare type __ΩHttpRequestParser = any[];
161
284
  export declare type __ΩHttpPath = any[];
162
285
  export declare type __ΩHttpHeader = any[];
163
286
  export declare type __ΩHttpQuery = any[];