@tsed/common 6.86.1 → 6.87.2
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/builder/PlatformBuilder.d.ts +0 -1
- package/lib/builder/PlatformControllerBuilder.d.ts +12 -14
- package/lib/domain/ControllerProvider.d.ts +1 -4
- package/lib/index.d.ts +0 -1
- package/lib/index.js +234 -239
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +233 -239
- package/lib/index.modern.js.map +1 -1
- package/lib/interfaces/index.d.ts +0 -1
- package/lib/services/Platform.d.ts +0 -1
- package/lib/services/PlatformMiddlewaresChain.d.ts +6 -0
- package/lib/services/PlatformRouter.d.ts +1 -0
- package/lib/services/PlatformTest.d.ts +1 -1
- package/lib/services/index.d.ts +1 -0
- package/lib/utils/createInjector.d.ts +7 -2
- package/lib/utils/index.d.ts +0 -1
- package/package.json +15 -15
- package/lib/interfaces/PlatformRouterMethods.d.ts +0 -10
- package/lib/registries/ControllerRegistry.d.ts +0 -1
- package/lib/utils/createPlatformApplication.d.ts +0 -2
package/lib/index.modern.js
CHANGED
|
@@ -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,
|
|
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';
|
|
@@ -17,13 +17,13 @@ import { importProviders } from '@tsed/components-scan';
|
|
|
17
17
|
export * from '@tsed/components-scan';
|
|
18
18
|
export * from '@tsed/platform-log-middleware';
|
|
19
19
|
import { __decorate, __metadata, __param } from 'tslib';
|
|
20
|
-
import { AnyToPromise, AnyToPromiseStatus, nameOf, Store, descriptorOf, prototypeOf, deepMerge, isFunction, DecoratorTypes, isStream, uniq, isBoolean, isNumber, isString, getValue, Env,
|
|
20
|
+
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
21
|
import { Exception, NotAcceptable } from '@tsed/exceptions';
|
|
22
22
|
import { JsonParameterStore, JsonMethodStore, JsonEntityStore, JsonEntityComponent, getOperationsRoutes, OperationMethods, JsonOperationRoute, JsonPropertyStore, getProperties, concatPath, Returns, Consumes, Produces, JsonEntityFn } from '@tsed/schema';
|
|
23
23
|
export { All, Delete, Get, Head, Location, Options, Patch, Post, Put, Redirect } from '@tsed/schema';
|
|
24
24
|
import { promisify } from 'util';
|
|
25
|
-
import Http, { ServerResponse, IncomingMessage } from 'http';
|
|
26
25
|
import Https from 'https';
|
|
26
|
+
import Http, { ServerResponse, IncomingMessage } from 'http';
|
|
27
27
|
|
|
28
28
|
function _extends() {
|
|
29
29
|
_extends = Object.assign || function (target) {
|
|
@@ -977,6 +977,7 @@ const PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
|
|
|
977
977
|
let PlatformRouter = PlatformRouter_1 = class PlatformRouter {
|
|
978
978
|
constructor(platformHandler) {
|
|
979
979
|
this.platformHandler = platformHandler;
|
|
980
|
+
this.isBuilt = false;
|
|
980
981
|
this.rawRouter = this.raw = PlatformRouter_1.createRawRouter();
|
|
981
982
|
}
|
|
982
983
|
/**
|
|
@@ -1283,72 +1284,77 @@ __decorate([__param(0, Context()), __metadata("design:type", Function), __metada
|
|
|
1283
1284
|
|
|
1284
1285
|
AcceptMimesMiddleware = __decorate([Middleware()], AcceptMimesMiddleware);
|
|
1285
1286
|
|
|
1286
|
-
|
|
1287
|
-
* Create Ts.ED context handler
|
|
1288
|
-
* @param fn
|
|
1289
|
-
* @ignore
|
|
1290
|
-
*/
|
|
1287
|
+
const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
|
|
1291
1288
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1289
|
+
let AUTO_INC = 0;
|
|
1290
|
+
class ControllerProvider extends Provider {
|
|
1291
|
+
constructor(provide, options = {}) {
|
|
1292
|
+
super(provide, options);
|
|
1293
|
+
this.type = ProviderType.CONTROLLER;
|
|
1294
|
+
this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
*
|
|
1298
|
+
*/
|
|
1296
1299
|
|
|
1297
|
-
/**
|
|
1298
|
-
* @ignore
|
|
1299
|
-
*/
|
|
1300
1300
|
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
}
|
|
1304
|
-
/**
|
|
1305
|
-
|
|
1306
|
-
|
|
1301
|
+
get routerOptions() {
|
|
1302
|
+
return this.store.get(ROUTER_OPTIONS) || {};
|
|
1303
|
+
}
|
|
1304
|
+
/**
|
|
1305
|
+
*
|
|
1306
|
+
* @param value
|
|
1307
|
+
*/
|
|
1307
1308
|
|
|
1308
1309
|
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
this.provider = provider;
|
|
1310
|
+
set routerOptions(value) {
|
|
1311
|
+
this.store.set(ROUTER_OPTIONS, value);
|
|
1312
1312
|
}
|
|
1313
1313
|
/**
|
|
1314
|
-
*
|
|
1314
|
+
*
|
|
1315
|
+
* @returns {any[]}
|
|
1315
1316
|
*/
|
|
1316
1317
|
|
|
1317
1318
|
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
}
|
|
1319
|
+
get middlewares() {
|
|
1320
|
+
return Object.assign({
|
|
1321
|
+
use: [],
|
|
1322
|
+
useAfter: [],
|
|
1323
|
+
useBefore: []
|
|
1324
|
+
}, this.store.get("middlewares", {}));
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
*
|
|
1328
|
+
* @param middlewares
|
|
1329
|
+
*/
|
|
1324
1330
|
|
|
1325
|
-
this.buildMiddlewares(useBefore) // Controller before-middleware
|
|
1326
|
-
.buildEndpoints() // All endpoints and his middlewares
|
|
1327
|
-
.buildChildrenCtrls(injector); // Children controllers
|
|
1328
1331
|
|
|
1329
|
-
|
|
1330
|
-
|
|
1332
|
+
set middlewares(middlewares) {
|
|
1333
|
+
const mdlwrs = this.middlewares;
|
|
1331
1334
|
|
|
1332
|
-
|
|
1333
|
-
getOperationsRoutes(this.provider.token).forEach(operationRoute => {
|
|
1334
|
-
this.buildEndpoint(operationRoute);
|
|
1335
|
-
});
|
|
1336
|
-
return this;
|
|
1337
|
-
}
|
|
1335
|
+
const concat = (key, a, b) => a[key] = a[key].concat(b[key]);
|
|
1338
1336
|
|
|
1339
|
-
|
|
1340
|
-
|
|
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
|
|
1337
|
+
Object.keys(middlewares).forEach(key => {
|
|
1338
|
+
concat(key, mdlwrs, middlewares);
|
|
1348
1339
|
});
|
|
1340
|
+
this.store.set("middlewares", mdlwrs);
|
|
1349
1341
|
}
|
|
1350
1342
|
|
|
1351
|
-
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Create Ts.ED context handler
|
|
1347
|
+
* @param fn
|
|
1348
|
+
* @ignore
|
|
1349
|
+
*/
|
|
1350
|
+
|
|
1351
|
+
function useCtxHandler(fn) {
|
|
1352
|
+
fn.type = HandlerType.CTX_FN;
|
|
1353
|
+
return fn;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
let PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
|
|
1357
|
+
get(provider, operationRoute) {
|
|
1352
1358
|
const {
|
|
1353
1359
|
endpoint
|
|
1354
1360
|
} = operationRoute;
|
|
@@ -1362,11 +1368,10 @@ class PlatformControllerBuilder {
|
|
|
1362
1368
|
use,
|
|
1363
1369
|
useAfter
|
|
1364
1370
|
}
|
|
1365
|
-
} =
|
|
1371
|
+
} = provider;
|
|
1366
1372
|
const hasFiles = [...operationRoute.endpoint.children.values()].find(item => item.paramType === ParamTypes.FILES);
|
|
1367
1373
|
return [].concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(PlatformAcceptMimesMiddleware).concat(hasFiles && PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
|
|
1368
1374
|
.concat(use) // Controller use-middlewares
|
|
1369
|
-
// .concat(endpoint.cache && PlatformCacheMiddleware)
|
|
1370
1375
|
.concat(mldwrs) // Endpoint middlewares
|
|
1371
1376
|
.concat(endpoint) // Endpoint metadata
|
|
1372
1377
|
.concat(afterMiddlewares) // Endpoint after-middlewares
|
|
@@ -1374,32 +1379,97 @@ class PlatformControllerBuilder {
|
|
|
1374
1379
|
.filter(item => !!item);
|
|
1375
1380
|
}
|
|
1376
1381
|
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
+
};
|
|
1383
|
+
PlatformMiddlewaresChain = __decorate([Injectable()], PlatformMiddlewaresChain);
|
|
1384
|
+
|
|
1385
|
+
GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
|
|
1386
|
+
onInvoke(provider, locals, {
|
|
1387
|
+
injector
|
|
1388
|
+
}) {
|
|
1389
|
+
const router = createRouter(injector, provider);
|
|
1390
|
+
locals.set(PlatformRouter, router);
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
});
|
|
1394
|
+
/**
|
|
1395
|
+
* @ignore
|
|
1396
|
+
*/
|
|
1397
|
+
|
|
1398
|
+
function formatMethod(method) {
|
|
1399
|
+
return (method === OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* @ignore
|
|
1403
|
+
*/
|
|
1404
|
+
|
|
1405
|
+
|
|
1406
|
+
function getRouter(injector, provider) {
|
|
1407
|
+
return injector.get(provider.tokenRouter);
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* @ignore
|
|
1411
|
+
*/
|
|
1412
|
+
|
|
1413
|
+
function createRouter(injector, provider) {
|
|
1414
|
+
const token = provider.tokenRouter;
|
|
1415
|
+
|
|
1416
|
+
if (injector.has(token)) {
|
|
1417
|
+
return getRouter(injector, provider);
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
const router = PlatformRouter.create(injector, provider.routerOptions);
|
|
1421
|
+
return injector.add(token, {
|
|
1422
|
+
useValue: router
|
|
1423
|
+
}).invoke(token);
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* @ignore
|
|
1427
|
+
* @param injector
|
|
1428
|
+
* @param provider
|
|
1429
|
+
*/
|
|
1430
|
+
|
|
1431
|
+
function buildRouter(injector, provider) {
|
|
1432
|
+
const {
|
|
1433
|
+
middlewares: {
|
|
1434
|
+
useBefore
|
|
1435
|
+
},
|
|
1436
|
+
children
|
|
1437
|
+
} = provider; // Controller lifecycle
|
|
1438
|
+
|
|
1439
|
+
const router = createRouter(injector, provider);
|
|
1440
|
+
|
|
1441
|
+
if (!router.isBuilt) {
|
|
1442
|
+
router.isBuilt = true;
|
|
1443
|
+
const platformMiddlewaresChain = injector.get(PlatformMiddlewaresChain);
|
|
1444
|
+
useBefore // Controller before-middleware
|
|
1445
|
+
.filter(o => typeof o === "function").forEach(middleware => {
|
|
1446
|
+
router.use(middleware);
|
|
1447
|
+
}); // build all endpoints and his middlewares
|
|
1448
|
+
|
|
1449
|
+
getOperationsRoutes(provider.token).forEach(operationRoute => {
|
|
1450
|
+
const handlers = platformMiddlewaresChain == null ? void 0 : platformMiddlewaresChain.get(provider, operationRoute);
|
|
1451
|
+
router.addRoute({
|
|
1452
|
+
handlers,
|
|
1453
|
+
token: operationRoute.token,
|
|
1454
|
+
method: formatMethod(operationRoute.method),
|
|
1455
|
+
path: operationRoute.path,
|
|
1456
|
+
isFinal: operationRoute.isFinal
|
|
1457
|
+
});
|
|
1458
|
+
}); // build children controllers
|
|
1459
|
+
|
|
1382
1460
|
children.forEach(child => {
|
|
1383
|
-
const
|
|
1461
|
+
const childProvider = injector.getProvider(child);
|
|
1384
1462
|
/* istanbul ignore next */
|
|
1385
1463
|
|
|
1386
|
-
if (!
|
|
1464
|
+
if (!childProvider) {
|
|
1387
1465
|
throw new Error("Controller component not found in the ControllerRegistry");
|
|
1388
1466
|
}
|
|
1389
1467
|
|
|
1390
|
-
|
|
1391
|
-
router.use(provider.path, provider.getRouter());
|
|
1468
|
+
router.use(childProvider.path, buildRouter(injector, childProvider));
|
|
1392
1469
|
});
|
|
1393
1470
|
}
|
|
1394
1471
|
|
|
1395
|
-
|
|
1396
|
-
const router = this.provider.getRouter();
|
|
1397
|
-
middlewares.filter(o => typeof o === "function").forEach(middleware => {
|
|
1398
|
-
router.use(middleware);
|
|
1399
|
-
});
|
|
1400
|
-
return this;
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1472
|
+
return router;
|
|
1403
1473
|
}
|
|
1404
1474
|
|
|
1405
1475
|
/**
|
|
@@ -1996,71 +2066,6 @@ class PlatformRouteDetails extends JsonOperationRoute {
|
|
|
1996
2066
|
|
|
1997
2067
|
}
|
|
1998
2068
|
|
|
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
2069
|
/**
|
|
2065
2070
|
* @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
|
|
2066
2071
|
*/
|
|
@@ -2084,13 +2089,6 @@ let PropertyMetadata = class PropertyMetadata extends JsonPropertyStore {
|
|
|
2084
2089
|
};
|
|
2085
2090
|
PropertyMetadata = __decorate([JsonEntityComponent(DecoratorTypes.PROP)], PropertyMetadata);
|
|
2086
2091
|
|
|
2087
|
-
GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
|
|
2088
|
-
onInvoke(provider, locals) {
|
|
2089
|
-
locals.set(PlatformRouter, provider.getRouter());
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
|
-
});
|
|
2093
|
-
|
|
2094
2092
|
/**
|
|
2095
2093
|
* `Platform` is used to provide all routes collected by annotation `@Controller`.
|
|
2096
2094
|
*
|
|
@@ -2137,7 +2135,7 @@ let Platform = class Platform {
|
|
|
2137
2135
|
provider
|
|
2138
2136
|
});
|
|
2139
2137
|
|
|
2140
|
-
this.app.use(ctrlPath, ...[].concat(
|
|
2138
|
+
this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));
|
|
2141
2139
|
this._routes = getOperationsRoutes(provider.token, {
|
|
2142
2140
|
withChildren: true,
|
|
2143
2141
|
basePath
|
|
@@ -2182,7 +2180,7 @@ let Platform = class Platform {
|
|
|
2182
2180
|
injector
|
|
2183
2181
|
} = this;
|
|
2184
2182
|
injector.getProviders(ProviderType.CONTROLLER).map(provider => {
|
|
2185
|
-
|
|
2183
|
+
createRouter(injector, provider);
|
|
2186
2184
|
});
|
|
2187
2185
|
}
|
|
2188
2186
|
/**
|
|
@@ -2197,52 +2195,32 @@ let Platform = class Platform {
|
|
|
2197
2195
|
} = this;
|
|
2198
2196
|
injector.getProviders(ProviderType.CONTROLLER).map(provider => {
|
|
2199
2197
|
if (!provider.hasParent()) {
|
|
2200
|
-
return
|
|
2198
|
+
return buildRouter(injector, provider);
|
|
2201
2199
|
}
|
|
2202
2200
|
});
|
|
2203
2201
|
}
|
|
2204
2202
|
|
|
2205
2203
|
};
|
|
2206
2204
|
Platform = __decorate([Injectable({
|
|
2207
|
-
scope: ProviderScope.SINGLETON
|
|
2205
|
+
scope: ProviderScope.SINGLETON,
|
|
2206
|
+
imports: [PlatformMiddlewaresChain]
|
|
2208
2207
|
}), __metadata("design:paramtypes", [InjectorService, PlatformApplication])], Platform);
|
|
2209
2208
|
|
|
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
2209
|
/**
|
|
2232
|
-
* Inject the
|
|
2210
|
+
* Inject the Https.Server instance.
|
|
2233
2211
|
*
|
|
2234
2212
|
* ### Example
|
|
2235
2213
|
*
|
|
2236
2214
|
* ```typescript
|
|
2237
|
-
* import {
|
|
2215
|
+
* import {HttpsServer, Service} from "@tsed/common";
|
|
2238
2216
|
*
|
|
2239
2217
|
* @Service()
|
|
2240
2218
|
* export default class OtherService {
|
|
2241
|
-
* constructor(@
|
|
2219
|
+
* constructor(@HttpsServer httpServer: HttpServer) {}
|
|
2242
2220
|
* }
|
|
2243
2221
|
* ```
|
|
2244
2222
|
*
|
|
2245
|
-
* > Note: TypeScript transform and store `
|
|
2223
|
+
* > 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
2224
|
*
|
|
2247
2225
|
* @param {Type<any>} target
|
|
2248
2226
|
* @param {string} targetKey
|
|
@@ -2251,8 +2229,8 @@ function createPlatformApplication(injector) {
|
|
|
2251
2229
|
* @decorator
|
|
2252
2230
|
*/
|
|
2253
2231
|
|
|
2254
|
-
function
|
|
2255
|
-
return Inject(
|
|
2232
|
+
function HttpsServer(target, targetKey, descriptor) {
|
|
2233
|
+
return Inject(HttpsServer)(target, targetKey, descriptor);
|
|
2256
2234
|
}
|
|
2257
2235
|
|
|
2258
2236
|
function listenServer(http, settings) {
|
|
@@ -2274,56 +2252,57 @@ function listenServer(http, settings) {
|
|
|
2274
2252
|
return promise;
|
|
2275
2253
|
}
|
|
2276
2254
|
|
|
2277
|
-
function
|
|
2278
|
-
injector.
|
|
2255
|
+
function createHttpsServer(injector) {
|
|
2256
|
+
injector.invoke(HttpsServer);
|
|
2279
2257
|
}
|
|
2280
2258
|
registerProvider({
|
|
2281
|
-
provide:
|
|
2282
|
-
deps: [PlatformApplication],
|
|
2259
|
+
provide: HttpsServer,
|
|
2260
|
+
deps: [PlatformApplication, Configuration],
|
|
2283
2261
|
scope: ProviderScope.SINGLETON,
|
|
2284
2262
|
global: true,
|
|
2285
2263
|
|
|
2286
|
-
useFactory(platformApplication) {
|
|
2287
|
-
|
|
2264
|
+
useFactory(platformApplication, settings) {
|
|
2265
|
+
const options = settings.httpsOptions;
|
|
2266
|
+
return Https.createServer(options, platformApplication.callback());
|
|
2288
2267
|
}
|
|
2289
2268
|
|
|
2290
2269
|
});
|
|
2291
|
-
async function
|
|
2270
|
+
async function listenHttpsServer(injector) {
|
|
2292
2271
|
const {
|
|
2293
2272
|
settings
|
|
2294
2273
|
} = injector;
|
|
2295
|
-
const server = injector.get(
|
|
2274
|
+
const server = injector.get(HttpsServer);
|
|
2296
2275
|
|
|
2297
|
-
if (settings.
|
|
2276
|
+
if (settings.httpsPort !== false && server) {
|
|
2298
2277
|
const {
|
|
2299
2278
|
address,
|
|
2300
2279
|
port
|
|
2301
|
-
} = settings.
|
|
2302
|
-
injector.logger.debug(`Start server on
|
|
2280
|
+
} = settings.getHttpsPort();
|
|
2281
|
+
injector.logger.debug(`Start server on https://${address}:${port}`);
|
|
2303
2282
|
const options = await listenServer(server, {
|
|
2304
2283
|
address,
|
|
2305
2284
|
port
|
|
2306
2285
|
});
|
|
2307
|
-
settings.
|
|
2308
|
-
injector.logger.info(`Listen server on
|
|
2286
|
+
settings.setHttpsPort(options);
|
|
2287
|
+
injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
|
|
2309
2288
|
}
|
|
2310
2289
|
}
|
|
2311
2290
|
|
|
2312
2291
|
/**
|
|
2313
|
-
* Inject the
|
|
2292
|
+
* Inject the Http.Server instance.
|
|
2314
2293
|
*
|
|
2315
2294
|
* ### Example
|
|
2316
2295
|
*
|
|
2317
2296
|
* ```typescript
|
|
2318
|
-
* import {
|
|
2297
|
+
* import {HttpServer, Service} from "@tsed/common";
|
|
2319
2298
|
*
|
|
2320
2299
|
* @Service()
|
|
2321
2300
|
* export default class OtherService {
|
|
2322
|
-
* constructor(@
|
|
2301
|
+
* constructor(@HttpServer httpServer: HttpServer) {}
|
|
2323
2302
|
* }
|
|
2324
2303
|
* ```
|
|
2325
2304
|
*
|
|
2326
|
-
* > Note: TypeScript transform and store `
|
|
2305
|
+
* > 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
2306
|
*
|
|
2328
2307
|
* @param {Type<any>} target
|
|
2329
2308
|
* @param {string} targetKey
|
|
@@ -2332,46 +2311,79 @@ async function listenHttpServer(injector) {
|
|
|
2332
2311
|
* @decorator
|
|
2333
2312
|
*/
|
|
2334
2313
|
|
|
2335
|
-
function
|
|
2336
|
-
return Inject(
|
|
2314
|
+
function HttpServer(target, targetKey, descriptor) {
|
|
2315
|
+
return Inject(HttpServer)(target, targetKey, descriptor);
|
|
2337
2316
|
}
|
|
2338
2317
|
|
|
2339
|
-
function
|
|
2340
|
-
injector.
|
|
2318
|
+
function createHttpServer(injector) {
|
|
2319
|
+
injector.invoke(HttpServer);
|
|
2341
2320
|
}
|
|
2342
2321
|
registerProvider({
|
|
2343
|
-
provide:
|
|
2344
|
-
deps: [PlatformApplication
|
|
2322
|
+
provide: HttpServer,
|
|
2323
|
+
deps: [PlatformApplication],
|
|
2345
2324
|
scope: ProviderScope.SINGLETON,
|
|
2346
2325
|
global: true,
|
|
2347
2326
|
|
|
2348
|
-
useFactory(platformApplication
|
|
2349
|
-
|
|
2350
|
-
return Https.createServer(options, platformApplication.callback());
|
|
2327
|
+
useFactory(platformApplication) {
|
|
2328
|
+
return Http.createServer(platformApplication.callback());
|
|
2351
2329
|
}
|
|
2352
2330
|
|
|
2353
2331
|
});
|
|
2354
|
-
async function
|
|
2332
|
+
async function listenHttpServer(injector) {
|
|
2355
2333
|
const {
|
|
2356
2334
|
settings
|
|
2357
2335
|
} = injector;
|
|
2358
|
-
const server = injector.get(
|
|
2336
|
+
const server = injector.get(HttpServer);
|
|
2359
2337
|
|
|
2360
|
-
if (settings.
|
|
2338
|
+
if (settings.httpPort !== false && server) {
|
|
2361
2339
|
const {
|
|
2362
2340
|
address,
|
|
2363
2341
|
port
|
|
2364
|
-
} = settings.
|
|
2365
|
-
injector.logger.debug(`Start server on
|
|
2342
|
+
} = settings.getHttpPort();
|
|
2343
|
+
injector.logger.debug(`Start server on http://${address}:${port}`);
|
|
2366
2344
|
const options = await listenServer(server, {
|
|
2367
2345
|
address,
|
|
2368
2346
|
port
|
|
2369
2347
|
});
|
|
2370
|
-
settings.
|
|
2371
|
-
injector.logger.info(`Listen server on
|
|
2348
|
+
settings.setHttpPort(options);
|
|
2349
|
+
injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
|
|
2372
2350
|
}
|
|
2373
2351
|
}
|
|
2374
2352
|
|
|
2353
|
+
$log.name = "TSED";
|
|
2354
|
+
const DEFAULT_PROVIDERS = [{
|
|
2355
|
+
provide: PlatformHandler
|
|
2356
|
+
}, {
|
|
2357
|
+
provide: PlatformResponse
|
|
2358
|
+
}, {
|
|
2359
|
+
provide: PlatformRequest
|
|
2360
|
+
}, {
|
|
2361
|
+
provide: PlatformRouter
|
|
2362
|
+
}, {
|
|
2363
|
+
provide: PlatformApplication
|
|
2364
|
+
}, {
|
|
2365
|
+
provide: Platform
|
|
2366
|
+
}];
|
|
2367
|
+
function createInjector({
|
|
2368
|
+
providers = [],
|
|
2369
|
+
settings = {}
|
|
2370
|
+
}) {
|
|
2371
|
+
const injector = new InjectorService();
|
|
2372
|
+
injector.addProvider(PlatformConfiguration);
|
|
2373
|
+
injector.settings = injector.invoke(PlatformConfiguration);
|
|
2374
|
+
injector.logger = $log;
|
|
2375
|
+
injector.settings.set(settings);
|
|
2376
|
+
setLoggerLevel(injector);
|
|
2377
|
+
providers = [...DEFAULT_PROVIDERS, ...providers];
|
|
2378
|
+
toMap(providers, "provide").forEach((provider, token) => {
|
|
2379
|
+
injector.addProvider(token, provider);
|
|
2380
|
+
});
|
|
2381
|
+
injector.invoke(PlatformApplication);
|
|
2382
|
+
createHttpsServer(injector);
|
|
2383
|
+
createHttpServer(injector);
|
|
2384
|
+
return injector;
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2375
2387
|
/**
|
|
2376
2388
|
* @ignore
|
|
2377
2389
|
* @deprecated User injector.load(container, module) instead
|
|
@@ -2512,19 +2524,6 @@ function getConfiguration(configuration = {}, module = null) {
|
|
|
2512
2524
|
return config;
|
|
2513
2525
|
}
|
|
2514
2526
|
|
|
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
2527
|
/**
|
|
2529
2528
|
* @platform
|
|
2530
2529
|
*/
|
|
@@ -2553,7 +2552,13 @@ class PlatformBuilder {
|
|
|
2553
2552
|
this.current = new Date();
|
|
2554
2553
|
this.name = name;
|
|
2555
2554
|
_classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = module;
|
|
2556
|
-
|
|
2555
|
+
const configuration = getConfiguration(settings, module);
|
|
2556
|
+
configuration.PLATFORM_NAME = name;
|
|
2557
|
+
_classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector({
|
|
2558
|
+
settings: configuration,
|
|
2559
|
+
providers
|
|
2560
|
+
});
|
|
2561
|
+
this.log("Injector created...");
|
|
2557
2562
|
}
|
|
2558
2563
|
|
|
2559
2564
|
get injector() {
|
|
@@ -2832,20 +2837,6 @@ class PlatformBuilder {
|
|
|
2832
2837
|
await this.callHook("$afterRoutesInit");
|
|
2833
2838
|
}
|
|
2834
2839
|
|
|
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
2840
|
}
|
|
2850
2841
|
|
|
2851
2842
|
/**
|
|
@@ -3218,8 +3209,8 @@ function mapReturnedResponse(_ref) {
|
|
|
3218
3209
|
*/
|
|
3219
3210
|
|
|
3220
3211
|
class PlatformTest extends DITest {
|
|
3221
|
-
static async create(
|
|
3222
|
-
DITest.injector = PlatformTest.createInjector(getConfiguration(
|
|
3212
|
+
static async create(settings = {}) {
|
|
3213
|
+
DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
|
|
3223
3214
|
const container = createContainer();
|
|
3224
3215
|
await DITest.injector.load(container);
|
|
3225
3216
|
}
|
|
@@ -3229,7 +3220,10 @@ class PlatformTest extends DITest {
|
|
|
3229
3220
|
|
|
3230
3221
|
|
|
3231
3222
|
static createInjector(settings = {}) {
|
|
3232
|
-
return createInjector(
|
|
3223
|
+
return createInjector({
|
|
3224
|
+
providers: [],
|
|
3225
|
+
settings: DITest.configure(settings)
|
|
3226
|
+
});
|
|
3233
3227
|
}
|
|
3234
3228
|
/**
|
|
3235
3229
|
* Load the server silently without listening port and configure it on test profile.
|
|
@@ -3413,5 +3407,5 @@ class PlatformTest extends DITest {
|
|
|
3413
3407
|
*/
|
|
3414
3408
|
class PlatformModule {}
|
|
3415
3409
|
|
|
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,
|
|
3410
|
+
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, bindEndpointMiddleware, buildRouter, createContext, createHttpServer, createHttpsServer, createInjector, createRouter, getRouter, listenHttpServer, listenHttpsServer, listenServer, loadInjector, mapReturnedResponse, printRoutes, useCtxHandler };
|
|
3417
3411
|
//# sourceMappingURL=index.modern.js.map
|