Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as Express from "express";
import {ServerSettingsService, Service, ExpressApplication} from "@tsed/common";
@Service()
export class ServeStaticService {
constructor(@ExpressApplication private expressApp: Express.Application, private serverSettingsService: ServerSettingsService) {}
$afterRoutesInit() {
/* istanbul ignore else */
if (require.resolve("serve-static")) {
Object.keys(this.serverSettingsService.serveStatic).forEach(path => {
[].concat(this.serverSettingsService.serveStatic[path] as any).forEach((directory: string) => this.mount(path, directory));
});
}
}
mount(path: string, directory: string) {
const serveStatic = require("serve-static");
const middleware = serveStatic(directory);
this.expressApp.use(path, (request: any, response: any, next: any) => {
ServerSettingsService,
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";
import {PROVIDER_TYPE_SOCKET_SERVICE} from "../registries/SocketServiceRegistry";
/**
*
*/
@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,
import {Service} from "@tsed/common";
@Service()
export class TokenService {
private _token: string = "EMPTY";
token(token?: string) {
if (token) {
this._token = token;
}
return this._token;
}
isValid(token: string | undefined) {
return String(token).match(/token/);
}
}
import {Controller, Get, InjectorService, ParseService, Service} from "@tsed/common";
import {bootstrap, inject, TestContext} from "@tsed/testing";
import {expect} from "chai";
import * as Sinon from "sinon";
import {AcceptMimesMiddleware} from "../../packages/common/src/mvc/components/AcceptMimesMiddleware";
import {Hidden} from "../../packages/swagger/src";
import {CalendarCtrl} from "./app/controllers/calendars/CalendarCtrl";
import {FakeServer} from "./app/FakeServer";
@Service()
class DbService {
async getData() {
return {data: "data"};
}
}
@Controller("/testMyCtrl")
@Hidden()
export class MyCtrl {
constructor(private dbService: DbService) {
}
@Get("/")
public getData() {
return this.dbService.getData();
}
import {Constant, OnInit, Service} from "@tsed/common";
import {ConnectionOptions} from "typeorm";
import {TypeORMService} from "./services/TypeORMService";
@Service()
export class TypeORMModule implements OnInit {
@Constant("typeorm", {})
private settings: {[key: string]: ConnectionOptions};
constructor(private typeORMService: TypeORMService) {}
$onInit(): Promise | void {
const promises = Object.keys(this.settings).map(key => this.typeORMService.createConnection(key, this.settings[key]));
return Promise.all(promises);
}
}
import {Inject, Service} from "@tsed/common";
import {MongooseModel} from "@tsed/mongoose";
import {$log} from "ts-log-debug";
import {Calendar} from "../../models/calendars/Calendar";
@Service()
export class CalendarsService {
@Inject(Calendar)
private Calendar: MongooseModel;
$onInit() {
this.reload();
}
async reload() {
const calendars = await this.Calendar.find({});
if (calendars.length === 0) {
const promises = require("../../../resources/calendars.json").map(calendar => this.save(calendar));
await Promise.all(promises);
}
}
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) {}
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 {Service} from "@tsed/common";
import {NotFound} from "ts-httpexceptions";
import {Calendar} from "../../interfaces/Calendar";
import {MemoryStorage} from "../storage/MemoryStorage";
@Service()
export class CalendarsService {
constructor(private memoryStorage: MemoryStorage) {
this.memoryStorage.set("calendars", require("../../../resources/calendars.json"));
}
/**
* Find a calendar by his ID.
* @param id
* @returns {undefined|Calendar}
*/
async find(id: string): Promise {
const calendars: Calendar[] = await this.query();
return calendars.find(calendar => calendar.id === id);
}
/**
import {Service} from "@tsed/common";
import {IUser} from "../../interfaces/User";
import {MemoryStorage} from "../storage/MemoryStorage";
@Service()
export class UsersService {
constructor(private memoryStorage: MemoryStorage) {
this.memoryStorage.set("users", require("../../../resources/users.json"));
}
async find(id: string) {
const users: IUser[] = await this.query();
return users.find((value: IUser) => value._id === id);
}
async findByEmail(email: string) {
const users: IUser[] = await this.query();
return users.find((value: IUser) => value.email === email);
}
async findByCredential(email: string, password: string) {