How to use the @tsed/common.Constant function in @tsed/common

To help you get started, we’ve selected a few @tsed/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / packages / socketio / src / SocketIOModule.ts View on Github external
import {AfterListen, Constant, HttpServer, HttpsServer, Inject, InjectorService, Module, Provider} from "@tsed/common";
import {nameOf} from "@tsed/core";
import * as SocketIO from "socket.io"; // tslint:disable-line: no-unused-variable
import {$log} from "ts-log-debug";
import {IO} from "./decorators/io";
import {ISocketProviderMetadata} from "./interfaces/ISocketProviderMetadata";
import {PROVIDER_TYPE_SOCKET_SERVICE} from "./registries/SocketServiceRegistry";
import {SocketIOService} from "./services/SocketIOService";

@Module()
export class SocketIOModule implements AfterListen {
  @Constant("logger.disableRoutesSummary", false)
  disableRoutesSummary: boolean;

  @Constant("socketIO", {})
  settings: SocketIO.ServerOptions;

  @Constant("httpPort")
  httpPort: string | number;

  @Constant("httpsPort")
  httpsPort: string | number;

  constructor(
    private injector: InjectorService,
    @Inject(HttpServer) private httpServer: HttpServer,
    @Inject(HttpsServer) private httpsServer: HttpsServer,
    @IO private io: SocketIO.Server,
github TypedProject / ts-express-decorators / src / socketio / services / SocketIOService.ts View on Github external
Service,
  Constant
} from "@tsed/common";
import {nameOf} from "@tsed/core";
import * as SocketIO from "socket.io"; // tslint:disable-line: no-unused-variable
import {$log} from "ts-log-debug";
import {SocketHandlersBuilder} from "../class/SocketHandlersBuilder";
import {IO} from "../decorators/io";
import {ISocketProviderMetadata} from "../interfaces/ISocketProviderMetadata";

/**
 *
 */
@Service()
export class SocketIOService implements OnServerReady {
  @Constant("logger.disableRoutesSummary", false)
  disableRoutesSummary: boolean;

  /**
   *
   * @type {Map}
   */
  private namespaces: Map = new Map();

  constructor(
    private injector: InjectorService,
    @Inject(HttpServer) private httpServer: HttpServer,
    @Inject(HttpsServer) private httpsServer: HttpsServer,
    @IO private io: SocketIO.Server,
    private serverSettingsService: ServerSettingsService,
    private converterService: ConverterService
  ) {}
github TypedProject / ts-express-decorators / packages / socketio / src / SocketIOModule.ts View on Github external
import {AfterListen, Constant, HttpServer, HttpsServer, Inject, InjectorService, Module, Provider} from "@tsed/common";
import {nameOf} from "@tsed/core";
import * as SocketIO from "socket.io"; // tslint:disable-line: no-unused-variable
import {$log} from "ts-log-debug";
import {IO} from "./decorators/io";
import {ISocketProviderMetadata} from "./interfaces/ISocketProviderMetadata";
import {PROVIDER_TYPE_SOCKET_SERVICE} from "./registries/SocketServiceRegistry";
import {SocketIOService} from "./services/SocketIOService";

@Module()
export class SocketIOModule implements AfterListen {
  @Constant("logger.disableRoutesSummary", false)
  disableRoutesSummary: boolean;

  @Constant("socketIO", {})
  settings: SocketIO.ServerOptions;

  @Constant("httpPort")
  httpPort: string | number;

  @Constant("httpsPort")
  httpsPort: string | number;

  constructor(
    private injector: InjectorService,
    @Inject(HttpServer) private httpServer: HttpServer,
    @Inject(HttpsServer) private httpsServer: HttpsServer,
    @IO private io: SocketIO.Server,
    private socketIOService: SocketIOService
  ) {}
github TypedProject / ts-express-decorators / packages / graphql / src / GraphQLModule.ts View on Github external
import {AfterListen, Constant, Injectable, OnInit, ServerSettingsService} from "@tsed/common";
import {$log} from "ts-log-debug";
import {IGraphQLSettings} from "./interfaces/IGraphQLSettings";
import {GraphQLService} from "./services/GraphQLService";

@Injectable()
export class GraphQLModule implements OnInit, AfterListen {
  @Constant("graphql", {})
  private settings: {[key: string]: IGraphQLSettings};

  constructor(private graphQLService: GraphQLService, private serverSettingsService: ServerSettingsService) {}

  $onInit(): Promise | void {
    const promises = Object.keys(this.settings).map(async key => this.graphQLService.createServer(key, this.settings[key]));

    return Promise.all(promises);
  }

  $afterListen(): Promise | void {
    const host = this.serverSettingsService.getHttpPort();

    Object.keys(this.settings).map(async key => {
      const {path} = this.settings[key];
      $log.info(`[${key}] GraphQL server is available on http://${host.address}:${host.port}/${path.replace(/^\//, "")}`);
github TypedProject / ts-express-decorators / src / mongoose / services / MongooseService.ts View on Github external
import {AfterRoutesInit, Constant, ExpressApplication, OnInit, Service} from "@tsed/common";
import * as Mongoose from "mongoose";
import {$log} from "ts-log-debug";
import {MDBConnection} from "../interfaces/MDBConnection";
import {ValidationErrorMiddleware} from "../middlewares/ValidationErrorMiddleware";

@Service()
export class MongooseService implements OnInit, AfterRoutesInit {
  @Constant("mongoose.url") private url: string;

  @Constant("mongoose.connectionOptions") private connectionOptions: Mongoose.ConnectionOptions;

  @Constant("mongoose.urls") private urls: {[key: string]: MDBConnection};

  /**
   *
   * @type {Map}
   * @private
   */
  private _instances: Map = new Map();

  constructor(@ExpressApplication private expressApp: ExpressApplication) {}

  $onInit(): Promise | void {
    const promises: Promise[] = [];
github TypedProject / ts-express-decorators / packages / passport / src / PassportModule.ts View on Github external
import {BeforeRoutesInit, Constant, ExpressApplication, Module, OnInit, Provider, ProviderScope} from "@tsed/common";

import * as Passport from "passport";
import {ProtocolRegistry} from "./registries/ProtocolRegistries";
import {PassportSerializerService} from "./services/PassportSerializerService";
import {ProtocolsService} from "./services/ProtocolsService";

@Module({
  scope: ProviderScope.SINGLETON
})
export class PassportModule implements OnInit, BeforeRoutesInit {
  @Constant("passport.userProperty")
  userProperty: string;

  @Constant("passport.pauseStream")
  pauseStream: boolean;

  constructor(
    @ExpressApplication private expressApplication: ExpressApplication,
    private protocolsService: ProtocolsService,
    private passportSerializer: PassportSerializerService
  ) {}

  $onInit(): Promise | void {
    Passport.serializeUser(this.passportSerializer.serialize.bind(this.passportSerializer));
    Passport.deserializeUser(this.passportSerializer.deserialize.bind(this.passportSerializer));

    ProtocolRegistry.forEach((provider: Provider) => this.protocolsService.invoke(provider));

    return undefined;
  }
github TypedProject / ts-express-decorators / packages / passport / src / PassportModule.ts View on Github external
import {BeforeRoutesInit, Constant, ExpressApplication, Module, OnInit, Provider, ProviderScope} from "@tsed/common";

import * as Passport from "passport";
import {ProtocolRegistry} from "./registries/ProtocolRegistries";
import {PassportSerializerService} from "./services/PassportSerializerService";
import {ProtocolsService} from "./services/ProtocolsService";

@Module({
  scope: ProviderScope.SINGLETON
})
export class PassportModule implements OnInit, BeforeRoutesInit {
  @Constant("passport.userProperty")
  userProperty: string;

  @Constant("passport.pauseStream")
  pauseStream: boolean;

  constructor(
    @ExpressApplication private expressApplication: ExpressApplication,
    private protocolsService: ProtocolsService,
    private passportSerializer: PassportSerializerService
  ) {}

  $onInit(): Promise | void {
    Passport.serializeUser(this.passportSerializer.serialize.bind(this.passportSerializer));
    Passport.deserializeUser(this.passportSerializer.deserialize.bind(this.passportSerializer));

    ProtocolRegistry.forEach((provider: Provider) => this.protocolsService.invoke(provider));
github TypedProject / ts-express-decorators / packages / graphql / src / services / GraphQLService.ts View on Github external
import {Constant, ExpressApplication, HttpServer, InjectorService, Provider, Service} from "@tsed/common";
import {Type} from "@tsed/core";
import {DataSource} from "apollo-datasource";
import {ApolloServer} from "apollo-server-express";
import {GraphQLSchema} from "graphql";
import {$log} from "ts-log-debug";
import * as typeGraphql from "type-graphql";
import {buildSchema, BuildSchemaOptions} from "type-graphql";
import {IGraphQLServer} from "../interfaces/IGraphQLServer";
import {IGraphQLSettings} from "../interfaces/IGraphQLSettings";
import {PROVIDER_TYPE_DATASOURCE_SERVICE} from "../registries/DataSourceServiceRegistry";
import {PROVIDER_TYPE_RESOLVER_SERVICE} from "../registries/ResolverServiceRegistry";

@Service()
export class GraphQLService {
  @Constant("httpPort")
  httpPort: string | number;
  /**
   *
   * @type {Map}
   * @private
   */
  private _servers: Map = new Map();

  constructor(
    @ExpressApplication private expressApp: ExpressApplication,
    @HttpServer private httpServer: HttpServer,
    private injectorService: InjectorService
  ) {}

  /**
   *
github TypedProject / ts-express-decorators / docs / docs / snippets / middlewares / global-middleware.ts View on Github external
import {Constant, IMiddleware, Middleware, Req} from "@tsed/common";
import {NotAcceptable} from "ts-httpexceptions";

@Middleware()
export default class GlobalAcceptMimesMiddleware implements IMiddleware {
  @Constant("acceptMimes")
  acceptMimes: string[];

  use(@Req() request: Req) {
    this.acceptMimes
      .forEach((mime) => {
        if (!request.accepts(mime)) {
          throw new NotAcceptable(mime);
        }
      });
  }
}
github TypedProject / ts-express-decorators / examples / getting-started / src / services / calendars / CalendarsService.ts View on Github external
import {Constant, Service} from "@tsed/common";
import {NotFound} from "ts-httpexceptions";
import {Calendar, CreateCalendar} from "../../models/Calendar";
import {MemoryStorage} from "../storage/MemoryStorage";

@Service()
export class CalendarsService {

  @Constant("calendar.token")
  useToken: boolean;

  constructor(private memoryStorage: MemoryStorage) {
    this.memoryStorage.set("calendars", require("../../../resources/calendars.json").map((o) => {
      return Object.assign(new Calendar, o);
    }));
  }

  /**
   * Find a calendar by his ID.
   * @param id
   * @returns {undefined|Calendar}
   */
  async find(id: string): Promise {
    const calendars: Calendar[] = await this.query();