@tsed/common 6.87.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.
@@ -113,5 +113,4 @@ export declare abstract class PlatformBuilder<App = TsED.Application, Router = T
113
113
  protected listenServers(): Promise<void>;
114
114
  protected logRoutes(): Promise<void>;
115
115
  protected loadRoutes(): Promise<void>;
116
- protected createInjector(module: Type<any>, providers: IProvider[], settings: any): void;
117
116
  }
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) {
@@ -2215,36 +2215,21 @@ exports.Platform = tslib.__decorate([di.Injectable({
2215
2215
  imports: [exports.PlatformMiddlewaresChain]
2216
2216
  }), tslib.__metadata("design:paramtypes", [di.InjectorService, exports.PlatformApplication])], exports.Platform);
2217
2217
 
2218
- logger.$log.name = "TSED";
2219
- function createInjector(settings = {}) {
2220
- const injector = new di.InjectorService();
2221
- injector.addProvider(exports.PlatformConfiguration);
2222
- injector.settings = injector.invoke(exports.PlatformConfiguration);
2223
- injector.logger = logger.$log;
2224
- injector.settings.set(settings);
2225
- di.setLoggerLevel(injector);
2226
- return injector;
2227
- }
2228
-
2229
- function createPlatformApplication(injector) {
2230
- injector.forkProvider(exports.PlatformApplication);
2231
- }
2232
-
2233
2218
  /**
2234
- * Inject the Http.Server instance.
2219
+ * Inject the Https.Server instance.
2235
2220
  *
2236
2221
  * ### Example
2237
2222
  *
2238
2223
  * ```typescript
2239
- * import {HttpServer, Service} from "@tsed/common";
2224
+ * import {HttpsServer, Service} from "@tsed/common";
2240
2225
  *
2241
2226
  * @Service()
2242
2227
  * export default class OtherService {
2243
- * constructor(@HttpServer httpServer: HttpServer) {}
2228
+ * constructor(@HttpsServer httpServer: HttpServer) {}
2244
2229
  * }
2245
2230
  * ```
2246
2231
  *
2247
- * > 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.
2248
2233
  *
2249
2234
  * @param {Type<any>} target
2250
2235
  * @param {string} targetKey
@@ -2253,8 +2238,8 @@ function createPlatformApplication(injector) {
2253
2238
  * @decorator
2254
2239
  */
2255
2240
 
2256
- function HttpServer(target, targetKey, descriptor) {
2257
- return di.Inject(HttpServer)(target, targetKey, descriptor);
2241
+ function HttpsServer(target, targetKey, descriptor) {
2242
+ return di.Inject(HttpsServer)(target, targetKey, descriptor);
2258
2243
  }
2259
2244
 
2260
2245
  function listenServer(http, settings) {
@@ -2276,56 +2261,57 @@ function listenServer(http, settings) {
2276
2261
  return promise;
2277
2262
  }
2278
2263
 
2279
- function createHttpServer(injector) {
2280
- injector.forkProvider(HttpServer);
2264
+ function createHttpsServer(injector) {
2265
+ injector.invoke(HttpsServer);
2281
2266
  }
2282
2267
  di.registerProvider({
2283
- provide: HttpServer,
2284
- deps: [exports.PlatformApplication],
2268
+ provide: HttpsServer,
2269
+ deps: [exports.PlatformApplication, di.Configuration],
2285
2270
  scope: di.ProviderScope.SINGLETON,
2286
2271
  global: true,
2287
2272
 
2288
- useFactory(platformApplication) {
2289
- 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());
2290
2276
  }
2291
2277
 
2292
2278
  });
2293
- async function listenHttpServer(injector) {
2279
+ async function listenHttpsServer(injector) {
2294
2280
  const {
2295
2281
  settings
2296
2282
  } = injector;
2297
- const server = injector.get(HttpServer);
2283
+ const server = injector.get(HttpsServer);
2298
2284
 
2299
- if (settings.httpPort !== false && server) {
2285
+ if (settings.httpsPort !== false && server) {
2300
2286
  const {
2301
2287
  address,
2302
2288
  port
2303
- } = settings.getHttpPort();
2304
- injector.logger.debug(`Start server on http://${address}:${port}`);
2289
+ } = settings.getHttpsPort();
2290
+ injector.logger.debug(`Start server on https://${address}:${port}`);
2305
2291
  const options = await listenServer(server, {
2306
2292
  address,
2307
2293
  port
2308
2294
  });
2309
- settings.setHttpPort(options);
2310
- 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}`);
2311
2297
  }
2312
2298
  }
2313
2299
 
2314
2300
  /**
2315
- * Inject the Https.Server instance.
2301
+ * Inject the Http.Server instance.
2316
2302
  *
2317
2303
  * ### Example
2318
2304
  *
2319
2305
  * ```typescript
2320
- * import {HttpsServer, Service} from "@tsed/common";
2306
+ * import {HttpServer, Service} from "@tsed/common";
2321
2307
  *
2322
2308
  * @Service()
2323
2309
  * export default class OtherService {
2324
- * constructor(@HttpsServer httpServer: HttpServer) {}
2310
+ * constructor(@HttpServer httpServer: HttpServer) {}
2325
2311
  * }
2326
2312
  * ```
2327
2313
  *
2328
- * > 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.
2329
2315
  *
2330
2316
  * @param {Type<any>} target
2331
2317
  * @param {string} targetKey
@@ -2334,46 +2320,79 @@ async function listenHttpServer(injector) {
2334
2320
  * @decorator
2335
2321
  */
2336
2322
 
2337
- function HttpsServer(target, targetKey, descriptor) {
2338
- return di.Inject(HttpsServer)(target, targetKey, descriptor);
2323
+ function HttpServer(target, targetKey, descriptor) {
2324
+ return di.Inject(HttpServer)(target, targetKey, descriptor);
2339
2325
  }
2340
2326
 
2341
- function createHttpsServer(injector) {
2342
- injector.forkProvider(HttpsServer);
2327
+ function createHttpServer(injector) {
2328
+ injector.invoke(HttpServer);
2343
2329
  }
2344
2330
  di.registerProvider({
2345
- provide: HttpsServer,
2346
- deps: [exports.PlatformApplication, di.Configuration],
2331
+ provide: HttpServer,
2332
+ deps: [exports.PlatformApplication],
2347
2333
  scope: di.ProviderScope.SINGLETON,
2348
2334
  global: true,
2349
2335
 
2350
- useFactory(platformApplication, settings) {
2351
- const options = settings.httpsOptions;
2352
- return Https__default['default'].createServer(options, platformApplication.callback());
2336
+ useFactory(platformApplication) {
2337
+ return Http__default['default'].createServer(platformApplication.callback());
2353
2338
  }
2354
2339
 
2355
2340
  });
2356
- async function listenHttpsServer(injector) {
2341
+ async function listenHttpServer(injector) {
2357
2342
  const {
2358
2343
  settings
2359
2344
  } = injector;
2360
- const server = injector.get(HttpsServer);
2345
+ const server = injector.get(HttpServer);
2361
2346
 
2362
- if (settings.httpsPort !== false && server) {
2347
+ if (settings.httpPort !== false && server) {
2363
2348
  const {
2364
2349
  address,
2365
2350
  port
2366
- } = settings.getHttpsPort();
2367
- injector.logger.debug(`Start server on https://${address}:${port}`);
2351
+ } = settings.getHttpPort();
2352
+ injector.logger.debug(`Start server on http://${address}:${port}`);
2368
2353
  const options = await listenServer(server, {
2369
2354
  address,
2370
2355
  port
2371
2356
  });
2372
- settings.setHttpsPort(options);
2373
- 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}`);
2374
2359
  }
2375
2360
  }
2376
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
+
2377
2396
  /**
2378
2397
  * @ignore
2379
2398
  * @deprecated User injector.load(container, module) instead
@@ -2514,19 +2533,6 @@ function getConfiguration(configuration = {}, module = null) {
2514
2533
  return config;
2515
2534
  }
2516
2535
 
2517
- const DEFAULT_PROVIDERS = [{
2518
- provide: exports.PlatformHandler
2519
- }, {
2520
- provide: exports.PlatformResponse
2521
- }, {
2522
- provide: exports.PlatformRequest
2523
- }, {
2524
- provide: exports.PlatformRouter
2525
- }, {
2526
- provide: exports.PlatformApplication
2527
- }, {
2528
- provide: exports.Platform
2529
- }];
2530
2536
  /**
2531
2537
  * @platform
2532
2538
  */
@@ -2555,7 +2561,13 @@ class PlatformBuilder {
2555
2561
  this.current = new Date();
2556
2562
  this.name = name;
2557
2563
  _classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = module;
2558
- 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...");
2559
2571
  }
2560
2572
 
2561
2573
  get injector() {
@@ -2834,20 +2846,6 @@ class PlatformBuilder {
2834
2846
  await this.callHook("$afterRoutesInit");
2835
2847
  }
2836
2848
 
2837
- createInjector(module, providers, settings) {
2838
- const configuration = getConfiguration(settings, module);
2839
- configuration.PLATFORM_NAME = this.name;
2840
- _classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector(configuration);
2841
- providers = [...DEFAULT_PROVIDERS, ...providers];
2842
- core.toMap(providers, "provide").forEach((provider, token) => {
2843
- this.injector.addProvider(token, provider);
2844
- });
2845
- createPlatformApplication(this.injector);
2846
- createHttpsServer(this.injector);
2847
- createHttpServer(this.injector);
2848
- this.log("Injector created...");
2849
- }
2850
-
2851
2849
  }
2852
2850
 
2853
2851
  /**
@@ -3220,8 +3218,8 @@ function mapReturnedResponse(_ref) {
3220
3218
  */
3221
3219
 
3222
3220
  class PlatformTest extends di.DITest {
3223
- static async create(options = {}) {
3224
- di.DITest.injector = PlatformTest.createInjector(getConfiguration(options, null));
3221
+ static async create(settings = {}) {
3222
+ di.DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
3225
3223
  const container = di.createContainer();
3226
3224
  await di.DITest.injector.load(container);
3227
3225
  }
@@ -3231,7 +3229,10 @@ class PlatformTest extends di.DITest {
3231
3229
 
3232
3230
 
3233
3231
  static createInjector(settings = {}) {
3234
- return createInjector(di.DITest.configure(settings));
3232
+ return createInjector({
3233
+ providers: [],
3234
+ settings: di.DITest.configure(settings)
3235
+ });
3235
3236
  }
3236
3237
  /**
3237
3238
  * Load the server silently without listening port and configure it on test profile.
@@ -3518,7 +3519,6 @@ exports.createContext = createContext;
3518
3519
  exports.createHttpServer = createHttpServer;
3519
3520
  exports.createHttpsServer = createHttpsServer;
3520
3521
  exports.createInjector = createInjector;
3521
- exports.createPlatformApplication = createPlatformApplication;
3522
3522
  exports.createRouter = createRouter;
3523
3523
  exports.getRouter = getRouter;
3524
3524
  exports.listenHttpServer = listenHttpServer;