@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.
- package/lib/builder/PlatformBuilder.d.ts +0 -1
- package/lib/index.js +88 -88
- package/lib/index.js.map +1 -1
- package/lib/index.modern.js +90 -89
- package/lib/index.modern.js.map +1 -1
- package/lib/services/PlatformTest.d.ts +1 -1
- package/lib/utils/createInjector.d.ts +7 -2
- package/lib/utils/index.d.ts +0 -1
- package/package.json +15 -15
- 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, Provider, ProviderType, GlobalProviders, Scope, DIContext,
|
|
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) {
|
|
@@ -2206,36 +2206,21 @@ Platform = __decorate([Injectable({
|
|
|
2206
2206
|
imports: [PlatformMiddlewaresChain]
|
|
2207
2207
|
}), __metadata("design:paramtypes", [InjectorService, PlatformApplication])], Platform);
|
|
2208
2208
|
|
|
2209
|
-
$log.name = "TSED";
|
|
2210
|
-
function createInjector(settings = {}) {
|
|
2211
|
-
const injector = new InjectorService();
|
|
2212
|
-
injector.addProvider(PlatformConfiguration);
|
|
2213
|
-
injector.settings = injector.invoke(PlatformConfiguration);
|
|
2214
|
-
injector.logger = $log;
|
|
2215
|
-
injector.settings.set(settings);
|
|
2216
|
-
setLoggerLevel(injector);
|
|
2217
|
-
return injector;
|
|
2218
|
-
}
|
|
2219
|
-
|
|
2220
|
-
function createPlatformApplication(injector) {
|
|
2221
|
-
injector.forkProvider(PlatformApplication);
|
|
2222
|
-
}
|
|
2223
|
-
|
|
2224
2209
|
/**
|
|
2225
|
-
* Inject the
|
|
2210
|
+
* Inject the Https.Server instance.
|
|
2226
2211
|
*
|
|
2227
2212
|
* ### Example
|
|
2228
2213
|
*
|
|
2229
2214
|
* ```typescript
|
|
2230
|
-
* import {
|
|
2215
|
+
* import {HttpsServer, Service} from "@tsed/common";
|
|
2231
2216
|
*
|
|
2232
2217
|
* @Service()
|
|
2233
2218
|
* export default class OtherService {
|
|
2234
|
-
* constructor(@
|
|
2219
|
+
* constructor(@HttpsServer httpServer: HttpServer) {}
|
|
2235
2220
|
* }
|
|
2236
2221
|
* ```
|
|
2237
2222
|
*
|
|
2238
|
-
* > 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.
|
|
2239
2224
|
*
|
|
2240
2225
|
* @param {Type<any>} target
|
|
2241
2226
|
* @param {string} targetKey
|
|
@@ -2244,8 +2229,8 @@ function createPlatformApplication(injector) {
|
|
|
2244
2229
|
* @decorator
|
|
2245
2230
|
*/
|
|
2246
2231
|
|
|
2247
|
-
function
|
|
2248
|
-
return Inject(
|
|
2232
|
+
function HttpsServer(target, targetKey, descriptor) {
|
|
2233
|
+
return Inject(HttpsServer)(target, targetKey, descriptor);
|
|
2249
2234
|
}
|
|
2250
2235
|
|
|
2251
2236
|
function listenServer(http, settings) {
|
|
@@ -2267,56 +2252,57 @@ function listenServer(http, settings) {
|
|
|
2267
2252
|
return promise;
|
|
2268
2253
|
}
|
|
2269
2254
|
|
|
2270
|
-
function
|
|
2271
|
-
injector.
|
|
2255
|
+
function createHttpsServer(injector) {
|
|
2256
|
+
injector.invoke(HttpsServer);
|
|
2272
2257
|
}
|
|
2273
2258
|
registerProvider({
|
|
2274
|
-
provide:
|
|
2275
|
-
deps: [PlatformApplication],
|
|
2259
|
+
provide: HttpsServer,
|
|
2260
|
+
deps: [PlatformApplication, Configuration],
|
|
2276
2261
|
scope: ProviderScope.SINGLETON,
|
|
2277
2262
|
global: true,
|
|
2278
2263
|
|
|
2279
|
-
useFactory(platformApplication) {
|
|
2280
|
-
|
|
2264
|
+
useFactory(platformApplication, settings) {
|
|
2265
|
+
const options = settings.httpsOptions;
|
|
2266
|
+
return Https.createServer(options, platformApplication.callback());
|
|
2281
2267
|
}
|
|
2282
2268
|
|
|
2283
2269
|
});
|
|
2284
|
-
async function
|
|
2270
|
+
async function listenHttpsServer(injector) {
|
|
2285
2271
|
const {
|
|
2286
2272
|
settings
|
|
2287
2273
|
} = injector;
|
|
2288
|
-
const server = injector.get(
|
|
2274
|
+
const server = injector.get(HttpsServer);
|
|
2289
2275
|
|
|
2290
|
-
if (settings.
|
|
2276
|
+
if (settings.httpsPort !== false && server) {
|
|
2291
2277
|
const {
|
|
2292
2278
|
address,
|
|
2293
2279
|
port
|
|
2294
|
-
} = settings.
|
|
2295
|
-
injector.logger.debug(`Start server on
|
|
2280
|
+
} = settings.getHttpsPort();
|
|
2281
|
+
injector.logger.debug(`Start server on https://${address}:${port}`);
|
|
2296
2282
|
const options = await listenServer(server, {
|
|
2297
2283
|
address,
|
|
2298
2284
|
port
|
|
2299
2285
|
});
|
|
2300
|
-
settings.
|
|
2301
|
-
injector.logger.info(`Listen server on
|
|
2286
|
+
settings.setHttpsPort(options);
|
|
2287
|
+
injector.logger.info(`Listen server on https://${options.address}:${options.port}`);
|
|
2302
2288
|
}
|
|
2303
2289
|
}
|
|
2304
2290
|
|
|
2305
2291
|
/**
|
|
2306
|
-
* Inject the
|
|
2292
|
+
* Inject the Http.Server instance.
|
|
2307
2293
|
*
|
|
2308
2294
|
* ### Example
|
|
2309
2295
|
*
|
|
2310
2296
|
* ```typescript
|
|
2311
|
-
* import {
|
|
2297
|
+
* import {HttpServer, Service} from "@tsed/common";
|
|
2312
2298
|
*
|
|
2313
2299
|
* @Service()
|
|
2314
2300
|
* export default class OtherService {
|
|
2315
|
-
* constructor(@
|
|
2301
|
+
* constructor(@HttpServer httpServer: HttpServer) {}
|
|
2316
2302
|
* }
|
|
2317
2303
|
* ```
|
|
2318
2304
|
*
|
|
2319
|
-
* > 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.
|
|
2320
2306
|
*
|
|
2321
2307
|
* @param {Type<any>} target
|
|
2322
2308
|
* @param {string} targetKey
|
|
@@ -2325,46 +2311,79 @@ async function listenHttpServer(injector) {
|
|
|
2325
2311
|
* @decorator
|
|
2326
2312
|
*/
|
|
2327
2313
|
|
|
2328
|
-
function
|
|
2329
|
-
return Inject(
|
|
2314
|
+
function HttpServer(target, targetKey, descriptor) {
|
|
2315
|
+
return Inject(HttpServer)(target, targetKey, descriptor);
|
|
2330
2316
|
}
|
|
2331
2317
|
|
|
2332
|
-
function
|
|
2333
|
-
injector.
|
|
2318
|
+
function createHttpServer(injector) {
|
|
2319
|
+
injector.invoke(HttpServer);
|
|
2334
2320
|
}
|
|
2335
2321
|
registerProvider({
|
|
2336
|
-
provide:
|
|
2337
|
-
deps: [PlatformApplication
|
|
2322
|
+
provide: HttpServer,
|
|
2323
|
+
deps: [PlatformApplication],
|
|
2338
2324
|
scope: ProviderScope.SINGLETON,
|
|
2339
2325
|
global: true,
|
|
2340
2326
|
|
|
2341
|
-
useFactory(platformApplication
|
|
2342
|
-
|
|
2343
|
-
return Https.createServer(options, platformApplication.callback());
|
|
2327
|
+
useFactory(platformApplication) {
|
|
2328
|
+
return Http.createServer(platformApplication.callback());
|
|
2344
2329
|
}
|
|
2345
2330
|
|
|
2346
2331
|
});
|
|
2347
|
-
async function
|
|
2332
|
+
async function listenHttpServer(injector) {
|
|
2348
2333
|
const {
|
|
2349
2334
|
settings
|
|
2350
2335
|
} = injector;
|
|
2351
|
-
const server = injector.get(
|
|
2336
|
+
const server = injector.get(HttpServer);
|
|
2352
2337
|
|
|
2353
|
-
if (settings.
|
|
2338
|
+
if (settings.httpPort !== false && server) {
|
|
2354
2339
|
const {
|
|
2355
2340
|
address,
|
|
2356
2341
|
port
|
|
2357
|
-
} = settings.
|
|
2358
|
-
injector.logger.debug(`Start server on
|
|
2342
|
+
} = settings.getHttpPort();
|
|
2343
|
+
injector.logger.debug(`Start server on http://${address}:${port}`);
|
|
2359
2344
|
const options = await listenServer(server, {
|
|
2360
2345
|
address,
|
|
2361
2346
|
port
|
|
2362
2347
|
});
|
|
2363
|
-
settings.
|
|
2364
|
-
injector.logger.info(`Listen server on
|
|
2348
|
+
settings.setHttpPort(options);
|
|
2349
|
+
injector.logger.info(`Listen server on http://${options.address}:${options.port}`);
|
|
2365
2350
|
}
|
|
2366
2351
|
}
|
|
2367
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
|
+
|
|
2368
2387
|
/**
|
|
2369
2388
|
* @ignore
|
|
2370
2389
|
* @deprecated User injector.load(container, module) instead
|
|
@@ -2505,19 +2524,6 @@ function getConfiguration(configuration = {}, module = null) {
|
|
|
2505
2524
|
return config;
|
|
2506
2525
|
}
|
|
2507
2526
|
|
|
2508
|
-
const DEFAULT_PROVIDERS = [{
|
|
2509
|
-
provide: PlatformHandler
|
|
2510
|
-
}, {
|
|
2511
|
-
provide: PlatformResponse
|
|
2512
|
-
}, {
|
|
2513
|
-
provide: PlatformRequest
|
|
2514
|
-
}, {
|
|
2515
|
-
provide: PlatformRouter
|
|
2516
|
-
}, {
|
|
2517
|
-
provide: PlatformApplication
|
|
2518
|
-
}, {
|
|
2519
|
-
provide: Platform
|
|
2520
|
-
}];
|
|
2521
2527
|
/**
|
|
2522
2528
|
* @platform
|
|
2523
2529
|
*/
|
|
@@ -2546,7 +2552,13 @@ class PlatformBuilder {
|
|
|
2546
2552
|
this.current = new Date();
|
|
2547
2553
|
this.name = name;
|
|
2548
2554
|
_classPrivateFieldLooseBase(this, _rootModule)[_rootModule] = module;
|
|
2549
|
-
|
|
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...");
|
|
2550
2562
|
}
|
|
2551
2563
|
|
|
2552
2564
|
get injector() {
|
|
@@ -2825,20 +2837,6 @@ class PlatformBuilder {
|
|
|
2825
2837
|
await this.callHook("$afterRoutesInit");
|
|
2826
2838
|
}
|
|
2827
2839
|
|
|
2828
|
-
createInjector(module, providers, settings) {
|
|
2829
|
-
const configuration = getConfiguration(settings, module);
|
|
2830
|
-
configuration.PLATFORM_NAME = this.name;
|
|
2831
|
-
_classPrivateFieldLooseBase(this, _injector)[_injector] = createInjector(configuration);
|
|
2832
|
-
providers = [...DEFAULT_PROVIDERS, ...providers];
|
|
2833
|
-
toMap(providers, "provide").forEach((provider, token) => {
|
|
2834
|
-
this.injector.addProvider(token, provider);
|
|
2835
|
-
});
|
|
2836
|
-
createPlatformApplication(this.injector);
|
|
2837
|
-
createHttpsServer(this.injector);
|
|
2838
|
-
createHttpServer(this.injector);
|
|
2839
|
-
this.log("Injector created...");
|
|
2840
|
-
}
|
|
2841
|
-
|
|
2842
2840
|
}
|
|
2843
2841
|
|
|
2844
2842
|
/**
|
|
@@ -3211,8 +3209,8 @@ function mapReturnedResponse(_ref) {
|
|
|
3211
3209
|
*/
|
|
3212
3210
|
|
|
3213
3211
|
class PlatformTest extends DITest {
|
|
3214
|
-
static async create(
|
|
3215
|
-
DITest.injector = PlatformTest.createInjector(getConfiguration(
|
|
3212
|
+
static async create(settings = {}) {
|
|
3213
|
+
DITest.injector = PlatformTest.createInjector(getConfiguration(settings));
|
|
3216
3214
|
const container = createContainer();
|
|
3217
3215
|
await DITest.injector.load(container);
|
|
3218
3216
|
}
|
|
@@ -3222,7 +3220,10 @@ class PlatformTest extends DITest {
|
|
|
3222
3220
|
|
|
3223
3221
|
|
|
3224
3222
|
static createInjector(settings = {}) {
|
|
3225
|
-
return createInjector(
|
|
3223
|
+
return createInjector({
|
|
3224
|
+
providers: [],
|
|
3225
|
+
settings: DITest.configure(settings)
|
|
3226
|
+
});
|
|
3226
3227
|
}
|
|
3227
3228
|
/**
|
|
3228
3229
|
* Load the server silently without listening port and configure it on test profile.
|
|
@@ -3406,5 +3407,5 @@ class PlatformTest extends DITest {
|
|
|
3406
3407
|
*/
|
|
3407
3408
|
class PlatformModule {}
|
|
3408
3409
|
|
|
3409
|
-
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,
|
|
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 };
|
|
3410
3411
|
//# sourceMappingURL=index.modern.js.map
|