@tsed/common 6.75.4 → 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.
@@ -1,4 +1,4 @@
1
- import { DIConfiguration, ProviderType, ProviderScope, Injectable, Configuration, InjectorService, Inject, Constant, Scope, DIContext, Provider, Module, setLoggerLevel, GlobalProviders, registerProvider, createContainer, Container, getConfiguration, DITest } from '@tsed/di';
1
+ import { DIConfiguration, ProviderType, ProviderScope, Injectable, Inject, InjectorService, Constant, Scope, DIContext, Provider, setLoggerLevel, GlobalProviders, registerProvider, Configuration, createContainer, Container, getConfiguration, DITest } from '@tsed/di';
2
2
  export * from '@tsed/di';
3
3
  import { ParamTypes, ParamMetadata, PlatformParams, Context, UseParam, mapParamsOptions } from '@tsed/platform-params';
4
4
  export * from '@tsed/platform-params';
@@ -8,7 +8,7 @@ export * from '@tsed/platform-response-filter';
8
8
  export * from '@tsed/platform-cache';
9
9
  import { Middleware, getMiddlewaresForHook } from '@tsed/platform-middlewares';
10
10
  export * from '@tsed/platform-middlewares';
11
- import { renderView, PlatformViews } from '@tsed/platform-views';
11
+ import { PlatformViews } from '@tsed/platform-views';
12
12
  export * from '@tsed/platform-views';
13
13
  import { importProviders } from '@tsed/components-scan';
14
14
  export * from '@tsed/components-scan';
@@ -16,12 +16,11 @@ export * from '@tsed/platform-log-middleware';
16
16
  import { $log, colorize } from '@tsed/logger';
17
17
  export { $log, Logger } from '@tsed/logger';
18
18
  import { __decorate, __metadata, __param } from 'tslib';
19
- import { Env, AnyToPromise, AnyToPromiseStatus, nameOf, Store, descriptorOf, classOf, prototypeOf, deepMerge, isFunction, DecoratorTypes, isSerializable, isStream, uniq, isBoolean, isNumber, isString, toMap, constructorOf, StoreMerge, Metadata, useDecorators, useMethodDecorators, isClass } from '@tsed/core';
19
+ import { Env, AnyToPromise, AnyToPromiseStatus, nameOf, Store, descriptorOf, classOf, prototypeOf, deepMerge, isFunction, DecoratorTypes, isStream, uniq, isBoolean, isNumber, isString, getValue, toMap, constructorOf, StoreMerge, Metadata, useDecorators, useMethodDecorators, isClass } from '@tsed/core';
20
20
  import { PerfLogger } from '@tsed/perf';
21
21
  import { Exception, NotAcceptable } from '@tsed/exceptions';
22
22
  import { JsonEntityStore, getOperationsStores, JsonEntityComponent, OperationMethods, getProperties, Returns, Consumes, JsonEntityFn, Produces } from '@tsed/schema';
23
23
  export { All, Delete, Get, Head, Location, Options, Patch, Post, Put, Redirect } from '@tsed/schema';
24
- import { serialize, deserialize } from '@tsed/json-mapper';
25
24
  import { promisify } from 'util';
26
25
  import Http, { ServerResponse, IncomingMessage } from 'http';
27
26
  import Https from 'https';
@@ -308,6 +307,27 @@ let PlatformConfiguration = PlatformConfiguration_1 = class PlatformConfiguratio
308
307
  this.setRaw("httpsPort", `${settings.address}:${settings.port}`);
309
308
  }
310
309
 
310
+ getBestHost() {
311
+ const {
312
+ httpsPort,
313
+ httpPort
314
+ } = this;
315
+
316
+ if (httpsPort) {
317
+ const host = this.getHttpsPort();
318
+ return _extends({
319
+ protocol: "https"
320
+ }, host);
321
+ }
322
+
323
+ if (httpPort) {
324
+ const host = this.getHttpPort();
325
+ return _extends({
326
+ protocol: "http"
327
+ }, host);
328
+ }
329
+ }
330
+
311
331
  };
312
332
  PlatformConfiguration = PlatformConfiguration_1 = __decorate([Injectable({
313
333
  scope: ProviderScope.SINGLETON,
@@ -727,57 +747,6 @@ function setResponseHeaders(ctx) {
727
747
  }
728
748
  }
729
749
 
730
- var _converterSettings;
731
- /**
732
- * @deprecated Since 2021-10-03. Use serialize/deserialize functions from @tsed/json-mapper instead
733
- */
734
-
735
- let ConverterService = (_converterSettings = /*#__PURE__*/_classPrivateFieldLooseKey("converterSettings"), class ConverterService {
736
- constructor(injectorService, configuration) {
737
- Object.defineProperty(this, _converterSettings, {
738
- writable: true,
739
- value: void 0
740
- });
741
- this.injectorService = injectorService;
742
- _classPrivateFieldLooseBase(this, _converterSettings)[_converterSettings] = configuration.get("converter") || {};
743
- }
744
-
745
- /**
746
- * Convert instance to plainObject.
747
- *
748
- * @param obj
749
- * @param options
750
- */
751
- serialize(obj, options = {}) {
752
- return serialize(obj, _extends({
753
- useAlias: true,
754
- additionalProperties: _classPrivateFieldLooseBase(this, _converterSettings)[_converterSettings].additionalProperties === "accept"
755
- }, options));
756
- }
757
- /**
758
- * Convert a plainObject to targetType.
759
- *
760
- * ### Options
761
- *
762
- * - `ignoreCallback`: callback called for each object which will be deserialized. The callback can return a boolean to avoid the default converter behavior.
763
- * - `checkRequiredValue`: Disable the required check condition.
764
- *
765
- * @param obj Object source that will be deserialized
766
- * @param options Mapping options
767
- * @returns {any}
768
- */
769
-
770
-
771
- deserialize(obj, options = {}) {
772
- return deserialize(obj, _extends({
773
- useAlias: true,
774
- additionalProperties: _classPrivateFieldLooseBase(this, _converterSettings)[_converterSettings].additionalProperties === "accept"
775
- }, options));
776
- }
777
-
778
- });
779
- ConverterService = __decorate([Injectable(), __param(1, Configuration()), __metadata("design:paramtypes", [InjectorService, Object])], ConverterService);
780
-
781
750
  /**
782
751
  * Platform Handler abstraction layer. Wrap original class method to a pure platform handler (Express, Koa, etc...).
783
752
  * @platform
@@ -830,23 +799,13 @@ let PlatformHandler = class PlatformHandler {
830
799
 
831
800
  async flush(data, ctx) {
832
801
  const {
833
- response,
834
- endpoint
802
+ response
835
803
  } = ctx;
836
804
 
837
805
  if (!response.isDone()) {
838
- // FIXME should be move to responseFilter module
839
- if (endpoint) {
840
- if (endpoint.view) {
841
- data = await this.render(data, ctx);
842
- } else if (isSerializable(data)) {
843
- data = this.injector.get(ConverterService).serialize(data, _extends({}, endpoint.getResponseOptions(response.statusCode), {
844
- endpoint: true
845
- }));
846
- }
847
- }
848
-
849
- response.body(this.responseFilter.transform(data, ctx));
806
+ data = await this.responseFilter.serialize(data, ctx);
807
+ data = await this.responseFilter.transform(data, ctx);
808
+ response.body(data);
850
809
  }
851
810
  }
852
811
 
@@ -1017,17 +976,6 @@ let PlatformHandler = class PlatformHandler {
1017
976
  callReturnedMiddleware(middleware, ctx, next) {
1018
977
  return middleware(ctx.getRequest(), ctx.getResponse(), next);
1019
978
  }
1020
- /**
1021
- * Render the view if the endpoint has a configured view.
1022
- * @param data
1023
- * @param ctx
1024
- * @protected
1025
- */
1026
-
1027
-
1028
- async render(data, ctx) {
1029
- return renderView(data, ctx);
1030
- }
1031
979
  /**
1032
980
  * create Raw handler
1033
981
  * @param metadata
@@ -1501,8 +1449,8 @@ class PlatformControllerBuilder {
1501
1449
 
1502
1450
  let handlers = [];
1503
1451
  const hasFiles = [...endpoint.children.values()].find(item => item.paramType === ParamTypes.FILES);
1504
- handlers = handlers.concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(PlatformAcceptMimesMiddleware).concat(hasFiles && PlatformMulterMiddleware).concat(use) // Controller use-middlewares
1505
- .concat(beforeMiddlewares) // Endpoint before-middlewares
1452
+ handlers = handlers.concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(PlatformAcceptMimesMiddleware).concat(hasFiles && PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
1453
+ .concat(use) // Controller use-middlewares
1506
1454
  // .concat(endpoint.cache && PlatformCacheMiddleware)
1507
1455
  .concat(mldwrs) // Endpoint middlewares
1508
1456
  .concat(endpoint) // Endpoint metadata
@@ -2450,16 +2398,6 @@ Platform = __decorate([Injectable({
2450
2398
  scope: ProviderScope.SINGLETON
2451
2399
  }), __metadata("design:paramtypes", [InjectorService, PlatformApplication])], Platform);
2452
2400
 
2453
- /**
2454
- * @ignore
2455
- * @deprecated Will be removed in v7
2456
- */
2457
-
2458
- let PlatformModule = class PlatformModule {};
2459
- PlatformModule = __decorate([Module({
2460
- imports: [InjectorService, ConverterService, Platform]
2461
- })], PlatformModule);
2462
-
2463
2401
  $log.name = "TSED";
2464
2402
  function createInjector(settings = {}) {
2465
2403
  const injector = new InjectorService();
@@ -2632,7 +2570,7 @@ async function listenHttpsServer(injector) {
2632
2570
 
2633
2571
  async function loadInjector(injector, container = createContainer()) {
2634
2572
  injector.bootstrap(container);
2635
- return injector.load(container, PlatformModule);
2573
+ return injector.load(container);
2636
2574
  }
2637
2575
 
2638
2576
  function printRoutes(routes) {
@@ -2713,10 +2651,11 @@ function createContext(injector) {
2713
2651
 
2714
2652
  function mapOptions$1(options) {
2715
2653
  const opts = typeof options === "string" ? {
2716
- root: options,
2717
- hook: "$afterRoutesInit"
2654
+ root: options
2718
2655
  } : options;
2719
- return opts;
2656
+ return _extends({}, opts, {
2657
+ hook: getValue(opts, "hook", "$afterRoutesInit")
2658
+ });
2720
2659
  }
2721
2660
 
2722
2661
  function getStaticsOptions(statics) {
@@ -2888,7 +2827,7 @@ class PlatformBuilder {
2888
2827
  await this.callHook("$beforeInit");
2889
2828
  this.log("Build providers");
2890
2829
  const container = createContainer(constructorOf(this.rootModule));
2891
- await injector.load(container, PlatformModule);
2830
+ await injector.load(container);
2892
2831
  this.log("Settings and injector loaded");
2893
2832
  await this.callHook("$afterInit");
2894
2833
  }
@@ -3448,7 +3387,7 @@ class PlatformTest extends DITest {
3448
3387
  static async create(options = {}) {
3449
3388
  DITest.injector = PlatformTest.createInjector(options);
3450
3389
  const container = createContainer();
3451
- await DITest.injector.load(container, PlatformModule);
3390
+ await DITest.injector.load(container);
3452
3391
  }
3453
3392
  /**
3454
3393
  * Create a new injector with the right default services
@@ -3640,5 +3579,11 @@ GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
3640
3579
 
3641
3580
  });
3642
3581
 
3643
- export { AcceptMime, AcceptMimesMiddleware, AnyToPromiseWithCtx, ControllerProvider, ConverterService, 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 };
3582
+ /**
3583
+ * @ignore
3584
+ * @deprecated Will be removed in v7
3585
+ */
3586
+ class PlatformModule {}
3587
+
3588
+ 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 };
3644
3589
  //# sourceMappingURL=index.modern.js.map