Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
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
) {}
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
) {}
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(/^\//, "")}`);
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[] = [];
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;
}
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));
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
) {}
/**
*
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);
}
});
}
}
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();