@tsed/common 6.75.7 → 6.75.8

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.
@@ -77,4 +77,9 @@ export declare class PlatformConfiguration extends DIConfiguration {
77
77
  address: string;
78
78
  port: number;
79
79
  }): void;
80
+ getBestHost(): {
81
+ address: string;
82
+ port: number;
83
+ protocol: string;
84
+ } | undefined;
80
85
  }
package/lib/index.js CHANGED
@@ -13,7 +13,6 @@ var core = require('@tsed/core');
13
13
  var perf = require('@tsed/perf');
14
14
  var exceptions = require('@tsed/exceptions');
15
15
  var schema = require('@tsed/schema');
16
- var jsonMapper = require('@tsed/json-mapper');
17
16
  var util = require('util');
18
17
  var Http = require('http');
19
18
  var Https = require('https');
@@ -325,6 +324,27 @@ exports.PlatformConfiguration = PlatformConfiguration_1 = class PlatformConfigur
325
324
  this.setRaw("httpsPort", `${settings.address}:${settings.port}`);
326
325
  }
327
326
 
327
+ getBestHost() {
328
+ const {
329
+ httpsPort,
330
+ httpPort
331
+ } = this;
332
+
333
+ if (httpsPort) {
334
+ const host = this.getHttpsPort();
335
+ return _extends({
336
+ protocol: "https"
337
+ }, host);
338
+ }
339
+
340
+ if (httpPort) {
341
+ const host = this.getHttpPort();
342
+ return _extends({
343
+ protocol: "http"
344
+ }, host);
345
+ }
346
+ }
347
+
328
348
  };
329
349
  exports.PlatformConfiguration = PlatformConfiguration_1 = tslib.__decorate([di.Injectable({
330
350
  scope: di.ProviderScope.SINGLETON,
@@ -744,57 +764,6 @@ function setResponseHeaders(ctx) {
744
764
  }
745
765
  }
746
766
 
747
- var _converterSettings;
748
- /**
749
- * @deprecated Since 2021-10-03. Use serialize/deserialize functions from @tsed/json-mapper instead
750
- */
751
-
752
- exports.ConverterService = (_converterSettings = /*#__PURE__*/_classPrivateFieldLooseKey("converterSettings"), class ConverterService {
753
- constructor(injectorService, configuration) {
754
- Object.defineProperty(this, _converterSettings, {
755
- writable: true,
756
- value: void 0
757
- });
758
- this.injectorService = injectorService;
759
- _classPrivateFieldLooseBase(this, _converterSettings)[_converterSettings] = configuration.get("converter") || {};
760
- }
761
-
762
- /**
763
- * Convert instance to plainObject.
764
- *
765
- * @param obj
766
- * @param options
767
- */
768
- serialize(obj, options = {}) {
769
- return jsonMapper.serialize(obj, _extends({
770
- useAlias: true,
771
- additionalProperties: _classPrivateFieldLooseBase(this, _converterSettings)[_converterSettings].additionalProperties === "accept"
772
- }, options));
773
- }
774
- /**
775
- * Convert a plainObject to targetType.
776
- *
777
- * ### Options
778
- *
779
- * - `ignoreCallback`: callback called for each object which will be deserialized. The callback can return a boolean to avoid the default converter behavior.
780
- * - `checkRequiredValue`: Disable the required check condition.
781
- *
782
- * @param obj Object source that will be deserialized
783
- * @param options Mapping options
784
- * @returns {any}
785
- */
786
-
787
-
788
- deserialize(obj, options = {}) {
789
- return jsonMapper.deserialize(obj, _extends({
790
- useAlias: true,
791
- additionalProperties: _classPrivateFieldLooseBase(this, _converterSettings)[_converterSettings].additionalProperties === "accept"
792
- }, options));
793
- }
794
-
795
- });
796
- exports.ConverterService = tslib.__decorate([di.Injectable(), tslib.__param(1, di.Configuration()), tslib.__metadata("design:paramtypes", [di.InjectorService, Object])], exports.ConverterService);
797
-
798
767
  /**
799
768
  * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
800
769
  * @platform
@@ -845,23 +814,13 @@ exports.PlatformHandler = class PlatformHandler {
845
814
 
846
815
  async flush(data, ctx) {
847
816
  const {
848
- response,
849
- endpoint
817
+ response
850
818
  } = ctx;
851
819
 
852
820
  if (!response.isDone()) {
853
- // FIXME should be move to responseFilter module
854
- if (endpoint) {
855
- if (endpoint.view) {
856
- data = await this.render(data, ctx);
857
- } else if (core.isSerializable(data)) {
858
- data = this.injector.get(exports.ConverterService).serialize(data, _extends({}, endpoint.getResponseOptions(response.statusCode), {
859
- endpoint: true
860
- }));
861
- }
862
- }
863
-
864
- response.body(this.responseFilter.transform(data, ctx));
821
+ data = await this.responseFilter.serialize(data, ctx);
822
+ data = await this.responseFilter.transform(data, ctx);
823
+ response.body(data);
865
824
  }
866
825
  }
867
826
 
@@ -1028,17 +987,6 @@ exports.PlatformHandler = class PlatformHandler {
1028
987
  callReturnedMiddleware(middleware, ctx, next) {
1029
988
  return middleware(ctx.getRequest(), ctx.getResponse(), next);
1030
989
  }
1031
- /**
1032
- * Render the view if the endpoint has a configured view.
1033
- * @param data
1034
- * @param ctx
1035
- * @protected
1036
- */
1037
-
1038
-
1039
- async render(data, ctx) {
1040
- return platformViews.renderView(data, ctx);
1041
- }
1042
990
  /**
1043
991
  * create Raw handler
1044
992
  * @param metadata
@@ -1510,8 +1458,8 @@ class PlatformControllerBuilder {
1510
1458
 
1511
1459
  let handlers = [];
1512
1460
  const hasFiles = [...endpoint.children.values()].find(item => item.paramType === platformParams.ParamTypes.FILES);
1513
- handlers = handlers.concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(exports.PlatformAcceptMimesMiddleware).concat(hasFiles && exports.PlatformMulterMiddleware).concat(use) // Controller use-middlewares
1514
- .concat(beforeMiddlewares) // Endpoint before-middlewares
1461
+ handlers = handlers.concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(exports.PlatformAcceptMimesMiddleware).concat(hasFiles && exports.PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
1462
+ .concat(use) // Controller use-middlewares
1515
1463
  // .concat(endpoint.cache && PlatformCacheMiddleware)
1516
1464
  .concat(mldwrs) // Endpoint middlewares
1517
1465
  .concat(endpoint) // Endpoint metadata
@@ -2459,16 +2407,6 @@ exports.Platform = tslib.__decorate([di.Injectable({
2459
2407
  scope: di.ProviderScope.SINGLETON
2460
2408
  }), tslib.__metadata("design:paramtypes", [di.InjectorService, exports.PlatformApplication])], exports.Platform);
2461
2409
 
2462
- /**
2463
- * @ignore
2464
- * @deprecated Will be removed in v7
2465
- */
2466
-
2467
- exports.PlatformModule = class PlatformModule {};
2468
- exports.PlatformModule = tslib.__decorate([di.Module({
2469
- imports: [di.InjectorService, exports.ConverterService, exports.Platform]
2470
- })], exports.PlatformModule);
2471
-
2472
2410
  logger.$log.name = "TSED";
2473
2411
  function createInjector(settings = {}) {
2474
2412
  const injector = new di.InjectorService();
@@ -2641,7 +2579,7 @@ async function listenHttpsServer(injector) {
2641
2579
 
2642
2580
  async function loadInjector(injector, container = di.createContainer()) {
2643
2581
  injector.bootstrap(container);
2644
- return injector.load(container, exports.PlatformModule);
2582
+ return injector.load(container);
2645
2583
  }
2646
2584
 
2647
2585
  function printRoutes(routes) {
@@ -2898,7 +2836,7 @@ class PlatformBuilder {
2898
2836
  await this.callHook("$beforeInit");
2899
2837
  this.log("Build providers");
2900
2838
  const container = di.createContainer(core.constructorOf(this.rootModule));
2901
- await injector.load(container, exports.PlatformModule);
2839
+ await injector.load(container);
2902
2840
  this.log("Settings and injector loaded");
2903
2841
  await this.callHook("$afterInit");
2904
2842
  }
@@ -3458,7 +3396,7 @@ class PlatformTest extends di.DITest {
3458
3396
  static async create(options = {}) {
3459
3397
  di.DITest.injector = PlatformTest.createInjector(options);
3460
3398
  const container = di.createContainer();
3461
- await di.DITest.injector.load(container, exports.PlatformModule);
3399
+ await di.DITest.injector.load(container);
3462
3400
  }
3463
3401
  /**
3464
3402
  * Create a new injector with the right default services
@@ -3650,6 +3588,12 @@ di.GlobalProviders.createRegistry(di.ProviderType.CONTROLLER, ControllerProvider
3650
3588
 
3651
3589
  });
3652
3590
 
3591
+ /**
3592
+ * @ignore
3593
+ * @deprecated Will be removed in v7
3594
+ */
3595
+ class PlatformModule {}
3596
+
3653
3597
  Object.defineProperty(exports, '$log', {
3654
3598
  enumerable: true,
3655
3599
  get: function () {
@@ -3739,6 +3683,7 @@ exports.PLATFORM_ROUTER_OPTIONS = PLATFORM_ROUTER_OPTIONS;
3739
3683
  exports.PlatformBuilder = PlatformBuilder;
3740
3684
  exports.PlatformContext = PlatformContext;
3741
3685
  exports.PlatformControllerBuilder = PlatformControllerBuilder;
3686
+ exports.PlatformModule = PlatformModule;
3742
3687
  exports.PlatformRouteDetails = PlatformRouteDetails;
3743
3688
  exports.PlatformTest = PlatformTest;
3744
3689
  exports.ROUTER_OPTIONS = ROUTER_OPTIONS;