Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Deprecated, ProxyMap, Type} from "@tsed/core";
import {Provider, Service, ProviderType, InjectorService} from "@tsed/di";
import {UnknowFilterError} from "../errors/UnknowFilterError";
import {IFilter} from "../interfaces";
import {FilterRegistry} from "../registries/FilterRegistry";
/**
* @deprecated This service will be removed in a future release. Use injectorService directly.
*/
@Service()
export class FilterService extends ProxyMap | any, Provider> {
constructor(private injectorService: InjectorService) {
super(injectorService, {filter: {type: ProviderType.FILTER}});
}
/**
*
* @param target
* @returns {ControllerProvider}
*/
@Deprecated("static FilterService.get(). Removed feature.")
/* istanbul ignore next */
static get(target: Type): Provider | undefined {
return FilterRegistry.get(target);
}
import {Deprecated, ProxyMap, Type} from "@tsed/core";
import {Provider, Service, ProviderType, ProviderRegistry, InjectorService} from "@tsed/di";
import {UnknowMiddlewareError} from "../errors/UnknowMiddlewareError";
import {IMiddleware} from "../interfaces";
/**
* @deprecated This service will be removed in a future release. Use injectorService directly.
*/
@Service()
export class MiddlewareService extends ProxyMap | any, Provider> {
constructor(private injectorService: InjectorService) {
super(injectorService, {filter: {type: ProviderType.MIDDLEWARE}});
}
/**
*
* @param target
* @returns {Provider}
* @deprecated
*/
@Deprecated("static MiddlewareService.get(). Removed feature.")
/* istanbul ignore next */
static get(target: Type): Provider | undefined {
return ProviderRegistry.get(target);
}
import {Service} from "@tsed/di";
import * as Express from "express";
import {IServerMountDirectories} from "../../config";
import {ExpressApplication} from "../decorators/expressApplication";
@Service()
export class ServeStaticService {
constructor(@ExpressApplication private expressApp: Express.Application) {}
statics(statics: IServerMountDirectories) {
/* istanbul ignore else */
Object.keys(statics).forEach(path => {
[].concat(statics[path] as any).forEach((directory: string) => this.mount(path, directory));
});
}
mount(path: string, directory: string) {
const middleware = Express.static(directory);
this.expressApp.use(path, (request: any, response: any, next: any) => {
if (!response.headersSent) {
middleware(request, response, next);
} else {
import {Deprecated, ProxyMap, Type} from "@tsed/core";
import {Configuration, Injectable, InjectorService, ProviderScope, ProviderType} from "@tsed/di";
import {ControllerProvider} from "../models/ControllerProvider";
import {ControllerRegistry} from "../registries/ControllerRegistry";
import {IRouteController, RouteService} from "./RouteService";
/**
* @private
* @deprecated
*/
@Injectable({
scope: ProviderScope.SINGLETON,
global: true
})
export class ControllerService extends ProxyMap | any, ControllerProvider> {
constructor(
private injectorService: InjectorService,
@Configuration() private settings: Configuration,
private routeService: RouteService
) {
super(injectorService as any, {filter: {type: ProviderType.CONTROLLER}});
}
/**
* @deprecated
*/
/* istanbul ignore next */
const rootDir = process.cwd();
/**
* @deprecated
*/
export let globalServerSettings: ServerSettingsService;
/**
* @deprecated
*/
// tslint:disable-next-line: variable-name
export let GlobalServerSettings: ServerSettingsService;
/**
* `ServerSettingsService` contains all information about [ServerLoader](/api/common/server/components/ServerLoader.md) configuration.
*/
@Injectable({
scope: ProviderScope.SINGLETON,
global: true
})
export class ServerSettingsService implements IServerSettings, IDISettings {
protected map = new Map();
constructor() {
this.rootDir = rootDir;
this.env = (process.env.NODE_ENV as Env) || Env.DEV;
this.port = 8080;
this.httpsPort = 8000;
this.version = "1.0.0";
this.uploadDir = "${rootDir}/uploads";
this.controllerScope = ProviderScope.SINGLETON;
this.logger = {
debug: false,
level: "info",
export function createInjector(settings: any = {}) {
const injector = new InjectorService();
// Init settings
injector.settings = createSettingsService(injector);
injector.logger = $log;
injector.settings.scopes = {
...(settings.scopes || {}),
[ProviderType.CONTROLLER]: settings.controllerScope
};
// @ts-ignore
injector.settings.set(settings);
/* istanbul ignore next */
if (injector.settings.env === "test") {
injector.logger.stop();
}
return injector;
}
import {GlobalProviders, ProviderType, TypedProvidersRegistry} from "@tsed/di";
import {ControllerProvider} from "../models/ControllerProvider";
import {ExpressRouter} from "../services/ExpressRouter";
// tslint:disable-next-line: variable-name
export const ControllerRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(ProviderType.CONTROLLER, ControllerProvider, {
injectable: false,
onInvoke(provider: ControllerProvider, locals: any) {
locals.set(ExpressRouter, provider.router);
}
});
* }
*
* registerMiddleware({provide: FooMiddleware});
* // or
* registerMiddleware(FooMiddleware);
*
* const injector = new InjectorService()
* injector.load();
*
* const myFooService = injector.get(FooMiddleware);
* fooMiddleware.use(); // test
* ```
*
* @param provider Provider configuration.
*/
export const registerMiddleware = GlobalProviders.createRegisterFn(ProviderType.MIDDLEWARE);
import {GlobalProviders, Provider, ProviderType, TypedProvidersRegistry} from "@tsed/di";
/**
*
* @type {Registry, Provider>}
*/
// tslint:disable-next-line: variable-name
export const MiddlewareRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(ProviderType.MIDDLEWARE, Provider, {
injectable: true,
buildable: true
});
/**
* Add a new middleware in the `ProviderRegistry`. This middleware will be built when `InjectorService` will be loaded.
*
* #### Example
*
* ```typescript
* import {registerMiddleware, InjectorService} from "@tsed/common";
*
* export default class FooMiddleware {
* constructor(){}
* use() {
* return "test";
* }
import {Provider, ProviderType, TypedProvidersRegistry, GlobalProviders} from "@tsed/di";
/**
*
* @type {Registry, IProvider>}
*/
// tslint:disable-next-line: variable-name
export const InterceptorRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(ProviderType.INTERCEPTOR, Provider, {
injectable: true,
buildable: true
});
/**
* Add a new interceptor in the `ProviderRegistry`. This interceptor will be built when `InjectorService` will be loaded.
*
* #### Example
*
* ```typescript
* import {registerInterceptor, InjectorService} from "@tsed/common";
*
* export default class MyInterceptor {
* constructor(){}
* aroundInvoke() {
* return "test";
* }