@tsed/common 6.75.6 → 6.75.10
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/config/services/PlatformConfiguration.d.ts +5 -0
- package/lib/decorators/params/endpointInfo.d.ts +4 -1
- package/lib/index.js +41 -95
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +44 -99
- package/lib/index.modern.js.map +1 -1
- package/lib/services/PlatformHandler.d.ts +0 -7
- package/lib/services/index.d.ts +0 -1
- package/package.json +15 -15
- package/lib/services/ConverterService.d.ts +0 -30
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EndpointMetadata } from "../../domain/EndpointMetadata";
|
|
2
|
-
export declare type EndpointInfo = EndpointMetadata;
|
|
3
2
|
/**
|
|
4
3
|
* Get the current endpoint metadata.
|
|
5
4
|
* @decorator
|
|
@@ -8,3 +7,7 @@ export declare type EndpointInfo = EndpointMetadata;
|
|
|
8
7
|
* @deprecated Use `@Context() $ctx: Context` then `$ctx.endpoint` instead.
|
|
9
8
|
*/
|
|
10
9
|
export declare function EndpointInfo(): Function;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
export declare type EndpointInfo = EndpointMetadata;
|
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
|
-
|
|
854
|
-
|
|
855
|
-
|
|
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(
|
|
1514
|
-
.concat(
|
|
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
|
|
2582
|
+
return injector.load(container);
|
|
2645
2583
|
}
|
|
2646
2584
|
|
|
2647
2585
|
function printRoutes(routes) {
|
|
@@ -2722,10 +2660,11 @@ function createContext(injector) {
|
|
|
2722
2660
|
|
|
2723
2661
|
function mapOptions$1(options) {
|
|
2724
2662
|
const opts = typeof options === "string" ? {
|
|
2725
|
-
root: options
|
|
2726
|
-
hook: "$afterRoutesInit"
|
|
2663
|
+
root: options
|
|
2727
2664
|
} : options;
|
|
2728
|
-
return opts
|
|
2665
|
+
return _extends({}, opts, {
|
|
2666
|
+
hook: core.getValue(opts, "hook", "$afterRoutesInit")
|
|
2667
|
+
});
|
|
2729
2668
|
}
|
|
2730
2669
|
|
|
2731
2670
|
function getStaticsOptions(statics) {
|
|
@@ -2897,7 +2836,7 @@ class PlatformBuilder {
|
|
|
2897
2836
|
await this.callHook("$beforeInit");
|
|
2898
2837
|
this.log("Build providers");
|
|
2899
2838
|
const container = di.createContainer(core.constructorOf(this.rootModule));
|
|
2900
|
-
await injector.load(container
|
|
2839
|
+
await injector.load(container);
|
|
2901
2840
|
this.log("Settings and injector loaded");
|
|
2902
2841
|
await this.callHook("$afterInit");
|
|
2903
2842
|
}
|
|
@@ -3457,7 +3396,7 @@ class PlatformTest extends di.DITest {
|
|
|
3457
3396
|
static async create(options = {}) {
|
|
3458
3397
|
di.DITest.injector = PlatformTest.createInjector(options);
|
|
3459
3398
|
const container = di.createContainer();
|
|
3460
|
-
await di.DITest.injector.load(container
|
|
3399
|
+
await di.DITest.injector.load(container);
|
|
3461
3400
|
}
|
|
3462
3401
|
/**
|
|
3463
3402
|
* Create a new injector with the right default services
|
|
@@ -3649,6 +3588,12 @@ di.GlobalProviders.createRegistry(di.ProviderType.CONTROLLER, ControllerProvider
|
|
|
3649
3588
|
|
|
3650
3589
|
});
|
|
3651
3590
|
|
|
3591
|
+
/**
|
|
3592
|
+
* @ignore
|
|
3593
|
+
* @deprecated Will be removed in v7
|
|
3594
|
+
*/
|
|
3595
|
+
class PlatformModule {}
|
|
3596
|
+
|
|
3652
3597
|
Object.defineProperty(exports, '$log', {
|
|
3653
3598
|
enumerable: true,
|
|
3654
3599
|
get: function () {
|
|
@@ -3738,6 +3683,7 @@ exports.PLATFORM_ROUTER_OPTIONS = PLATFORM_ROUTER_OPTIONS;
|
|
|
3738
3683
|
exports.PlatformBuilder = PlatformBuilder;
|
|
3739
3684
|
exports.PlatformContext = PlatformContext;
|
|
3740
3685
|
exports.PlatformControllerBuilder = PlatformControllerBuilder;
|
|
3686
|
+
exports.PlatformModule = PlatformModule;
|
|
3741
3687
|
exports.PlatformRouteDetails = PlatformRouteDetails;
|
|
3742
3688
|
exports.PlatformTest = PlatformTest;
|
|
3743
3689
|
exports.ROUTER_OPTIONS = ROUTER_OPTIONS;
|