@tsed/common 6.86.2 → 6.88.0

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.
package/lib/index.js CHANGED
@@ -6,7 +6,6 @@ var platformExceptions = require('@tsed/platform-exceptions');
6
6
  var platformResponseFilter = require('@tsed/platform-response-filter');
7
7
  var platformCache = require('@tsed/platform-cache');
8
8
  var platformMiddlewares = require('@tsed/platform-middlewares');
9
- var platformViews = require('@tsed/platform-views');
10
9
  var componentsScan = require('@tsed/components-scan');
11
10
  var platformLogMiddleware = require('@tsed/platform-log-middleware');
12
11
  var tslib = require('tslib');
@@ -14,8 +13,8 @@ var core = require('@tsed/core');
14
13
  var exceptions = require('@tsed/exceptions');
15
14
  var schema = require('@tsed/schema');
16
15
  var util = require('util');
17
- var Http = require('http');
18
16
  var Https = require('https');
17
+ var Http = require('http');
19
18
 
20
19
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
20
 
@@ -39,8 +38,8 @@ function _interopNamespace(e) {
39
38
  return n;
40
39
  }
41
40
 
42
- var Http__default = /*#__PURE__*/_interopDefaultLegacy(Http);
43
41
  var Https__default = /*#__PURE__*/_interopDefaultLegacy(Https);
42
+ var Http__default = /*#__PURE__*/_interopDefaultLegacy(Http);
44
43
 
45
44
  function _extends() {
46
45
  _extends = Object.assign || function (target) {
@@ -986,6 +985,7 @@ const PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
986
985
  exports.PlatformRouter = PlatformRouter_1 = class PlatformRouter {
987
986
  constructor(platformHandler) {
988
987
  this.platformHandler = platformHandler;
988
+ this.isBuilt = false;
989
989
  this.rawRouter = this.raw = PlatformRouter_1.createRawRouter();
990
990
  }
991
991
  /**
@@ -1292,72 +1292,77 @@ tslib.__decorate([tslib.__param(0, platformParams.Context()), tslib.__metadata("
1292
1292
 
1293
1293
  exports.AcceptMimesMiddleware = tslib.__decorate([platformMiddlewares.Middleware()], exports.AcceptMimesMiddleware);
1294
1294
 
1295
- /**
1296
- * Create Ts.ED context handler
1297
- * @param fn
1298
- * @ignore
1299
- */
1295
+ const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
1300
1296
 
1301
- function useCtxHandler(fn) {
1302
- fn.type = exports.HandlerType.CTX_FN;
1303
- return fn;
1304
- }
1297
+ let AUTO_INC = 0;
1298
+ class ControllerProvider extends di.Provider {
1299
+ constructor(provide, options = {}) {
1300
+ super(provide, options);
1301
+ this.type = di.ProviderType.CONTROLLER;
1302
+ this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;
1303
+ }
1304
+ /**
1305
+ *
1306
+ */
1305
1307
 
1306
- /**
1307
- * @ignore
1308
- */
1309
1308
 
1310
- function formatMethod(method) {
1311
- return (method === schema.OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
1312
- }
1313
- /**
1314
- * @ignore
1315
- */
1309
+ get routerOptions() {
1310
+ return this.store.get(ROUTER_OPTIONS) || {};
1311
+ }
1312
+ /**
1313
+ *
1314
+ * @param value
1315
+ */
1316
1316
 
1317
1317
 
1318
- class PlatformControllerBuilder {
1319
- constructor(provider) {
1320
- this.provider = provider;
1318
+ set routerOptions(value) {
1319
+ this.store.set(ROUTER_OPTIONS, value);
1321
1320
  }
1322
1321
  /**
1323
- * @returns {any}
1322
+ *
1323
+ * @returns {any[]}
1324
1324
  */
1325
1325
 
1326
1326
 
1327
- build(injector) {
1328
- const {
1329
- middlewares: {
1330
- useBefore
1331
- }
1332
- } = this.provider; // Controller lifecycle
1327
+ get middlewares() {
1328
+ return Object.assign({
1329
+ use: [],
1330
+ useAfter: [],
1331
+ useBefore: []
1332
+ }, this.store.get("middlewares", {}));
1333
+ }
1334
+ /**
1335
+ *
1336
+ * @param middlewares
1337
+ */
1333
1338
 
1334
- this.buildMiddlewares(useBefore) // Controller before-middleware
1335
- .buildEndpoints() // All endpoints and his middlewares
1336
- .buildChildrenCtrls(injector); // Children controllers
1337
1339
 
1338
- return this.provider.getRouter();
1339
- }
1340
+ set middlewares(middlewares) {
1341
+ const mdlwrs = this.middlewares;
1340
1342
 
1341
- buildEndpoints() {
1342
- schema.getOperationsRoutes(this.provider.token).forEach(operationRoute => {
1343
- this.buildEndpoint(operationRoute);
1344
- });
1345
- return this;
1346
- }
1343
+ const concat = (key, a, b) => a[key] = a[key].concat(b[key]);
1347
1344
 
1348
- buildEndpoint(operationRoute) {
1349
- let handlers = this.getMiddlewares(operationRoute);
1350
- const router = this.provider.getRouter();
1351
- router.addRoute({
1352
- handlers,
1353
- token: operationRoute.token,
1354
- method: formatMethod(operationRoute.method),
1355
- path: operationRoute.path,
1356
- isFinal: operationRoute.isFinal
1345
+ Object.keys(middlewares).forEach(key => {
1346
+ concat(key, mdlwrs, middlewares);
1357
1347
  });
1348
+ this.store.set("middlewares", mdlwrs);
1358
1349
  }
1359
1350
 
1360
- getMiddlewares(operationRoute) {
1351
+ }
1352
+
1353
+ /**
1354
+ * Create Ts.ED context handler
1355
+ * @param fn
1356
+ * @ignore
1357
+ */
1358
+
1359
+ function useCtxHandler(fn) {
1360
+ fn.type = exports.HandlerType.CTX_FN;
1361
+ return fn;
1362
+ }
1363
+
1364
+ exports.PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
1365
+ get(provider, operationRoute) {
1361
1366
  const {
1362
1367
  endpoint
1363
1368
  } = operationRoute;
@@ -1371,11 +1376,10 @@ class PlatformControllerBuilder {
1371
1376
  use,
1372
1377
  useAfter
1373
1378
  }
1374
- } = this.provider;
1379
+ } = provider;
1375
1380
  const hasFiles = [...operationRoute.endpoint.children.values()].find(item => item.paramType === platformParams.ParamTypes.FILES);
1376
1381
  return [].concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(exports.PlatformAcceptMimesMiddleware).concat(hasFiles && exports.PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
1377
1382
  .concat(use) // Controller use-middlewares
1378
- // .concat(endpoint.cache && PlatformCacheMiddleware)
1379
1383
  .concat(mldwrs) // Endpoint middlewares
1380
1384
  .concat(endpoint) // Endpoint metadata
1381
1385
  .concat(afterMiddlewares) // Endpoint after-middlewares
@@ -1383,32 +1387,97 @@ class PlatformControllerBuilder {
1383
1387
  .filter(item => !!item);
1384
1388
  }
1385
1389
 
1386
- buildChildrenCtrls(injector) {
1387
- const {
1388
- children
1389
- } = this.provider;
1390
- const router = this.provider.getRouter();
1390
+ };
1391
+ exports.PlatformMiddlewaresChain = tslib.__decorate([di.Injectable()], exports.PlatformMiddlewaresChain);
1392
+
1393
+ di.GlobalProviders.createRegistry(di.ProviderType.CONTROLLER, ControllerProvider, {
1394
+ onInvoke(provider, locals, {
1395
+ injector
1396
+ }) {
1397
+ const router = createRouter(injector, provider);
1398
+ locals.set(exports.PlatformRouter, router);
1399
+ }
1400
+
1401
+ });
1402
+ /**
1403
+ * @ignore
1404
+ */
1405
+
1406
+ function formatMethod(method) {
1407
+ return (method === schema.OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
1408
+ }
1409
+ /**
1410
+ * @ignore
1411
+ */
1412
+
1413
+
1414
+ function getRouter(injector, provider) {
1415
+ return injector.get(provider.tokenRouter);
1416
+ }
1417
+ /**
1418
+ * @ignore
1419
+ */
1420
+
1421
+ function createRouter(injector, provider) {
1422
+ const token = provider.tokenRouter;
1423
+
1424
+ if (injector.has(token)) {
1425
+ return getRouter(injector, provider);
1426
+ }
1427
+
1428
+ const router = exports.PlatformRouter.create(injector, provider.routerOptions);
1429
+ return injector.add(token, {
1430
+ useValue: router
1431
+ }).invoke(token);
1432
+ }
1433
+ /**
1434
+ * @ignore
1435
+ * @param injector
1436
+ * @param provider
1437
+ */
1438
+
1439
+ function buildRouter(injector, provider) {
1440
+ const {
1441
+ middlewares: {
1442
+ useBefore
1443
+ },
1444
+ children
1445
+ } = provider; // Controller lifecycle
1446
+
1447
+ const router = createRouter(injector, provider);
1448
+
1449
+ if (!router.isBuilt) {
1450
+ router.isBuilt = true;
1451
+ const platformMiddlewaresChain = injector.get(exports.PlatformMiddlewaresChain);
1452
+ useBefore // Controller before-middleware
1453
+ .filter(o => typeof o === "function").forEach(middleware => {
1454
+ router.use(middleware);
1455
+ }); // build all endpoints and his middlewares
1456
+
1457
+ schema.getOperationsRoutes(provider.token).forEach(operationRoute => {
1458
+ const handlers = platformMiddlewaresChain == null ? void 0 : platformMiddlewaresChain.get(provider, operationRoute);
1459
+ router.addRoute({
1460
+ handlers,
1461
+ token: operationRoute.token,
1462
+ method: formatMethod(operationRoute.method),
1463
+ path: operationRoute.path,
1464
+ isFinal: operationRoute.isFinal
1465
+ });
1466
+ }); // build children controllers
1467
+
1391
1468
  children.forEach(child => {
1392
- const provider = injector.getProvider(child);
1469
+ const childProvider = injector.getProvider(child);
1393
1470
  /* istanbul ignore next */
1394
1471
 
1395
- if (!provider) {
1472
+ if (!childProvider) {
1396
1473
  throw new Error("Controller component not found in the ControllerRegistry");
1397
1474
  }
1398
1475
 
1399
- new PlatformControllerBuilder(provider).build(injector);
1400
- router.use(provider.path, provider.getRouter());
1401
- });
1402
- }
1403
-
1404
- buildMiddlewares(middlewares) {
1405
- const router = this.provider.getRouter();
1406
- middlewares.filter(o => typeof o === "function").forEach(middleware => {
1407
- router.use(middleware);
1476
+ router.use(childProvider.path, buildRouter(injector, childProvider));
1408
1477
  });
1409
- return this;
1410
1478
  }
1411
1479
 
1480
+ return router;
1412
1481
  }
1413
1482
 
1414
1483
  /**
@@ -1419,7 +1488,8 @@ class PlatformControllerBuilder {
1419
1488
  exports.PlatformRequest = class PlatformRequest {
1420
1489
  constructor({
1421
1490
  request
1422
- }) {
1491
+ }, $ctx) {
1492
+ this.$ctx = $ctx;
1423
1493
  this.raw = request;
1424
1494
  }
1425
1495
 
@@ -1550,7 +1620,9 @@ exports.PlatformRequest = class PlatformRequest {
1550
1620
  // @ts-ignore
1551
1621
  delete this.raw; // @ts-ignore
1552
1622
 
1553
- delete this.response;
1623
+ delete this.response; // @ts-ignore
1624
+
1625
+ delete this.$ctx;
1554
1626
  }
1555
1627
  /**
1556
1628
  * Return the Framework response object (express, koa, etc...)
@@ -1570,7 +1642,7 @@ exports.PlatformRequest = class PlatformRequest {
1570
1642
  }
1571
1643
 
1572
1644
  };
1573
- exports.PlatformRequest = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object])], exports.PlatformRequest);
1645
+ exports.PlatformRequest = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object, Function])], exports.PlatformRequest);
1574
1646
 
1575
1647
  var PlatformResponse_1;
1576
1648
 
@@ -1584,7 +1656,8 @@ const onFinished = require("on-finished");
1584
1656
  exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1585
1657
  constructor({
1586
1658
  response
1587
- }) {
1659
+ }, $ctx) {
1660
+ this.$ctx = $ctx;
1588
1661
  this.raw = response;
1589
1662
  }
1590
1663
  /**
@@ -1801,7 +1874,11 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1801
1874
 
1802
1875
 
1803
1876
  async render(path, options = {}) {
1804
- return this.platformViews.render(path, _extends({}, this.locals, options));
1877
+ const {
1878
+ PlatformViews
1879
+ } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@tsed/platform-views')); });
1880
+ const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);
1881
+ return platformViews.render(path, _extends({}, this.locals, options));
1805
1882
  }
1806
1883
  /**
1807
1884
  * Send any data to your consumer.
@@ -1873,7 +1950,9 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1873
1950
  delete this.raw;
1874
1951
  delete this.data; // @ts-ignore
1875
1952
 
1876
- delete this.request;
1953
+ delete this.request; // @ts-ignore
1954
+
1955
+ delete this.$ctx;
1877
1956
  }
1878
1957
 
1879
1958
  isHeadersSent() {
@@ -1881,7 +1960,7 @@ exports.PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1881
1960
  }
1882
1961
 
1883
1962
  };
1884
- exports.PlatformResponse = PlatformResponse_1 = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object])], exports.PlatformResponse);
1963
+ exports.PlatformResponse = PlatformResponse_1 = tslib.__decorate([di.Injectable(), di.Scope(di.ProviderScope.INSTANCE), tslib.__metadata("design:paramtypes", [Object, Function])], exports.PlatformResponse);
1885
1964
 
1886
1965
  const _excluded$2 = ["event", "endpoint", "ignoreUrlPatterns", "ResponseKlass", "RequestKlass"];
1887
1966
  class PlatformContext extends di.DIContext {
@@ -1903,8 +1982,8 @@ class PlatformContext extends di.DIContext {
1903
1982
  this.ignoreUrlPatterns = [];
1904
1983
  endpoint && (this.endpoint = endpoint);
1905
1984
  this.ignoreUrlPatterns = ignoreUrlPatterns.map(pattern => typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern);
1906
- this.response = new ResponseKlass(event);
1907
- this.request = new RequestKlass(event);
1985
+ this.response = new ResponseKlass(event, this);
1986
+ this.request = new RequestKlass(event, this);
1908
1987
  this.response.request = this.request;
1909
1988
  this.request.response = this.response;
1910
1989
  this.request.request.$ctx = this;
@@ -2005,71 +2084,6 @@ class PlatformRouteDetails extends schema.JsonOperationRoute {
2005
2084
 
2006
2085
  }
2007
2086
 
2008
- const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
2009
-
2010
- class ControllerProvider extends di.Provider {
2011
- constructor(provide, options = {}) {
2012
- super(provide, options);
2013
- this.type = di.ProviderType.CONTROLLER;
2014
- }
2015
- /**
2016
- *
2017
- */
2018
-
2019
-
2020
- get routerOptions() {
2021
- return this.store.get(ROUTER_OPTIONS) || {};
2022
- }
2023
- /**
2024
- *
2025
- * @param value
2026
- */
2027
-
2028
-
2029
- set routerOptions(value) {
2030
- this.store.set(ROUTER_OPTIONS, value);
2031
- }
2032
- /**
2033
- *
2034
- * @returns {any[]}
2035
- */
2036
-
2037
-
2038
- get middlewares() {
2039
- return Object.assign({
2040
- use: [],
2041
- useAfter: [],
2042
- useBefore: []
2043
- }, this.store.get("middlewares", {}));
2044
- }
2045
- /**
2046
- *
2047
- * @param middlewares
2048
- */
2049
-
2050
-
2051
- set middlewares(middlewares) {
2052
- const mdlwrs = this.middlewares;
2053
-
2054
- const concat = (key, a, b) => a[key] = a[key].concat(b[key]);
2055
-
2056
- Object.keys(middlewares).forEach(key => {
2057
- concat(key, mdlwrs, middlewares);
2058
- });
2059
- this.store.set("middlewares", mdlwrs);
2060
- }
2061
-
2062
- getRouter() {
2063
- return this.router;
2064
- }
2065
-
2066
- setRouter(router) {
2067
- this.router = router;
2068
- return this;
2069
- }
2070
-
2071
- }
2072
-
2073
2087
  /**
2074
2088
  * @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
2075
2089
  */
@@ -2093,13 +2107,6 @@ exports.PropertyMetadata = class PropertyMetadata extends schema.JsonPropertySto
2093
2107
  };
2094
2108
  exports.PropertyMetadata = tslib.__decorate([schema.JsonEntityComponent(core.DecoratorTypes.PROP)], exports.PropertyMetadata);
2095
2109
 
2096
- di.GlobalProviders.createRegistry(di.ProviderType.CONTROLLER, ControllerProvider, {
2097
- onInvoke(provider, locals) {
2098
- locals.set(exports.PlatformRouter, provider.getRouter());
2099
- }
2100
-
2101
- });
2102
-
2103
2110
  /**
2104
2111
  * `Platform` is used to provide all routes collected by annotation `@Controller`.
2105
2112
  *
@@ -2146,7 +2153,7 @@ exports.Platform = class Platform {
2146
2153
  provider
2147
2154
  });
2148
2155
 
2149
- this.app.use(ctrlPath, ...[].concat(provider.getRouter().callback()));
2156
+ this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));
2150
2157
  this._routes = schema.getOperationsRoutes(provider.token, {
2151
2158
  withChildren: true,
2152
2159
  basePath
@@ -2191,7 +2198,7 @@ exports.Platform = class Platform {
2191
2198
  injector
2192
2199
  } = this;
2193
2200
  injector.getProviders(di.ProviderType.CONTROLLER).map(provider => {
2194
- provider.setRouter(exports.PlatformRouter.create(injector, provider.routerOptions));
2201
+ createRouter(injector, provider);
2195
2202
  });
2196
2203
  }
2197
2204
  /**
@@ -2206,52 +2213,32 @@ exports.Platform = class Platform {
2206
2213
  } = this;
2207
2214
  injector.getProviders(di.ProviderType.CONTROLLER).map(provider => {
2208
2215
  if (!provider.hasParent()) {
2209
- return new PlatformControllerBuilder(provider).build(injector);
2216
+ return buildRouter(injector, provider);
2210
2217
  }
2211
2218
  });
2212
2219
  }
2213
2220
 
2214
2221
  };
2215
2222
  exports.Platform = tslib.__decorate([di.Injectable({
2216
- scope: di.ProviderScope.SINGLETON
2223
+ scope: di.ProviderScope.SINGLETON,
2224
+ imports: [exports.PlatformMiddlewaresChain]
2217
2225
  }), tslib.__metadata("design:paramtypes", [di.InjectorService, exports.PlatformApplication])], exports.Platform);
2218
2226
 
2219
- logger.$log.name = "TSED";
2220
- function createInjector(settings = {}) {
2221
- const injector = new di.InjectorService();
2222
- injector.settings = createSettingsService(injector);
2223
- injector.logger = logger.$log;
2224
- injector.settings.set(settings);
2225
- di.setLoggerLevel(injector);
2226
- return injector;
2227
- }
2228
-
2229
- function createSettingsService(injector) {
2230
- const provider = di.GlobalProviders.get(exports.PlatformConfiguration).clone();
2231
- provider.instance = injector.invoke(provider.useClass);
2232
- injector.addProvider(exports.PlatformConfiguration, provider);
2233
- return provider.instance;
2234
- }
2235
-
2236
- function createPlatformApplication(injector) {
2237
- injector.forkProvider(exports.PlatformApplication);
2238
- }
2239
-
2240
2227
  /**
2241
- * Inject the Http.Server instance.
2228
+ * Inject the Https.Server instance.
2242
2229
  *
2243
2230
  * ### Example
2244
2231
  *
2245
2232
  * ```typescript
2246
- * import {HttpServer, Service} from "@tsed/common";
2233
+ * import {HttpsServer, Service} from "@tsed/common";
2247
2234
  *
2248
2235
  * @Service()
2249
2236
  * export default class OtherService {
2250
- * constructor(@HttpServer httpServer: HttpServer) {}
2237
+ * constructor(@HttpsServer httpServer: HttpServer) {}
2251
2238
  * }
2252
2239
  * ```
2253
2240
  *
2254
- * > Note: TypeScript transform and store `HttpServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2241
+ * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2255
2242
  *
2256
2243
  * @param {Type<any>} target
2257
2244
  * @param {string} targetKey
@@ -2260,8 +2247,8 @@ function createPlatformApplication(injector) {
2260
2247
  * @decorator
2261
2248
  */
2262
2249
 
2263
- function HttpServer(target, targetKey, descriptor) {
2264
- return di.Inject(HttpServer)(target, targetKey, descriptor);
2250
+ function HttpsServer(target, targetKey, descriptor) {
2251
+ return di.Inject(HttpsServer)(target, targetKey, descriptor);
2265
2252
  }
2266
2253
 
2267
2254
  function listenServer(http, settings) {
@@ -2283,56 +2270,57 @@ function listenServer(http, settings) {
2283
2270
  return promise;
2284
2271
  }
2285
2272
 
2286
- function createHttpServer(injector) {
2287
- injector.forkProvider(HttpServer);
2273
+ function createHttpsServer(injector) {
2274
+ injector.invoke(HttpsServer);
2288
2275
  }
2289
2276
  di.registerProvider({
2290
- provide: HttpServer,
2291
- deps: [exports.PlatformApplication],
2277
+ provide: HttpsServer,
2278
+ deps: [exports.PlatformApplication, di.Configuration],
2292
2279
  scope: di.ProviderScope.SINGLETON,
2293
2280
  global: true,
2294
2281
 
2295
- useFactory(platformApplication) {
2296
- return Http__default['default'].createServer(platformApplication.callback());
2282
+ useFactory(platformApplication, settings) {
2283
+ const options = settings.httpsOptions;
2284
+ return Https__default['default'].createServer(options, platformApplication.callback());
2297
2285
  }
2298
2286
 
2299
2287
  });
2300
- async function listenHttpServer(injector) {
2288
+ async function listenHttpsServer(injector) {
2301
2289
  const {
2302
2290
  settings
2303
2291
  } = injector;
2304
- const server = injector.get(HttpServer);
2292
+ const server = injector.get(HttpsServer);
2305
2293
 
2306
- if (settings.httpPort !== false && server) {
2294
+ if (settings.httpsPort !== false && server) {
2307
2295
  const {
2308
2296
  address,
2309
2297
  port
2310
- } = settings.getHttpPort();
2311
- injector.logger.debug(`Start server on http://${address}:${port}`);
2298
+ } = settings.getHttpsPort();
2299
+ injector.logger.debug(`Start server on https://${address}:${port}`);
2312
2300
  const options = await listenServer(server, {
2313
2301
  address,
2314
2302
  port
2315
2303
  });
2316
- settings.setHttpPort(options);
2317
- injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
2304
+ settings.setHttpsPort(options);
2305
+ injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
2318
2306
  }
2319
2307
  }
2320
2308
 
2321
2309
  /**
2322
- * Inject the Https.Server instance.
2310
+ * Inject the Http.Server instance.
2323
2311
  *
2324
2312
  * ### Example
2325
2313
  *
2326
2314
  * ```typescript
2327
- * import {HttpsServer, Service} from "@tsed/common";
2315
+ * import {HttpServer, Service} from "@tsed/common";
2328
2316
  *
2329
2317
  * @Service()
2330
2318
  * export default class OtherService {
2331
- * constructor(@HttpsServer httpServer: HttpServer) {}
2319
+ * constructor(@HttpServer httpServer: HttpServer) {}
2332
2320
  * }
2333
2321
  * ```
2334
2322
  *
2335
- * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2323
+ * > Note: TypeScript transform and store `HttpServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2336
2324
  *
2337
2325
  * @param {Type<any>} target
2338
2326
  * @param {string} targetKey
@@ -2341,46 +2329,79 @@ async function listenHttpServer(injector) {
2341
2329
  * @decorator
2342
2330
  */
2343
2331
 
2344
- function HttpsServer(target, targetKey, descriptor) {
2345
- return di.Inject(HttpsServer)(target, targetKey, descriptor);
2332
+ function HttpServer(target, targetKey, descriptor) {
2333
+ return di.Inject(HttpServer)(target, targetKey, descriptor);
2346
2334
  }
2347
2335
 
2348
- function createHttpsServer(injector) {
2349
- injector.forkProvider(HttpsServer);
2336
+ function createHttpServer(injector) {
2337
+ injector.invoke(HttpServer);
2350
2338
  }
2351
2339
  di.registerProvider({
2352
- provide: HttpsServer,
2353
- deps: [exports.PlatformApplication, di.Configuration],
2340
+ provide: HttpServer,
2341
+ deps: [exports.PlatformApplication],
2354
2342
  scope: di.ProviderScope.SINGLETON,
2355
2343
  global: true,
2356
2344
 
2357
- useFactory(platformApplication, settings) {
2358
- const options = settings.httpsOptions;
2359
- return Https__default['default'].createServer(options, platformApplication.callback());
2345
+ useFactory(platformApplication) {
2346
+ return Http__default['default'].createServer(platformApplication.callback());
2360
2347
  }
2361
2348
 
2362
2349
  });
2363
- async function listenHttpsServer(injector) {
2350
+ async function listenHttpServer(injector) {
2364
2351
  const {
2365
2352
  settings
2366
2353
  } = injector;
2367
- const server = injector.get(HttpsServer);
2354
+ const server = injector.get(HttpServer);
2368
2355
 
2369
- if (settings.httpsPort !== false && server) {
2356
+ if (settings.httpPort !== false && server) {
2370
2357
  const {
2371
2358
  address,
2372
2359
  port
2373
- } = settings.getHttpsPort();
2374
- injector.logger.debug(`Start server on https://${address}:${port}`);
2360
+ } = settings.getHttpPort();
2361
+ injector.logger.debug(`Start server on http://${address}:${port}`);
2375
2362
  const options = await listenServer(server, {
2376
2363
  address,
2377
2364
  port
2378
2365
  });
2379
- settings.setHttpsPort(options);
2380
- injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
2366
+ settings.setHttpPort(options);
2367
+ injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
2381
2368
  }
2382
2369
  }
2383
2370
 
2371
+ logger.$log.name = "TSED";
2372
+ const DEFAULT_PROVIDERS = [{
2373
+ provide: exports.PlatformHandler
2374
+ }, {
2375
+ provide: exports.PlatformResponse
2376
+ }, {
2377
+ provide: exports.PlatformRequest
2378
+ }, {
2379
+ provide: exports.PlatformRouter
2380
+ }, {
2381
+ provide: exports.PlatformApplication
2382
+ }, {
2383
+ provide: exports.Platform
2384
+ }];
2385
+ function createInjector({
2386
+ providers = [],
2387
+ settings = {}
2388
+ }) {
2389
+ const injector = new di.InjectorService();
2390
+ injector.addProvider(exports.PlatformConfiguration);
2391
+ injector.settings = injector.invoke(exports.PlatformConfiguration);
2392
+ injector.logger = logger.$log;
2393
+ injector.settings.set(settings);
2394
+ di.setLoggerLevel(injector);
2395
+ providers = [...DEFAULT_PROVIDERS, ...providers];
2396
+ core.toMap(providers, "provide").forEach((provider, token) => {
2397
+ injector.addProvider(token, provider);
2398
+ });
2399
+ injector.invoke(exports.PlatformApplication);
2400
+ createHttpsServer(injector);
2401
+ createHttpServer(injector);
2402
+ return injector;
2403
+ }
2404
+
2384
2405
  /**
2385
2406
  * @ignore
2386
2407
  * @deprecated User injector.load(container, module) instead
@@ -2439,7 +2460,6 @@ function createContext(injector) {
2439
2460
 
2440
2461
  const ResponseKlass = (_injector$getProvider = injector.getProvider(exports.PlatformResponse)) == null ? void 0 : _injector$getProvider.useClass;
2441
2462
  const RequestKlass = (_injector$getProvider2 = injector.getProvider(exports.PlatformRequest)) == null ? void 0 : _injector$getProvider2.useClass;
2442
- const platformViews$1 = injector.get(platformViews.PlatformViews);
2443
2463
 
2444
2464
  const _ref = injector.settings.logger || {},
2445
2465
  {
@@ -2457,7 +2477,6 @@ function createContext(injector) {
2457
2477
  ResponseKlass,
2458
2478
  RequestKlass
2459
2479
  }));
2460
- ctx.response.platformViews = platformViews$1;
2461
2480
  ctx.response.onEnd(async () => {
2462
2481
  await ctx.emit("$onResponse", ctx);
2463
2482
  await ctx.destroy();
@@ -2521,19 +2540,6 @@ function getConfiguration(configuration = {}, module = null) {
2521
2540
  return config;
2522
2541
  }
2523
2542
 
2524
- const DEFAULT_PROVIDERS = [{
2525
- provide: exports.PlatformHandler
2526
- }, {
2527
- provide: exports.PlatformResponse
2528
- }, {
2529
- provide: exports.PlatformRequest
2530
- }, {
2531
- provide: exports.PlatformRouter
2532
- }, {
2533
- provide: exports.PlatformApplication
2534
- }, {
2535
- provide: exports.Platform
2536
- }];
2537
2543
  /**
2538
2544
  * @platform
2539
2545
  */
@@ -2562,7 +2568,13 @@ class PlatformBuilder {
2562
2568
  this.current = new Date();
2563
2569
  this.name = name;
2564
2570
  _classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = module;
2565
- this.createInjector(module, providers, settings);
2571
+ const configuration = getConfiguration(settings, module);
2572
+ configuration.PLATFORM_NAME = name;
2573
+ _classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector({
2574
+ settings: configuration,
2575
+ providers
2576
+ });
2577
+ this.log("Injector created...");
2566
2578
  }
2567
2579
 
2568
2580
  get injector() {
@@ -2841,20 +2853,6 @@ class PlatformBuilder {
2841
2853
  await this.callHook("$afterRoutesInit");
2842
2854
  }
2843
2855
 
2844
- createInjector(module, providers, settings) {
2845
- const configuration = getConfiguration(settings, module);
2846
- configuration.PLATFORM_NAME = this.name;
2847
- _classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector(configuration);
2848
- providers = [...DEFAULT_PROVIDERS, ...providers];
2849
- core.toMap(providers, "provide").forEach((provider, token) => {
2850
- this.injector.addProvider(token, provider);
2851
- });
2852
- createPlatformApplication(this.injector);
2853
- createHttpsServer(this.injector);
2854
- createHttpServer(this.injector);
2855
- this.log("Injector created...");
2856
- }
2857
-
2858
2856
  }
2859
2857
 
2860
2858
  /**
@@ -3045,6 +3043,39 @@ function EndpointFn(fn) {
3045
3043
  return schema.JsonEntityFn(fn);
3046
3044
  }
3047
3045
 
3046
+ /**
3047
+ * Use a view and sends the rendered HTML string to the client. Optional parameter:
3048
+ *
3049
+ * * viewOptions, an object whose properties define local variables for the view.
3050
+ *
3051
+ * The view argument is a string that is the file path of the view file to render.
3052
+ * This can be an absolute path, or a path relative to the views setting.
3053
+ * If the path does not contain a file extension, then the view engine setting determines the file extension.
3054
+ * If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
3055
+ * and render it using the loaded module’s __express function.
3056
+ *
3057
+ * For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
3058
+ *
3059
+ * > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
3060
+ * and as so for security reasons should not contain input from the end-user.
3061
+ *
3062
+ * @param path Relative path to the view file.
3063
+ * @param options Additional options
3064
+ * @decorator
3065
+ * @operation
3066
+ * @response
3067
+ * @ignores
3068
+ * @deprecated Use View decorator from @tsed/platform-views instead.
3069
+ */
3070
+ // istanbul ignore next
3071
+
3072
+ function View(path, options) {
3073
+ return core.StoreSet("view", {
3074
+ path,
3075
+ options
3076
+ });
3077
+ }
3078
+
3048
3079
  /**
3049
3080
  * Return the current response data. Prefer the @@Context@@ decorator to get or set data.
3050
3081
  *
@@ -3227,8 +3258,8 @@ function mapReturnedResponse(_ref) {
3227
3258
  */
3228
3259
 
3229
3260
  class PlatformTest extends di.DITest {
3230
- static async create(options = {}) {
3231
- di.DITest.injector = PlatformTest.createInjector(getConfiguration(options, null));
3261
+ static async create(settings = {}) {
3262
+ di.DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
3232
3263
  const container = di.createContainer();
3233
3264
  await di.DITest.injector.load(container);
3234
3265
  }
@@ -3238,7 +3269,10 @@ class PlatformTest extends di.DITest {
3238
3269
 
3239
3270
 
3240
3271
  static createInjector(settings = {}) {
3241
- return createInjector(di.DITest.configure(settings));
3272
+ return createInjector({
3273
+ providers: [],
3274
+ settings: di.DITest.configure(settings)
3275
+ });
3242
3276
  }
3243
3277
  /**
3244
3278
  * Load the server silently without listening port and configure it on test profile.
@@ -3402,7 +3436,7 @@ class PlatformTest extends di.DITest {
3402
3436
  request: (options == null ? void 0 : (_options$request = options.request) == null ? void 0 : _options$request.request) || (options == null ? void 0 : (_options$event = options.event) == null ? void 0 : _options$event.request) || PlatformTest.createRequest(),
3403
3437
  response: (options == null ? void 0 : (_options$response = options.response) == null ? void 0 : _options$response.response) || (options == null ? void 0 : (_options$event2 = options.event) == null ? void 0 : _options$event2.response) || PlatformTest.createResponse()
3404
3438
  };
3405
- const ctx = new PlatformContext(_extends({
3439
+ return new PlatformContext(_extends({
3406
3440
  id: "id",
3407
3441
  injector: di.DITest.injector,
3408
3442
  logger: di.DITest.injector.logger,
@@ -3410,8 +3444,6 @@ class PlatformTest extends di.DITest {
3410
3444
  }, options, {
3411
3445
  event
3412
3446
  }));
3413
- ctx.response.platformViews = PlatformTest.get(platformViews.PlatformViews);
3414
- return ctx;
3415
3447
  }
3416
3448
 
3417
3449
  }
@@ -3510,7 +3542,6 @@ exports.Next = Next;
3510
3542
  exports.PLATFORM_ROUTER_OPTIONS = PLATFORM_ROUTER_OPTIONS;
3511
3543
  exports.PlatformBuilder = PlatformBuilder;
3512
3544
  exports.PlatformContext = PlatformContext;
3513
- exports.PlatformControllerBuilder = PlatformControllerBuilder;
3514
3545
  exports.PlatformModule = PlatformModule;
3515
3546
  exports.PlatformRouteDetails = PlatformRouteDetails;
3516
3547
  exports.PlatformTest = PlatformTest;
@@ -3520,12 +3551,15 @@ exports.Request = Request;
3520
3551
  exports.Res = Res;
3521
3552
  exports.Response = Response;
3522
3553
  exports.ResponseData = ResponseData;
3554
+ exports.View = View;
3523
3555
  exports.bindEndpointMiddleware = bindEndpointMiddleware;
3556
+ exports.buildRouter = buildRouter;
3524
3557
  exports.createContext = createContext;
3525
3558
  exports.createHttpServer = createHttpServer;
3526
3559
  exports.createHttpsServer = createHttpsServer;
3527
3560
  exports.createInjector = createInjector;
3528
- exports.createPlatformApplication = createPlatformApplication;
3561
+ exports.createRouter = createRouter;
3562
+ exports.getRouter = getRouter;
3529
3563
  exports.listenHttpServer = listenHttpServer;
3530
3564
  exports.listenHttpsServer = listenHttpsServer;
3531
3565
  exports.listenServer = listenServer;
@@ -3581,14 +3615,6 @@ Object.keys(platformMiddlewares).forEach(function (k) {
3581
3615
  }
3582
3616
  });
3583
3617
  });
3584
- Object.keys(platformViews).forEach(function (k) {
3585
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
3586
- enumerable: true,
3587
- get: function () {
3588
- return platformViews[k];
3589
- }
3590
- });
3591
- });
3592
3618
  Object.keys(componentsScan).forEach(function (k) {
3593
3619
  if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
3594
3620
  enumerable: true,