Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Dependencies, Container } from 'constitute';
import * as _ from 'lodash';
import { Logger } from '../../shared/logger';
@Dependencies(Container)
export class Statistics {
constructor(container) {
const StatisticsDb = require('./statistics.db').StatisticsDb;
try {
container.schedulePostConstructor((statisticsDb) => {
this.statisticsDb = statisticsDb;
}, [StatisticsDb]);
} catch (e) {
Logger.error('Statistics', e);
}
}
// clear current variables and set new
init(opts) {
this._id = undefined;
this.stats = undefined;
bodyLength > maxBodyLength ? TOO_LONG_BODY : res.body || ''
);
}).on('redirect', function () {
logger.verbose('[HTTP_REDIRECT_%s] [%s %s] [%s] [RES_HEADERS: %s] [RES_BODY: %s]', this._debugId,
this.method.toUpperCase(), this.uri.href, this.response.statusCode, JSON.stringify(ignoreDebug(this.response.headers)), '');
});
this._debugId = ++debugId;
return proto._initBeforeDebug.apply(this, arguments);
};
debugFlag = true;
};
/* eslint-enable */
@Dependencies(Config, Logger) //eslint-disable-line new-cap
export default class HttpClient extends ServiceInterface {
/**
* @param config {Config}
* @param logger {Logger}
*/
constructor(config, logger) {
super();
this.config = config.get();
this.client = request;
requestDebug(logger);
}
getProto() {
return request;
}
import { ItemGenerator } from '../../shared/item-generator';
import { MonsterGenerator } from '../../shared/monster-generator';
import { ShopGenerator } from '../../shared/shop-generator';
import { DataUpdater } from '../../shared/data-updater';
import { EventHandler } from '../events/eventhandler';
import { FindItem } from '../events/events/FindItem';
import * as Events from '../events/events/_all';
import * as Achievements from '../achievements/achievements/_all';
import { DirtyChecker } from './player.dirtychecker';
import { emitter } from './_emitter';
@Dependencies(PlayerDb)
export class Player extends Character {
constructor(playerDb) {
super();
this.$playerDb = playerDb;
this.$playerMovement = PlayerMovement;
this.$itemGenerator = ItemGenerator;
this.$dataUpdater = DataUpdater;
}
init(opts, save = true) {
this.$dirty = new DirtyChecker();
this.$canSave = save;
super.init(opts);
if(!this.joinDate) this.joinDate = Date.now();
import Ioredis from 'ioredis';
import { Dependencies } from 'constitute';
import Config from './config';
import ServiceInterface from './interface';
let redisClient = null;
@Dependencies(Config) //eslint-disable-line new-cap
export default class Redis extends ServiceInterface {
/**
* @param config Config
*/
constructor(config) {
super();
this.config = config;
this.options = null;
}
getProto() {
return Ioredis;
}
getRedis() {
return Ioredis;
}
set(key, value, minutes) {
return minutes ?
this.redis
.set(this.key(key), JSON.stringify(value), 'ex', minutes * 60) :
this.redis
.set(this.key(key), JSON.stringify(value));
}
flush() {
return this.redis.flushall();
}
}
@Dependencies(Config, Redis) //eslint-disable-line new-cap
export default class Cache extends ServiceInterface {
constructor(config) {
super();
this.config = config.get('cache');
this.prefix = this.config.prefix || 'eva';
this.driver = this.config.driver;
this.store = null;
}
setStore(store) {
this.store = store;
return this;
}
/**
* @returns {Store}
getContext() {
return getNamespace(this.name);
}
createContext() {
return getNamespace(this.name).createContext();
}
reset() {
reset(this.name);
return this;
}
}
@Dependencies(Config) //eslint-disable-line new-cap
export default class Namespace extends ServiceInterface {
/**
* @param config {Config}
*/
constructor(config) {
super();
this.config = config.get('namespace');
this.defaultName = config.defaultName || 'eva.ns';
this.store = null;
this.name = null;
}
isEnabled() {
return this.config.enable;
}
import { Dependencies } from 'constitute';
import jwt from 'jwt-simple';
import Config from './config';
import Redis from './redis';
import ServiceInterface from './interface';
@Dependencies(Config, Redis) //eslint-disable-line new-cap
export default class JsonWebToken extends ServiceInterface {
/**
* @param config {Config}
* @param redis {Redis}
*/
constructor(config, redis) {
super();
this.redis = redis.getInstance();
this.config = config.get('token');
}
getProto() {
return jwt;
}
getRedis() {
import { Dependencies } from 'constitute';
import moment from 'moment-timezone';
import winston from 'winston';
import { inspect } from 'util';
import Env from './env';
import Config from './config';
import Namespace from './namespace';
import ServiceInterface from './interface';
@Dependencies(Env, Config, Namespace) //eslint-disable-line new-cap
export default class Logger extends ServiceInterface {
/**
* @param env {Env}
* @param config {Config}
* @param namespace {Namespace}
*/
constructor(env, config, namespace) {
super();
this.env = env;
this.config = config;
this.namespace = namespace;
let level = env.isProduction() ? 'info' : 'debug';
if (process.env.LOG_LEVEL) {
level = process.env.LOG_LEVEL;
}
import _ from 'lodash';
import { Dependencies } from 'constitute';
import springConfigClient from 'cloud-config-client';
import Env from './env';
import EngineConfig from '../config';
import ServiceInterface from './interface';
let config = null;
@Dependencies(Env) //eslint-disable-line new-cap
export default class Config extends ServiceInterface {
/**
* @param env {Env}
*/
constructor(env) {
super();
this.env = env;
this.path = null;
this.mergedFiles = [];
}
setPath(path) {
this.path = path;
return this;
}
import { Dependencies } from 'constitute';
import HttpClient from './http_client';
import Namespace from './namespace';
import { RestServiceLogicException, RestServiceIOException } from '../exceptions';
import ServiceInterface from './interface';
@Dependencies(HttpClient, Namespace) //eslint-disable-line new-cap
export default class RestClient extends ServiceInterface {
/**
* @param {HttpClient} client
* @param {Namespace} ns
*/
constructor(client, ns) {
super();
this.client = client;
this.ns = ns;
this.baseUrl = null;
}
setBaseUrl(baseUrl) {
this.baseUrl = baseUrl;
return this;
}