@tsed/platform-express 7.0.0-alpha.2 → 7.0.0-beta.1

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 (118) hide show
  1. package/lib/cjs/components/PlatformExpress.js +141 -0
  2. package/lib/cjs/components/PlatformExpress.js.map +1 -0
  3. package/lib/{decorators → cjs/decorators}/caseSensitive.js +1 -1
  4. package/lib/cjs/decorators/caseSensitive.js.map +1 -0
  5. package/lib/cjs/decorators/index.js +8 -0
  6. package/lib/cjs/decorators/index.js.map +1 -0
  7. package/lib/{decorators → cjs/decorators}/mergeParams.js +1 -1
  8. package/lib/cjs/decorators/mergeParams.js.map +1 -0
  9. package/lib/{decorators → cjs/decorators}/routerSettings.js +1 -1
  10. package/lib/cjs/decorators/routerSettings.js.map +1 -0
  11. package/lib/{decorators → cjs/decorators}/strict.js +1 -1
  12. package/lib/cjs/decorators/strict.js.map +1 -0
  13. package/lib/cjs/index.js +16 -0
  14. package/lib/cjs/index.js.map +1 -0
  15. package/lib/{interfaces → cjs/interfaces}/PlatformExpressSettings.js +0 -0
  16. package/lib/cjs/interfaces/PlatformExpressSettings.js.map +1 -0
  17. package/lib/{interfaces → cjs/interfaces}/PlatformExpressStaticsOptions.js +0 -0
  18. package/lib/cjs/interfaces/PlatformExpressStaticsOptions.js.map +1 -0
  19. package/lib/cjs/interfaces/index.js +6 -0
  20. package/lib/cjs/interfaces/index.js.map +1 -0
  21. package/lib/cjs/middlewares/rawBodyMiddleware.js +27 -0
  22. package/lib/cjs/middlewares/rawBodyMiddleware.js.map +1 -0
  23. package/lib/{middlewares → cjs/middlewares}/staticsMiddleware.js +1 -1
  24. package/lib/cjs/middlewares/staticsMiddleware.js.map +1 -0
  25. package/lib/{services → cjs/services}/PlatformExpressApplication.js +6 -5
  26. package/lib/cjs/services/PlatformExpressApplication.js.map +1 -0
  27. package/lib/{services → cjs/services}/PlatformExpressHandler.js +0 -0
  28. package/lib/cjs/services/PlatformExpressHandler.js.map +1 -0
  29. package/lib/{services → cjs/services}/PlatformExpressRequest.js +0 -0
  30. package/lib/cjs/services/PlatformExpressRequest.js.map +1 -0
  31. package/lib/{services → cjs/services}/PlatformExpressResponse.js +0 -0
  32. package/lib/cjs/services/PlatformExpressResponse.js.map +1 -0
  33. package/lib/{services → cjs/services}/PlatformExpressRouter.js +6 -6
  34. package/lib/cjs/services/PlatformExpressRouter.js.map +1 -0
  35. package/lib/cjs/services/index.js +9 -0
  36. package/lib/cjs/services/index.js.map +1 -0
  37. package/lib/esm/components/PlatformExpress.js +118 -0
  38. package/lib/esm/components/PlatformExpress.js.map +1 -0
  39. package/lib/esm/decorators/caseSensitive.js +27 -0
  40. package/lib/esm/decorators/caseSensitive.js.map +1 -0
  41. package/lib/esm/decorators/index.js +5 -0
  42. package/lib/esm/decorators/index.js.map +1 -0
  43. package/lib/esm/decorators/mergeParams.js +27 -0
  44. package/lib/esm/decorators/mergeParams.js.map +1 -0
  45. package/lib/esm/decorators/routerSettings.js +28 -0
  46. package/lib/esm/decorators/routerSettings.js.map +1 -0
  47. package/lib/esm/decorators/strict.js +27 -0
  48. package/lib/esm/decorators/strict.js.map +1 -0
  49. package/lib/esm/index.js +13 -0
  50. package/lib/esm/index.js.map +1 -0
  51. package/lib/esm/interfaces/PlatformExpressSettings.js +2 -0
  52. package/lib/esm/interfaces/PlatformExpressSettings.js.map +1 -0
  53. package/lib/esm/interfaces/PlatformExpressStaticsOptions.js +2 -0
  54. package/lib/esm/interfaces/PlatformExpressStaticsOptions.js.map +1 -0
  55. package/lib/esm/interfaces/index.js +3 -0
  56. package/lib/esm/interfaces/index.js.map +1 -0
  57. package/lib/esm/middlewares/rawBodyMiddleware.js +22 -0
  58. package/lib/esm/middlewares/rawBodyMiddleware.js.map +1 -0
  59. package/lib/esm/middlewares/staticsMiddleware.js +16 -0
  60. package/lib/esm/middlewares/staticsMiddleware.js.map +1 -0
  61. package/lib/esm/services/PlatformExpressApplication.js +29 -0
  62. package/lib/esm/services/PlatformExpressApplication.js.map +1 -0
  63. package/lib/esm/services/PlatformExpressHandler.js +27 -0
  64. package/lib/esm/services/PlatformExpressHandler.js.map +1 -0
  65. package/lib/esm/services/PlatformExpressRequest.js +8 -0
  66. package/lib/esm/services/PlatformExpressRequest.js.map +1 -0
  67. package/lib/esm/services/PlatformExpressResponse.js +8 -0
  68. package/lib/esm/services/PlatformExpressResponse.js.map +1 -0
  69. package/lib/esm/services/PlatformExpressRouter.js +31 -0
  70. package/lib/esm/services/PlatformExpressRouter.js.map +1 -0
  71. package/lib/esm/services/index.js +6 -0
  72. package/lib/esm/services/index.js.map +1 -0
  73. package/lib/types/components/PlatformExpress.d.ts +42 -0
  74. package/lib/{decorators → types/decorators}/caseSensitive.d.ts +0 -0
  75. package/lib/{decorators → types/decorators}/index.d.ts +0 -0
  76. package/lib/{decorators → types/decorators}/mergeParams.d.ts +0 -0
  77. package/lib/{decorators → types/decorators}/routerSettings.d.ts +0 -0
  78. package/lib/{decorators → types/decorators}/strict.d.ts +0 -0
  79. package/lib/{index.d.ts → types/index.d.ts} +0 -0
  80. package/lib/{interfaces → types/interfaces}/PlatformExpressSettings.d.ts +0 -0
  81. package/lib/{interfaces → types/interfaces}/PlatformExpressStaticsOptions.d.ts +0 -0
  82. package/lib/{interfaces → types/interfaces}/index.d.ts +0 -0
  83. package/lib/types/middlewares/rawBodyMiddleware.d.ts +4 -0
  84. package/lib/{middlewares → types/middlewares}/staticsMiddleware.d.ts +0 -0
  85. package/lib/{services → types/services}/PlatformExpressApplication.d.ts +0 -0
  86. package/lib/{services → types/services}/PlatformExpressHandler.d.ts +0 -0
  87. package/lib/{services → types/services}/PlatformExpressRequest.d.ts +0 -0
  88. package/lib/{services → types/services}/PlatformExpressResponse.d.ts +0 -0
  89. package/lib/{services → types/services}/PlatformExpressRouter.d.ts +0 -0
  90. package/lib/{services → types/services}/index.d.ts +0 -0
  91. package/package.json +28 -22
  92. package/tsconfig.compile.esm.json +23 -0
  93. package/lib/components/PlatformExpress.d.ts +0 -28
  94. package/lib/components/PlatformExpress.js +0 -79
  95. package/lib/components/PlatformExpress.js.map +0 -1
  96. package/lib/decorators/caseSensitive.js.map +0 -1
  97. package/lib/decorators/index.js +0 -8
  98. package/lib/decorators/index.js.map +0 -1
  99. package/lib/decorators/mergeParams.js.map +0 -1
  100. package/lib/decorators/routerSettings.js.map +0 -1
  101. package/lib/decorators/strict.js.map +0 -1
  102. package/lib/index.js +0 -16
  103. package/lib/index.js.map +0 -1
  104. package/lib/interfaces/PlatformExpressSettings.js.map +0 -1
  105. package/lib/interfaces/PlatformExpressStaticsOptions.js.map +0 -1
  106. package/lib/interfaces/index.js +0 -6
  107. package/lib/interfaces/index.js.map +0 -1
  108. package/lib/middlewares/rawBodyMiddleware.d.ts +0 -1
  109. package/lib/middlewares/rawBodyMiddleware.js +0 -14
  110. package/lib/middlewares/rawBodyMiddleware.js.map +0 -1
  111. package/lib/middlewares/staticsMiddleware.js.map +0 -1
  112. package/lib/services/PlatformExpressApplication.js.map +0 -1
  113. package/lib/services/PlatformExpressHandler.js.map +0 -1
  114. package/lib/services/PlatformExpressRequest.js.map +0 -1
  115. package/lib/services/PlatformExpressResponse.js.map +0 -1
  116. package/lib/services/PlatformExpressRouter.js.map +0 -1
  117. package/lib/services/index.js +0 -9
  118. package/lib/services/index.js.map +0 -1
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.PlatformExpress = void 0;
23
+ const common_1 = require("@tsed/common");
24
+ const core_1 = require("@tsed/core");
25
+ const rawBodyMiddleware_1 = require("../middlewares/rawBodyMiddleware");
26
+ const services_1 = require("../services");
27
+ /**
28
+ * @platform
29
+ * @express
30
+ */
31
+ class PlatformExpress {
32
+ constructor(platform) {
33
+ this.platform = platform;
34
+ this.providers = [
35
+ {
36
+ provide: common_1.PlatformApplication,
37
+ useClass: services_1.PlatformExpressApplication
38
+ },
39
+ {
40
+ provide: common_1.PlatformRouter,
41
+ useClass: services_1.PlatformExpressRouter
42
+ },
43
+ {
44
+ provide: common_1.PlatformHandler,
45
+ useClass: services_1.PlatformExpressHandler
46
+ },
47
+ {
48
+ provide: common_1.PlatformResponse,
49
+ useClass: services_1.PlatformExpressResponse
50
+ },
51
+ {
52
+ provide: common_1.PlatformRequest,
53
+ useClass: services_1.PlatformExpressRequest
54
+ }
55
+ ];
56
+ }
57
+ /**
58
+ * Create new serverless application. In this mode, the component scan are disabled.
59
+ * @param module
60
+ * @param settings
61
+ */
62
+ static create(module, settings = {}) {
63
+ return common_1.PlatformBuilder.create(module, {
64
+ ...settings,
65
+ adapter: PlatformExpress
66
+ });
67
+ }
68
+ /**
69
+ * Bootstrap a server application
70
+ * @param module
71
+ * @param settings
72
+ */
73
+ static async bootstrap(module, settings = {}) {
74
+ return common_1.PlatformBuilder.bootstrap(module, {
75
+ ...settings,
76
+ adapter: PlatformExpress
77
+ });
78
+ }
79
+ useRouter() {
80
+ const { logger, app } = this.platform;
81
+ logger.debug("Mount app router");
82
+ app.getApp().use(rawBodyMiddleware_1.rawBodyMiddleware);
83
+ app.getApp().use(app.getRouter());
84
+ return this;
85
+ }
86
+ async beforeLoadRoutes() {
87
+ const { injector, app } = this.platform;
88
+ // disable x-powered-by header
89
+ injector.settings.get("env") === core_1.Env.PROD && app.getApp().disable("x-powered-by");
90
+ await this.configureViewsEngine();
91
+ }
92
+ async afterLoadRoutes() {
93
+ const { injector, app } = this.platform;
94
+ // NOT FOUND
95
+ app.use((req, res, next) => {
96
+ var _a;
97
+ !res.headersSent && ((_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.resourceNotFound(req.$ctx));
98
+ });
99
+ // EXCEPTION FILTERS
100
+ app.use((err, req, res, next) => {
101
+ var _a;
102
+ !res.headersSent && ((_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(err, req.$ctx));
103
+ });
104
+ }
105
+ useContext() {
106
+ const { logger, app, injector } = this.platform;
107
+ logger.debug("Mount app context");
108
+ const invoke = (0, common_1.createContext)(injector);
109
+ app.getApp().use(async (request, response, next) => {
110
+ await invoke({ request, response });
111
+ return next();
112
+ });
113
+ return this;
114
+ }
115
+ async configureViewsEngine() {
116
+ const { settings, injector, app } = this.platform;
117
+ try {
118
+ const { exists, disabled } = settings.get("views") || {};
119
+ if (exists && !disabled) {
120
+ const { PlatformViews } = await Promise.resolve().then(() => __importStar(require("@tsed/platform-views")));
121
+ const platformViews = injector.get(PlatformViews);
122
+ const express = app.getApp();
123
+ platformViews.getEngines().forEach(({ extension, engine }) => {
124
+ express.engine(extension, engine.render);
125
+ });
126
+ platformViews.viewEngine && express.set("view engine", platformViews.viewEngine);
127
+ platformViews.root && express.set("views", platformViews.root);
128
+ }
129
+ }
130
+ catch (error) {
131
+ // istanbul ignore next
132
+ injector.logger.warn({
133
+ event: "PLATFORM_VIEWS_ERROR",
134
+ message: "Unable to configure the PlatformViews service on your environment.",
135
+ error
136
+ });
137
+ }
138
+ }
139
+ }
140
+ exports.PlatformExpress = PlatformExpress;
141
+ //# sourceMappingURL=PlatformExpress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,yCAUsB;AACtB,qCAAqC;AACrC,wEAAmE;AACnE,0CAMqB;AAErB;;;GAGG;AACH,MAAa,eAAe;IAwB1B,YAAoB,QAA8D;QAA9D,aAAQ,GAAR,QAAQ,CAAsD;QAvBzE,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,4BAAmB;gBAC5B,QAAQ,EAAE,qCAA0B;aACrC;YACD;gBACE,OAAO,EAAE,uBAAc;gBACvB,QAAQ,EAAE,gCAAqB;aAChC;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,iCAAsB;aACjC;YACD;gBACE,OAAO,EAAE,yBAAgB;gBACzB,QAAQ,EAAE,kCAAuB;aAClC;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,iCAAsB;aACjC;SACF,CAAC;IAEmF,CAAC;IAEtF;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAiB,EAAE,WAAwC,EAAE;QACzE,OAAO,wBAAe,CAAC,MAAM,CAAsC,MAAM,EAAE;YACzE,GAAG,QAAQ;YACX,OAAO,EAAE,eAAe;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,MAAiB,EAAE,WAAwC,EAAE;QAClF,OAAO,wBAAe,CAAC,SAAS,CAAsC,MAAM,EAAE;YAC5E,GAAG,QAAQ;YACX,OAAO,EAAE,eAAe;SACzB,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,MAAM,EAAC,MAAM,EAAE,GAAG,EAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;QAEpC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACjC,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,qCAAiB,CAAC,CAAC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uB;YACvB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AA3HD,0CA2HC","sourcesContent":["import Express from \"express\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {\n createContext,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter\n} from \"@tsed/common\";\nimport {Env, Type} from \"@tsed/core\";\nimport {rawBodyMiddleware} from \"../middlewares/rawBodyMiddleware\";\nimport {\n PlatformExpressApplication,\n PlatformExpressHandler,\n PlatformExpressRequest,\n PlatformExpressResponse,\n PlatformExpressRouter\n} from \"../services\";\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {\n readonly providers = [\n {\n provide: PlatformApplication,\n useClass: PlatformExpressApplication\n },\n {\n provide: PlatformRouter,\n useClass: PlatformExpressRouter\n },\n {\n provide: PlatformHandler,\n useClass: PlatformExpressHandler\n },\n {\n provide: PlatformResponse,\n useClass: PlatformExpressResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformExpressRequest\n }\n ];\n\n constructor(private platform: PlatformBuilder<Express.Application, Express.Router>) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Express.Application, Express.Router>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Express.Application, Express.Router>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n useRouter(): this {\n const {logger, app} = this.platform;\n\n logger.debug(\"Mount app router\");\n app.getApp().use(rawBodyMiddleware);\n app.getApp().use(app.getRouter());\n\n return this;\n }\n\n async beforeLoadRoutes() {\n const {injector, app} = this.platform;\n // disable x-powered-by header\n injector.settings.get(\"env\") === Env.PROD && app.getApp().disable(\"x-powered-by\");\n\n await this.configureViewsEngine();\n }\n\n async afterLoadRoutes() {\n const {injector, app} = this.platform;\n // NOT FOUND\n app.use((req: any, res: any, next: any) => {\n !res.headersSent && injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound(req.$ctx);\n });\n\n // EXCEPTION FILTERS\n app.use((err: any, req: any, res: any, next: any) => {\n !res.headersSent && injector.get<PlatformExceptions>(PlatformExceptions)?.catch(err, req.$ctx);\n });\n }\n\n useContext(): this {\n const {logger, app, injector} = this.platform;\n\n logger.debug(\"Mount app context\");\n\n const invoke = createContext(injector);\n\n app.getApp().use(async (request: any, response: any, next: any) => {\n await invoke({request, response});\n\n return next();\n });\n\n return this;\n }\n\n private async configureViewsEngine() {\n const {settings, injector, app} = this.platform;\n try {\n const {exists, disabled} = settings.get(\"views\") || {};\n\n if (exists && !disabled) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = injector.get<PlatformViews>(PlatformViews)!;\n const express = app.getApp();\n\n platformViews.getEngines().forEach(({extension, engine}) => {\n express.engine(extension, engine.render);\n });\n\n platformViews.viewEngine && express.set(\"view engine\", platformViews.viewEngine);\n platformViews.root && express.set(\"views\", platformViews.root);\n }\n } catch (error) {\n // istanbul ignore next\n injector.logger.warn({\n event: \"PLATFORM_VIEWS_ERROR\",\n message: \"Unable to configure the PlatformViews service on your environment.\",\n error\n });\n }\n }\n}\n"]}
@@ -25,7 +25,7 @@ const routerSettings_1 = require("./routerSettings");
25
25
  * @express
26
26
  */
27
27
  function CaseSensitive(caseSensitive) {
28
- return routerSettings_1.RouterSettings({ caseSensitive });
28
+ return (0, routerSettings_1.RouterSettings)({ caseSensitive });
29
29
  }
30
30
  exports.CaseSensitive = CaseSensitive;
31
31
  //# sourceMappingURL=caseSensitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caseSensitive.js","sourceRoot":"","sources":["../../../src/decorators/caseSensitive.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,aAAa,CAAC,aAAsB;IAClD,OAAO,IAAA,+BAAc,EAAC,EAAC,aAAa,EAAC,CAAC,CAAC;AACzC,CAAC;AAFD,sCAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @CaseSensitive(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param caseSensitive\n * @returns {Function}\n * @decorator\n * @express\n */\nexport function CaseSensitive(caseSensitive: boolean) {\n return RouterSettings({caseSensitive});\n}\n"]}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./routerSettings"), exports);
5
+ (0, tslib_1.__exportStar)(require("./caseSensitive"), exports);
6
+ (0, tslib_1.__exportStar)(require("./mergeParams"), exports);
7
+ (0, tslib_1.__exportStar)(require("./strict"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,gEAAiC;AACjC,+DAAgC;AAChC,6DAA8B;AAC9B,wDAAyB","sourcesContent":["export * from \"./routerSettings\";\nexport * from \"./caseSensitive\";\nexport * from \"./mergeParams\";\nexport * from \"./strict\";\n"]}
@@ -25,7 +25,7 @@ const routerSettings_1 = require("./routerSettings");
25
25
  * @express
26
26
  */
27
27
  function MergeParams(mergeParams = true) {
28
- return routerSettings_1.RouterSettings({ mergeParams });
28
+ return (0, routerSettings_1.RouterSettings)({ mergeParams });
29
29
  }
30
30
  exports.MergeParams = MergeParams;
31
31
  //# sourceMappingURL=mergeParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeParams.js","sourceRoot":"","sources":["../../../src/decorators/mergeParams.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,WAAW,CAAC,cAAuB,IAAI;IACrD,OAAO,IAAA,+BAAc,EAAC,EAAC,WAAW,EAAC,CAAC,CAAC;AACvC,CAAC;AAFD,kCAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @MergeParams(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param mergeParams\n * @returns {Function}\n * @decorator\n * @express\n */\nexport function MergeParams(mergeParams: boolean = true) {\n return RouterSettings({mergeParams});\n}\n"]}
@@ -26,7 +26,7 @@ const core_1 = require("@tsed/core");
26
26
  * @express
27
27
  */
28
28
  function RouterSettings(routerOptions) {
29
- return core_1.StoreMerge(common_1.ROUTER_OPTIONS, routerOptions);
29
+ return (0, core_1.StoreMerge)(common_1.ROUTER_OPTIONS, routerOptions);
30
30
  }
31
31
  exports.RouterSettings = RouterSettings;
32
32
  //# sourceMappingURL=routerSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routerSettings.js","sourceRoot":"","sources":["../../../src/decorators/routerSettings.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,qCAAsC;AAGtC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,cAAc,CAAC,aAA4B;IACzD,OAAO,IAAA,iBAAU,EAAC,uBAAc,EAAE,aAAa,CAAC,CAAC;AACnD,CAAC;AAFD,wCAEC","sourcesContent":["import {ROUTER_OPTIONS} from \"@tsed/common\";\nimport {StoreMerge} from \"@tsed/core\";\nimport {RouterOptions} from \"express\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @RouterSettings({mergeParams: true})\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * caseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * mergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @returns {(target:any)=>void}\n * @decorator\n * @param routerOptions\n * @express\n */\nexport function RouterSettings(routerOptions: RouterOptions): Function {\n return StoreMerge(ROUTER_OPTIONS, routerOptions);\n}\n"]}
@@ -25,7 +25,7 @@ const routerSettings_1 = require("./routerSettings");
25
25
  * @express
26
26
  */
27
27
  function Strict(strict) {
28
- return routerSettings_1.RouterSettings({ strict });
28
+ return (0, routerSettings_1.RouterSettings)({ strict });
29
29
  }
30
30
  exports.Strict = Strict;
31
31
  //# sourceMappingURL=strict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strict.js","sourceRoot":"","sources":["../../../src/decorators/strict.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAEhD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,MAAM,CAAC,MAAe;IACpC,OAAO,IAAA,+BAAc,EAAC,EAAC,MAAM,EAAC,CAAC,CAAC;AAClC,CAAC;AAFD,wBAEC","sourcesContent":["import {RouterSettings} from \"./routerSettings\";\n\n/**\n * Specify the behavior of the router controller.\n *\n * ```typescript\n * @Controller(\"/\")\n * @Strict(true)\n * class MyCtrl {\n *\n * }\n * ```\n *\n * Property | Description | Default\n * ---|---|---\n * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.\n * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false\n * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.\n *\n * @param strict\n * @returns {Function}\n * @decorator\n * @express\n */\nexport function Strict(strict: boolean) {\n return RouterSettings({strict});\n}\n"]}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const common_1 = require("@tsed/common");
5
+ const PlatformExpress_1 = require("./components/PlatformExpress");
6
+ common_1.PlatformTest.adapter = PlatformExpress_1.PlatformExpress;
7
+ common_1.PlatformBuilder.adapter = PlatformExpress_1.PlatformExpress;
8
+ // interfaces
9
+ (0, tslib_1.__exportStar)(require("./interfaces"), exports);
10
+ // decorators
11
+ (0, tslib_1.__exportStar)(require("./decorators"), exports);
12
+ // services
13
+ (0, tslib_1.__exportStar)(require("./services"), exports);
14
+ // components
15
+ (0, tslib_1.__exportStar)(require("./components/PlatformExpress"), exports);
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA2D;AAE3D,kEAA6D;AAE7D,qBAAY,CAAC,OAAO,GAAG,iCAAsB,CAAC;AAC9C,wBAAe,CAAC,OAAO,GAAG,iCAAsB,CAAC;AAEjD,aAAa;AACb,4DAA6B;AAE7B,aAAa;AACb,4DAA6B;AAE7B,WAAW;AACX,0DAA2B;AAE3B,aAAa;AACb,4EAA6C","sourcesContent":["import {PlatformBuilder, PlatformTest} from \"@tsed/common\";\n\nimport {PlatformExpress} from \"./components/PlatformExpress\";\n\nPlatformTest.adapter = PlatformExpress as any;\nPlatformBuilder.adapter = PlatformExpress as any;\n\n// interfaces\nexport * from \"./interfaces\";\n\n// decorators\nexport * from \"./decorators\";\n\n// services\nexport * from \"./services\";\n\n// components\nexport * from \"./components/PlatformExpress\";\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {RouterOptions} from \"express\";\n\nexport interface PlatformExpressSettings {\n /**\n * Global configuration for the Express.Router. See express [documentation](http://expressjs.com/en/api.html#express.router).\n */\n router?: RouterOptions;\n\n app?: Express.Application;\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressStaticsOptions.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressStaticsOptions.ts"],"names":[],"mappings":"","sourcesContent":["import Express from \"express\";\n\nexport interface PlatformExpressStaticsOptions {\n /**\n * Enable or disable setting Cache-Control response header, defaults to true.\n * Disabling this will ignore the immutable and maxAge options.\n */\n cacheControl?: boolean;\n\n /**\n * Set how \"dotfiles\" are treated when encountered. A dotfile is a file or directory that begins with a dot (\".\").\n * Note this check is done on the path itself without checking if the path actually exists on the disk.\n * If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to \"deny\").\n * The default value is 'ignore'.\n * 'allow' No special treatment for dotfiles\n * 'deny' Send a 403 for any request for a dotfile\n * 'ignore' Pretend like the dotfile does not exist and call next()\n */\n dotfiles?: string;\n\n /**\n * Enable or disable etag generation, defaults to true.\n */\n etag?: boolean;\n\n /**\n * Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for.\n * The first that exists will be served. Example: ['html', 'htm'].\n * The default value is false.\n */\n extensions?: string[] | false;\n\n /**\n * Let client errors fall-through as unhandled requests, otherwise forward a client error.\n * The default value is true.\n */\n fallthrough?: boolean;\n\n /**\n * Enable or disable the immutable directive in the Cache-Control response header.\n * If enabled, the maxAge option should also be specified to enable caching. The immutable directive will prevent supported clients from making conditional requests during the life of the maxAge option to check if the file has changed.\n */\n immutable?: boolean;\n\n /**\n * By default this module will send \"index.html\" files in response to a request on a directory.\n * To disable this set false or to supply a new index pass a string or an array in preferred order.\n */\n index?: boolean | string | string[];\n\n /**\n * Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.\n */\n lastModified?: boolean;\n\n /**\n * Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.\n */\n maxAge?: number | string;\n\n /**\n * Redirect to trailing \"/\" when the pathname is a dir. Defaults to true.\n */\n redirect?: boolean;\n\n /**\n * Function to set custom headers on response. Alterations to the headers need to occur synchronously.\n * The function is called as fn(res, path, stat), where the arguments are:\n * res the response object\n * path the file path that is being sent\n * stat the stat object of the file that is being sent\n */\n setHeaders?: (res: Express.Response, path: string, stat: any) => any;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./PlatformExpressSettings"), exports);
5
+ (0, tslib_1.__exportStar)(require("./PlatformExpressStaticsOptions"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAGA,yEAA0C;AAC1C,+EAAgD","sourcesContent":["import Express from \"express\";\nimport {PlatformExpressSettings} from \"./PlatformExpressSettings\";\n\nexport * from \"./PlatformExpressSettings\";\nexport * from \"./PlatformExpressStaticsOptions\";\n\ndeclare global {\n namespace TsED {\n export interface Configuration {\n /**\n * Configuration related to Express platform application.\n */\n express: PlatformExpressSettings;\n }\n\n export interface NextFunction extends Express.NextFunction {}\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rawBodyMiddleware = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const bytes_1 = (0, tslib_1.__importDefault)(require("bytes"));
6
+ const limit = bytes_1.default.parse("100kb");
7
+ function isLimitReached(length) {
8
+ return limit !== null && length !== null && length > limit;
9
+ }
10
+ function getContentLength(request) {
11
+ const contentLength = request.get("content-length");
12
+ return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;
13
+ }
14
+ function rawBodyMiddleware(request, response, next) {
15
+ if (request.method !== "GET") {
16
+ const length = getContentLength(request);
17
+ if (!isLimitReached(length) && request.is(["application/x-www-form-urlencoded", "application/json"])) {
18
+ request.rawBody = "";
19
+ request.on("data", (chunk) => {
20
+ request.rawBody += chunk;
21
+ });
22
+ }
23
+ }
24
+ next();
25
+ }
26
+ exports.rawBodyMiddleware = rawBodyMiddleware;
27
+ //# sourceMappingURL=rawBodyMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rawBodyMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/rawBodyMiddleware.ts"],"names":[],"mappings":";;;;AACA,+DAA0B;AAE1B,MAAM,KAAK,GAAG,eAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAEnC,SAAS,cAAc,CAAC,MAAqB;IAC3C,OAAO,KAAK,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC;AAC7D,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAoC;IAC5D,MAAM,aAAa,GAAQ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACzD,OAAO,aAAa,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7F,CAAC;AAED,SAAgB,iBAAiB,CAAC,OAAoC,EAAE,QAAa,EAAE,IAAS;IAC9F,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,EAAE;QAC5B,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAEzC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC,CAAC,mCAAmC,EAAE,kBAAkB,CAAC,CAAC,EAAE;YACpG,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC;YACrB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACnC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;YAC3B,CAAC,CAAC,CAAC;SACJ;KACF;IAED,IAAI,EAAE,CAAC;AACT,CAAC;AAbD,8CAaC","sourcesContent":["import {Request} from \"express\";\nimport bytes from \"bytes\";\n\nconst limit = bytes.parse(\"100kb\");\n\nfunction isLimitReached(length: number | null) {\n return limit !== null && length !== null && length > limit;\n}\n\nfunction getContentLength(request: Request & {rawBody: string}) {\n const contentLength: any = request.get(\"content-length\");\n return contentLength != null && !isNaN(contentLength) ? parseInt(contentLength, 10) : null;\n}\n\nexport function rawBodyMiddleware(request: Request & {rawBody: string}, response: any, next: any) {\n if (request.method !== \"GET\") {\n const length = getContentLength(request);\n\n if (!isLimitReached(length) && request.is([\"application/x-www-form-urlencoded\", \"application/json\"])) {\n request.rawBody = \"\";\n request.on(\"data\", (chunk: string) => {\n request.rawBody += chunk;\n });\n }\n }\n\n next();\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.staticsMiddleware = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const express_1 = tslib_1.__importDefault(require("express"));
5
+ const express_1 = (0, tslib_1.__importDefault)(require("express"));
6
6
  /**
7
7
  * @ignore
8
8
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"staticsMiddleware.js","sourceRoot":"","sources":["../../../src/middlewares/staticsMiddleware.ts"],"names":[],"mappings":";;;;AAAA,mEAA8B;AAE9B;;GAEG;AACH,SAAgB,iBAAiB,CAAC,SAAiB,EAAE,UAAe,EAAE;IACpE,MAAM,UAAU,GAAG,iBAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAEtD,OAAO,CAAC,OAAY,EAAE,QAAa,EAAE,IAAS,EAAE,EAAE;QAChD,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE;YACzB,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;SACrC;aAAM;YACL,IAAI,EAAE,CAAC;SACR;IACH,CAAC,CAAC;AACJ,CAAC;AAVD,8CAUC","sourcesContent":["import Express from \"express\";\n\n/**\n * @ignore\n */\nexport function staticsMiddleware(directory: string, options: any = {}) {\n const middleware = Express.static(directory, options);\n\n return (request: any, response: any, next: any) => {\n if (!response.headersSent) {\n middleware(request, response, next);\n } else {\n next();\n }\n };\n}\n"]}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlatformExpressApplication = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@tsed/common");
6
- const express_1 = tslib_1.__importDefault(require("express"));
6
+ const express_1 = (0, tslib_1.__importDefault)(require("express"));
7
7
  const PlatformExpressRouter_1 = require("./PlatformExpressRouter");
8
8
  /**
9
9
  * @platform
@@ -14,7 +14,7 @@ let PlatformExpressApplication = class PlatformExpressApplication extends Platfo
14
14
  super(platformHandler, configuration, {
15
15
  mergeParams: true
16
16
  });
17
- this.rawApp = configuration.get("express.app") || express_1.default();
17
+ this.rawApp = configuration.get("express.app") || (0, express_1.default)();
18
18
  }
19
19
  getApp() {
20
20
  return this.rawApp;
@@ -23,9 +23,10 @@ let PlatformExpressApplication = class PlatformExpressApplication extends Platfo
23
23
  return this.rawApp;
24
24
  }
25
25
  };
26
- PlatformExpressApplication = tslib_1.__decorate([
27
- tslib_1.__param(0, common_1.Inject()), tslib_1.__param(1, common_1.Configuration()),
28
- tslib_1.__metadata("design:paramtypes", [common_1.PlatformHandler, Object])
26
+ PlatformExpressApplication = (0, tslib_1.__decorate)([
27
+ (0, tslib_1.__param)(0, (0, common_1.Inject)()),
28
+ (0, tslib_1.__param)(1, (0, common_1.Configuration)()),
29
+ (0, tslib_1.__metadata)("design:paramtypes", [common_1.PlatformHandler, Object])
29
30
  ], PlatformExpressApplication);
30
31
  exports.PlatformExpressApplication = PlatformExpressApplication;
31
32
  //# sourceMappingURL=PlatformExpressApplication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressApplication.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressApplication.ts"],"names":[],"mappings":";;;;AAAA,yCAAwG;AACxG,mEAA8B;AAE9B,mEAA8D;AAU9D;;;GAGG;AACH,IAAa,0BAA0B,GAAvC,MAAa,0BAA2B,SAAQ,6CAAqB;IAKnE,YAAsB,eAAgC,EAAmB,aAA4B;QACnG,KAAK,CAAC,eAAe,EAAE,aAAa,EAAE;YACpC,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,IAAA,iBAAO,GAAE,CAAC;IAC9D,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF,CAAA;AApBY,0BAA0B;IAKxB,wBAAA,IAAA,eAAM,GAAE,CAAA;IAAoC,wBAAA,IAAA,sBAAa,GAAE,CAAA;kDAAjC,wBAAe;GAL3C,0BAA0B,CAoBtC;AApBY,gEAA0B","sourcesContent":["import {Configuration, createContext, Inject, PlatformApplication, PlatformHandler} from \"@tsed/common\";\nimport Express from \"express\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {PlatformExpressRouter} from \"./PlatformExpressRouter\";\n\ndeclare global {\n namespace TsED {\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressApplication extends PlatformExpressRouter implements PlatformApplication<Express.Application, Express.Router> {\n app: Express.Application;\n rawApp: Express.Application;\n rawRouter: Express.Router;\n\n constructor(@Inject() platformHandler: PlatformHandler, @Configuration() configuration: Configuration) {\n super(platformHandler, configuration, {\n mergeParams: true\n });\n\n this.rawApp = configuration.get(\"express.app\") || Express();\n }\n\n getApp() {\n return this.rawApp;\n }\n\n callback() {\n return this.rawApp;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressHandler.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressHandler.ts"],"names":[],"mappings":";;;AAAA,yCAA6F;AAE7F;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,wBAAe;IAC/C,gBAAgB,CAAC,QAAyB;QAClD,IAAI,QAAQ,CAAC,IAAI,KAAK,oBAAW,CAAC,cAAc,EAAE;YAChD,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC9C,OAAO,KAAK,EAAE,GAAQ,EAAE,GAAQ,EAAE,GAAQ,EAAE,IAAS,EAAE,EAAE,CACvD,OAAO,CAAC;gBACN,GAAG;gBACH,IAAI;gBACJ,IAAI,EAAE,GAAG,CAAC,IAAI;aACf,CAAC,CAAC;SACN;QAED,OAAO,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,cAAgC;QAC3D,IAAI;YACF,OAAO,MAAM,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;SACjD;QAAC,OAAO,EAAE,EAAE;YACX,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;SACzC;IACH,CAAC;CACF;AAtBD,wDAsBC","sourcesContent":["import {HandlerMetadata, HandlerType, OnRequestOptions, PlatformHandler} from \"@tsed/common\";\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressHandler extends PlatformHandler {\n protected createRawHandler(metadata: HandlerMetadata): Function {\n if (metadata.type === HandlerType.ERR_MIDDLEWARE) {\n const handler = this.compileHandler(metadata);\n return async (err: any, req: any, res: any, next: any) =>\n handler({\n err,\n next,\n $ctx: req.$ctx\n });\n }\n\n return super.createRawHandler(metadata);\n }\n\n protected async onCtxRequest(requestOptions: OnRequestOptions): Promise<any> {\n try {\n return await super.onCtxRequest(requestOptions);\n } catch (er) {\n return this.onError(er, requestOptions);\n }\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressRequest.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressRequest.ts"],"names":[],"mappings":";;;AAAA,yCAA8D;AAmB9D;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,wBAAgC;CAAG;AAA/E,wDAA+E","sourcesContent":["import {PlatformContext, PlatformRequest} from \"@tsed/common\";\nimport type Express from \"express\";\n\ndeclare module \"express\" {\n export interface Request {\n id: string;\n $ctx: PlatformContext;\n }\n}\n\ndeclare global {\n namespace TsED {\n export interface Request extends Express.Request {\n id: string;\n $ctx: PlatformContext;\n }\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressRequest extends PlatformRequest<Express.Request> {}\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressResponse.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressResponse.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;AAS9C;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,yBAAkC;CAAG;AAAlF,0DAAkF","sourcesContent":["import {PlatformResponse} from \"@tsed/common\";\nimport type Express from \"express\";\n\ndeclare global {\n namespace TsED {\n export interface Response extends Express.Response {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressResponse extends PlatformResponse<Express.Response> {}\n"]}
@@ -4,7 +4,7 @@ exports.PlatformExpressRouter = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@tsed/common");
6
6
  const di_1 = require("@tsed/di");
7
- const express_1 = tslib_1.__importDefault(require("express"));
7
+ const express_1 = (0, tslib_1.__importDefault)(require("express"));
8
8
  const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
9
9
  /**
10
10
  * @platform
@@ -21,14 +21,14 @@ let PlatformExpressRouter = class PlatformExpressRouter extends common_1.Platfor
21
21
  }
22
22
  statics(endpoint, options) {
23
23
  const { root, ...props } = options;
24
- this.use(endpoint, staticsMiddleware_1.staticsMiddleware(root, props));
24
+ this.use(endpoint, (0, staticsMiddleware_1.staticsMiddleware)(root, props));
25
25
  return this;
26
26
  }
27
27
  };
28
- PlatformExpressRouter = tslib_1.__decorate([
29
- tslib_1.__param(1, di_1.Configuration()),
30
- tslib_1.__param(2, di_1.Inject(common_1.PLATFORM_ROUTER_OPTIONS)),
31
- tslib_1.__metadata("design:paramtypes", [common_1.PlatformHandler, Object, Object])
28
+ PlatformExpressRouter = (0, tslib_1.__decorate)([
29
+ (0, tslib_1.__param)(1, (0, di_1.Configuration)()),
30
+ (0, tslib_1.__param)(2, (0, di_1.Inject)(common_1.PLATFORM_ROUTER_OPTIONS)),
31
+ (0, tslib_1.__metadata)("design:paramtypes", [common_1.PlatformHandler, Object, Object])
32
32
  ], PlatformExpressRouter);
33
33
  exports.PlatformExpressRouter = PlatformExpressRouter;
34
34
  //# sourceMappingURL=PlatformExpressRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpressRouter.js","sourceRoot":"","sources":["../../../src/services/PlatformExpressRouter.ts"],"names":[],"mappings":";;;;AAAA,yCAA8G;AAC9G,iCAA+C;AAC/C,mEAA8B;AAE9B,wEAAmE;AAQnE;;;GAGG;AACH,IAAa,qBAAqB,GAAlC,MAAa,qBAAsB,SAAQ,uBAA8B;IACvE,YACE,QAAyB,EACR,aAA4B,EACZ,gBAAwC,EAAE;;QAE3E,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEhB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAC3B;YACE,WAAW,EAAE,IAAI;SAClB,EACD,CAAA,MAAA,aAAa,CAAC,OAAO,0CAAE,MAAM,KAAI,EAAE,EACnC,aAAa,CACd,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,GAAG,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,CAAC,QAAgB,EAAE,OAA+B;QACvD,MAAM,EAAC,IAAI,EAAE,GAAG,KAAK,EAAC,GAAG,OAAO,CAAC;QAEjC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAA,qCAAiB,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QAEnD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAzBY,qBAAqB;IAG7B,wBAAA,IAAA,kBAAa,GAAE,CAAA;IACf,wBAAA,IAAA,WAAM,EAAC,gCAAuB,CAAC,CAAA;kDAFtB,wBAAe;GAFhB,qBAAqB,CAyBjC;AAzBY,sDAAqB","sourcesContent":["import {PLATFORM_ROUTER_OPTIONS, PlatformHandler, PlatformRouter, PlatformStaticsOptions} from \"@tsed/common\";\nimport {Configuration, Inject} from \"@tsed/di\";\nimport Express from \"express\";\nimport {RouterOptions} from \"express\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\n\ndeclare global {\n namespace TsED {\n export interface Router extends Express.Router {}\n }\n}\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpressRouter extends PlatformRouter<Express.Router> {\n constructor(\n platform: PlatformHandler,\n @Configuration() configuration: Configuration,\n @Inject(PLATFORM_ROUTER_OPTIONS) routerOptions: Partial<RouterOptions> = {}\n ) {\n super(platform);\n\n const options = Object.assign(\n {\n mergeParams: true\n },\n configuration.express?.router || {},\n routerOptions\n );\n this.rawRouter = this.raw = Express.Router(options);\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n this.use(endpoint, staticsMiddleware(root, props));\n\n return this;\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./PlatformExpressApplication"), exports);
5
+ (0, tslib_1.__exportStar)(require("./PlatformExpressHandler"), exports);
6
+ (0, tslib_1.__exportStar)(require("./PlatformExpressResponse"), exports);
7
+ (0, tslib_1.__exportStar)(require("./PlatformExpressRequest"), exports);
8
+ (0, tslib_1.__exportStar)(require("./PlatformExpressRouter"), exports);
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,4EAA6C;AAC7C,wEAAyC;AACzC,yEAA0C;AAC1C,wEAAyC;AACzC,uEAAwC","sourcesContent":["export * from \"./PlatformExpressApplication\";\nexport * from \"./PlatformExpressHandler\";\nexport * from \"./PlatformExpressResponse\";\nexport * from \"./PlatformExpressRequest\";\nexport * from \"./PlatformExpressRouter\";\n"]}
@@ -0,0 +1,118 @@
1
+ import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse, PlatformRouter } from "@tsed/common";
2
+ import { Env } from "@tsed/core";
3
+ import { rawBodyMiddleware } from "../middlewares/rawBodyMiddleware";
4
+ import { PlatformExpressApplication, PlatformExpressHandler, PlatformExpressRequest, PlatformExpressResponse, PlatformExpressRouter } from "../services";
5
+ /**
6
+ * @platform
7
+ * @express
8
+ */
9
+ export class PlatformExpress {
10
+ constructor(platform) {
11
+ this.platform = platform;
12
+ this.providers = [
13
+ {
14
+ provide: PlatformApplication,
15
+ useClass: PlatformExpressApplication
16
+ },
17
+ {
18
+ provide: PlatformRouter,
19
+ useClass: PlatformExpressRouter
20
+ },
21
+ {
22
+ provide: PlatformHandler,
23
+ useClass: PlatformExpressHandler
24
+ },
25
+ {
26
+ provide: PlatformResponse,
27
+ useClass: PlatformExpressResponse
28
+ },
29
+ {
30
+ provide: PlatformRequest,
31
+ useClass: PlatformExpressRequest
32
+ }
33
+ ];
34
+ }
35
+ /**
36
+ * Create new serverless application. In this mode, the component scan are disabled.
37
+ * @param module
38
+ * @param settings
39
+ */
40
+ static create(module, settings = {}) {
41
+ return PlatformBuilder.create(module, {
42
+ ...settings,
43
+ adapter: PlatformExpress
44
+ });
45
+ }
46
+ /**
47
+ * Bootstrap a server application
48
+ * @param module
49
+ * @param settings
50
+ */
51
+ static async bootstrap(module, settings = {}) {
52
+ return PlatformBuilder.bootstrap(module, {
53
+ ...settings,
54
+ adapter: PlatformExpress
55
+ });
56
+ }
57
+ useRouter() {
58
+ const { logger, app } = this.platform;
59
+ logger.debug("Mount app router");
60
+ app.getApp().use(rawBodyMiddleware);
61
+ app.getApp().use(app.getRouter());
62
+ return this;
63
+ }
64
+ async beforeLoadRoutes() {
65
+ const { injector, app } = this.platform;
66
+ // disable x-powered-by header
67
+ injector.settings.get("env") === Env.PROD && app.getApp().disable("x-powered-by");
68
+ await this.configureViewsEngine();
69
+ }
70
+ async afterLoadRoutes() {
71
+ const { injector, app } = this.platform;
72
+ // NOT FOUND
73
+ app.use((req, res, next) => {
74
+ var _a;
75
+ !res.headersSent && ((_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.resourceNotFound(req.$ctx));
76
+ });
77
+ // EXCEPTION FILTERS
78
+ app.use((err, req, res, next) => {
79
+ var _a;
80
+ !res.headersSent && ((_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(err, req.$ctx));
81
+ });
82
+ }
83
+ useContext() {
84
+ const { logger, app, injector } = this.platform;
85
+ logger.debug("Mount app context");
86
+ const invoke = createContext(injector);
87
+ app.getApp().use(async (request, response, next) => {
88
+ await invoke({ request, response });
89
+ return next();
90
+ });
91
+ return this;
92
+ }
93
+ async configureViewsEngine() {
94
+ const { settings, injector, app } = this.platform;
95
+ try {
96
+ const { exists, disabled } = settings.get("views") || {};
97
+ if (exists && !disabled) {
98
+ const { PlatformViews } = await import("@tsed/platform-views");
99
+ const platformViews = injector.get(PlatformViews);
100
+ const express = app.getApp();
101
+ platformViews.getEngines().forEach(({ extension, engine }) => {
102
+ express.engine(extension, engine.render);
103
+ });
104
+ platformViews.viewEngine && express.set("view engine", platformViews.viewEngine);
105
+ platformViews.root && express.set("views", platformViews.root);
106
+ }
107
+ }
108
+ catch (error) {
109
+ // istanbul ignore next
110
+ injector.logger.warn({
111
+ event: "PLATFORM_VIEWS_ERROR",
112
+ message: "Unable to configure the PlatformViews service on your environment.",
113
+ error
114
+ });
115
+ }
116
+ }
117
+ }
118
+ //# sourceMappingURL=PlatformExpress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EAEb,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,GAAG,EAAO,MAAM,YAAY,CAAC;AACrC,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,MAAM,OAAO,eAAe;IAwB1B,YAAoB,QAA8D;QAA9D,aAAQ,GAAR,QAAQ,CAAsD;QAvBzE,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,mBAAmB;gBAC5B,QAAQ,EAAE,0BAA0B;aACrC;YACD;gBACE,OAAO,EAAE,cAAc;gBACvB,QAAQ,EAAE,qBAAqB;aAChC;YACD;gBACE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Q,CAAC;QAChD,IAAI;YACF,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAEvD,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE;gBACvB,MAAM,EAAC,aAAa,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;gBAC7D,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAgB,aAAa,CAAE,CAAC;gBAClE,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;gBAE7B,aAAa,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,CAAC,EAAC,SAAS,EAAE,MAAM,EAAC,EAAE,EAAE;oBACzD,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBAC3C,CAAC,CAAC,CAAC;gBAEH,aAAa,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;gBACjF,aAAa,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC;aAChE;SACF;QAAC,OAAO,KAAK,EAAE;YACd,uBAAuB;YACvB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnB,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;CACF","sourcesContent":["import Express from \"express\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {\n createContext,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformExceptions,\n PlatformHandler,\n PlatformRequest,\n PlatformResponse,\n PlatformRouter\n} from \"@tsed/common\";\nimport {Env, Type} from \"@tsed/core\";\nimport {rawBodyMiddleware} from \"../middlewares/rawBodyMiddleware\";\nimport {\n PlatformExpressApplication,\n PlatformExpressHandler,\n PlatformExpressRequest,\n PlatformExpressResponse,\n PlatformExpressRouter\n} from \"../services\";\n\n/**\n * @platform\n * @express\n */\nexport class PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {\n readonly providers = [\n {\n provide: PlatformApplication,\n useClass: PlatformExpressApplication\n },\n {\n provide: PlatformRouter,\n useClass: PlatformExpressRouter\n },\n {\n provide: PlatformHandler,\n useClass: PlatformExpressHandler\n },\n {\n provide: PlatformResponse,\n useClass: PlatformExpressResponse\n },\n {\n provide: PlatformRequest,\n useClass: PlatformExpressRequest\n }\n ];\n\n constructor(private platform: PlatformBuilder<Express.Application, Express.Router>) {}\n\n /**\n * Create new serverless application. In this mode, the component scan are disabled.\n * @param module\n * @param settings\n */\n static create(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.create<Express.Application, Express.Router>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n /**\n * Bootstrap a server application\n * @param module\n * @param settings\n */\n static async bootstrap(module: Type<any>, settings: Partial<TsED.Configuration> = {}) {\n return PlatformBuilder.bootstrap<Express.Application, Express.Router>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n useRouter(): this {\n const {logger, app} = this.platform;\n\n logger.debug(\"Mount app router\");\n app.getApp().use(rawBodyMiddleware);\n app.getApp().use(app.getRouter());\n\n return this;\n }\n\n async beforeLoadRoutes() {\n const {injector, app} = this.platform;\n // disable x-powered-by header\n injector.settings.get(\"env\") === Env.PROD && app.getApp().disable(\"x-powered-by\");\n\n await this.configureViewsEngine();\n }\n\n async afterLoadRoutes() {\n const {injector, app} = this.platform;\n // NOT FOUND\n app.use((req: any, res: any, next: any) => {\n !res.headersSent && injector.get<PlatformExceptions>(PlatformExceptions)?.resourceNotFound(req.$ctx);\n });\n\n // EXCEPTION FILTERS\n app.use((err: any, req: any, res: any, next: any) => {\n !res.headersSent && injector.get<PlatformExceptions>(PlatformExceptions)?.catch(err, req.$ctx);\n });\n }\n\n useContext(): this {\n const {logger, app, injector} = this.platform;\n\n logger.debug(\"Mount app context\");\n\n const invoke = createContext(injector);\n\n app.getApp().use(async (request: any, response: any, next: any) => {\n await invoke({request, response});\n\n return next();\n });\n\n return this;\n }\n\n private async configureViewsEngine() {\n const {settings, injector, app} = this.platform;\n try {\n const {exists, disabled} = settings.get(\"views\") || {};\n\n if (exists && !disabled) {\n const {PlatformViews} = await import(\"@tsed/platform-views\");\n const platformViews = injector.get<PlatformViews>(PlatformViews)!;\n const express = app.getApp();\n\n platformViews.getEngines().forEach(({extension, engine}) => {\n express.engine(extension, engine.render);\n });\n\n platformViews.viewEngine && express.set(\"view engine\", platformViews.viewEngine);\n platformViews.root && express.set(\"views\", platformViews.root);\n }\n } catch (error) {\n // istanbul ignore next\n injector.logger.warn({\n event: \"PLATFORM_VIEWS_ERROR\",\n message: \"Unable to configure the PlatformViews service on your environment.\",\n error\n });\n }\n }\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import { RouterSettings } from "./routerSettings";
2
+ /**
3
+ * Specify the behavior of the router controller.
4
+ *
5
+ * ```typescript
6
+ * @Controller("/")
7
+ * @CaseSensitive(true)
8
+ * class MyCtrl {
9
+ *
10
+ * }
11
+ * ```
12
+ *
13
+ * Property | Description | Default
14
+ * ---|---|---
15
+ * CaseSensitive | Enable case sensitivity. | Disabled by default, treating “/Foo” and “/foo” as the same.
16
+ * MergeParams | Preserve the req.params values from the parent router. If the parent and the child have conflicting param names, the child’s value take precedence. | false
17
+ * Strict | Enable strict routing. | Disabled by default, “/foo” and “/foo/” are treated the same by the router.
18
+ *
19
+ * @param caseSensitive
20
+ * @returns {Function}
21
+ * @decorator
22
+ * @express
23
+ */
24
+ export function CaseSensitive(caseSensitive) {
25
+ return RouterSettings({ caseSensitive });
26
+ }
27
+ //# sourceMappingURL=caseSensitive.js.map