@tsed/common 6.75.10 → 6.77.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.
- package/lib/builder/PlatformBuilder.d.ts +0 -1
- package/lib/builder/PlatformControllerBuilder.d.ts +1 -1
- package/lib/decorators/method/endpointFn.d.ts +1 -0
- package/lib/domain/ControllerProvider.d.ts +0 -26
- package/lib/domain/EndpointMetadata.d.ts +0 -7
- package/lib/domain/PlatformRouteDetails.d.ts +4 -5
- package/lib/index.d.ts +2 -0
- package/lib/index.js +103 -268
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +107 -272
- package/lib/index.modern.js.map +1 -1
- package/lib/interfaces/PlatformRouteOptions.d.ts +6 -4
- package/lib/services/Platform.d.ts +3 -8
- package/lib/services/PlatformRouter.d.ts +2 -2
- package/package.json +17 -16
- package/lib/utils/getControllerPath.d.ts +0 -2
package/lib/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var logger = require('@tsed/logger');
|
|
2
|
+
require('@tsed/logger-file');
|
|
1
3
|
var di = require('@tsed/di');
|
|
2
4
|
var platformParams = require('@tsed/platform-params');
|
|
3
5
|
var platformExceptions = require('@tsed/platform-exceptions');
|
|
@@ -7,7 +9,6 @@ var platformMiddlewares = require('@tsed/platform-middlewares');
|
|
|
7
9
|
var platformViews = require('@tsed/platform-views');
|
|
8
10
|
var componentsScan = require('@tsed/components-scan');
|
|
9
11
|
var platformLogMiddleware = require('@tsed/platform-log-middleware');
|
|
10
|
-
var logger = require('@tsed/logger');
|
|
11
12
|
var tslib = require('tslib');
|
|
12
13
|
var core = require('@tsed/core');
|
|
13
14
|
var perf = require('@tsed/perf');
|
|
@@ -508,7 +509,6 @@ class HandlerMetadata {
|
|
|
508
509
|
|
|
509
510
|
}
|
|
510
511
|
|
|
511
|
-
var EndpointMetadata_1;
|
|
512
512
|
/**
|
|
513
513
|
* EndpointMetadata contains metadata about a controller and his method.
|
|
514
514
|
* Each annotation (@Get, @Body...) attached to a method are stored in a endpoint.
|
|
@@ -526,7 +526,7 @@ var EndpointMetadata_1;
|
|
|
526
526
|
*
|
|
527
527
|
*/
|
|
528
528
|
|
|
529
|
-
exports.EndpointMetadata =
|
|
529
|
+
exports.EndpointMetadata = class EndpointMetadata extends schema.JsonEntityStore {
|
|
530
530
|
constructor(options) {
|
|
531
531
|
super(_extends({
|
|
532
532
|
store: core.Store.fromMethod(options.target, options.propertyKey),
|
|
@@ -580,21 +580,6 @@ exports.EndpointMetadata = EndpointMetadata_1 = class EndpointMetadata extends s
|
|
|
580
580
|
set acceptMimes(mimes) {
|
|
581
581
|
this.store.set("acceptMimes", mimes);
|
|
582
582
|
}
|
|
583
|
-
/**
|
|
584
|
-
* Get all endpoints from a given class and his parents.
|
|
585
|
-
* @param {Type<any>} target
|
|
586
|
-
* @returns {EndpointMetadata[]}
|
|
587
|
-
*/
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
static getEndpoints(target) {
|
|
591
|
-
const operations = schema.getOperationsStores(target);
|
|
592
|
-
return Array.from(operations.values()).map(endpoint => {
|
|
593
|
-
endpoint = endpoint.clone();
|
|
594
|
-
endpoint.token = core.classOf(target);
|
|
595
|
-
return endpoint;
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
583
|
/**
|
|
599
584
|
* Get an endpoint.
|
|
600
585
|
* @param target
|
|
@@ -656,26 +641,8 @@ exports.EndpointMetadata = EndpointMetadata_1 = class EndpointMetadata extends s
|
|
|
656
641
|
return this;
|
|
657
642
|
}
|
|
658
643
|
|
|
659
|
-
clone() {
|
|
660
|
-
const endpoint = new EndpointMetadata_1(_extends({}, this, {
|
|
661
|
-
target: this.target,
|
|
662
|
-
propertyKey: this.propertyKey,
|
|
663
|
-
descriptor: this.descriptor,
|
|
664
|
-
store: this.store,
|
|
665
|
-
children: this.children
|
|
666
|
-
}));
|
|
667
|
-
endpoint.collectionType = this.collectionType;
|
|
668
|
-
endpoint._type = this._type;
|
|
669
|
-
endpoint._operation = this.operation;
|
|
670
|
-
endpoint._schema = this._schema;
|
|
671
|
-
endpoint.middlewares = [...this.middlewares];
|
|
672
|
-
endpoint.afterMiddlewares = [...this.afterMiddlewares];
|
|
673
|
-
endpoint.beforeMiddlewares = [...this.beforeMiddlewares];
|
|
674
|
-
return endpoint;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
644
|
};
|
|
678
|
-
exports.EndpointMetadata =
|
|
645
|
+
exports.EndpointMetadata = tslib.__decorate([schema.JsonEntityComponent(core.DecoratorTypes.METHOD), tslib.__metadata("design:paramtypes", [Object])], exports.EndpointMetadata);
|
|
679
646
|
|
|
680
647
|
function isMetadata(input) {
|
|
681
648
|
return input instanceof HandlerMetadata;
|
|
@@ -693,7 +660,7 @@ function createHandlerMetadata(injector, obj, routeOptions = {}) {
|
|
|
693
660
|
let options;
|
|
694
661
|
|
|
695
662
|
if (obj instanceof exports.EndpointMetadata) {
|
|
696
|
-
const provider = injector.getProvider(
|
|
663
|
+
const provider = injector.getProvider(routeOptions.token);
|
|
697
664
|
options = {
|
|
698
665
|
token: provider.token,
|
|
699
666
|
target: provider.useClass,
|
|
@@ -1037,6 +1004,7 @@ exports.PlatformHandler = tslib.__decorate([di.Injectable({
|
|
|
1037
1004
|
scope: di.ProviderScope.SINGLETON
|
|
1038
1005
|
}), tslib.__metadata("design:paramtypes", [di.InjectorService, platformParams.PlatformParams])], exports.PlatformHandler);
|
|
1039
1006
|
|
|
1007
|
+
const _excluded$3 = ["method", "path", "handlers"];
|
|
1040
1008
|
var PlatformRouter_1;
|
|
1041
1009
|
/**
|
|
1042
1010
|
* @ignore
|
|
@@ -1088,15 +1056,15 @@ exports.PlatformRouter = PlatformRouter_1 = class PlatformRouter {
|
|
|
1088
1056
|
const {
|
|
1089
1057
|
method,
|
|
1090
1058
|
path,
|
|
1091
|
-
handlers
|
|
1092
|
-
|
|
1093
|
-
|
|
1059
|
+
handlers
|
|
1060
|
+
} = options,
|
|
1061
|
+
opts = _objectWithoutPropertiesLoose(options, _excluded$3); // @ts-ignore
|
|
1062
|
+
|
|
1094
1063
|
|
|
1095
|
-
this.getRouter()[method](path, ...this.mapHandlers(handlers, {
|
|
1064
|
+
this.getRouter()[method](path, ...this.mapHandlers(handlers, _extends({
|
|
1096
1065
|
method,
|
|
1097
|
-
path
|
|
1098
|
-
|
|
1099
|
-
}));
|
|
1066
|
+
path
|
|
1067
|
+
}, opts)));
|
|
1100
1068
|
return this;
|
|
1101
1069
|
}
|
|
1102
1070
|
|
|
@@ -1385,7 +1353,6 @@ class PlatformControllerBuilder {
|
|
|
1385
1353
|
this.provider = provider;
|
|
1386
1354
|
}
|
|
1387
1355
|
/**
|
|
1388
|
-
*
|
|
1389
1356
|
* @returns {any}
|
|
1390
1357
|
*/
|
|
1391
1358
|
|
|
@@ -1405,48 +1372,32 @@ class PlatformControllerBuilder {
|
|
|
1405
1372
|
}
|
|
1406
1373
|
|
|
1407
1374
|
buildEndpoints() {
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
} = this.provider;
|
|
1411
|
-
const operationPaths = new Map();
|
|
1412
|
-
|
|
1413
|
-
const getKey = (method, path) => `${method}-${path}`;
|
|
1414
|
-
|
|
1415
|
-
const updateFinalRouteState = key => {
|
|
1416
|
-
if (operationPaths.has(key)) {
|
|
1417
|
-
operationPaths.get(key).isFinal = false;
|
|
1418
|
-
}
|
|
1419
|
-
};
|
|
1420
|
-
|
|
1421
|
-
const setFinalRoute = (key, operationPath) => {
|
|
1422
|
-
operationPaths.set(key, operationPath);
|
|
1423
|
-
operationPath.isFinal = true;
|
|
1424
|
-
};
|
|
1425
|
-
|
|
1426
|
-
endpoints.forEach(({
|
|
1427
|
-
operation
|
|
1428
|
-
}) => {
|
|
1429
|
-
operation == null ? void 0 : operation.operationPaths.forEach(operationPath => {
|
|
1430
|
-
if (operationPath.method !== schema.OperationMethods.CUSTOM) {
|
|
1431
|
-
const key = getKey(operationPath.method, operationPath.path);
|
|
1432
|
-
updateFinalRouteState(key);
|
|
1433
|
-
updateFinalRouteState(getKey(schema.OperationMethods.ALL, operationPath.path));
|
|
1434
|
-
setFinalRoute(key, operationPath);
|
|
1435
|
-
}
|
|
1436
|
-
});
|
|
1437
|
-
});
|
|
1438
|
-
endpoints.forEach(endpoint => {
|
|
1439
|
-
this.buildEndpoint(endpoint);
|
|
1375
|
+
schema.getOperationsRoutes(this.provider.token).forEach(operationRoute => {
|
|
1376
|
+
this.buildEndpoint(operationRoute);
|
|
1440
1377
|
});
|
|
1441
1378
|
return this;
|
|
1442
1379
|
}
|
|
1443
1380
|
|
|
1444
|
-
buildEndpoint(
|
|
1381
|
+
buildEndpoint(operationRoute) {
|
|
1382
|
+
let handlers = this.getMiddlewares(operationRoute);
|
|
1383
|
+
const router = this.provider.getRouter();
|
|
1384
|
+
router.addRoute({
|
|
1385
|
+
handlers,
|
|
1386
|
+
token: operationRoute.token,
|
|
1387
|
+
method: formatMethod(operationRoute.method),
|
|
1388
|
+
path: operationRoute.path,
|
|
1389
|
+
isFinal: operationRoute.isFinal
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
getMiddlewares(operationRoute) {
|
|
1394
|
+
const {
|
|
1395
|
+
endpoint
|
|
1396
|
+
} = operationRoute;
|
|
1445
1397
|
const {
|
|
1446
1398
|
beforeMiddlewares,
|
|
1447
1399
|
middlewares: mldwrs,
|
|
1448
|
-
afterMiddlewares
|
|
1449
|
-
operation
|
|
1400
|
+
afterMiddlewares
|
|
1450
1401
|
} = endpoint;
|
|
1451
1402
|
const {
|
|
1452
1403
|
middlewares: {
|
|
@@ -1454,35 +1405,15 @@ class PlatformControllerBuilder {
|
|
|
1454
1405
|
useAfter
|
|
1455
1406
|
}
|
|
1456
1407
|
} = this.provider;
|
|
1457
|
-
const
|
|
1458
|
-
|
|
1459
|
-
let handlers = [];
|
|
1460
|
-
const hasFiles = [...endpoint.children.values()].find(item => item.paramType === platformParams.ParamTypes.FILES);
|
|
1461
|
-
handlers = handlers.concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(exports.PlatformAcceptMimesMiddleware).concat(hasFiles && exports.PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
|
|
1408
|
+
const hasFiles = [...operationRoute.endpoint.children.values()].find(item => item.paramType === platformParams.ParamTypes.FILES);
|
|
1409
|
+
return [].concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(exports.PlatformAcceptMimesMiddleware).concat(hasFiles && exports.PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
|
|
1462
1410
|
.concat(use) // Controller use-middlewares
|
|
1463
1411
|
// .concat(endpoint.cache && PlatformCacheMiddleware)
|
|
1464
1412
|
.concat(mldwrs) // Endpoint middlewares
|
|
1465
1413
|
.concat(endpoint) // Endpoint metadata
|
|
1466
1414
|
.concat(afterMiddlewares) // Endpoint after-middlewares
|
|
1467
1415
|
.concat(useAfter) // Controller after middlewares (equivalent to afterEach)
|
|
1468
|
-
.filter(item => !!item);
|
|
1469
|
-
|
|
1470
|
-
operation == null ? void 0 : operation.operationPaths.forEach(({
|
|
1471
|
-
path,
|
|
1472
|
-
method,
|
|
1473
|
-
isFinal
|
|
1474
|
-
}) => {
|
|
1475
|
-
router.addRoute({
|
|
1476
|
-
method: formatMethod(method),
|
|
1477
|
-
path,
|
|
1478
|
-
handlers,
|
|
1479
|
-
isFinal
|
|
1480
|
-
});
|
|
1481
|
-
});
|
|
1482
|
-
|
|
1483
|
-
if (!(operation != null && operation.operationPaths.size)) {
|
|
1484
|
-
router.use(...handlers);
|
|
1485
|
-
}
|
|
1416
|
+
.filter(item => !!item);
|
|
1486
1417
|
}
|
|
1487
1418
|
|
|
1488
1419
|
buildChildrenCtrls(injector) {
|
|
@@ -1565,7 +1496,7 @@ exports.PlatformRequest = class PlatformRequest {
|
|
|
1565
1496
|
}
|
|
1566
1497
|
|
|
1567
1498
|
get rawBody() {
|
|
1568
|
-
return this.raw.rawBody;
|
|
1499
|
+
return this.raw.rawBody || this.raw.body;
|
|
1569
1500
|
}
|
|
1570
1501
|
/**
|
|
1571
1502
|
* When using `cookie-parser` middleware, this property is an object that contains cookies sent by the request.
|
|
@@ -2087,18 +2018,14 @@ class PlatformContext extends di.DIContext {
|
|
|
2087
2018
|
|
|
2088
2019
|
}
|
|
2089
2020
|
|
|
2090
|
-
class PlatformRouteDetails {
|
|
2091
|
-
constructor({
|
|
2092
|
-
|
|
2093
|
-
endpoint
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
this.
|
|
2098
|
-
this.endpoint = endpoint;
|
|
2099
|
-
this.method = method;
|
|
2100
|
-
this.url = url;
|
|
2101
|
-
this.rawBody = !!endpoint.params.find(param => param.paramType === platformParams.ParamTypes.RAW_BODY);
|
|
2021
|
+
class PlatformRouteDetails extends schema.JsonOperationRoute {
|
|
2022
|
+
constructor(options = {}) {
|
|
2023
|
+
super(options);
|
|
2024
|
+
this.rawBody = !!this.endpoint.params.find(param => param.paramType === platformParams.ParamTypes.RAW_BODY);
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
get url() {
|
|
2028
|
+
return this.fullPath;
|
|
2102
2029
|
}
|
|
2103
2030
|
|
|
2104
2031
|
get name() {
|
|
@@ -2137,37 +2064,6 @@ class ControllerProvider extends di.Provider {
|
|
|
2137
2064
|
constructor(provide, options = {}) {
|
|
2138
2065
|
super(provide, options);
|
|
2139
2066
|
this.type = di.ProviderType.CONTROLLER;
|
|
2140
|
-
this.entity = schema.JsonEntityStore.from(provide);
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
get path() {
|
|
2144
|
-
return this.entity.path;
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
set path(path) {
|
|
2148
|
-
this.entity.path = path;
|
|
2149
|
-
}
|
|
2150
|
-
/**
|
|
2151
|
-
*
|
|
2152
|
-
* @returns {EndpointMetadata[]}
|
|
2153
|
-
*/
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
get endpoints() {
|
|
2157
|
-
return exports.EndpointMetadata.getEndpoints(this.provide);
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
get children() {
|
|
2161
|
-
return this.store.get("childrenControllers", []);
|
|
2162
|
-
}
|
|
2163
|
-
/**
|
|
2164
|
-
*
|
|
2165
|
-
* @returns {ControllerProvider}
|
|
2166
|
-
*/
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
get parent() {
|
|
2170
|
-
return this.store.get("parentController");
|
|
2171
2067
|
}
|
|
2172
2068
|
/**
|
|
2173
2069
|
*
|
|
@@ -2215,24 +2111,6 @@ class ControllerProvider extends di.Provider {
|
|
|
2215
2111
|
});
|
|
2216
2112
|
this.store.set("middlewares", mdlwrs);
|
|
2217
2113
|
}
|
|
2218
|
-
/**
|
|
2219
|
-
*
|
|
2220
|
-
* @returns {boolean}
|
|
2221
|
-
*/
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
hasChildren() {
|
|
2225
|
-
return !!this.children.length;
|
|
2226
|
-
}
|
|
2227
|
-
/**
|
|
2228
|
-
*
|
|
2229
|
-
* @returns {boolean}
|
|
2230
|
-
*/
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
hasParent() {
|
|
2234
|
-
return !!this.store.get("parentController");
|
|
2235
|
-
}
|
|
2236
2114
|
|
|
2237
2115
|
getRouter() {
|
|
2238
2116
|
return this.router;
|
|
@@ -2261,9 +2139,12 @@ exports.PropertyMetadata = class PropertyMetadata extends schema.JsonEntityStore
|
|
|
2261
2139
|
};
|
|
2262
2140
|
exports.PropertyMetadata = tslib.__decorate([schema.JsonEntityComponent(core.DecoratorTypes.PROP)], exports.PropertyMetadata);
|
|
2263
2141
|
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2142
|
+
di.GlobalProviders.createRegistry(di.ProviderType.CONTROLLER, ControllerProvider, {
|
|
2143
|
+
onInvoke(provider, locals) {
|
|
2144
|
+
locals.set(exports.PlatformRouter, provider.getRouter());
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
});
|
|
2267
2148
|
|
|
2268
2149
|
/**
|
|
2269
2150
|
* `Platform` is used to provide all routes collected by annotation `@Controller`.
|
|
@@ -2288,42 +2169,44 @@ exports.Platform = class Platform {
|
|
|
2288
2169
|
return this._routes;
|
|
2289
2170
|
}
|
|
2290
2171
|
|
|
2291
|
-
$onInit() {
|
|
2292
|
-
this.buildControllers();
|
|
2293
|
-
}
|
|
2294
|
-
|
|
2295
2172
|
addRoutes(routes) {
|
|
2296
2173
|
routes.forEach(routeSettings => {
|
|
2297
2174
|
this.addRoute(routeSettings.route, routeSettings.token);
|
|
2298
2175
|
});
|
|
2299
2176
|
}
|
|
2300
2177
|
|
|
2301
|
-
addRoute(
|
|
2178
|
+
addRoute(basePath, token) {
|
|
2302
2179
|
const {
|
|
2303
2180
|
injector
|
|
2304
2181
|
} = this;
|
|
2182
|
+
const provider = injector.getProvider(token);
|
|
2305
2183
|
|
|
2306
|
-
if (
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
if (provider.type === di.ProviderType.CONTROLLER) {
|
|
2310
|
-
const route = getControllerPath(endpoint, provider);
|
|
2311
|
-
|
|
2312
|
-
if (!provider.hasParent()) {
|
|
2313
|
-
const routes = this.buildRoutes(route, provider);
|
|
2184
|
+
if (!provider || provider.hasParent()) {
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
2314
2187
|
|
|
2315
|
-
|
|
2188
|
+
const ctrlPath = schema.concatPath(basePath, schema.JsonEntityStore.from(provider.token).path);
|
|
2316
2189
|
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2190
|
+
this._controllers.push({
|
|
2191
|
+
route: ctrlPath,
|
|
2192
|
+
provider
|
|
2193
|
+
});
|
|
2321
2194
|
|
|
2322
|
-
|
|
2323
|
-
|
|
2195
|
+
this.app.use(ctrlPath, ...[].concat(provider.getRouter().callback()));
|
|
2196
|
+
this._routes = schema.getOperationsRoutes(provider.token, {
|
|
2197
|
+
withChildren: true,
|
|
2198
|
+
basePath
|
|
2199
|
+
}).reduce((routes, operationRoute) => {
|
|
2200
|
+
if (injector.hasProvider(token)) {
|
|
2201
|
+
const provider = injector.getProvider(operationRoute.token);
|
|
2202
|
+
const route = new PlatformRouteDetails(_extends({}, operationRoute, {
|
|
2203
|
+
provider
|
|
2204
|
+
}));
|
|
2205
|
+
return routes.concat(route);
|
|
2324
2206
|
}
|
|
2325
|
-
}
|
|
2326
2207
|
|
|
2208
|
+
return routes;
|
|
2209
|
+
}, this._routes);
|
|
2327
2210
|
return this;
|
|
2328
2211
|
}
|
|
2329
2212
|
/**
|
|
@@ -2339,6 +2222,10 @@ exports.Platform = class Platform {
|
|
|
2339
2222
|
getMountedControllers() {
|
|
2340
2223
|
return this._controllers;
|
|
2341
2224
|
}
|
|
2225
|
+
|
|
2226
|
+
$onInit() {
|
|
2227
|
+
this.buildControllers();
|
|
2228
|
+
}
|
|
2342
2229
|
/**
|
|
2343
2230
|
* Create routers from the collected controllers.
|
|
2344
2231
|
* @private
|
|
@@ -2369,38 +2256,6 @@ exports.Platform = class Platform {
|
|
|
2369
2256
|
}
|
|
2370
2257
|
});
|
|
2371
2258
|
}
|
|
2372
|
-
/**
|
|
2373
|
-
*
|
|
2374
|
-
* @param ctrl
|
|
2375
|
-
* @param endpointUrl
|
|
2376
|
-
*/
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
buildRoutes(endpointUrl, ctrl) {
|
|
2380
|
-
const {
|
|
2381
|
-
injector
|
|
2382
|
-
} = this;
|
|
2383
|
-
let routes = [];
|
|
2384
|
-
routes = ctrl.children.map(ctrl => injector.getProvider(ctrl)).reduce((routes, provider) => {
|
|
2385
|
-
return routes.concat(this.buildRoutes(`${endpointUrl}${provider.path}`, provider));
|
|
2386
|
-
}, routes);
|
|
2387
|
-
ctrl.endpoints.forEach(endpoint => {
|
|
2388
|
-
endpoint.operationPaths.forEach(({
|
|
2389
|
-
path,
|
|
2390
|
-
method
|
|
2391
|
-
}) => {
|
|
2392
|
-
if (method) {
|
|
2393
|
-
routes.push(new PlatformRouteDetails({
|
|
2394
|
-
provider: ctrl,
|
|
2395
|
-
endpoint,
|
|
2396
|
-
method,
|
|
2397
|
-
url: `${endpointUrl}${path || ""}`.replace(/\/\//gi, "/")
|
|
2398
|
-
}));
|
|
2399
|
-
}
|
|
2400
|
-
});
|
|
2401
|
-
});
|
|
2402
|
-
return routes;
|
|
2403
|
-
}
|
|
2404
2259
|
|
|
2405
2260
|
};
|
|
2406
2261
|
exports.Platform = tslib.__decorate([di.Injectable({
|
|
@@ -2679,7 +2534,6 @@ function getStaticsOptions(statics) {
|
|
|
2679
2534
|
}, []);
|
|
2680
2535
|
}
|
|
2681
2536
|
|
|
2682
|
-
const SKIP_HOOKS = ["$beforeInit", "$afterInit", "$onInit", "$onMountingMiddlewares"];
|
|
2683
2537
|
const {
|
|
2684
2538
|
bind,
|
|
2685
2539
|
start,
|
|
@@ -2690,26 +2544,26 @@ const {
|
|
|
2690
2544
|
* @platform
|
|
2691
2545
|
*/
|
|
2692
2546
|
|
|
2693
|
-
var _rootModule = /*#__PURE__*/_classPrivateFieldLooseKey("rootModule");
|
|
2694
|
-
|
|
2695
2547
|
var _injector = /*#__PURE__*/_classPrivateFieldLooseKey("injector");
|
|
2696
2548
|
|
|
2697
2549
|
var _providers = /*#__PURE__*/_classPrivateFieldLooseKey("providers");
|
|
2698
2550
|
|
|
2551
|
+
var _rootModule = /*#__PURE__*/_classPrivateFieldLooseKey("rootModule");
|
|
2552
|
+
|
|
2699
2553
|
class PlatformBuilder {
|
|
2700
2554
|
constructor({
|
|
2701
2555
|
name,
|
|
2702
2556
|
providers
|
|
2703
2557
|
}) {
|
|
2704
|
-
Object.defineProperty(this,
|
|
2558
|
+
Object.defineProperty(this, _injector, {
|
|
2705
2559
|
writable: true,
|
|
2706
2560
|
value: void 0
|
|
2707
2561
|
});
|
|
2708
|
-
Object.defineProperty(this,
|
|
2562
|
+
Object.defineProperty(this, _providers, {
|
|
2709
2563
|
writable: true,
|
|
2710
2564
|
value: void 0
|
|
2711
2565
|
});
|
|
2712
|
-
Object.defineProperty(this,
|
|
2566
|
+
Object.defineProperty(this, _rootModule, {
|
|
2713
2567
|
writable: true,
|
|
2714
2568
|
value: void 0
|
|
2715
2569
|
});
|
|
@@ -2726,7 +2580,7 @@ class PlatformBuilder {
|
|
|
2726
2580
|
}
|
|
2727
2581
|
|
|
2728
2582
|
get rootModule() {
|
|
2729
|
-
return _classPrivateFieldLooseBase(this, _rootModule)[_rootModule];
|
|
2583
|
+
return _classPrivateFieldLooseBase(this, _injector)[_injector].get(_classPrivateFieldLooseBase(this, _rootModule)[_rootModule]);
|
|
2730
2584
|
}
|
|
2731
2585
|
|
|
2732
2586
|
get app() {
|
|
@@ -2833,9 +2687,12 @@ class PlatformBuilder {
|
|
|
2833
2687
|
const {
|
|
2834
2688
|
injector
|
|
2835
2689
|
} = this;
|
|
2836
|
-
await this.callHook("$beforeInit");
|
|
2837
2690
|
this.log("Build providers");
|
|
2838
|
-
const container = di.createContainer(
|
|
2691
|
+
const container = di.createContainer();
|
|
2692
|
+
container.addProvider(_classPrivateFieldLooseBase(this, _rootModule)[_rootModule], {
|
|
2693
|
+
type: "server:module",
|
|
2694
|
+
scope: di.ProviderScope.SINGLETON
|
|
2695
|
+
});
|
|
2839
2696
|
await injector.load(container);
|
|
2840
2697
|
this.log("Settings and injector loaded");
|
|
2841
2698
|
await this.callHook("$afterInit");
|
|
@@ -2865,26 +2722,18 @@ class PlatformBuilder {
|
|
|
2865
2722
|
|
|
2866
2723
|
async callHook(hook, ...args) {
|
|
2867
2724
|
const {
|
|
2868
|
-
injector
|
|
2869
|
-
rootModule
|
|
2725
|
+
injector
|
|
2870
2726
|
} = this;
|
|
2871
2727
|
log(hook);
|
|
2872
2728
|
|
|
2873
2729
|
if (!this.disableBootstrapLog) {
|
|
2874
2730
|
injector.logger.info(`\x1B[1mCall hook ${hook}\x1B[22m`);
|
|
2875
|
-
} // call hook for the Server
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
if (hook in rootModule) {
|
|
2879
|
-
await rootModule[hook](...args);
|
|
2880
2731
|
} // Load middlewares for the given hook
|
|
2881
2732
|
|
|
2882
2733
|
|
|
2883
2734
|
this.loadMiddlewaresFor(hook); // call hooks added by providers
|
|
2884
2735
|
|
|
2885
|
-
|
|
2886
|
-
await injector.emit(hook);
|
|
2887
|
-
}
|
|
2736
|
+
await injector.emit(hook);
|
|
2888
2737
|
}
|
|
2889
2738
|
|
|
2890
2739
|
async loadStatics(hook) {
|
|
@@ -2954,7 +2803,6 @@ class PlatformBuilder {
|
|
|
2954
2803
|
this.createInjector(module, _extends({}, settings, {
|
|
2955
2804
|
PLATFORM_NAME: this.name
|
|
2956
2805
|
}));
|
|
2957
|
-
this.createRootModule(module);
|
|
2958
2806
|
await this.runLifecycle();
|
|
2959
2807
|
return this;
|
|
2960
2808
|
}
|
|
@@ -3003,6 +2851,7 @@ class PlatformBuilder {
|
|
|
3003
2851
|
}
|
|
3004
2852
|
|
|
3005
2853
|
createInjector(module, settings) {
|
|
2854
|
+
_classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = module;
|
|
3006
2855
|
const configuration = di.getConfiguration(module, settings);
|
|
3007
2856
|
_classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector(configuration); // configure locals providers
|
|
3008
2857
|
|
|
@@ -3014,12 +2863,6 @@ class PlatformBuilder {
|
|
|
3014
2863
|
createHttpServer(this.injector);
|
|
3015
2864
|
}
|
|
3016
2865
|
|
|
3017
|
-
createRootModule(module) {
|
|
3018
|
-
_classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = this.injector.invoke(module);
|
|
3019
|
-
this.injector.delete(core.constructorOf(_classPrivateFieldLooseBase(this, _rootModule)[_rootModule]));
|
|
3020
|
-
this.injector.delete(core.classOf(_classPrivateFieldLooseBase(this, _rootModule)[_rootModule]));
|
|
3021
|
-
}
|
|
3022
|
-
|
|
3023
2866
|
}
|
|
3024
2867
|
|
|
3025
2868
|
/**
|
|
@@ -3176,16 +3019,6 @@ function MultipartFile(name, maxCount) {
|
|
|
3176
3019
|
};
|
|
3177
3020
|
}
|
|
3178
3021
|
|
|
3179
|
-
/**
|
|
3180
|
-
*
|
|
3181
|
-
* @param fn
|
|
3182
|
-
* @decorator
|
|
3183
|
-
*/
|
|
3184
|
-
|
|
3185
|
-
function EndpointFn(fn) {
|
|
3186
|
-
return schema.JsonEntityFn(fn);
|
|
3187
|
-
}
|
|
3188
|
-
|
|
3189
3022
|
/**
|
|
3190
3023
|
* Set a mime list which are acceptable and checks if the specified content types are acceptable, based on the request’s Accept HTTP header field.
|
|
3191
3024
|
*
|
|
@@ -3206,9 +3039,18 @@ function EndpointFn(fn) {
|
|
|
3206
3039
|
*/
|
|
3207
3040
|
|
|
3208
3041
|
function AcceptMime(...mimes) {
|
|
3209
|
-
return core.useDecorators(schema.Produces(...mimes),
|
|
3210
|
-
|
|
3211
|
-
|
|
3042
|
+
return core.useDecorators(schema.Produces(...mimes), core.StoreSet("acceptMimes", mimes));
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
/**
|
|
3046
|
+
*
|
|
3047
|
+
* @param fn
|
|
3048
|
+
* @decorator
|
|
3049
|
+
* @deprecated Deprecated since 2021-10-05. Use JsonEntityFn instead.
|
|
3050
|
+
*/
|
|
3051
|
+
|
|
3052
|
+
function EndpointFn(fn) {
|
|
3053
|
+
return schema.JsonEntityFn(fn);
|
|
3212
3054
|
}
|
|
3213
3055
|
|
|
3214
3056
|
/**
|
|
@@ -3581,13 +3423,6 @@ class PlatformTest extends di.DITest {
|
|
|
3581
3423
|
|
|
3582
3424
|
}
|
|
3583
3425
|
|
|
3584
|
-
di.GlobalProviders.createRegistry(di.ProviderType.CONTROLLER, ControllerProvider, {
|
|
3585
|
-
onInvoke(provider, locals) {
|
|
3586
|
-
locals.set(exports.PlatformRouter, provider.getRouter());
|
|
3587
|
-
}
|
|
3588
|
-
|
|
3589
|
-
});
|
|
3590
|
-
|
|
3591
3426
|
/**
|
|
3592
3427
|
* @ignore
|
|
3593
3428
|
* @deprecated Will be removed in v7
|