@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/index.js CHANGED
@@ -14,8 +14,8 @@ var core = require('@tsed/core');
14
14
  var exceptions = require('@tsed/exceptions');
15
15
  var schema = require('@tsed/schema');
16
16
  var util = require('util');
17
- var Http = require('http');
18
17
  var Https = require('https');
18
+ var Http = require('http');
19
19
 
20
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
21
 
@@ -39,8 +39,8 @@ function _interopNamespace(e) {
39
39
  return n;
40
40
  }
41
41
 
42
- var Http__default = /*#__PURE__*/_interopDefaultLegacy(Http);
43
42
  var Https__default = /*#__PURE__*/_interopDefaultLegacy(Https);
43
+ var Http__default = /*#__PURE__*/_interopDefaultLegacy(Http);
44
44
 
45
45
  function _extends() {
46
46
  _extends = Object.assign || function (target) {
@@ -986,6 +986,7 @@ const PLATFORM_ROUTER_OPTIONS = Symbol.for("PlatformRouterOptions");
986
986
  exports.PlatformRouter = PlatformRouter_1 = class PlatformRouter {
987
987
  constructor(platformHandler) {
988
988
  this.platformHandler = platformHandler;
989
+ this.isBuilt = false;
989
990
  this.rawRouter = this.raw = PlatformRouter_1.createRawRouter();
990
991
  }
991
992
  /**
@@ -1292,72 +1293,77 @@ tslib.__decorate([tslib.__param(0, platformParams.Context()), tslib.__metadata("
1292
1293
 
1293
1294
  exports.AcceptMimesMiddleware = tslib.__decorate([platformMiddlewares.Middleware()], exports.AcceptMimesMiddleware);
1294
1295
 
1295
- /**
1296
- * Create Ts.ED context handler
1297
- * @param fn
1298
- * @ignore
1299
- */
1296
+ const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
1300
1297
 
1301
- function useCtxHandler(fn) {
1302
- fn.type = exports.HandlerType.CTX_FN;
1303
- return fn;
1304
- }
1298
+ let AUTO_INC = 0;
1299
+ class ControllerProvider extends di.Provider {
1300
+ constructor(provide, options = {}) {
1301
+ super(provide, options);
1302
+ this.type = di.ProviderType.CONTROLLER;
1303
+ this.tokenRouter = `${this.name}_ROUTER_${AUTO_INC++}`;
1304
+ }
1305
+ /**
1306
+ *
1307
+ */
1305
1308
 
1306
- /**
1307
- * @ignore
1308
- */
1309
1309
 
1310
- function formatMethod(method) {
1311
- return (method === schema.OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
1312
- }
1313
- /**
1314
- * @ignore
1315
- */
1310
+ get routerOptions() {
1311
+ return this.store.get(ROUTER_OPTIONS) || {};
1312
+ }
1313
+ /**
1314
+ *
1315
+ * @param value
1316
+ */
1316
1317
 
1317
1318
 
1318
- class PlatformControllerBuilder {
1319
- constructor(provider) {
1320
- this.provider = provider;
1319
+ set routerOptions(value) {
1320
+ this.store.set(ROUTER_OPTIONS, value);
1321
1321
  }
1322
1322
  /**
1323
- * @returns {any}
1323
+ *
1324
+ * @returns {any[]}
1324
1325
  */
1325
1326
 
1326
1327
 
1327
- build(injector) {
1328
- const {
1329
- middlewares: {
1330
- useBefore
1331
- }
1332
- } = this.provider; // Controller lifecycle
1328
+ get middlewares() {
1329
+ return Object.assign({
1330
+ use: [],
1331
+ useAfter: [],
1332
+ useBefore: []
1333
+ }, this.store.get("middlewares", {}));
1334
+ }
1335
+ /**
1336
+ *
1337
+ * @param middlewares
1338
+ */
1333
1339
 
1334
- this.buildMiddlewares(useBefore) // Controller before-middleware
1335
- .buildEndpoints() // All endpoints and his middlewares
1336
- .buildChildrenCtrls(injector); // Children controllers
1337
1340
 
1338
- return this.provider.getRouter();
1339
- }
1341
+ set middlewares(middlewares) {
1342
+ const mdlwrs = this.middlewares;
1340
1343
 
1341
- buildEndpoints() {
1342
- schema.getOperationsRoutes(this.provider.token).forEach(operationRoute => {
1343
- this.buildEndpoint(operationRoute);
1344
- });
1345
- return this;
1346
- }
1344
+ const concat = (key, a, b) => a[key] = a[key].concat(b[key]);
1347
1345
 
1348
- buildEndpoint(operationRoute) {
1349
- let handlers = this.getMiddlewares(operationRoute);
1350
- const router = this.provider.getRouter();
1351
- router.addRoute({
1352
- handlers,
1353
- token: operationRoute.token,
1354
- method: formatMethod(operationRoute.method),
1355
- path: operationRoute.path,
1356
- isFinal: operationRoute.isFinal
1346
+ Object.keys(middlewares).forEach(key => {
1347
+ concat(key, mdlwrs, middlewares);
1357
1348
  });
1349
+ this.store.set("middlewares", mdlwrs);
1358
1350
  }
1359
1351
 
1360
- getMiddlewares(operationRoute) {
1352
+ }
1353
+
1354
+ /**
1355
+ * Create Ts.ED context handler
1356
+ * @param fn
1357
+ * @ignore
1358
+ */
1359
+
1360
+ function useCtxHandler(fn) {
1361
+ fn.type = exports.HandlerType.CTX_FN;
1362
+ return fn;
1363
+ }
1364
+
1365
+ exports.PlatformMiddlewaresChain = class PlatformMiddlewaresChain {
1366
+ get(provider, operationRoute) {
1361
1367
  const {
1362
1368
  endpoint
1363
1369
  } = operationRoute;
@@ -1371,11 +1377,10 @@ class PlatformControllerBuilder {
1371
1377
  use,
1372
1378
  useAfter
1373
1379
  }
1374
- } = this.provider;
1380
+ } = provider;
1375
1381
  const hasFiles = [...operationRoute.endpoint.children.values()].find(item => item.paramType === platformParams.ParamTypes.FILES);
1376
1382
  return [].concat(useCtxHandler(bindEndpointMiddleware(endpoint))).concat(exports.PlatformAcceptMimesMiddleware).concat(hasFiles && exports.PlatformMulterMiddleware).concat(beforeMiddlewares) // Endpoint before-middlewares
1377
1383
  .concat(use) // Controller use-middlewares
1378
- // .concat(endpoint.cache && PlatformCacheMiddleware)
1379
1384
  .concat(mldwrs) // Endpoint middlewares
1380
1385
  .concat(endpoint) // Endpoint metadata
1381
1386
  .concat(afterMiddlewares) // Endpoint after-middlewares
@@ -1383,32 +1388,97 @@ class PlatformControllerBuilder {
1383
1388
  .filter(item => !!item);
1384
1389
  }
1385
1390
 
1386
- buildChildrenCtrls(injector) {
1387
- const {
1388
- children
1389
- } = this.provider;
1390
- const router = this.provider.getRouter();
1391
+ };
1392
+ exports.PlatformMiddlewaresChain = tslib.__decorate([di.Injectable()], exports.PlatformMiddlewaresChain);
1393
+
1394
+ di.GlobalProviders.createRegistry(di.ProviderType.CONTROLLER, ControllerProvider, {
1395
+ onInvoke(provider, locals, {
1396
+ injector
1397
+ }) {
1398
+ const router = createRouter(injector, provider);
1399
+ locals.set(exports.PlatformRouter, router);
1400
+ }
1401
+
1402
+ });
1403
+ /**
1404
+ * @ignore
1405
+ */
1406
+
1407
+ function formatMethod(method) {
1408
+ return (method === schema.OperationMethods.CUSTOM ? "use" : method || "use").toLowerCase();
1409
+ }
1410
+ /**
1411
+ * @ignore
1412
+ */
1413
+
1414
+
1415
+ function getRouter(injector, provider) {
1416
+ return injector.get(provider.tokenRouter);
1417
+ }
1418
+ /**
1419
+ * @ignore
1420
+ */
1421
+
1422
+ function createRouter(injector, provider) {
1423
+ const token = provider.tokenRouter;
1424
+
1425
+ if (injector.has(token)) {
1426
+ return getRouter(injector, provider);
1427
+ }
1428
+
1429
+ const router = exports.PlatformRouter.create(injector, provider.routerOptions);
1430
+ return injector.add(token, {
1431
+ useValue: router
1432
+ }).invoke(token);
1433
+ }
1434
+ /**
1435
+ * @ignore
1436
+ * @param injector
1437
+ * @param provider
1438
+ */
1439
+
1440
+ function buildRouter(injector, provider) {
1441
+ const {
1442
+ middlewares: {
1443
+ useBefore
1444
+ },
1445
+ children
1446
+ } = provider; // Controller lifecycle
1447
+
1448
+ const router = createRouter(injector, provider);
1449
+
1450
+ if (!router.isBuilt) {
1451
+ router.isBuilt = true;
1452
+ const platformMiddlewaresChain = injector.get(exports.PlatformMiddlewaresChain);
1453
+ useBefore // Controller before-middleware
1454
+ .filter(o => typeof o === "function").forEach(middleware => {
1455
+ router.use(middleware);
1456
+ }); // build all endpoints and his middlewares
1457
+
1458
+ schema.getOperationsRoutes(provider.token).forEach(operationRoute => {
1459
+ const handlers = platformMiddlewaresChain == null ? void 0 : platformMiddlewaresChain.get(provider, operationRoute);
1460
+ router.addRoute({
1461
+ handlers,
1462
+ token: operationRoute.token,
1463
+ method: formatMethod(operationRoute.method),
1464
+ path: operationRoute.path,
1465
+ isFinal: operationRoute.isFinal
1466
+ });
1467
+ }); // build children controllers
1468
+
1391
1469
  children.forEach(child => {
1392
- const provider = injector.getProvider(child);
1470
+ const childProvider = injector.getProvider(child);
1393
1471
  /* istanbul ignore next */
1394
1472
 
1395
- if (!provider) {
1473
+ if (!childProvider) {
1396
1474
  throw new Error("Controller component not found in the ControllerRegistry");
1397
1475
  }
1398
1476
 
1399
- new PlatformControllerBuilder(provider).build(injector);
1400
- router.use(provider.path, provider.getRouter());
1477
+ router.use(childProvider.path, buildRouter(injector, childProvider));
1401
1478
  });
1402
1479
  }
1403
1480
 
1404
- buildMiddlewares(middlewares) {
1405
- const router = this.provider.getRouter();
1406
- middlewares.filter(o => typeof o === "function").forEach(middleware => {
1407
- router.use(middleware);
1408
- });
1409
- return this;
1410
- }
1411
-
1481
+ return router;
1412
1482
  }
1413
1483
 
1414
1484
  /**
@@ -2005,71 +2075,6 @@ class PlatformRouteDetails extends schema.JsonOperationRoute {
2005
2075
 
2006
2076
  }
2007
2077
 
2008
- const ROUTER_OPTIONS = Symbol.for("ROUTER_OPTIONS");
2009
-
2010
- class ControllerProvider extends di.Provider {
2011
- constructor(provide, options = {}) {
2012
- super(provide, options);
2013
- this.type = di.ProviderType.CONTROLLER;
2014
- }
2015
- /**
2016
- *
2017
- */
2018
-
2019
-
2020
- get routerOptions() {
2021
- return this.store.get(ROUTER_OPTIONS) || {};
2022
- }
2023
- /**
2024
- *
2025
- * @param value
2026
- */
2027
-
2028
-
2029
- set routerOptions(value) {
2030
- this.store.set(ROUTER_OPTIONS, value);
2031
- }
2032
- /**
2033
- *
2034
- * @returns {any[]}
2035
- */
2036
-
2037
-
2038
- get middlewares() {
2039
- return Object.assign({
2040
- use: [],
2041
- useAfter: [],
2042
- useBefore: []
2043
- }, this.store.get("middlewares", {}));
2044
- }
2045
- /**
2046
- *
2047
- * @param middlewares
2048
- */
2049
-
2050
-
2051
- set middlewares(middlewares) {
2052
- const mdlwrs = this.middlewares;
2053
-
2054
- const concat = (key, a, b) => a[key] = a[key].concat(b[key]);
2055
-
2056
- Object.keys(middlewares).forEach(key => {
2057
- concat(key, mdlwrs, middlewares);
2058
- });
2059
- this.store.set("middlewares", mdlwrs);
2060
- }
2061
-
2062
- getRouter() {
2063
- return this.router;
2064
- }
2065
-
2066
- setRouter(router) {
2067
- this.router = router;
2068
- return this;
2069
- }
2070
-
2071
- }
2072
-
2073
2078
  /**
2074
2079
  * @deprecated Since 2020-11-11. Use getProperties from @tsed/schema
2075
2080
  */
@@ -2093,13 +2098,6 @@ exports.PropertyMetadata = class PropertyMetadata extends schema.JsonPropertySto
2093
2098
  };
2094
2099
  exports.PropertyMetadata = tslib.__decorate([schema.JsonEntityComponent(core.DecoratorTypes.PROP)], exports.PropertyMetadata);
2095
2100
 
2096
- di.GlobalProviders.createRegistry(di.ProviderType.CONTROLLER, ControllerProvider, {
2097
- onInvoke(provider, locals) {
2098
- locals.set(exports.PlatformRouter, provider.getRouter());
2099
- }
2100
-
2101
- });
2102
-
2103
2101
  /**
2104
2102
  * `Platform` is used to provide all routes collected by annotation `@Controller`.
2105
2103
  *
@@ -2146,7 +2144,7 @@ exports.Platform = class Platform {
2146
2144
  provider
2147
2145
  });
2148
2146
 
2149
- this.app.use(ctrlPath, ...[].concat(provider.getRouter().callback()));
2147
+ this.app.use(ctrlPath, ...[].concat(getRouter(injector, provider).callback()));
2150
2148
  this._routes = schema.getOperationsRoutes(provider.token, {
2151
2149
  withChildren: true,
2152
2150
  basePath
@@ -2191,7 +2189,7 @@ exports.Platform = class Platform {
2191
2189
  injector
2192
2190
  } = this;
2193
2191
  injector.getProviders(di.ProviderType.CONTROLLER).map(provider => {
2194
- provider.setRouter(exports.PlatformRouter.create(injector, provider.routerOptions));
2192
+ createRouter(injector, provider);
2195
2193
  });
2196
2194
  }
2197
2195
  /**
@@ -2206,52 +2204,32 @@ exports.Platform = class Platform {
2206
2204
  } = this;
2207
2205
  injector.getProviders(di.ProviderType.CONTROLLER).map(provider => {
2208
2206
  if (!provider.hasParent()) {
2209
- return new PlatformControllerBuilder(provider).build(injector);
2207
+ return buildRouter(injector, provider);
2210
2208
  }
2211
2209
  });
2212
2210
  }
2213
2211
 
2214
2212
  };
2215
2213
  exports.Platform = tslib.__decorate([di.Injectable({
2216
- scope: di.ProviderScope.SINGLETON
2214
+ scope: di.ProviderScope.SINGLETON,
2215
+ imports: [exports.PlatformMiddlewaresChain]
2217
2216
  }), tslib.__metadata("design:paramtypes", [di.InjectorService, exports.PlatformApplication])], exports.Platform);
2218
2217
 
2219
- logger.$log.name = "TSED";
2220
- function createInjector(settings = {}) {
2221
- const injector = new di.InjectorService();
2222
- injector.settings = createSettingsService(injector);
2223
- injector.logger = logger.$log;
2224
- injector.settings.set(settings);
2225
- di.setLoggerLevel(injector);
2226
- return injector;
2227
- }
2228
-
2229
- function createSettingsService(injector) {
2230
- const provider = di.GlobalProviders.get(exports.PlatformConfiguration).clone();
2231
- provider.instance = injector.invoke(provider.useClass);
2232
- injector.addProvider(exports.PlatformConfiguration, provider);
2233
- return provider.instance;
2234
- }
2235
-
2236
- function createPlatformApplication(injector) {
2237
- injector.forkProvider(exports.PlatformApplication);
2238
- }
2239
-
2240
2218
  /**
2241
- * Inject the Http.Server instance.
2219
+ * Inject the Https.Server instance.
2242
2220
  *
2243
2221
  * ### Example
2244
2222
  *
2245
2223
  * ```typescript
2246
- * import {HttpServer, Service} from "@tsed/common";
2224
+ * import {HttpsServer, Service} from "@tsed/common";
2247
2225
  *
2248
2226
  * @Service()
2249
2227
  * export default class OtherService {
2250
- * constructor(@HttpServer httpServer: HttpServer) {}
2228
+ * constructor(@HttpsServer httpServer: HttpServer) {}
2251
2229
  * }
2252
2230
  * ```
2253
2231
  *
2254
- * > Note: TypeScript transform and store `HttpServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2232
+ * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2255
2233
  *
2256
2234
  * @param {Type<any>} target
2257
2235
  * @param {string} targetKey
@@ -2260,8 +2238,8 @@ function createPlatformApplication(injector) {
2260
2238
  * @decorator
2261
2239
  */
2262
2240
 
2263
- function HttpServer(target, targetKey, descriptor) {
2264
- return di.Inject(HttpServer)(target, targetKey, descriptor);
2241
+ function HttpsServer(target, targetKey, descriptor) {
2242
+ return di.Inject(HttpsServer)(target, targetKey, descriptor);
2265
2243
  }
2266
2244
 
2267
2245
  function listenServer(http, settings) {
@@ -2283,56 +2261,57 @@ function listenServer(http, settings) {
2283
2261
  return promise;
2284
2262
  }
2285
2263
 
2286
- function createHttpServer(injector) {
2287
- injector.forkProvider(HttpServer);
2264
+ function createHttpsServer(injector) {
2265
+ injector.invoke(HttpsServer);
2288
2266
  }
2289
2267
  di.registerProvider({
2290
- provide: HttpServer,
2291
- deps: [exports.PlatformApplication],
2268
+ provide: HttpsServer,
2269
+ deps: [exports.PlatformApplication, di.Configuration],
2292
2270
  scope: di.ProviderScope.SINGLETON,
2293
2271
  global: true,
2294
2272
 
2295
- useFactory(platformApplication) {
2296
- return Http__default['default'].createServer(platformApplication.callback());
2273
+ useFactory(platformApplication, settings) {
2274
+ const options = settings.httpsOptions;
2275
+ return Https__default['default'].createServer(options, platformApplication.callback());
2297
2276
  }
2298
2277
 
2299
2278
  });
2300
- async function listenHttpServer(injector) {
2279
+ async function listenHttpsServer(injector) {
2301
2280
  const {
2302
2281
  settings
2303
2282
  } = injector;
2304
- const server = injector.get(HttpServer);
2283
+ const server = injector.get(HttpsServer);
2305
2284
 
2306
- if (settings.httpPort !== false && server) {
2285
+ if (settings.httpsPort !== false && server) {
2307
2286
  const {
2308
2287
  address,
2309
2288
  port
2310
- } = settings.getHttpPort();
2311
- injector.logger.debug(`Start server on http://${address}:${port}`);
2289
+ } = settings.getHttpsPort();
2290
+ injector.logger.debug(`Start server on https://${address}:${port}`);
2312
2291
  const options = await listenServer(server, {
2313
2292
  address,
2314
2293
  port
2315
2294
  });
2316
- settings.setHttpPort(options);
2317
- injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
2295
+ settings.setHttpsPort(options);
2296
+ injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
2318
2297
  }
2319
2298
  }
2320
2299
 
2321
2300
  /**
2322
- * Inject the Https.Server instance.
2301
+ * Inject the Http.Server instance.
2323
2302
  *
2324
2303
  * ### Example
2325
2304
  *
2326
2305
  * ```typescript
2327
- * import {HttpsServer, Service} from "@tsed/common";
2306
+ * import {HttpServer, Service} from "@tsed/common";
2328
2307
  *
2329
2308
  * @Service()
2330
2309
  * export default class OtherService {
2331
- * constructor(@HttpsServer httpServer: HttpServer) {}
2310
+ * constructor(@HttpServer httpServer: HttpServer) {}
2332
2311
  * }
2333
2312
  * ```
2334
2313
  *
2335
- * > Note: TypeScript transform and store `HttpsServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2314
+ * > Note: TypeScript transform and store `HttpServer` as `Function` type in the metadata. So to inject a factory, you must use the `@Inject(type)` decorator.
2336
2315
  *
2337
2316
  * @param {Type<any>} target
2338
2317
  * @param {string} targetKey
@@ -2341,46 +2320,79 @@ async function listenHttpServer(injector) {
2341
2320
  * @decorator
2342
2321
  */
2343
2322
 
2344
- function HttpsServer(target, targetKey, descriptor) {
2345
- return di.Inject(HttpsServer)(target, targetKey, descriptor);
2323
+ function HttpServer(target, targetKey, descriptor) {
2324
+ return di.Inject(HttpServer)(target, targetKey, descriptor);
2346
2325
  }
2347
2326
 
2348
- function createHttpsServer(injector) {
2349
- injector.forkProvider(HttpsServer);
2327
+ function createHttpServer(injector) {
2328
+ injector.invoke(HttpServer);
2350
2329
  }
2351
2330
  di.registerProvider({
2352
- provide: HttpsServer,
2353
- deps: [exports.PlatformApplication, di.Configuration],
2331
+ provide: HttpServer,
2332
+ deps: [exports.PlatformApplication],
2354
2333
  scope: di.ProviderScope.SINGLETON,
2355
2334
  global: true,
2356
2335
 
2357
- useFactory(platformApplication, settings) {
2358
- const options = settings.httpsOptions;
2359
- return Https__default['default'].createServer(options, platformApplication.callback());
2336
+ useFactory(platformApplication) {
2337
+ return Http__default['default'].createServer(platformApplication.callback());
2360
2338
  }
2361
2339
 
2362
2340
  });
2363
- async function listenHttpsServer(injector) {
2341
+ async function listenHttpServer(injector) {
2364
2342
  const {
2365
2343
  settings
2366
2344
  } = injector;
2367
- const server = injector.get(HttpsServer);
2345
+ const server = injector.get(HttpServer);
2368
2346
 
2369
- if (settings.httpsPort !== false && server) {
2347
+ if (settings.httpPort !== false && server) {
2370
2348
  const {
2371
2349
  address,
2372
2350
  port
2373
- } = settings.getHttpsPort();
2374
- injector.logger.debug(`Start server on https://${address}:${port}`);
2351
+ } = settings.getHttpPort();
2352
+ injector.logger.debug(`Start server on http://${address}:${port}`);
2375
2353
  const options = await listenServer(server, {
2376
2354
  address,
2377
2355
  port
2378
2356
  });
2379
- settings.setHttpsPort(options);
2380
- injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
2357
+ settings.setHttpPort(options);
2358
+ injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
2381
2359
  }
2382
2360
  }
2383
2361
 
2362
+ logger.$log.name = "TSED";
2363
+ const DEFAULT_PROVIDERS = [{
2364
+ provide: exports.PlatformHandler
2365
+ }, {
2366
+ provide: exports.PlatformResponse
2367
+ }, {
2368
+ provide: exports.PlatformRequest
2369
+ }, {
2370
+ provide: exports.PlatformRouter
2371
+ }, {
2372
+ provide: exports.PlatformApplication
2373
+ }, {
2374
+ provide: exports.Platform
2375
+ }];
2376
+ function createInjector({
2377
+ providers = [],
2378
+ settings = {}
2379
+ }) {
2380
+ const injector = new di.InjectorService();
2381
+ injector.addProvider(exports.PlatformConfiguration);
2382
+ injector.settings = injector.invoke(exports.PlatformConfiguration);
2383
+ injector.logger = logger.$log;
2384
+ injector.settings.set(settings);
2385
+ di.setLoggerLevel(injector);
2386
+ providers = [...DEFAULT_PROVIDERS, ...providers];
2387
+ core.toMap(providers, "provide").forEach((provider, token) => {
2388
+ injector.addProvider(token, provider);
2389
+ });
2390
+ injector.invoke(exports.PlatformApplication);
2391
+ createHttpsServer(injector);
2392
+ createHttpServer(injector);
2393
+ return injector;
2394
+ }
2395
+
2384
2396
  /**
2385
2397
  * @ignore
2386
2398
  * @deprecated User injector.load(container, module) instead
@@ -2521,19 +2533,6 @@ function getConfiguration(configuration = {}, module = null) {
2521
2533
  return config;
2522
2534
  }
2523
2535
 
2524
- const DEFAULT_PROVIDERS = [{
2525
- provide: exports.PlatformHandler
2526
- }, {
2527
- provide: exports.PlatformResponse
2528
- }, {
2529
- provide: exports.PlatformRequest
2530
- }, {
2531
- provide: exports.PlatformRouter
2532
- }, {
2533
- provide: exports.PlatformApplication
2534
- }, {
2535
- provide: exports.Platform
2536
- }];
2537
2536
  /**
2538
2537
  * @platform
2539
2538
  */
@@ -2562,7 +2561,13 @@ class PlatformBuilder {
2562
2561
  this.current = new Date();
2563
2562
  this.name = name;
2564
2563
  _classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = module;
2565
- this.createInjector(module, providers, settings);
2564
+ const configuration = getConfiguration(settings, module);
2565
+ configuration.PLATFORM_NAME = name;
2566
+ _classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector({
2567
+ settings: configuration,
2568
+ providers
2569
+ });
2570
+ this.log("Injector created...");
2566
2571
  }
2567
2572
 
2568
2573
  get injector() {
@@ -2841,20 +2846,6 @@ class PlatformBuilder {
2841
2846
  await this.callHook("$afterRoutesInit");
2842
2847
  }
2843
2848
 
2844
- createInjector(module, providers, settings) {
2845
- const configuration = getConfiguration(settings, module);
2846
- configuration.PLATFORM_NAME = this.name;
2847
- _classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector(configuration);
2848
- providers = [...DEFAULT_PROVIDERS, ...providers];
2849
- core.toMap(providers, "provide").forEach((provider, token) => {
2850
- this.injector.addProvider(token, provider);
2851
- });
2852
- createPlatformApplication(this.injector);
2853
- createHttpsServer(this.injector);
2854
- createHttpServer(this.injector);
2855
- this.log("Injector created...");
2856
- }
2857
-
2858
2849
  }
2859
2850
 
2860
2851
  /**
@@ -3227,8 +3218,8 @@ function mapReturnedResponse(_ref) {
3227
3218
  */
3228
3219
 
3229
3220
  class PlatformTest extends di.DITest {
3230
- static async create(options = {}) {
3231
- di.DITest.injector = PlatformTest.createInjector(getConfiguration(options, null));
3221
+ static async create(settings = {}) {
3222
+ di.DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
3232
3223
  const container = di.createContainer();
3233
3224
  await di.DITest.injector.load(container);
3234
3225
  }
@@ -3238,7 +3229,10 @@ class PlatformTest extends di.DITest {
3238
3229
 
3239
3230
 
3240
3231
  static createInjector(settings = {}) {
3241
- return createInjector(di.DITest.configure(settings));
3232
+ return createInjector({
3233
+ providers: [],
3234
+ settings: di.DITest.configure(settings)
3235
+ });
3242
3236
  }
3243
3237
  /**
3244
3238
  * Load the server silently without listening port and configure it on test profile.
@@ -3510,7 +3504,6 @@ exports.Next = Next;
3510
3504
  exports.PLATFORM_ROUTER_OPTIONS = PLATFORM_ROUTER_OPTIONS;
3511
3505
  exports.PlatformBuilder = PlatformBuilder;
3512
3506
  exports.PlatformContext = PlatformContext;
3513
- exports.PlatformControllerBuilder = PlatformControllerBuilder;
3514
3507
  exports.PlatformModule = PlatformModule;
3515
3508
  exports.PlatformRouteDetails = PlatformRouteDetails;
3516
3509
  exports.PlatformTest = PlatformTest;
@@ -3521,11 +3514,13 @@ exports.Res = Res;
3521
3514
  exports.Response = Response;
3522
3515
  exports.ResponseData = ResponseData;
3523
3516
  exports.bindEndpointMiddleware = bindEndpointMiddleware;
3517
+ exports.buildRouter = buildRouter;
3524
3518
  exports.createContext = createContext;
3525
3519
  exports.createHttpServer = createHttpServer;
3526
3520
  exports.createHttpsServer = createHttpsServer;
3527
3521
  exports.createInjector = createInjector;
3528
- exports.createPlatformApplication = createPlatformApplication;
3522
+ exports.createRouter = createRouter;
3523
+ exports.getRouter = getRouter;
3529
3524
  exports.listenHttpServer = listenHttpServer;
3530
3525
  exports.listenHttpsServer = listenHttpsServer;
3531
3526
  exports.listenServer = listenServer;