@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.
@@ -1,7 +1,7 @@
1
1
  import { $log, colorize } from '@tsed/logger';
2
2
  export { $log, Logger } from '@tsed/logger';
3
3
  import '@tsed/logger-file';
4
- import { DIConfiguration, Injectable, ProviderScope, Inject, InjectorService, Constant, Scope, DIContext, Provider, ProviderType, GlobalProviders, setLoggerLevel, registerProvider, Configuration, createContainer, colors, DITest } from '@tsed/di';
4
+ import { DIConfiguration, Injectable, ProviderScope, Inject, InjectorService, Constant, Provider, ProviderType, GlobalProviders, Scope, DIContext, registerProvider, Configuration, setLoggerLevel, createContainer, colors, DITest } from '@tsed/di';
5
5
  export * from '@tsed/di';
6
6
  import { ParamTypes, PlatformParams, Context, UseParam, mapParamsOptions } from '@tsed/platform-params';
7
7
  export * from '@tsed/platform-params';
@@ -11,19 +11,17 @@ export * from '@tsed/platform-response-filter';
11
11
  export * from '@tsed/platform-cache';
12
12
  import { Middleware, getMiddlewaresForHook } from '@tsed/platform-middlewares';
13
13
  export * from '@tsed/platform-middlewares';
14
- import { PlatformViews } from '@tsed/platform-views';
15
- export * from '@tsed/platform-views';
16
14
  import { importProviders } from '@tsed/components-scan';
17
15
  export * from '@tsed/components-scan';
18
16
  export * from '@tsed/platform-log-middleware';
19
17
  import { __decorate, __metadata, __param } from 'tslib';
20
- import { AnyToPromise, AnyToPromiseStatus, nameOf, Store, descriptorOf, prototypeOf, deepMerge, isFunction, DecoratorTypes, isStream, uniq, isBoolean, isNumber, isString, getValue, Env, toMap, StoreMerge, Metadata, useDecorators, useMethodDecorators, StoreSet, isClass } from '@tsed/core';
18
+ import { AnyToPromise, AnyToPromiseStatus, nameOf, Store, descriptorOf, prototypeOf, deepMerge, isFunction, DecoratorTypes, isStream, uniq, isBoolean, isNumber, isString, toMap, getValue, Env, StoreMerge, Metadata, useDecorators, useMethodDecorators, StoreSet, isClass } from '@tsed/core';
21
19
  import { Exception, NotAcceptable } from '@tsed/exceptions';
22
20
  import { JsonParameterStore, JsonMethodStore, JsonEntityStore, JsonEntityComponent, getOperationsRoutes, OperationMethods, JsonOperationRoute, JsonPropertyStore, getProperties, concatPath, Returns, Consumes, Produces, JsonEntityFn } from '@tsed/schema';
23
21
  export { All, Delete, Get, Head, Location, Options, Patch, Post, Put, Redirect } from '@tsed/schema';
24
22
  import { promisify } from 'util';
25
- import Http, { ServerResponse, IncomingMessage } from 'http';
26
23
  import Https from 'https';
24
+ import Http, { ServerResponse, IncomingMessage } from 'http';
27
25
 
28
26
  function _extends() {
29
27
  _extends = Object.assign || function (target) {
@@ -977,6 +975,7 @@ const PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
977
975
  let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
978
976
  constructor(platformHandler) {
979
977
  this.platformHandler = platformHandler;
978
+ this.isBuilt = false;
980
979
  this.rawRouter = this.raw = PlatformRouter_1.createRawRouter();
981
980
  }
982
981
  /**
@@ -1283,72 +1282,77 @@ __decorate([__param(0, Context()), __metadata("design:type", Function), __metada
1283
1282
 
1284
1283
  AcceptMimesMiddleware = __decorate([Middleware()], AcceptMimesMiddleware);
1285
1284
 
1286
- /**
1287
- * Create Ts.ED context handler
1288
- * @param fn
1289
- * @ignore
1290
- */
1285
+ const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
1291
1286
 
1292
- function useCtxHandler(fn) {
1293
- fn.type = HandlerType.CTX_FN;
1294
- return fn;
1295
- }
1287
+ let AUTO_INC = 0;
1288
+ class ControllerProvider extends Provider {
1289
+ constructor(provide, options = {}) {
1290
+ super(provide, options);
1291
+ this.type = ProviderType.CONTROLLER;
1292
+ this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;
1293
+ }
1294
+ /**
1295
+ *
1296
+ */
1296
1297
 
1297
- /**
1298
- * @ignore
1299
- */
1300
1298
 
1301
- function formatMethod(method) {
1302
- return (method === OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
1303
- }
1304
- /**
1305
- * @ignore
1306
- */
1299
+ get routerOptions() {
1300
+ return this.store.get(ROUTER_OPTIONS) || {};
1301
+ }
1302
+ /**
1303
+ *
1304
+ * @param value
1305
+ */
1307
1306
 
1308
1307
 
1309
- class PlatformControllerBuilder {
1310
- constructor(provider) {
1311
- this.provider = provider;
1308
+ set routerOptions(value) {
1309
+ this.store.set(ROUTER_OPTIONS, value);
1312
1310
  }
1313
1311
  /**
1314
- * @returns {any}
1312
+ *
1313
+ * @returns {any[]}
1315
1314
  */
1316
1315
 
1317
1316
 
1318
- build(injector) {
1319
- const {
1320
- middlewares: {
1321
- useBefore
1322
- }
1323
- } = this.provider; // Controller lifecycle
1317
+ get middlewares() {
1318
+ return Object.assign({
1319
+ use: [],
1320
+ useAfter: [],
1321
+ useBefore: []
1322
+ }, this.store.get("middlewares", {}));
1323
+ }
1324
+ /**
1325
+ *
1326
+ * @param middlewares
1327
+ */
1324
1328
 
1325
- this.buildMiddlewares(useBefore) // Controller before-middleware
1326
- .buildEndpoints() // All endpoints and his middlewares
1327
- .buildChildrenCtrls(injector); // Children controllers
1328
1329
 
1329
- return this.provider.getRouter();
1330
- }
1330
+ set middlewares(middlewares) {
1331
+ const mdlwrs = this.middlewares;
1331
1332
 
1332
- buildEndpoints() {
1333
- getOperationsRoutes(this.provider.token).forEach(operationRoute => {
1334
- this.buildEndpoint(operationRoute);
1335
- });
1336
- return this;
1337
- }
1333
+ const concat = (key, a, b) => a[key] = a[key].concat(b[key]);
1338
1334
 
1339
- buildEndpoint(operationRoute) {
1340
- let handlers = this.getMiddlewares(operationRoute);
1341
- const router = this.provider.getRouter();
1342
- router.addRoute({
1343
- handlers,
1344
- token: operationRoute.token,
1345
- method: formatMethod(operationRoute.method),
1346
- path: operationRoute.path,
1347
- isFinal: operationRoute.isFinal
1335
+ Object.keys(middlewares).forEach(key => {
1336
+ concat(key, mdlwrs, middlewares);
1348
1337
  });
1338
+ this.store.set("middlewares", mdlwrs);
1349
1339
  }
1350
1340
 
1351
- getMiddlewares(operationRoute) {
1341
+ }
1342
+
1343
+ /**
1344
+ * Create Ts.ED context handler
1345
+ * @param fn
1346
+ * @ignore
1347
+ */
1348
+
1349
+ function useCtxHandler(fn) {
1350
+ fn.type = HandlerType.CTX_FN;
1351
+ return fn;
1352
+ }
1353
+
1354
+ let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
1355
+ get(provider, operationRoute) {
1352
1356
  const {
1353
1357
  endpoint
1354
1358
  } = operationRoute;
@@ -1362,11 +1366,10 @@ class PlatformControllerBuilder {
1362
1366
  use,
1363
1367
  useAfter
1364
1368
  }
1365
- } = this.provider;
1369
+ } = provider;
1366
1370
  const hasFiles = [...operationRoute.endpoint.children.values()].find(item => item.paramType === ParamTypes.FILES);
1367
1371
  return [].concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(PlatformAcceptMimesMiddleware).concat(hasFiles && PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
1368
1372
  .concat(use) // Controller use-middlewares
1369
- // .concat(endpoint.cache && PlatformCacheMiddleware)
1370
1373
  .concat(mldwrs) // Endpoint middlewares
1371
1374
  .concat(endpoint) // Endpoint metadata
1372
1375
  .concat(afterMiddlewares) // Endpoint after-middlewares
@@ -1374,32 +1377,97 @@ class PlatformControllerBuilder {
1374
1377
  .filter(item => !!item);
1375
1378
  }
1376
1379
 
1377
- buildChildrenCtrls(injector) {
1378
- const {
1379
- children
1380
- } = this.provider;
1381
- const router = this.provider.getRouter();
1380
+ };
1381
+ PlatformMiddlewaresChain = __decorate([Injectable()], PlatformMiddlewaresChain);
1382
+
1383
+ GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
1384
+ onInvoke(provider, locals, {
1385
+ injector
1386
+ }) {
1387
+ const router = createRouter(injector, provider);
1388
+ locals.set(PlatformRouter, router);
1389
+ }
1390
+
1391
+ });
1392
+ /**
1393
+ * @ignore
1394
+ */
1395
+
1396
+ function formatMethod(method) {
1397
+ return (method === OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
1398
+ }
1399
+ /**
1400
+ * @ignore
1401
+ */
1402
+
1403
+
1404
+ function getRouter(injector, provider) {
1405
+ return injector.get(provider.tokenRouter);
1406
+ }
1407
+ /**
1408
+ * @ignore
1409
+ */
1410
+
1411
+ function createRouter(injector, provider) {
1412
+ const token = provider.tokenRouter;
1413
+
1414
+ if (injector.has(token)) {
1415
+ return getRouter(injector, provider);
1416
+ }
1417
+
1418
+ const router = PlatformRouter.create(injector, provider.routerOptions);
1419
+ return injector.add(token, {
1420
+ useValue: router
1421
+ }).invoke(token);
1422
+ }
1423
+ /**
1424
+ * @ignore
1425
+ * @param injector
1426
+ * @param provider
1427
+ */
1428
+
1429
+ function buildRouter(injector, provider) {
1430
+ const {
1431
+ middlewares: {
1432
+ useBefore
1433
+ },
1434
+ children
1435
+ } = provider; // Controller lifecycle
1436
+
1437
+ const router = createRouter(injector, provider);
1438
+
1439
+ if (!router.isBuilt) {
1440
+ router.isBuilt = true;
1441
+ const platformMiddlewaresChain = injector.get(PlatformMiddlewaresChain);
1442
+ useBefore // Controller before-middleware
1443
+ .filter(o => typeof o === "function").forEach(middleware => {
1444
+ router.use(middleware);
1445
+ }); // build all endpoints and his middlewares
1446
+
1447
+ getOperationsRoutes(provider.token).forEach(operationRoute => {
1448
+ const handlers = platformMiddlewaresChain == null ? void 0 : platformMiddlewaresChain.get(provider, operationRoute);
1449
+ router.addRoute({
1450
+ handlers,
1451
+ token: operationRoute.token,
1452
+ method: formatMethod(operationRoute.method),
1453
+ path: operationRoute.path,
1454
+ isFinal: operationRoute.isFinal
1455
+ });
1456
+ }); // build children controllers
1457
+
1382
1458
  children.forEach(child => {
1383
- const provider = injector.getProvider(child);
1459
+ const childProvider = injector.getProvider(child);
1384
1460
  /* istanbul ignore next */
1385
1461
 
1386
- if (!provider) {
1462
+ if (!childProvider) {
1387
1463
  throw new Error("Controller component not found in the ControllerRegistry");
1388
1464
  }
1389
1465
 
1390
- new PlatformControllerBuilder(provider).build(injector);
1391
- router.use(provider.path, provider.getRouter());
1392
- });
1393
- }
1394
-
1395
- buildMiddlewares(middlewares) {
1396
- const router = this.provider.getRouter();
1397
- middlewares.filter(o => typeof o === "function").forEach(middleware => {
1398
- router.use(middleware);
1466
+ router.use(childProvider.path, buildRouter(injector, childProvider));
1399
1467
  });
1400
- return this;
1401
1468
  }
1402
1469
 
1470
+ return router;
1403
1471
  }
1404
1472
 
1405
1473
  /**
@@ -1410,7 +1478,8 @@ class PlatformControllerBuilder {
1410
1478
  let PlatformRequest = class PlatformRequest {
1411
1479
  constructor({
1412
1480
  request
1413
- }) {
1481
+ }, $ctx) {
1482
+ this.$ctx = $ctx;
1414
1483
  this.raw = request;
1415
1484
  }
1416
1485
 
@@ -1541,7 +1610,9 @@ let PlatformRequest = class PlatformRequest {
1541
1610
  // @ts-ignore
1542
1611
  delete this.raw; // @ts-ignore
1543
1612
 
1544
- delete this.response;
1613
+ delete this.response; // @ts-ignore
1614
+
1615
+ delete this.$ctx;
1545
1616
  }
1546
1617
  /**
1547
1618
  * Return the Framework response object (express, koa, etc...)
@@ -1561,7 +1632,7 @@ let PlatformRequest = class PlatformRequest {
1561
1632
  }
1562
1633
 
1563
1634
  };
1564
- PlatformRequest = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __metadata("design:paramtypes", [Object])], PlatformRequest);
1635
+ PlatformRequest = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __metadata("design:paramtypes", [Object, Function])], PlatformRequest);
1565
1636
 
1566
1637
  var PlatformResponse_1;
1567
1638
 
@@ -1575,7 +1646,8 @@ const onFinished = require("on-finished");
1575
1646
  let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1576
1647
  constructor({
1577
1648
  response
1578
- }) {
1649
+ }, $ctx) {
1650
+ this.$ctx = $ctx;
1579
1651
  this.raw = response;
1580
1652
  }
1581
1653
  /**
@@ -1792,7 +1864,11 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1792
1864
 
1793
1865
 
1794
1866
  async render(path, options = {}) {
1795
- return this.platformViews.render(path, _extends({}, this.locals, options));
1867
+ const {
1868
+ PlatformViews
1869
+ } = await import('@tsed/platform-views');
1870
+ const platformViews = await this.$ctx.injector.lazyInvoke(PlatformViews);
1871
+ return platformViews.render(path, _extends({}, this.locals, options));
1796
1872
  }
1797
1873
  /**
1798
1874
  * Send any data to your consumer.
@@ -1864,7 +1940,9 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1864
1940
  delete this.raw;
1865
1941
  delete this.data; // @ts-ignore
1866
1942
 
1867
- delete this.request;
1943
+ delete this.request; // @ts-ignore
1944
+
1945
+ delete this.$ctx;
1868
1946
  }
1869
1947
 
1870
1948
  isHeadersSent() {
@@ -1872,7 +1950,7 @@ let PlatformResponse = PlatformResponse_1 = class PlatformResponse {
1872
1950
  }
1873
1951
 
1874
1952
  };
1875
- PlatformResponse = PlatformResponse_1 = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __metadata("design:paramtypes", [Object])], PlatformResponse);
1953
+ PlatformResponse = PlatformResponse_1 = __decorate([Injectable(), Scope(ProviderScope.INSTANCE), __metadata("design:paramtypes", [Object, Function])], PlatformResponse);
1876
1954
 
1877
1955
  const _excluded$2 = ["event", "endpoint", "ignoreUrlPatterns", "ResponseKlass", "RequestKlass"];
1878
1956
  class PlatformContext extends DIContext {
@@ -1894,8 +1972,8 @@ class PlatformContext extends DIContext {
1894
1972
  this.ignoreUrlPatterns = [];
1895
1973
  endpoint && (this.endpoint = endpoint);
1896
1974
  this.ignoreUrlPatterns = ignoreUrlPatterns.map(pattern => typeof pattern === "string" ? new RegExp(pattern, "gi") : pattern);
1897
- this.response = new ResponseKlass(event);
1898
- this.request = new RequestKlass(event);
1975
+ this.response = new ResponseKlass(event, this);
1976
+ this.request = new RequestKlass(event, this);
1899
1977
  this.response.request = this.request;
1900
1978
  this.request.response = this.response;
1901
1979
  this.request.request.$ctx = this;
@@ -1996,71 +2074,6 @@ class PlatformRouteDetails extends JsonOperationRoute {
1996
2074
 
1997
2075
  }
1998
2076
 
1999
- const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
2000
-
2001
- class ControllerProvider extends Provider {
2002
- constructor(provide, options = {}) {
2003
- super(provide, options);
2004
- this.type = ProviderType.CONTROLLER;
2005
- }
2006
- /**
2007
- *
2008
- */
2009
-
2010
-
2011
- get routerOptions() {
2012
- return this.store.get(ROUTER_OPTIONS) || {};
2013
- }
2014
- /**
2015
- *
2016
- * @param value
2017
- */
2018
-
2019
-
2020
- set routerOptions(value) {
2021
- this.store.set(ROUTER_OPTIONS, value);
2022
- }
2023
- /**
2024
- *
2025
- * @returns {any[]}
2026
- */
2027
-
2028
-
2029
- get middlewares() {
2030
- return Object.assign({
2031
- use: [],
2032
- useAfter: [],
2033
- useBefore: []
2034
- }, this.store.get("middlewares", {}));
2035
- }
2036
- /**
2037
- *
2038
- * @param middlewares
2039
- */
2040
-
2041
-
2042
- set middlewares(middlewares) {
2043
- const mdlwrs = this.middlewares;
2044
-
2045
- const concat = (key, a, b) => a[key] = a[key].concat(b[key]);
2046
-
2047
- Object.keys(middlewares).forEach(key => {
2048
- concat(key, mdlwrs, middlewares);
2049
- });
2050
- this.store.set("middlewares", mdlwrs);
2051
- }
2052
-
2053
- getRouter() {
2054
- return this.router;
2055
- }
2056
-
2057
- setRouter(router) {
2058
- this.router = router;
2059
- return this;
2060
- }
2061
-
2062
- }
2063
-
2064
2077
  /**
2065
2078
  * @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
2066
2079
  */
@@ -2084,13 +2097,6 @@ let PropertyMetadata = class PropertyMetadata extends JsonPropertyStore {
2084
2097
  };
2085
2098
  PropertyMetadata = __decorate([JsonEntityComponent(DecoratorTypes.PROP)], PropertyMetadata);
2086
2099
 
2087
- GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
2088
- onInvoke(provider, locals) {
2089
- locals.set(PlatformRouter, provider.getRouter());
2090
- }
2091
-
2092
- });
2093
-
2094
2100
  /**
2095
2101
  * `Platform` is used to provide all routes collected by annotation `@Controller`.
2096
2102
  *
@@ -2137,7 +2143,7 @@ let Platform = class Platform {
2137
2143
  provider
2138
2144
  });
2139
2145
 
2140
- this.app.use(ctrlPath, ...[].concat(provider.getRouter().callback()));
2146
+ this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));
2141
2147
  this._routes = getOperationsRoutes(provider.token, {
2142
2148
  withChildren: true,
2143
2149
  basePath
@@ -2182,7 +2188,7 @@ let Platform = class Platform {
2182
2188
  injector
2183
2189
  } = this;
2184
2190
  injector.getProviders(ProviderType.CONTROLLER).map(provider => {
2185
- provider.setRouter(PlatformRouter.create(injector, provider.routerOptions));
2191
+ createRouter(injector, provider);
2186
2192
  });
2187
2193
  }
2188
2194
  /**
@@ -2197,52 +2203,32 @@ let Platform = class Platform {
2197
2203
  } = this;
2198
2204
  injector.getProviders(ProviderType.CONTROLLER).map(provider => {
2199
2205
  if (!provider.hasParent()) {
2200
- return new PlatformControllerBuilder(provider).build(injector);
2206
+ return buildRouter(injector, provider);
2201
2207
  }
2202
2208
  });
2203
2209
  }
2204
2210
 
2205
2211
  };
2206
2212
  Platform = __decorate([Injectable({
2207
- scope: ProviderScope.SINGLETON
2213
+ scope: ProviderScope.SINGLETON,
2214
+ imports: [PlatformMiddlewaresChain]
2208
2215
  }), __metadata("design:paramtypes", [InjectorService, PlatformApplication])], Platform);
2209
2216
 
2210
- $log.name = "TSED";
2211
- function createInjector(settings = {}) {
2212
- const injector = new InjectorService();
2213
- injector.settings = createSettingsService(injector);
2214
- injector.logger = $log;
2215
- injector.settings.set(settings);
2216
- setLoggerLevel(injector);
2217
- return injector;
2218
- }
2219
-
2220
- function createSettingsService(injector) {
2221
- const provider = GlobalProviders.get(PlatformConfiguration).clone();
2222
- provider.instance = injector.invoke(provider.useClass);
2223
- injector.addProvider(PlatformConfiguration, provider);
2224
- return provider.instance;
2225
- }
2226
-
2227
- function createPlatformApplication(injector) {
2228
- injector.forkProvider(PlatformApplication);
2229
- }
2230
-
2231
2217
  /**
2232
- * Inject the Http.Server instance.
2218
+ * Inject the Https.Server instance.
2233
2219
  *
2234
2220
  * ### Example
2235
2221
  *
2236
2222
  * ```typescript
2237
- * import {HttpServer, Service} from "@tsed/common";
2223
+ * import {HttpsServer, Service} from "@tsed/common";
2238
2224
  *
2239
2225
  * @Service()
2240
2226
  * export default class OtherService {
2241
- * constructor(@HttpServer httpServer: HttpServer) {}
2227
+ * constructor(@HttpsServer httpServer: HttpServer) {}
2242
2228
  * }
2243
2229
  * ```
2244
2230
  *
2245
- * > Note: TypeScript transform and store `HttpServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2231
+ * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2246
2232
  *
2247
2233
  * @param {Type<any>} target
2248
2234
  * @param {string} targetKey
@@ -2251,8 +2237,8 @@ function createPlatformApplication(injector) {
2251
2237
  * @decorator
2252
2238
  */
2253
2239
 
2254
- function HttpServer(target, targetKey, descriptor) {
2255
- return Inject(HttpServer)(target, targetKey, descriptor);
2240
+ function HttpsServer(target, targetKey, descriptor) {
2241
+ return Inject(HttpsServer)(target, targetKey, descriptor);
2256
2242
  }
2257
2243
 
2258
2244
  function listenServer(http, settings) {
@@ -2274,56 +2260,57 @@ function listenServer(http, settings) {
2274
2260
  return promise;
2275
2261
  }
2276
2262
 
2277
- function createHttpServer(injector) {
2278
- injector.forkProvider(HttpServer);
2263
+ function createHttpsServer(injector) {
2264
+ injector.invoke(HttpsServer);
2279
2265
  }
2280
2266
  registerProvider({
2281
- provide: HttpServer,
2282
- deps: [PlatformApplication],
2267
+ provide: HttpsServer,
2268
+ deps: [PlatformApplication, Configuration],
2283
2269
  scope: ProviderScope.SINGLETON,
2284
2270
  global: true,
2285
2271
 
2286
- useFactory(platformApplication) {
2287
- return Http.createServer(platformApplication.callback());
2272
+ useFactory(platformApplication, settings) {
2273
+ const options = settings.httpsOptions;
2274
+ return Https.createServer(options, platformApplication.callback());
2288
2275
  }
2289
2276
 
2290
2277
  });
2291
- async function listenHttpServer(injector) {
2278
+ async function listenHttpsServer(injector) {
2292
2279
  const {
2293
2280
  settings
2294
2281
  } = injector;
2295
- const server = injector.get(HttpServer);
2282
+ const server = injector.get(HttpsServer);
2296
2283
 
2297
- if (settings.httpPort !== false && server) {
2284
+ if (settings.httpsPort !== false && server) {
2298
2285
  const {
2299
2286
  address,
2300
2287
  port
2301
- } = settings.getHttpPort();
2302
- injector.logger.debug(`Start server on http://${address}:${port}`);
2288
+ } = settings.getHttpsPort();
2289
+ injector.logger.debug(`Start server on https://${address}:${port}`);
2303
2290
  const options = await listenServer(server, {
2304
2291
  address,
2305
2292
  port
2306
2293
  });
2307
- settings.setHttpPort(options);
2308
- injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
2294
+ settings.setHttpsPort(options);
2295
+ injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
2309
2296
  }
2310
2297
  }
2311
2298
 
2312
2299
  /**
2313
- * Inject the Https.Server instance.
2300
+ * Inject the Http.Server instance.
2314
2301
  *
2315
2302
  * ### Example
2316
2303
  *
2317
2304
  * ```typescript
2318
- * import {HttpsServer, Service} from "@tsed/common";
2305
+ * import {HttpServer, Service} from "@tsed/common";
2319
2306
  *
2320
2307
  * @Service()
2321
2308
  * export default class OtherService {
2322
- * constructor(@HttpsServer httpServer: HttpServer) {}
2309
+ * constructor(@HttpServer httpServer: HttpServer) {}
2323
2310
  * }
2324
2311
  * ```
2325
2312
  *
2326
- * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2313
+ * > Note: TypeScript transform and store `HttpServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2327
2314
  *
2328
2315
  * @param {Type<any>} target
2329
2316
  * @param {string} targetKey
@@ -2332,46 +2319,79 @@ async function listenHttpServer(injector) {
2332
2319
  * @decorator
2333
2320
  */
2334
2321
 
2335
- function HttpsServer(target, targetKey, descriptor) {
2336
- return Inject(HttpsServer)(target, targetKey, descriptor);
2322
+ function HttpServer(target, targetKey, descriptor) {
2323
+ return Inject(HttpServer)(target, targetKey, descriptor);
2337
2324
  }
2338
2325
 
2339
- function createHttpsServer(injector) {
2340
- injector.forkProvider(HttpsServer);
2326
+ function createHttpServer(injector) {
2327
+ injector.invoke(HttpServer);
2341
2328
  }
2342
2329
  registerProvider({
2343
- provide: HttpsServer,
2344
- deps: [PlatformApplication, Configuration],
2330
+ provide: HttpServer,
2331
+ deps: [PlatformApplication],
2345
2332
  scope: ProviderScope.SINGLETON,
2346
2333
  global: true,
2347
2334
 
2348
- useFactory(platformApplication, settings) {
2349
- const options = settings.httpsOptions;
2350
- return Https.createServer(options, platformApplication.callback());
2335
+ useFactory(platformApplication) {
2336
+ return Http.createServer(platformApplication.callback());
2351
2337
  }
2352
2338
 
2353
2339
  });
2354
- async function listenHttpsServer(injector) {
2340
+ async function listenHttpServer(injector) {
2355
2341
  const {
2356
2342
  settings
2357
2343
  } = injector;
2358
- const server = injector.get(HttpsServer);
2344
+ const server = injector.get(HttpServer);
2359
2345
 
2360
- if (settings.httpsPort !== false && server) {
2346
+ if (settings.httpPort !== false && server) {
2361
2347
  const {
2362
2348
  address,
2363
2349
  port
2364
- } = settings.getHttpsPort();
2365
- injector.logger.debug(`Start server on https://${address}:${port}`);
2350
+ } = settings.getHttpPort();
2351
+ injector.logger.debug(`Start server on http://${address}:${port}`);
2366
2352
  const options = await listenServer(server, {
2367
2353
  address,
2368
2354
  port
2369
2355
  });
2370
- settings.setHttpsPort(options);
2371
- injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
2356
+ settings.setHttpPort(options);
2357
+ injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
2372
2358
  }
2373
2359
  }
2374
2360
 
2361
+ $log.name = "TSED";
2362
+ const DEFAULT_PROVIDERS = [{
2363
+ provide: PlatformHandler
2364
+ }, {
2365
+ provide: PlatformResponse
2366
+ }, {
2367
+ provide: PlatformRequest
2368
+ }, {
2369
+ provide: PlatformRouter
2370
+ }, {
2371
+ provide: PlatformApplication
2372
+ }, {
2373
+ provide: Platform
2374
+ }];
2375
+ function createInjector({
2376
+ providers = [],
2377
+ settings = {}
2378
+ }) {
2379
+ const injector = new InjectorService();
2380
+ injector.addProvider(PlatformConfiguration);
2381
+ injector.settings = injector.invoke(PlatformConfiguration);
2382
+ injector.logger = $log;
2383
+ injector.settings.set(settings);
2384
+ setLoggerLevel(injector);
2385
+ providers = [...DEFAULT_PROVIDERS, ...providers];
2386
+ toMap(providers, "provide").forEach((provider, token) => {
2387
+ injector.addProvider(token, provider);
2388
+ });
2389
+ injector.invoke(PlatformApplication);
2390
+ createHttpsServer(injector);
2391
+ createHttpServer(injector);
2392
+ return injector;
2393
+ }
2394
+
2375
2395
  /**
2376
2396
  * @ignore
2377
2397
  * @deprecated User injector.load(container, module) instead
@@ -2430,7 +2450,6 @@ function createContext(injector) {
2430
2450
 
2431
2451
  const ResponseKlass = (_injector$getProvider = injector.getProvider(PlatformResponse)) == null ? void 0 : _injector$getProvider.useClass;
2432
2452
  const RequestKlass = (_injector$getProvider2 = injector.getProvider(PlatformRequest)) == null ? void 0 : _injector$getProvider2.useClass;
2433
- const platformViews = injector.get(PlatformViews);
2434
2453
 
2435
2454
  const _ref = injector.settings.logger || {},
2436
2455
  {
@@ -2448,7 +2467,6 @@ function createContext(injector) {
2448
2467
  ResponseKlass,
2449
2468
  RequestKlass
2450
2469
  }));
2451
- ctx.response.platformViews = platformViews;
2452
2470
  ctx.response.onEnd(async () => {
2453
2471
  await ctx.emit("$onResponse", ctx);
2454
2472
  await ctx.destroy();
@@ -2512,19 +2530,6 @@ function getConfiguration(configuration = {}, module = null) {
2512
2530
  return config;
2513
2531
  }
2514
2532
 
2515
- const DEFAULT_PROVIDERS = [{
2516
- provide: PlatformHandler
2517
- }, {
2518
- provide: PlatformResponse
2519
- }, {
2520
- provide: PlatformRequest
2521
- }, {
2522
- provide: PlatformRouter
2523
- }, {
2524
- provide: PlatformApplication
2525
- }, {
2526
- provide: Platform
2527
- }];
2528
2533
  /**
2529
2534
  * @platform
2530
2535
  */
@@ -2553,7 +2558,13 @@ class PlatformBuilder {
2553
2558
  this.current = new Date();
2554
2559
  this.name = name;
2555
2560
  _classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = module;
2556
- this.createInjector(module, providers, settings);
2561
+ const configuration = getConfiguration(settings, module);
2562
+ configuration.PLATFORM_NAME = name;
2563
+ _classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector({
2564
+ settings: configuration,
2565
+ providers
2566
+ });
2567
+ this.log("Injector created...");
2557
2568
  }
2558
2569
 
2559
2570
  get injector() {
@@ -2832,20 +2843,6 @@ class PlatformBuilder {
2832
2843
  await this.callHook("$afterRoutesInit");
2833
2844
  }
2834
2845
 
2835
- createInjector(module, providers, settings) {
2836
- const configuration = getConfiguration(settings, module);
2837
- configuration.PLATFORM_NAME = this.name;
2838
- _classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector(configuration);
2839
- providers = [...DEFAULT_PROVIDERS, ...providers];
2840
- toMap(providers, "provide").forEach((provider, token) => {
2841
- this.injector.addProvider(token, provider);
2842
- });
2843
- createPlatformApplication(this.injector);
2844
- createHttpsServer(this.injector);
2845
- createHttpServer(this.injector);
2846
- this.log("Injector created...");
2847
- }
2848
-
2849
2846
  }
2850
2847
 
2851
2848
  /**
@@ -3036,6 +3033,39 @@ function EndpointFn(fn) {
3036
3033
  return JsonEntityFn(fn);
3037
3034
  }
3038
3035
 
3036
+ /**
3037
+ * Use a view and sends the rendered HTML string to the client. Optional parameter:
3038
+ *
3039
+ * * viewOptions, an object whose properties define local variables for the view.
3040
+ *
3041
+ * The view argument is a string that is the file path of the view file to render.
3042
+ * This can be an absolute path, or a path relative to the views setting.
3043
+ * If the path does not contain a file extension, then the view engine setting determines the file extension.
3044
+ * If the path does contain a file extension, then Express will load the module for the specified template engine (via require())
3045
+ * and render it using the loaded module’s __express function.
3046
+ *
3047
+ * For more information, see [Using template engines with Express](http://expressjs.com/guide/using-template-engines.html).
3048
+ *
3049
+ * > NOTE: The view argument performs file system operations like reading a file from disk and evaluating Node.js modules,
3050
+ * and as so for security reasons should not contain input from the end-user.
3051
+ *
3052
+ * @param path Relative path to the view file.
3053
+ * @param options Additional options
3054
+ * @decorator
3055
+ * @operation
3056
+ * @response
3057
+ * @ignores
3058
+ * @deprecated Use View decorator from @tsed/platform-views instead.
3059
+ */
3060
+ // istanbul ignore next
3061
+
3062
+ function View(path, options) {
3063
+ return StoreSet("view", {
3064
+ path,
3065
+ options
3066
+ });
3067
+ }
3068
+
3039
3069
  /**
3040
3070
  * Return the current response data. Prefer the @@Context@@ decorator to get or set data.
3041
3071
  *
@@ -3218,8 +3248,8 @@ function mapReturnedResponse(_ref) {
3218
3248
  */
3219
3249
 
3220
3250
  class PlatformTest extends DITest {
3221
- static async create(options = {}) {
3222
- DITest.injector = PlatformTest.createInjector(getConfiguration(options, null));
3251
+ static async create(settings = {}) {
3252
+ DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
3223
3253
  const container = createContainer();
3224
3254
  await DITest.injector.load(container);
3225
3255
  }
@@ -3229,7 +3259,10 @@ class PlatformTest extends DITest {
3229
3259
 
3230
3260
 
3231
3261
  static createInjector(settings = {}) {
3232
- return createInjector(DITest.configure(settings));
3262
+ return createInjector({
3263
+ providers: [],
3264
+ settings: DITest.configure(settings)
3265
+ });
3233
3266
  }
3234
3267
  /**
3235
3268
  * Load the server silently without listening port and configure it on test profile.
@@ -3393,7 +3426,7 @@ class PlatformTest extends DITest {
3393
3426
  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(),
3394
3427
  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()
3395
3428
  };
3396
- const ctx = new PlatformContext(_extends({
3429
+ return new PlatformContext(_extends({
3397
3430
  id: "id",
3398
3431
  injector: DITest.injector,
3399
3432
  logger: DITest.injector.logger,
@@ -3401,8 +3434,6 @@ class PlatformTest extends DITest {
3401
3434
  }, options, {
3402
3435
  event
3403
3436
  }));
3404
- ctx.response.platformViews = PlatformTest.get(PlatformViews);
3405
- return ctx;
3406
3437
  }
3407
3438
 
3408
3439
  }
@@ -3413,5 +3444,5 @@ class PlatformTest extends DITest {
3413
3444
  */
3414
3445
  class PlatformModule {}
3415
3446
 
3416
- export { AcceptMime, AcceptMimesMiddleware, AnyToPromiseWithCtx, ControllerProvider, EndpointFn, EndpointInfo, EndpointMetadata, Err, GlobalAcceptMimesMiddleware, HandlerMetadata, HandlerType, HttpServer, HttpsServer, MulterFileSize, MulterOptions, MultipartFile, Next, PLATFORM_ROUTER_OPTIONS, Platform, PlatformAcceptMimesMiddleware, PlatformApplication, PlatformBuilder, PlatformConfiguration, PlatformContext, PlatformControllerBuilder, PlatformHandler, PlatformModule, PlatformMulterMiddleware, PlatformRequest, PlatformResponse, PlatformRouteDetails, PlatformRouter, PlatformTest, PropertyMetadata, ROUTER_OPTIONS, Req, Request, Res, Response, ResponseData, bindEndpointMiddleware, createContext, createHttpServer, createHttpsServer, createInjector, createPlatformApplication, listenHttpServer, listenHttpsServer, listenServer, loadInjector, mapReturnedResponse, printRoutes, useCtxHandler };
3447
+ export { AcceptMime, AcceptMimesMiddleware, AnyToPromiseWithCtx, ControllerProvider, EndpointFn, EndpointInfo, EndpointMetadata, Err, GlobalAcceptMimesMiddleware, HandlerMetadata, HandlerType, HttpServer, HttpsServer, MulterFileSize, MulterOptions, MultipartFile, Next, PLATFORM_ROUTER_OPTIONS, Platform, PlatformAcceptMimesMiddleware, PlatformApplication, PlatformBuilder, PlatformConfiguration, PlatformContext, PlatformHandler, PlatformMiddlewaresChain, PlatformModule, PlatformMulterMiddleware, PlatformRequest, PlatformResponse, PlatformRouteDetails, PlatformRouter, PlatformTest, PropertyMetadata, ROUTER_OPTIONS, Req, Request, Res, Response, ResponseData, View, bindEndpointMiddleware, buildRouter, createContext, createHttpServer, createHttpsServer, createInjector, createRouter, getRouter, listenHttpServer, listenHttpsServer, listenServer, loadInjector, mapReturnedResponse, printRoutes, useCtxHandler };
3417
3448
  //# sourceMappingURL=index.modern.js.map