@tsed/platform-express 7.0.0-beta.8 → 7.0.0-rc.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 (52) hide show
  1. package/coverage.json +6 -0
  2. package/jest.config.js +9 -0
  3. package/lib/cjs/components/PlatformExpress.js +67 -66
  4. package/lib/cjs/components/PlatformExpress.js.map +1 -1
  5. package/lib/cjs/index.js +0 -7
  6. package/lib/cjs/index.js.map +1 -1
  7. package/lib/cjs/interfaces/PlatformExpressSettings.js.map +1 -1
  8. package/lib/esm/components/PlatformExpress.js +67 -67
  9. package/lib/esm/components/PlatformExpress.js.map +1 -1
  10. package/lib/esm/index.js +0 -7
  11. package/lib/esm/index.js.map +1 -1
  12. package/lib/esm/interfaces/PlatformExpressSettings.js.map +1 -1
  13. package/lib/types/components/PlatformExpress.d.ts +12 -27
  14. package/lib/types/index.d.ts +0 -7
  15. package/lib/types/interfaces/PlatformExpressSettings.d.ts +4 -4
  16. package/package.json +28 -20
  17. package/readme.md +3 -2
  18. package/lib/cjs/decorators/caseSensitive.js +0 -31
  19. package/lib/cjs/decorators/caseSensitive.js.map +0 -1
  20. package/lib/cjs/decorators/mergeParams.js +0 -31
  21. package/lib/cjs/decorators/mergeParams.js.map +0 -1
  22. package/lib/cjs/decorators/routerSettings.js +0 -32
  23. package/lib/cjs/decorators/routerSettings.js.map +0 -1
  24. package/lib/cjs/decorators/strict.js +0 -31
  25. package/lib/cjs/decorators/strict.js.map +0 -1
  26. package/lib/cjs/services/PlatformExpressHandler.js +0 -31
  27. package/lib/cjs/services/PlatformExpressHandler.js.map +0 -1
  28. package/lib/cjs/services/PlatformExpressRequest.js +0 -12
  29. package/lib/cjs/services/PlatformExpressRequest.js.map +0 -1
  30. package/lib/cjs/services/PlatformExpressResponse.js +0 -12
  31. package/lib/cjs/services/PlatformExpressResponse.js.map +0 -1
  32. package/lib/esm/decorators/caseSensitive.js +0 -27
  33. package/lib/esm/decorators/caseSensitive.js.map +0 -1
  34. package/lib/esm/decorators/mergeParams.js +0 -27
  35. package/lib/esm/decorators/mergeParams.js.map +0 -1
  36. package/lib/esm/decorators/routerSettings.js +0 -28
  37. package/lib/esm/decorators/routerSettings.js.map +0 -1
  38. package/lib/esm/decorators/strict.js +0 -27
  39. package/lib/esm/decorators/strict.js.map +0 -1
  40. package/lib/esm/services/PlatformExpressHandler.js +0 -27
  41. package/lib/esm/services/PlatformExpressHandler.js.map +0 -1
  42. package/lib/esm/services/PlatformExpressRequest.js +0 -8
  43. package/lib/esm/services/PlatformExpressRequest.js.map +0 -1
  44. package/lib/esm/services/PlatformExpressResponse.js +0 -8
  45. package/lib/esm/services/PlatformExpressResponse.js.map +0 -1
  46. package/lib/types/decorators/caseSensitive.d.ts +0 -23
  47. package/lib/types/decorators/mergeParams.d.ts +0 -23
  48. package/lib/types/decorators/routerSettings.d.ts +0 -24
  49. package/lib/types/decorators/strict.d.ts +0 -23
  50. package/lib/types/services/PlatformExpressHandler.d.ts +0 -9
  51. package/lib/types/services/PlatformExpressRequest.d.ts +0 -8
  52. package/lib/types/services/PlatformExpressResponse.d.ts +0 -14
package/coverage.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "statements": 100,
3
+ "branches": 80.64,
4
+ "functions": 100,
5
+ "lines": 100
6
+ }
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ // For a detailed explanation regarding each configuration property, visit:
2
+ // https://jestjs.io/docs/en/configuration.html
3
+
4
+ module.exports = {
5
+ ...require("@tsed/jest-config")(__dirname, "platform-express"),
6
+ coverageThreshold: {
7
+ global: require("./coverage.json")
8
+ }
9
+ };
@@ -1,39 +1,23 @@
1
1
  "use strict";
2
- var _PlatformExpress_multer;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.PlatformExpress = void 0;
5
4
  const tslib_1 = require("tslib");
6
- const express_1 = tslib_1.__importDefault(require("express"));
7
5
  const common_1 = require("@tsed/common");
8
- const util_1 = require("util");
9
6
  const core_1 = require("@tsed/core");
10
- const PlatformExpressHandler_1 = require("../services/PlatformExpressHandler");
11
- const PlatformExpressResponse_1 = require("../services/PlatformExpressResponse");
12
- const PlatformExpressRequest_1 = require("../services/PlatformExpressRequest");
7
+ const express_1 = tslib_1.__importDefault(require("express"));
8
+ const util_1 = require("util");
13
9
  const staticsMiddleware_1 = require("../middlewares/staticsMiddleware");
14
10
  /**
15
11
  * @platform
16
12
  * @express
17
13
  */
18
14
  class PlatformExpress {
15
+ injector;
16
+ providers = [];
17
+ #multer;
19
18
  constructor(injector) {
20
19
  this.injector = injector;
21
- this.providers = [
22
- {
23
- provide: common_1.PlatformHandler,
24
- useClass: PlatformExpressHandler_1.PlatformExpressHandler
25
- },
26
- {
27
- provide: common_1.PlatformResponse,
28
- useClass: PlatformExpressResponse_1.PlatformExpressResponse
29
- },
30
- {
31
- provide: common_1.PlatformRequest,
32
- useClass: PlatformExpressRequest_1.PlatformExpressRequest
33
- }
34
- ];
35
- _PlatformExpress_multer.set(this, void 0);
36
- Promise.resolve().then(() => tslib_1.__importStar(require("multer"))).then(({ default: multer }) => (tslib_1.__classPrivateFieldSet(this, _PlatformExpress_multer, multer, "f")));
20
+ Promise.resolve().then(() => tslib_1.__importStar(require("multer"))).then(({ default: multer }) => (this.#multer = multer));
37
21
  }
38
22
  /**
39
23
  * Create new serverless application. In this mode, the component scan are disabled.
@@ -58,21 +42,15 @@ class PlatformExpress {
58
42
  });
59
43
  }
60
44
  onInit() {
61
- this.injector.settings.middlewares = (this.injector.settings.middlewares || []).filter((middleware) => {
45
+ const middlewares = this.injector.settings.get("middlewares", []);
46
+ this.injector.settings.set("middlewares", middlewares.filter((middleware) => {
62
47
  const name = (0, core_1.nameOf)(middleware);
63
48
  if (["textParser", "jsonParser", "rawParser", "urlencodedParser"].includes(name)) {
64
49
  this.injector.settings.set(`express.bodyParser.${name.replace("Parser", "")}`, () => middleware);
65
50
  return false;
66
51
  }
67
52
  return true;
68
- });
69
- }
70
- useRouter() {
71
- const { logger } = this.injector;
72
- const app = this.injector.get(common_1.PlatformApplication);
73
- logger.debug("Mount app router");
74
- app.getApp().use(app.getRouter());
75
- return this;
53
+ }));
76
54
  }
77
55
  async beforeLoadRoutes() {
78
56
  const injector = this.injector;
@@ -82,32 +60,75 @@ class PlatformExpress {
82
60
  await this.configureViewsEngine();
83
61
  }
84
62
  async afterLoadRoutes() {
85
- const injector = this.injector;
86
63
  const app = this.injector.get(common_1.PlatformApplication);
64
+ const platformExceptions = this.injector.get(common_1.PlatformExceptions);
87
65
  // NOT FOUND
88
66
  app.use((req, res, next) => {
89
- var _a;
90
- !res.headersSent && ((_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.resourceNotFound(req.$ctx));
67
+ const { $ctx } = req;
68
+ !$ctx.isDone() && platformExceptions?.resourceNotFound(req.$ctx);
91
69
  });
92
70
  // EXCEPTION FILTERS
93
71
  app.use((err, req, res, next) => {
94
- var _a;
95
- !res.headersSent && ((_a = injector.get(common_1.PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(err, req.$ctx));
72
+ const { $ctx } = req;
73
+ !$ctx.isDone() && platformExceptions?.catch(err, $ctx);
74
+ });
75
+ }
76
+ mapLayers(layers) {
77
+ const app = this.getPlatformApplication();
78
+ const rawApp = app.getApp();
79
+ layers.forEach((layer) => {
80
+ switch (layer.method) {
81
+ case "statics":
82
+ rawApp.use(layer.path, this.statics(layer.path, layer.opts));
83
+ return;
84
+ }
85
+ rawApp[layer.method](...layer.getArgs());
96
86
  });
97
87
  }
88
+ mapHandler(handler, metadata) {
89
+ switch (metadata.type) {
90
+ case common_1.PlatformHandlerType.RAW_FN:
91
+ case common_1.PlatformHandlerType.RAW_ERR_FN:
92
+ return handler;
93
+ case common_1.PlatformHandlerType.ERR_MIDDLEWARE:
94
+ return async (error, req, res, next) => {
95
+ return (0, common_1.runInContext)(req.$ctx, () => {
96
+ const { $ctx } = req;
97
+ $ctx.next = next;
98
+ $ctx.error = error;
99
+ return handler($ctx);
100
+ });
101
+ };
102
+ default:
103
+ return (req, res, next) => {
104
+ return (0, common_1.runInContext)(req.$ctx, () => {
105
+ req.$ctx.next = next;
106
+ handler(req.$ctx);
107
+ });
108
+ };
109
+ }
110
+ }
98
111
  useContext() {
99
- const { logger } = this.injector;
100
- logger.debug("Mount app context");
112
+ const app = this.getPlatformApplication();
101
113
  const invoke = (0, common_1.createContext)(this.injector);
102
- const app = this.injector.get(common_1.PlatformApplication);
103
- app.getApp().use(async (request, response, next) => {
104
- await invoke({ request, response });
105
- return next();
114
+ this.injector.logger.debug("Mount app context");
115
+ app.use(async (request, response, next) => {
116
+ const $ctx = await invoke({ request, response });
117
+ await $ctx.start();
118
+ $ctx.response.getRes().on("finish", () => $ctx.finish());
119
+ return (0, common_1.runInContext)($ctx, next);
106
120
  });
107
121
  return this;
108
122
  }
123
+ app() {
124
+ const app = this.injector.settings.get("express.app") || (0, express_1.default)();
125
+ return {
126
+ app,
127
+ callback: () => app
128
+ };
129
+ }
109
130
  multipart(options) {
110
- const m = tslib_1.__classPrivateFieldGet(this, _PlatformExpress_multer, "f").call(this, options);
131
+ const m = this.#multer(options);
111
132
  const makePromise = (multer, name) => {
112
133
  // istanbul ignore next
113
134
  if (!multer[name])
@@ -125,28 +146,6 @@ class PlatformExpress {
125
146
  makePromise(m, "single");
126
147
  return m;
127
148
  }
128
- app() {
129
- const app = this.injector.settings.get("express.app") || (0, express_1.default)();
130
- return {
131
- app,
132
- callback() {
133
- return app;
134
- }
135
- };
136
- }
137
- router(routerOptions = {}) {
138
- var _a;
139
- const options = Object.assign({
140
- mergeParams: true
141
- }, ((_a = this.injector.settings.express) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
142
- const router = express_1.default.Router(options);
143
- return {
144
- router,
145
- callback() {
146
- return router;
147
- }
148
- };
149
- }
150
149
  statics(endpoint, options) {
151
150
  const { root, ...props } = options;
152
151
  return (0, staticsMiddleware_1.staticsMiddleware)(root, props);
@@ -169,6 +168,9 @@ class PlatformExpress {
169
168
  }
170
169
  return parser({ ...options, ...additionalOptions });
171
170
  }
171
+ getPlatformApplication() {
172
+ return this.injector.get(common_1.PlatformApplication);
173
+ }
172
174
  async configureViewsEngine() {
173
175
  const injector = this.injector;
174
176
  const app = this.injector.get(common_1.PlatformApplication);
@@ -196,5 +198,4 @@ class PlatformExpress {
196
198
  }
197
199
  }
198
200
  exports.PlatformExpress = PlatformExpress;
199
- _PlatformExpress_multer = new WeakMap();
200
201
  //# sourceMappingURL=PlatformExpress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;;AACA,8DAA+C;AAE/C,yCAcsB;AACtB,+BAA+B;AAC/B,qCAAyD;AACzD,+EAA0E;AAC1E,iFAA4E;AAC5E,+EAA0E;AAC1E,wEAAmE;AA0BnE;;;GAGG;AACH,MAAa,eAAe;IAiB1B,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAhBtC,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,+CAAsB;aACjC;YACD;gBACE,OAAO,EAAE,yBAAgB;gBACzB,QAAQ,EAAE,iDAAuB;aAClC;YACD;gBACE,OAAO,EAAE,wBAAe;gBACxB,QAAQ,EAAE,+CAAsB;aACjC;SACF,CAAC;QACF,0CAAuB;QAGrB,0DAAO,QAAQ,IAAE,IAAI,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,+BAAA,IAAI,2BAAW,MAAM,MAAA,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;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;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AAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AA3ND,0CA2NC","sourcesContent":["import type multer from \"multer\";\nimport Express, {RouterOptions} from \"express\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {promisify} from \"util\";\nimport {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport {PlatformExpressHandler} from \"../services/PlatformExpressHandler\";\nimport {PlatformExpressResponse} from \"../services/PlatformExpressResponse\";\nimport {PlatformExpressRequest} from \"../services/PlatformExpressRequest\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\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 Router extends Express.Router {}\n\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n\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 PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {\n readonly providers = [\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 #multer: typeof multer;\n\n constructor(protected injector: InjectorService) {\n import(\"multer\").then(({default: multer}) => (this.#multer = multer));\n }\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 onInit() {\n this.injector.settings.middlewares = (this.injector.settings.middlewares || []).filter((middleware) => {\n const name = nameOf(middleware);\n if ([\"textParser\", \"jsonParser\", \"rawParser\", \"urlencodedParser\"].includes(name)) {\n this.injector.settings.set(`express.bodyParser.${name.replace(\"Parser\", \"\")}`, () => middleware);\n return false;\n }\n\n return true;\n });\n }\n\n useRouter(): this {\n const {logger} = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n logger.debug(\"Mount app router\");\n app.getApp().use(app.getRouter());\n\n return this;\n }\n\n async beforeLoadRoutes() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\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 = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\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} = this.injector;\n\n logger.debug(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\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 multipart(options: PlatformMulterSettings): PlatformMulter {\n const m = this.#multer(options);\n\n const makePromise = (multer: any, name: string) => {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n }\n\n app() {\n const app = this.injector.settings.get(\"express.app\") || Express();\n return {\n app,\n callback() {\n return app;\n }\n };\n }\n\n router(routerOptions: Partial<RouterOptions> = {}) {\n const options = Object.assign(\n {\n mergeParams: true\n },\n this.injector.settings.express?.router || {},\n routerOptions\n );\n\n const router = Express.Router(options);\n\n return {\n router,\n callback() {\n return router;\n }\n };\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n return staticsMiddleware(root, props);\n }\n\n bodyParser(type: \"json\" | \"raw\" | \"text\" | \"urlencoded\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`express.bodyParser.${type}`);\n let parser: any = Express[type];\n let options: OptionsJson & OptionsText & OptionsUrlencoded = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n switch (type) {\n case \"urlencoded\":\n options.extended = true;\n break;\n case \"raw\":\n options.type = () => true;\n break;\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private async configureViewsEngine() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n try {\n const {exists, disabled} = this.injector.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"]}
1
+ {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;;;AAAA,yCAasB;AACtB,qCAAyD;AAIzD,8DAA8B;AAE9B,+BAA+B;AAE/B,wEAAmE;AAwBnE;;;GAGG;AACH,MAAa,eAAe;IAIJ;IAHb,SAAS,GAAG,EAAE,CAAC;IACxB,OAAO,CAAgB;IAEvB,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAC7C,0DAAO,QAAQ,IAAE,IAAI,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAiB,EAAE,WAAwC,EAAE;QACzE,OAAO,wBAAe,CAAC,MAAM,CAAsB,MAAM,EAAE;YACzD,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,CAAsB,MAAM,EAAE;YAC5D,GAAG,QAAQ;YACX,OAAO,EAAE,eAAe;SACzB,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;QAElE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CACxB,aAAa,EAC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G,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;AArOD,0CAqOC","sourcesContent":["import {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformHandlerType,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformStaticsOptions,\n runInContext\n} from \"@tsed/common\";\nimport {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport {PlatformHandlerMetadata, PlatformLayer} from \"@tsed/platform-router\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\nimport Express from \"express\";\nimport type multer from \"multer\";\nimport {promisify} from \"util\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\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 Router extends Express.Router {}\n\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n\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 PlatformExpress implements PlatformAdapter<Express.Application> {\n readonly providers = [];\n #multer: typeof multer;\n\n constructor(protected injector: InjectorService) {\n import(\"multer\").then(({default: multer}) => (this.#multer = multer));\n }\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>(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>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n onInit() {\n const middlewares = this.injector.settings.get(\"middlewares\", []);\n\n this.injector.settings.set(\n \"middlewares\",\n middlewares.filter((middleware) => {\n const name = nameOf(middleware);\n if ([\"textParser\", \"jsonParser\", \"rawParser\", \"urlencodedParser\"].includes(name)) {\n this.injector.settings.set(`express.bodyParser.${name.replace(\"Parser\", \"\")}`, () => middleware);\n return false;\n }\n\n return true;\n })\n );\n }\n\n async beforeLoadRoutes() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\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 app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n const platformExceptions = this.injector.get<PlatformExceptions>(PlatformExceptions)!;\n\n // NOT FOUND\n app.use((req: any, res: any, next: any) => {\n const {$ctx} = req;\n !$ctx.isDone() && platformExceptions?.resourceNotFound(req.$ctx);\n });\n\n // EXCEPTION FILTERS\n app.use((err: any, req: any, res: any, next: any) => {\n const {$ctx} = req;\n !$ctx.isDone() && platformExceptions?.catch(err, $ctx);\n });\n }\n\n mapLayers(layers: PlatformLayer[]) {\n const app = this.getPlatformApplication();\n const rawApp: any = app.getApp();\n\n layers.forEach((layer) => {\n switch (layer.method) {\n case \"statics\":\n rawApp.use(layer.path, this.statics(layer.path as string, layer.opts as any));\n return;\n }\n\n rawApp[layer.method](...layer.getArgs());\n });\n }\n\n mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {\n switch (metadata.type) {\n case PlatformHandlerType.RAW_FN:\n case PlatformHandlerType.RAW_ERR_FN:\n return handler;\n case PlatformHandlerType.ERR_MIDDLEWARE:\n return async (error: unknown, req: any, res: any, next: any) => {\n return runInContext(req.$ctx, () => {\n const {$ctx} = req;\n\n $ctx.next = next;\n $ctx.error = error;\n\n return handler($ctx);\n });\n };\n default:\n return (req: any, res: any, next: any) => {\n return runInContext(req.$ctx, () => {\n req.$ctx.next = next;\n handler(req.$ctx);\n });\n };\n }\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n const invoke = createContext(this.injector);\n\n this.injector.logger.debug(\"Mount app context\");\n\n app.use(async (request: any, response: any, next: any) => {\n const $ctx = await invoke({request, response});\n await $ctx.start();\n\n $ctx.response.getRes().on(\"finish\", () => $ctx.finish());\n\n return runInContext($ctx, next);\n });\n\n return this;\n }\n\n app() {\n const app = this.injector.settings.get(\"express.app\") || Express();\n\n return {\n app,\n callback: () => app\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n const m = this.#multer(options);\n\n const makePromise = (multer: any, name: string) => {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n return staticsMiddleware(root, props);\n }\n\n bodyParser(type: \"json\" | \"raw\" | \"text\" | \"urlencoded\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`express.bodyParser.${type}`);\n let parser: any = Express[type];\n let options: OptionsJson & OptionsText & OptionsUrlencoded = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n switch (type) {\n case \"urlencoded\":\n options.extended = true;\n break;\n case \"raw\":\n options.type = () => true;\n break;\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private getPlatformApplication() {\n return this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n }\n\n private async configureViewsEngine() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n try {\n const {exists, disabled} = this.injector.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"]}
package/lib/cjs/index.js CHANGED
@@ -6,15 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const tslib_1 = require("tslib");
7
7
  tslib_1.__exportStar(require("./exports"), exports);
8
8
  tslib_1.__exportStar(require("./components/PlatformExpress"), exports);
9
- tslib_1.__exportStar(require("./decorators/caseSensitive"), exports);
10
- tslib_1.__exportStar(require("./decorators/mergeParams"), exports);
11
- tslib_1.__exportStar(require("./decorators/routerSettings"), exports);
12
- tslib_1.__exportStar(require("./decorators/strict"), exports);
13
9
  tslib_1.__exportStar(require("./interfaces/PlatformExpressSettings"), exports);
14
10
  tslib_1.__exportStar(require("./interfaces/PlatformExpressStaticsOptions"), exports);
15
11
  tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
16
12
  tslib_1.__exportStar(require("./middlewares/staticsMiddleware"), exports);
17
- tslib_1.__exportStar(require("./services/PlatformExpressHandler"), exports);
18
- tslib_1.__exportStar(require("./services/PlatformExpressRequest"), exports);
19
- tslib_1.__exportStar(require("./services/PlatformExpressResponse"), exports);
20
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,uEAA6C;AAC7C,qEAA2C;AAC3C,mEAAyC;AACzC,sEAA4C;AAC5C,8DAAoC;AACpC,+EAAqD;AACrD,qFAA2D;AAC3D,kEAAwC;AACxC,0EAAgD;AAChD,4EAAkD;AAClD,4EAAkD;AAClD,6EAAmD","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformExpress\";\nexport * from \"./decorators/caseSensitive\";\nexport * from \"./decorators/mergeParams\";\nexport * from \"./decorators/routerSettings\";\nexport * from \"./decorators/strict\";\nexport * from \"./interfaces/PlatformExpressSettings\";\nexport * from \"./interfaces/PlatformExpressStaticsOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformExpressHandler\";\nexport * from \"./services/PlatformExpressRequest\";\nexport * from \"./services/PlatformExpressResponse\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAA0B;AAC1B,uEAA6C;AAC7C,+EAAqD;AACrD,qFAA2D;AAC3D,kEAAwC;AACxC,0EAAgD","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformExpress\";\nexport * from \"./interfaces/PlatformExpressSettings\";\nexport * from \"./interfaces/PlatformExpressStaticsOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {RouterOptions} from \"express\";\nimport type {OptionsJson, OptionsText, Options, OptionsUrlencoded} from \"body-parser\";\nimport type {NextHandleFunction} from \"connect\";\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 * Express application\n */\n app?: Express.Application;\n\n /**\n * body parser configuration\n */\n bodyParser?: {\n json?: (opts?: OptionsJson) => NextHandleFunction | OptionsJson;\n text?: (opts?: OptionsText) => NextHandleFunction | OptionsText;\n raw?: (opts?: Options) => NextHandleFunction | Options;\n urlencoded?: (opts?: OptionsUrlencoded) => NextHandleFunction | OptionsUrlencoded;\n };\n}\n"]}
1
+ {"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {RouterOptions} from \"express\";\nimport type {OptionsJson, OptionsText, Options, OptionsUrlencoded} from \"body-parser\";\nimport type {NextHandleFunction} from \"connect\";\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 * Express application\n */\n app?: Express.Application;\n\n /**\n * body parser configuration\n */\n bodyParser?: {\n json?: ((opts?: OptionsJson) => NextHandleFunction) | OptionsJson;\n text?: ((opts?: OptionsText) => NextHandleFunction) | OptionsText;\n raw?: ((opts?: Options) => NextHandleFunction) | Options;\n urlencoded?: ((opts?: OptionsUrlencoded) => NextHandleFunction) | OptionsUrlencoded;\n };\n}\n"]}
@@ -1,36 +1,19 @@
1
- var _PlatformExpress_multer;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
1
+ import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandlerType, runInContext } from "@tsed/common";
2
+ import { Env, isFunction, nameOf } from "@tsed/core";
3
3
  import Express from "express";
4
- import { createContext, PlatformApplication, PlatformBuilder, PlatformExceptions, PlatformHandler, PlatformRequest, PlatformResponse } from "@tsed/common";
5
4
  import { promisify } from "util";
6
- import { Env, isFunction, nameOf } from "@tsed/core";
7
- import { PlatformExpressHandler } from "../services/PlatformExpressHandler.js";
8
- import { PlatformExpressResponse } from "../services/PlatformExpressResponse.js";
9
- import { PlatformExpressRequest } from "../services/PlatformExpressRequest.js";
10
5
  import { staticsMiddleware } from "../middlewares/staticsMiddleware.js";
11
6
  /**
12
7
  * @platform
13
8
  * @express
14
9
  */
15
10
  export class PlatformExpress {
11
+ injector;
12
+ providers = [];
13
+ #multer;
16
14
  constructor(injector) {
17
15
  this.injector = injector;
18
- this.providers = [
19
- {
20
- provide: PlatformHandler,
21
- useClass: PlatformExpressHandler
22
- },
23
- {
24
- provide: PlatformResponse,
25
- useClass: PlatformExpressResponse
26
- },
27
- {
28
- provide: PlatformRequest,
29
- useClass: PlatformExpressRequest
30
- }
31
- ];
32
- _PlatformExpress_multer.set(this, void 0);
33
- import("multer").then(({ default: multer }) => (__classPrivateFieldSet(this, _PlatformExpress_multer, multer, "f")));
16
+ import("multer").then(({ default: multer }) => (this.#multer = multer));
34
17
  }
35
18
  /**
36
19
  * Create new serverless application. In this mode, the component scan are disabled.
@@ -55,21 +38,15 @@ export class PlatformExpress {
55
38
  });
56
39
  }
57
40
  onInit() {
58
- this.injector.settings.middlewares = (this.injector.settings.middlewares || []).filter((middleware) => {
41
+ const middlewares = this.injector.settings.get("middlewares", []);
42
+ this.injector.settings.set("middlewares", middlewares.filter((middleware) => {
59
43
  const name = nameOf(middleware);
60
44
  if (["textParser", "jsonParser", "rawParser", "urlencodedParser"].includes(name)) {
61
45
  this.injector.settings.set(`express.bodyParser.${name.replace("Parser", "")}`, () => middleware);
62
46
  return false;
63
47
  }
64
48
  return true;
65
- });
66
- }
67
- useRouter() {
68
- const { logger } = this.injector;
69
- const app = this.injector.get(PlatformApplication);
70
- logger.debug("Mount app router");
71
- app.getApp().use(app.getRouter());
72
- return this;
49
+ }));
73
50
  }
74
51
  async beforeLoadRoutes() {
75
52
  const injector = this.injector;
@@ -79,32 +56,75 @@ export class PlatformExpress {
79
56
  await this.configureViewsEngine();
80
57
  }
81
58
  async afterLoadRoutes() {
82
- const injector = this.injector;
83
59
  const app = this.injector.get(PlatformApplication);
60
+ const platformExceptions = this.injector.get(PlatformExceptions);
84
61
  // NOT FOUND
85
62
  app.use((req, res, next) => {
86
- var _a;
87
- !res.headersSent && ((_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.resourceNotFound(req.$ctx));
63
+ const { $ctx } = req;
64
+ !$ctx.isDone() && platformExceptions?.resourceNotFound(req.$ctx);
88
65
  });
89
66
  // EXCEPTION FILTERS
90
67
  app.use((err, req, res, next) => {
91
- var _a;
92
- !res.headersSent && ((_a = injector.get(PlatformExceptions)) === null || _a === void 0 ? void 0 : _a.catch(err, req.$ctx));
68
+ const { $ctx } = req;
69
+ !$ctx.isDone() && platformExceptions?.catch(err, $ctx);
93
70
  });
94
71
  }
72
+ mapLayers(layers) {
73
+ const app = this.getPlatformApplication();
74
+ const rawApp = app.getApp();
75
+ layers.forEach((layer) => {
76
+ switch (layer.method) {
77
+ case "statics":
78
+ rawApp.use(layer.path, this.statics(layer.path, layer.opts));
79
+ return;
80
+ }
81
+ rawApp[layer.method](...layer.getArgs());
82
+ });
83
+ }
84
+ mapHandler(handler, metadata) {
85
+ switch (metadata.type) {
86
+ case PlatformHandlerType.RAW_FN:
87
+ case PlatformHandlerType.RAW_ERR_FN:
88
+ return handler;
89
+ case PlatformHandlerType.ERR_MIDDLEWARE:
90
+ return async (error, req, res, next) => {
91
+ return runInContext(req.$ctx, () => {
92
+ const { $ctx } = req;
93
+ $ctx.next = next;
94
+ $ctx.error = error;
95
+ return handler($ctx);
96
+ });
97
+ };
98
+ default:
99
+ return (req, res, next) => {
100
+ return runInContext(req.$ctx, () => {
101
+ req.$ctx.next = next;
102
+ handler(req.$ctx);
103
+ });
104
+ };
105
+ }
106
+ }
95
107
  useContext() {
96
- const { logger } = this.injector;
97
- logger.debug("Mount app context");
108
+ const app = this.getPlatformApplication();
98
109
  const invoke = createContext(this.injector);
99
- const app = this.injector.get(PlatformApplication);
100
- app.getApp().use(async (request, response, next) => {
101
- await invoke({ request, response });
102
- return next();
110
+ this.injector.logger.debug("Mount app context");
111
+ app.use(async (request, response, next) => {
112
+ const $ctx = await invoke({ request, response });
113
+ await $ctx.start();
114
+ $ctx.response.getRes().on("finish", () => $ctx.finish());
115
+ return runInContext($ctx, next);
103
116
  });
104
117
  return this;
105
118
  }
119
+ app() {
120
+ const app = this.injector.settings.get("express.app") || Express();
121
+ return {
122
+ app,
123
+ callback: () => app
124
+ };
125
+ }
106
126
  multipart(options) {
107
- const m = __classPrivateFieldGet(this, _PlatformExpress_multer, "f").call(this, options);
127
+ const m = this.#multer(options);
108
128
  const makePromise = (multer, name) => {
109
129
  // istanbul ignore next
110
130
  if (!multer[name])
@@ -122,28 +142,6 @@ export class PlatformExpress {
122
142
  makePromise(m, "single");
123
143
  return m;
124
144
  }
125
- app() {
126
- const app = this.injector.settings.get("express.app") || Express();
127
- return {
128
- app,
129
- callback() {
130
- return app;
131
- }
132
- };
133
- }
134
- router(routerOptions = {}) {
135
- var _a;
136
- const options = Object.assign({
137
- mergeParams: true
138
- }, ((_a = this.injector.settings.express) === null || _a === void 0 ? void 0 : _a.router) || {}, routerOptions);
139
- const router = Express.Router(options);
140
- return {
141
- router,
142
- callback() {
143
- return router;
144
- }
145
- };
146
- }
147
145
  statics(endpoint, options) {
148
146
  const { root, ...props } = options;
149
147
  return staticsMiddleware(root, props);
@@ -166,6 +164,9 @@ export class PlatformExpress {
166
164
  }
167
165
  return parser({ ...options, ...additionalOptions });
168
166
  }
167
+ getPlatformApplication() {
168
+ return this.injector.get(PlatformApplication);
169
+ }
169
170
  async configureViewsEngine() {
170
171
  const injector = this.injector;
171
172
  const app = this.injector.get(PlatformApplication);
@@ -192,5 +193,4 @@ export class PlatformExpress {
192
193
  }
193
194
  }
194
195
  }
195
- _PlatformExpress_multer = new WeakMap();
196
196
  //# sourceMappingURL=PlatformExpress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":";;AACA,OAAO,OAAwB,MAAM,SAAS,CAAC;AAE/C,OAAO,EACL,aAAa,EAGb,mBAAmB,EACnB,eAAe,EAEf,kBAAkB,EAClB,eAAe,EAGf,eAAe,EACf,gBAAgB,EAEjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AACzD,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,uBAAuB,EAAC,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAC,sBAAsB,EAAC,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AA0BnE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAiB1B,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAhBtC,cAAS,GAAG;YACnB;gBACE,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,sBAAsB;aACjC;YACD;gBACE,OAAO,EAAE,gBAA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AC,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 type multer from \"multer\";\nimport Express, {RouterOptions} from \"express\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformHandler,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformRequest,\n PlatformResponse,\n PlatformStaticsOptions\n} from \"@tsed/common\";\nimport {promisify} from \"util\";\nimport {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport {PlatformExpressHandler} from \"../services/PlatformExpressHandler\";\nimport {PlatformExpressResponse} from \"../services/PlatformExpressResponse\";\nimport {PlatformExpressRequest} from \"../services/PlatformExpressRequest\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\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 Router extends Express.Router {}\n\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n\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 PlatformExpress implements PlatformAdapter<Express.Application, Express.Router> {\n readonly providers = [\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 #multer: typeof multer;\n\n constructor(protected injector: InjectorService) {\n import(\"multer\").then(({default: multer}) => (this.#multer = multer));\n }\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 onInit() {\n this.injector.settings.middlewares = (this.injector.settings.middlewares || []).filter((middleware) => {\n const name = nameOf(middleware);\n if ([\"textParser\", \"jsonParser\", \"rawParser\", \"urlencodedParser\"].includes(name)) {\n this.injector.settings.set(`express.bodyParser.${name.replace(\"Parser\", \"\")}`, () => middleware);\n return false;\n }\n\n return true;\n });\n }\n\n useRouter(): this {\n const {logger} = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n logger.debug(\"Mount app router\");\n app.getApp().use(app.getRouter());\n\n return this;\n }\n\n async beforeLoadRoutes() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\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 = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\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} = this.injector;\n\n logger.debug(\"Mount app context\");\n\n const invoke = createContext(this.injector);\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\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 multipart(options: PlatformMulterSettings): PlatformMulter {\n const m = this.#multer(options);\n\n const makePromise = (multer: any, name: string) => {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n }\n\n app() {\n const app = this.injector.settings.get(\"express.app\") || Express();\n return {\n app,\n callback() {\n return app;\n }\n };\n }\n\n router(routerOptions: Partial<RouterOptions> = {}) {\n const options = Object.assign(\n {\n mergeParams: true\n },\n this.injector.settings.express?.router || {},\n routerOptions\n );\n\n const router = Express.Router(options);\n\n return {\n router,\n callback() {\n return router;\n }\n };\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n return staticsMiddleware(root, props);\n }\n\n bodyParser(type: \"json\" | \"raw\" | \"text\" | \"urlencoded\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`express.bodyParser.${type}`);\n let parser: any = Express[type];\n let options: OptionsJson & OptionsText & OptionsUrlencoded = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n switch (type) {\n case \"urlencoded\":\n options.extended = true;\n break;\n case \"raw\":\n options.type = () => true;\n break;\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private async configureViewsEngine() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n try {\n const {exists, disabled} = this.injector.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"]}
1
+ {"version":3,"file":"PlatformExpress.js","sourceRoot":"","sources":["../../../src/components/PlatformExpress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAGb,mBAAmB,EACnB,eAAe,EAEf,kBAAkB,EAClB,mBAAmB,EAInB,YAAY,EACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAO,MAAM,YAAY,CAAC;AAIzD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AAwBnE;;;GAGG;AACH,MAAM,OAAO,eAAe;IAIJ;IAHb,SAAS,GAAG,EAAE,CAAC;IACxB,OAAO,CAAgB;IAEvB,YAAsB,QAAyB;QAAzB,aAAQ,GAAR,QAAQ,CAAiB;QAC7C,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CA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,KAAK,EAAE,sBAAsB;gBAC7B,OAAO,EAAE,oEAAoE;gBAC7E,KAAK;aACN,CAAC,CAAC;SACJ;IACH,CAAC;CACF","sourcesContent":["import {\n createContext,\n InjectorService,\n PlatformAdapter,\n PlatformApplication,\n PlatformBuilder,\n PlatformContext,\n PlatformExceptions,\n PlatformHandlerType,\n PlatformMulter,\n PlatformMulterSettings,\n PlatformStaticsOptions,\n runInContext\n} from \"@tsed/common\";\nimport {Env, isFunction, nameOf, Type} from \"@tsed/core\";\nimport {PlatformHandlerMetadata, PlatformLayer} from \"@tsed/platform-router\";\nimport type {PlatformViews} from \"@tsed/platform-views\";\nimport {OptionsJson, OptionsText, OptionsUrlencoded} from \"body-parser\";\nimport Express from \"express\";\nimport type multer from \"multer\";\nimport {promisify} from \"util\";\nimport {PlatformExpressStaticsOptions} from \"../interfaces/PlatformExpressStaticsOptions\";\nimport {staticsMiddleware} from \"../middlewares/staticsMiddleware\";\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 Router extends Express.Router {}\n\n export interface Application extends Express.Application {}\n\n export interface StaticsOptions extends PlatformExpressStaticsOptions {}\n\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 PlatformExpress implements PlatformAdapter<Express.Application> {\n readonly providers = [];\n #multer: typeof multer;\n\n constructor(protected injector: InjectorService) {\n import(\"multer\").then(({default: multer}) => (this.#multer = multer));\n }\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>(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>(module, {\n ...settings,\n adapter: PlatformExpress\n });\n }\n\n onInit() {\n const middlewares = this.injector.settings.get(\"middlewares\", []);\n\n this.injector.settings.set(\n \"middlewares\",\n middlewares.filter((middleware) => {\n const name = nameOf(middleware);\n if ([\"textParser\", \"jsonParser\", \"rawParser\", \"urlencodedParser\"].includes(name)) {\n this.injector.settings.set(`express.bodyParser.${name.replace(\"Parser\", \"\")}`, () => middleware);\n return false;\n }\n\n return true;\n })\n );\n }\n\n async beforeLoadRoutes() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\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 app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n const platformExceptions = this.injector.get<PlatformExceptions>(PlatformExceptions)!;\n\n // NOT FOUND\n app.use((req: any, res: any, next: any) => {\n const {$ctx} = req;\n !$ctx.isDone() && platformExceptions?.resourceNotFound(req.$ctx);\n });\n\n // EXCEPTION FILTERS\n app.use((err: any, req: any, res: any, next: any) => {\n const {$ctx} = req;\n !$ctx.isDone() && platformExceptions?.catch(err, $ctx);\n });\n }\n\n mapLayers(layers: PlatformLayer[]) {\n const app = this.getPlatformApplication();\n const rawApp: any = app.getApp();\n\n layers.forEach((layer) => {\n switch (layer.method) {\n case \"statics\":\n rawApp.use(layer.path, this.statics(layer.path as string, layer.opts as any));\n return;\n }\n\n rawApp[layer.method](...layer.getArgs());\n });\n }\n\n mapHandler(handler: Function, metadata: PlatformHandlerMetadata) {\n switch (metadata.type) {\n case PlatformHandlerType.RAW_FN:\n case PlatformHandlerType.RAW_ERR_FN:\n return handler;\n case PlatformHandlerType.ERR_MIDDLEWARE:\n return async (error: unknown, req: any, res: any, next: any) => {\n return runInContext(req.$ctx, () => {\n const {$ctx} = req;\n\n $ctx.next = next;\n $ctx.error = error;\n\n return handler($ctx);\n });\n };\n default:\n return (req: any, res: any, next: any) => {\n return runInContext(req.$ctx, () => {\n req.$ctx.next = next;\n handler(req.$ctx);\n });\n };\n }\n }\n\n useContext(): this {\n const app = this.getPlatformApplication();\n const invoke = createContext(this.injector);\n\n this.injector.logger.debug(\"Mount app context\");\n\n app.use(async (request: any, response: any, next: any) => {\n const $ctx = await invoke({request, response});\n await $ctx.start();\n\n $ctx.response.getRes().on(\"finish\", () => $ctx.finish());\n\n return runInContext($ctx, next);\n });\n\n return this;\n }\n\n app() {\n const app = this.injector.settings.get(\"express.app\") || Express();\n\n return {\n app,\n callback: () => app\n };\n }\n\n multipart(options: PlatformMulterSettings): PlatformMulter {\n const m = this.#multer(options);\n\n const makePromise = (multer: any, name: string) => {\n // istanbul ignore next\n if (!multer[name]) return;\n\n const fn = multer[name];\n\n multer[name] = function apply(...args: any[]) {\n const middleware = Reflect.apply(fn, this, args);\n\n return (req: any, res: any) => promisify(middleware)(req, res);\n };\n };\n\n makePromise(m, \"any\");\n makePromise(m, \"array\");\n makePromise(m, \"fields\");\n makePromise(m, \"none\");\n makePromise(m, \"single\");\n\n return m;\n }\n\n statics(endpoint: string, options: PlatformStaticsOptions) {\n const {root, ...props} = options;\n\n return staticsMiddleware(root, props);\n }\n\n bodyParser(type: \"json\" | \"raw\" | \"text\" | \"urlencoded\", additionalOptions: any = {}): any {\n const opts = this.injector.settings.get(`express.bodyParser.${type}`);\n let parser: any = Express[type];\n let options: OptionsJson & OptionsText & OptionsUrlencoded = {};\n\n if (isFunction(opts)) {\n parser = opts;\n options = {};\n }\n\n switch (type) {\n case \"urlencoded\":\n options.extended = true;\n break;\n case \"raw\":\n options.type = () => true;\n break;\n }\n\n return parser({...options, ...additionalOptions});\n }\n\n private getPlatformApplication() {\n return this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n }\n\n private async configureViewsEngine() {\n const injector = this.injector;\n const app = this.injector.get<PlatformApplication<Express.Application>>(PlatformApplication)!;\n\n try {\n const {exists, disabled} = this.injector.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"]}
package/lib/esm/index.js CHANGED
@@ -3,15 +3,8 @@
3
3
  */
4
4
  export * from "./exports.js";
5
5
  export * from "./components/PlatformExpress.js";
6
- export * from "./decorators/caseSensitive.js";
7
- export * from "./decorators/mergeParams.js";
8
- export * from "./decorators/routerSettings.js";
9
- export * from "./decorators/strict.js";
10
6
  export * from "./interfaces/PlatformExpressSettings.js";
11
7
  export * from "./interfaces/PlatformExpressStaticsOptions.js";
12
8
  export * from "./interfaces/interfaces.js";
13
9
  export * from "./middlewares/staticsMiddleware.js";
14
- export * from "./services/PlatformExpressHandler.js";
15
- export * from "./services/PlatformExpressRequest.js";
16
- export * from "./services/PlatformExpressResponse.js";
17
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sCAAsC,CAAC;AACrD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformExpress\";\nexport * from \"./decorators/caseSensitive\";\nexport * from \"./decorators/mergeParams\";\nexport * from \"./decorators/routerSettings\";\nexport * from \"./decorators/strict\";\nexport * from \"./interfaces/PlatformExpressSettings\";\nexport * from \"./interfaces/PlatformExpressStaticsOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\nexport * from \"./services/PlatformExpressHandler\";\nexport * from \"./services/PlatformExpressRequest\";\nexport * from \"./services/PlatformExpressResponse\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./exports\";\nexport * from \"./components/PlatformExpress\";\nexport * from \"./interfaces/PlatformExpressSettings\";\nexport * from \"./interfaces/PlatformExpressStaticsOptions\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./middlewares/staticsMiddleware\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {RouterOptions} from \"express\";\nimport type {OptionsJson, OptionsText, Options, OptionsUrlencoded} from \"body-parser\";\nimport type {NextHandleFunction} from \"connect\";\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 * Express application\n */\n app?: Express.Application;\n\n /**\n * body parser configuration\n */\n bodyParser?: {\n json?: (opts?: OptionsJson) => NextHandleFunction | OptionsJson;\n text?: (opts?: OptionsText) => NextHandleFunction | OptionsText;\n raw?: (opts?: Options) => NextHandleFunction | Options;\n urlencoded?: (opts?: OptionsUrlencoded) => NextHandleFunction | OptionsUrlencoded;\n };\n}\n"]}
1
+ {"version":3,"file":"PlatformExpressSettings.js","sourceRoot":"","sources":["../../../src/interfaces/PlatformExpressSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {RouterOptions} from \"express\";\nimport type {OptionsJson, OptionsText, Options, OptionsUrlencoded} from \"body-parser\";\nimport type {NextHandleFunction} from \"connect\";\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 * Express application\n */\n app?: Express.Application;\n\n /**\n * body parser configuration\n */\n bodyParser?: {\n json?: ((opts?: OptionsJson) => NextHandleFunction) | OptionsJson;\n text?: ((opts?: OptionsText) => NextHandleFunction) | OptionsText;\n raw?: ((opts?: Options) => NextHandleFunction) | Options;\n urlencoded?: ((opts?: OptionsUrlencoded) => NextHandleFunction) | OptionsUrlencoded;\n };\n}\n"]}