diff --git a/.gitignore b/.gitignore index 2d2b47d..76fb2e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -node_modules \ No newline at end of file +node_modules +dist \ No newline at end of file diff --git a/dist/Application.d.ts b/dist/Application.d.ts deleted file mode 100644 index 6e32dfe..0000000 --- a/dist/Application.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import WebSocketListener from "./WebSocketListener"; -import ApplicationComponent from "./ApplicationComponent"; -import Controller from "./Controller"; -export default abstract class Application { - private readonly version; - private readonly controllers; - private readonly webSocketListeners; - private readonly components; - private ready; - protected constructor(version: string); - protected abstract init(): Promise; - protected use(thing: Controller | WebSocketListener | ApplicationComponent): void; - start(): Promise; - stop(): Promise; - private routes; - getWebSocketListeners(): { - [p: string]: WebSocketListener; - }; - isReady(): boolean; -} diff --git a/dist/Application.js b/dist/Application.js deleted file mode 100644 index 2552ede..0000000 --- a/dist/Application.js +++ /dev/null @@ -1,140 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import express from 'express'; -import { BadRequestError, HttpError, NotFoundHttpError, ServerError, ServiceUnavailableHttpError } from "./HttpError"; -import { lib } from "nunjucks"; -import Logger from "./Logger"; -import WebSocketListener from "./WebSocketListener"; -var TemplateError = lib.TemplateError; -import Controller from "./Controller"; -export default class Application { - constructor(version) { - this.controllers = []; - this.webSocketListeners = {}; - this.components = []; - this.ready = false; - this.version = version; - } - use(thing) { - if (thing instanceof Controller) { - this.controllers.push(thing); - } - else if (thing instanceof WebSocketListener) { - const path = thing.path(); - this.webSocketListeners[path] = thing; - Logger.info(`Added websocket listener on ${path}`); - } - else { - this.components.push(thing); - } - } - start() { - return __awaiter(this, void 0, void 0, function* () { - Logger.info(`${this.constructor.name} v${this.version} - hi`); - process.once('SIGINT', () => { - this.stop().catch(console.error); - }); - // Register all components and alike - yield this.init(); - // Init express - const app = express(); - const router = express.Router({}); - app.use(router); - // Error handler - app.use((err, req, res, next) => { - if (res.headersSent) { - return next(err); - } - let errorID; - let logStr = `${req.method} ${req.originalUrl} - `; - if (err instanceof BadRequestError || err instanceof ServiceUnavailableHttpError) { - logStr += `${err.errorCode} ${err.name}`; - errorID = Logger.silentError(err, logStr); - } - else { - errorID = Logger.error(err, logStr + `500 Internal Error`, err); - } - let httpError; - if (err instanceof HttpError) { - httpError = err; - } - else if (err instanceof TemplateError && err.cause instanceof HttpError) { - httpError = err.cause; - } - else { - httpError = new ServerError('Internal server error.', err); - } - res.status(httpError.errorCode); - res.format({ - html: () => { - res.render('errors/' + httpError.errorCode + '.njk', { - error_code: httpError.errorCode, - error_message: httpError.message, - error_instructions: httpError.instructions, - error_id: errorID, - }); - }, - json: () => { - res.json({ - status: 'error', - code: httpError.errorCode, - message: httpError.message, - instructions: httpError.instructions, - error_id: errorID, - }); - }, - default: () => { - res.type('txt').send(`${httpError.errorCode} - ${httpError.message}\n\n${httpError.instructions}\n\nError ID: ${errorID}`); - } - }); - }); - // Start all components - for (const component of this.components) { - yield component.start(app, router); - } - // Routes - this.routes(router); - this.ready = true; - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - Logger.info('Stopping application...'); - for (const component of this.components) { - yield component.stop(); - } - Logger.info(`${this.constructor.name} v${this.version} - bye`); - }); - } - routes(rootRouter) { - for (const controller of this.controllers) { - if (controller.hasGlobalHandlers()) { - controller.setupGlobalHandlers(rootRouter); - Logger.info(`Registered global middlewares for controller ${controller.constructor.name}`); - } - } - for (const controller of this.controllers) { - const router = express.Router(); - controller.setupRoutes(router); - rootRouter.use(controller.getRoutesPrefix(), router); - Logger.info(`> Registered routes for controller ${controller.constructor.name}`); - } - rootRouter.use((req) => { - throw new NotFoundHttpError('page', req.originalUrl); - }); - } - getWebSocketListeners() { - return this.webSocketListeners; - } - isReady() { - return this.ready; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQXBwbGljYXRpb24uanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbIkFwcGxpY2F0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sT0FBa0QsTUFBTSxTQUFTLENBQUM7QUFDekUsT0FBTyxFQUNILGVBQWUsRUFDZixTQUFTLEVBQ1QsaUJBQWlCLEVBQ2pCLFdBQVcsRUFDWCwyQkFBMkIsRUFDOUIsTUFBTSxhQUFhLENBQUM7QUFDckIsT0FBTyxFQUFDLEdBQUcsRUFBQyxNQUFNLFVBQVUsQ0FBQztBQUM3QixPQUFPLE1BQU0sTUFBTSxVQUFVLENBQUM7QUFDOUIsT0FBTyxpQkFBaUIsTUFBTSxxQkFBcUIsQ0FBQztBQUVwRCxJQUFPLGFBQWEsR0FBRyxHQUFHLENBQUMsYUFBYSxDQUFDO0FBQ3pDLE9BQU8sVUFBVSxNQUFNLGNBQWMsQ0FBQztBQUV0QyxNQUFNLENBQUMsT0FBTyxPQUFnQixXQUFXO0lBUXJDLFlBQXNCLE9BQWU7UUFOcEIsZ0JBQVcsR0FBaUIsRUFBRSxDQUFDO1FBQy9CLHVCQUFrQixHQUF1QyxFQUFFLENBQUM7UUFDNUQsZUFBVSxHQUFnQyxFQUFFLENBQUM7UUFFdEQsVUFBSyxHQUFZLEtBQUssQ0FBQztRQUczQixJQUFJLENBQUMsT0FBTyxHQUFHLE9BQU8sQ0FBQztJQUMzQixDQUFDO0lBSVMsR0FBRyxDQUFDLEtBQWlFO1FBQzNFLElBQUksS0FBSyxZQUFZLFVBQVUsRUFBRTtZQUM3QixJQUF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hdCh7XG4gICAgICAgICAgICAgICAgaHRtbDogKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICByZXMucmVuZGVyKCdlcnJvcnMvJyArIGh0dHBFcnJvci5lcnJvckNvZGUgKyAnLm5qaycsIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGVycm9yX2NvZGU6IGh0dHBFcnJvci5lcnJvckNvZGUsXG4gICAgICAgICAgICAgICAgICAgICAgICBlcnJvcl9tZXNzYWdlOiBodHRwRXJyb3IubWVzc2FnZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGVycm9yX2luc3RydWN0aW9uczogaHR0cEVycm9yLmluc3RydWN0aW9ucyxcbiAgICAgICAgICAgICAgICAgICAgICAgIGVycm9yX2lkOiBlcnJvcklELFxuICAgICAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIGpzb246ICgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgcmVzLmpzb24oe1xuICAgICAgICAgICAgICAgICAgICAgICAgc3RhdHVzOiAnZXJyb3InLFxuICAgICAgICAgICAgICAgICAgICAgICAgY29kZTogaHR0cEVycm9yLmVycm9yQ29kZSxcbiAgICAgICAgICAgICAgICAgICAgICAgIG1lc3NhZ2U6IGh0dHBFcnJvci5tZXNzYWdlLFxuICAgICAgICAgICAgICAgICAgICAgICAgaW5zdHJ1Y3Rpb25zOiBodHRwRXJyb3IuaW5zdHJ1Y3Rpb25zLFxuICAgICAgICAgICAgICAgICAgICAgICAgZXJyb3JfaWQ6IGVycm9ySUQsXG4gICAgICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgZGVmYXVsdDogKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICByZXMudHlwZSgndHh0Jykuc2VuZChgJHtodHRwRXJyb3IuZXJyb3JDb2RlfSAtICR7aHR0cEVycm9yLm1lc3NhZ2V9XFxuXFxuJHtodHRwRXJyb3IuaW5zdHJ1Y3Rpb25zfVxcblxcbkVycm9yIElEOiAke2Vycm9ySUR9YCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuXG4gICAgICAgIC8vIFN0YXJ0IGFsbCBjb21wb25lbnRzXG4gICAgICAgIGZvciAoY29uc3QgY29tcG9uZW50IG9mIHRoaXMuY29tcG9uZW50cykge1xuICAgICAgICAgICAgYXdhaXQgY29tcG9uZW50LnN0YXJ0KGFwcCwgcm91dGVyKTtcbiAgICAgICAgfVxuXG4gICAgICAgIC8vIFJvdXRlc1xuICAgICAgICB0aGlzLnJvdXRlcyhyb3V0ZXIpO1xuXG4gICAgICAgIHRoaXMucmVhZHkgPSB0cnVlO1xuICAgIH1cblxuICAgIGFzeW5jIHN0b3AoKTogUHJvbWlzZTx2b2lkPiB7XG4gICAgICAgIExvZ2dlci5pbmZvKCdTdG9wcGluZyBhcHBsaWNhdGlvbi4uLicpO1xuXG4gICAgICAgIGZvciAoY29uc3QgY29tcG9uZW50IG9mIHRoaXMuY29tcG9uZW50cykge1xuICAgICAgICAgICAgYXdhaXQgY29tcG9uZW50LnN0b3AoKTtcbiAgICAgICAgfVxuXG4gICAgICAgIExvZ2dlci5pbmZvKGAke3RoaXMuY29uc3RydWN0b3IubmFtZX0gdiR7dGhpcy52ZXJzaW9ufSAtIGJ5ZWApO1xuICAgIH1cblxuICAgIHByaXZhdGUgcm91dGVzKHJvb3RSb3V0ZXI6IFJvdXRlcikge1xuICAgICAgICBmb3IgKGNvbnN0IGNvbnRyb2xsZXIgb2YgdGhpcy5jb250cm9sbGVycykge1xuICAgICAgICAgICAgaWYgKGNvbnRyb2xsZXIuaGFzR2xvYmFsSGFuZGxlcnMoKSkge1xuICAgICAgICAgICAgICAgIGNvbnRyb2xsZXIuc2V0dXBHbG9iYWxIYW5kbGVycyhyb290Um91dGVyKTtcblxuICAgICAgICAgICAgICAgIExvZ2dlci5pbmZvKGBSZWdpc3RlcmVkIGdsb2JhbCBtaWRkbGV3YXJlcyBmb3IgY29udHJvbGxlciAke2NvbnRyb2xsZXIuY29uc3RydWN0b3IubmFtZX1gKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGZvciAoY29uc3QgY29udHJvbGxlciBvZiB0aGlzLmNvbnRyb2xsZXJzKSB7XG4gICAgICAgICAgICBjb25zdCByb3V0ZXIgPSBleHByZXNzLlJvdXRlcigpO1xuICAgICAgICAgICAgY29udHJvbGxlci5zZXR1cFJvdXRlcyhyb3V0ZXIpO1xuICAgICAgICAgICAgcm9vdFJvdXRlci51c2UoY29udHJvbGxlci5nZXRSb3V0ZXNQcmVmaXgoKSwgcm91dGVyKTtcblxuICAgICAgICAgICAgTG9nZ2VyLmluZm8oYD4gUmVnaXN0ZXJlZCByb3V0ZXMgZm9yIGNvbnRyb2xsZXIgJHtjb250cm9sbGVyLmNvbnN0cnVjdG9yLm5hbWV9YCk7XG4gICAgICAgIH1cblxuICAgICAgICByb290Um91dGVyLnVzZSgocmVxOiBSZXF1ZXN0KSA9PiB7XG4gICAgICAgICAgICB0aHJvdyBuZXcgTm90Rm91bmRIdHRwRXJyb3IoJ3BhZ2UnLCByZXEub3JpZ2luYWxVcmwpO1xuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBwdWJsaWMgZ2V0V2ViU29ja2V0TGlzdGVuZXJzKCk6IHsgW3A6IHN0cmluZ106IFdlYlNvY2tldExpc3RlbmVyIH0ge1xuICAgICAgICByZXR1cm4gdGhpcy53ZWJTb2NrZXRMaXN0ZW5lcnM7XG4gICAgfVxuXG4gICAgcHVibGljIGlzUmVhZHkoKTogYm9vbGVhbiB7XG4gICAgICAgIHJldHVybiB0aGlzLnJlYWR5O1xuICAgIH1cbn0iXX0= \ No newline at end of file diff --git a/dist/ApplicationComponent.d.ts b/dist/ApplicationComponent.d.ts deleted file mode 100644 index 3b7d47a..0000000 --- a/dist/ApplicationComponent.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Express, Router } from "express"; -export default abstract class ApplicationComponent { - private val?; - abstract start(app: Express, router: Router): Promise; - abstract stop(): Promise; - protected export(val: T): void; - import(): T; - protected prepare(name: string, prepare: () => Promise): Promise; - protected close(thingName: string, thing: any, fn: Function): Promise; -} diff --git a/dist/ApplicationComponent.js b/dist/ApplicationComponent.js deleted file mode 100644 index f102212..0000000 --- a/dist/ApplicationComponent.js +++ /dev/null @@ -1,55 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import Logger from "./Logger"; -import { sleep } from "./Utils"; -export default class ApplicationComponent { - export(val) { - this.val = val; - } - import() { - if (!this.val) - throw 'Cannot import if nothing was exported.'; - return this.val; - } - prepare(name, prepare) { - return __awaiter(this, void 0, void 0, function* () { - let err; - do { - try { - yield prepare(); - err = null; - } - catch (e) { - err = e; - Logger.error(err, `${name} failed to prepare; retrying in 5s...`); - yield sleep(5000); - } - } while (err); - Logger.info(`${name} ready!`); - }); - } - close(thingName, thing, fn) { - return __awaiter(this, void 0, void 0, function* () { - try { - yield new Promise((resolve, reject) => fn.call(thing, (err) => { - if (err) - reject(err); - else - resolve(); - })); - Logger.info(`${thingName} closed.`); - } - catch (e) { - Logger.error(e, `An error occurred while closing the ${thingName}.`); - } - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQXBwbGljYXRpb25Db21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbIkFwcGxpY2F0aW9uQ29tcG9uZW50LnRzIl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93ICdDYW5ub3QgaW1wb3J0IGlmIG5vdGhpbmcgd2FzIGV4cG9ydGVkLic7XG4gICAgICAgIHJldHVybiB0aGlzLnZhbDtcbiAgICB9XG5cbiAgICBwcm90ZWN0ZWQgYXN5bmMgcHJlcGFyZShuYW1lOiBzdHJpbmcsIHByZXBhcmU6ICgpID0+IFByb21pc2U8dm9pZD4pOiBQcm9taXNlPHZvaWQ+IHtcbiAgICAgICAgbGV0IGVycjtcbiAgICAgICAgZG8ge1xuICAgICAgICAgICAgdHJ5IHtcbiAgICAgICAgICAgICAgICBhd2FpdCBwcmVwYXJlKCk7XG4gICAgICAgICAgICAgICAgZXJyID0gbnVsbDtcbiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgICAgICBlcnIgPSBlO1xuICAgICAgICAgICAgICAgIExvZ2dlci5lcnJvcihlcnIsIGAke25hbWV9IGZhaWxlZCB0byBwcmVwYXJlOyByZXRyeWluZyBpbiA1cy4uLmApXG4gICAgICAgICAgICAgICAgYXdhaXQgc2xlZXAoNTAwMCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0gd2hpbGUgKGVycik7XG4gICAgICAgIExvZ2dlci5pbmZvKGAke25hbWV9IHJlYWR5IWApO1xuICAgIH1cblxuICAgIHByb3RlY3RlZCBhc3luYyBjbG9zZSh0aGluZ05hbWU6IHN0cmluZywgdGhpbmc6IGFueSwgZm46IEZ1bmN0aW9uKTogUHJvbWlzZTx2b2lkPiB7XG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICBhd2FpdCBuZXcgUHJvbWlzZSgocmVzb2x2ZSwgcmVqZWN0KSA9PiBmbi5jYWxsKHRoaW5nLCAoZXJyOiBhbnkpID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoZXJyKSByZWplY3QoZXJyKTtcbiAgICAgICAgICAgICAgICBlbHNlIHJlc29sdmUoKTtcbiAgICAgICAgICAgIH0pKTtcblxuICAgICAgICAgICAgTG9nZ2VyLmluZm8oYCR7dGhpbmdOYW1lfSBjbG9zZWQuYCk7XG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgIExvZ2dlci5lcnJvcihlLCBgQW4gZXJyb3Igb2NjdXJyZWQgd2hpbGUgY2xvc2luZyB0aGUgJHt0aGluZ05hbWV9LmApO1xuICAgICAgICB9XG4gICAgfVxufSJdfQ== \ No newline at end of file diff --git a/dist/Controller.d.ts b/dist/Controller.d.ts deleted file mode 100644 index af0b6df..0000000 --- a/dist/Controller.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { RequestHandler, Router } from "express"; -import { PathParams } from "express-serve-static-core"; -export default abstract class Controller { - private static readonly routes; - static route(route: string, params?: RouteParams, absolute?: boolean): string; - private router?; - getGlobalHandlers(): RequestHandler[]; - hasGlobalHandlers(): boolean; - setupGlobalHandlers(router: Router): void; - getRoutesPrefix(): string; - abstract routes(): void; - setupRoutes(router: Router): void; - protected use(handler: RequestHandler): void; - protected get(path: PathParams, handler: RequestHandler, routeName?: string, ...middlewares: RequestHandler[]): void; - protected post(path: PathParams, handler: RequestHandler, routeName?: string, ...middlewares: RequestHandler[]): void; - private wrap; - private registerRoutes; -} -export declare type RouteParams = { - [p: string]: string; -} | string[] | string | number; diff --git a/dist/Controller.js b/dist/Controller.js deleted file mode 100644 index a605402..0000000 --- a/dist/Controller.js +++ /dev/null @@ -1,104 +0,0 @@ -import config from "config"; -import Logger from "./Logger"; -export default class Controller { - static route(route, params = [], absolute = false) { - let path = this.routes[route]; - if (path === undefined) - throw new Error(`Unknown route for name ${route}.`); - if (typeof params === 'string' || typeof params === 'number') { - path = path.replace(/:[a-zA-Z_-]+\??/, '' + params); - } - else if (Array.isArray(params)) { - let i = 0; - for (const match of path.matchAll(/:[a-zA-Z_-]+\??/)) { - if (match.length > 0) { - path = path.replace(match[0], typeof params[i] !== 'undefined' ? params[i] : ''); - } - i++; - } - path = path.replace(/\/+/, '/'); - } - else { - for (const key in params) { - if (params.hasOwnProperty(key)) { - path = path.replace(new RegExp(`:${key}\\??`), params[key]); - } - } - } - return `${absolute ? config.get('public_url') : ''}${path}`; - } - getGlobalHandlers() { - return []; - } - hasGlobalHandlers() { - return this.getGlobalHandlers().length > 0; - } - setupGlobalHandlers(router) { - for (const globalHandler of this.getGlobalHandlers()) { - router.use(this.wrap(globalHandler)); - } - } - getRoutesPrefix() { - return '/'; - } - setupRoutes(router) { - this.router = router; - this.routes(); - } - use(handler) { - var _a; - (_a = this.router) === null || _a === void 0 ? void 0 : _a.use(this.wrap(handler)); - } - get(path, handler, routeName, ...middlewares) { - var _a, _b; - this.registerRoutes(path, handler, routeName); - for (const middleware of middlewares) { - (_a = this.router) === null || _a === void 0 ? void 0 : _a.get(path, this.wrap(middleware)); - } - (_b = this.router) === null || _b === void 0 ? void 0 : _b.get(path, this.wrap(handler)); - } - post(path, handler, routeName, ...middlewares) { - var _a, _b; - this.registerRoutes(path, handler, routeName); - for (const middleware of middlewares) { - (_a = this.router) === null || _a === void 0 ? void 0 : _a.post(path, this.wrap(middleware)); - } - (_b = this.router) === null || _b === void 0 ? void 0 : _b.post(path, this.wrap(handler)); - } - wrap(handler) { - return (req, res, next) => { - const promise = handler.call(this, req, res, next); - if (promise instanceof Promise) { - promise.catch(err => next(err)); - } - }; - } - registerRoutes(path, handler, routeName) { - if (typeof routeName !== 'string') { - routeName = handler.name - .replace(/(?:^|\.?)([A-Z])/g, (x, y) => '_' + y.toLowerCase()) - .replace(/(^_|get_|post_)/g, ''); - } - if (routeName.length === 0) - return; - let routePath = null; - if (path instanceof Array && path.length > 0) { - path = path[0]; - } - if (typeof path === 'string') { - const prefix = this.getRoutesPrefix(); - routePath = (prefix !== '/' ? prefix : '') + path; - } - if (!Controller.routes[routeName]) { - if (typeof routePath === 'string') { - Logger.info(`Route ${routeName} has path ${routePath}`); - Controller.routes[routeName] = routePath; - } - else { - Logger.warn(`Cannot assign path to route ${routeName}.`); - } - } - } -} -Controller.routes = {}; -//# sourceMappingURL=data:application/json;base64,e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gICAgICAgICAgICB9XG4gICAgICAgICAgICAgICAgaSsrO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcGF0aCA9IHBhdGgucmVwbGFjZSgvXFwvKy8sICcvJyk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBmb3IgKGNvbnN0IGtleSBpbiBwYXJhbXMpIHtcbiAgICAgICAgICAgICAgICBpZiAocGFyYW1zLmhhc093blByb3BlcnR5KGtleSkpIHtcbiAgICAgICAgICAgICAgICAgICAgcGF0aCA9IHBhdGgucmVwbGFjZShuZXcgUmVnRXhwKGA6JHtrZXl9XFxcXD8/YCksIHBhcmFtc1trZXldKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gYCR7YWJzb2x1dGUgPyBjb25maWcuZ2V0PHN0cmluZz4oJ3B1YmxpY191cmwnKSA6ICcnfSR7cGF0aH1gO1xuICAgIH1cblxuICAgIHByaXZhdGUgcm91dGVyPzogUm91dGVyO1xuXG4gICAgcHVibGljIGdldEdsb2JhbEhhbmRsZXJzKCk6IFJlcXVlc3RIYW5kbGVyW10ge1xuICAgICAgICByZXR1cm4gW107XG4gICAgfVxuXG4gICAgcHVibGljIGhhc0dsb2JhbEhhbmRsZXJzKCk6IGJvb2xlYW4ge1xuICAgICAgICByZXR1cm4gdGhpcy5nZXRHbG9iYWxIYW5kbGVycygpLmxlbmd0aCA+IDA7XG4gICAgfVxuXG4gICAgcHVibGljIHNldHVwR2xvYmFsSGFuZGxlcnMocm91dGVyOiBSb3V0ZXIpOiB2b2lkIHtcbiAgICAgICAgZm9yIChjb25zdCBnbG9iYWxIYW5kbGVyIG9mIHRoaXMuZ2V0R2xvYmFsSGFuZGxlcnMoKSkge1xuICAgICAgICAgICAgcm91dGVyLnVzZSh0aGlzLndyYXAoZ2xvYmFsSGFuZGxlcikpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgcHVibGljIGdldFJvdXRlc1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GF0aCwgaGFuZGxlciwgcm91dGVOYW1lKTtcbiAgICAgICAgZm9yIChjb25zdCBtaWRkbGV3YXJlIG9mIG1pZGRsZXdhcmVzKSB7XG4gICAgICAgICAgICB0aGlzLnJvdXRlcj8ucG9zdChwYXRoLCB0aGlzLndyYXAobWlkZGxld2FyZSkpO1xuICAgICAgICB9XG4gICAgICAgIHRoaXMucm91dGVyPy5wb3N0KHBhdGgsIHRoaXMud3JhcChoYW5kbGVyKSk7XG4gICAgfVxuXG4gICAgcHJpdmF0ZSB3cmFwKGhhbmRsZXI6IFJlcXVlc3RIYW5kbGVyKTogUmVxdWVzdEhhbmRsZXIge1xuICAgICAgICByZXR1cm4gKHJlcSwgcmVzLCBuZXh0KSA9PiB7XG4gICAgICAgICAgICBjb25zdCBwcm9taXNlID0gaGFuZGxlci5jYWxsKHRoaXMsIHJlcSwgcmVzLCBuZXh0KTtcbiAgICAgICAgICAgIGlmIChwcm9taXNlIGluc3RhbmNlb2YgUHJvbWlzZSkge1xuICAgICAgICAgICAgICAgIHByb21pc2UuY2F0Y2goZXJyID0+IG5leHQoZXJyKSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH07XG4gICAgfVxuXG4gICAgcHJpdmF0ZSByZWdpc3RlclJvdXRlcyhwYXRoOiBQYXRoUGFyYW1zLCBoYW5kbGVyOiBSZXF1ZXN0SGFuZGxlciwgcm91dGVOYW1lPzogc3RyaW5nKSB7XG4gICAgICAgIGlmICh0eXBlb2Ygcm91dGVOYW1lICE9PSAnc3RyaW5nJykge1xuICAgICAgICAgICAgcm91dGVOYW1lID0gaGFuZGxlci5uYW1lXG4gICAgICAgICAgICAgICAgLnJlcGxhY2UoLyg/Ol58XFwuPykoW0EtWl0pL2csICh4LCB5KSA9PiAnXycgKyB5LnRvTG93ZXJDYXNlKCkpXG4gICAgICAgICAgICAgICAgLnJlcGxhY2UoLyheX3xnZXRffHBvc3RfKS9nLCAnJyk7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAocm91dGVOYW1lLmxlbmd0aCA9PT0gMCkgcmV0dXJuO1xuXG4gICAgICAgIGxldCByb3V0ZVBhdGggPSBudWxsO1xuICAgICAgICBpZiAocGF0aCBpbnN0YW5jZW9mIEFycmF5ICYmIHBhdGgubGVuZ3RoID4gMCkge1xuICAgICAgICAgICAgcGF0aCA9IHBhdGhbMF07XG4gICAgICAgIH1cbiAgICAgICAgaWYgKHR5cGVvZiBwYXRoID09PSAnc3RyaW5nJykge1xuICAgICAgICAgICAgY29uc3QgcHJlZml4ID0gdGhpcy5nZXRSb3V0ZXNQcmVmaXgoKTtcbiAgICAgICAgICAgIHJvdXRlUGF0aCA9IChwcmVmaXggIT09ICcvJyA/IHByZWZpeCA6ICcnKSArIHBhdGg7XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoIUNvbnRyb2xsZXIucm91dGVzW3JvdXRlTmFtZV0pIHtcbiAgICAgICAgICAgIGlmICh0eXBlb2Ygcm91dGVQYXRoID09PSAnc3RyaW5nJykge1xuICAgICAgICAgICAgICAgIExvZ2dlci5pbmZvKGBSb3V0ZSAke3JvdXRlTmFtZX0gaGFzIHBhdGggJHtyb3V0ZVBhdGh9YCk7XG4gICAgICAgICAgICAgICAgQ29udHJvbGxlci5yb3V0ZXNbcm91dGVOYW1lXSA9IHJvdXRlUGF0aDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgTG9nZ2VyLndhcm4oYENhbm5vdCBhc3NpZ24gcGF0aCB0byByb3V0ZSAke3JvdXRlTmFtZX0uYCk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cbiAgICB9XG59XG5cbmV4cG9ydCB0eXBlIFJvdXRlUGFyYW1zID0geyBbcDogc3RyaW5nXTogc3RyaW5nIH0gfCBzdHJpbmdbXSB8IHN0cmluZyB8IG51bWJlcjsiXX0= \ No newline at end of file diff --git a/dist/HttpError.d.ts b/dist/HttpError.d.ts deleted file mode 100644 index b6e6831..0000000 --- a/dist/HttpError.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { WrappingError } from "./Utils"; -export declare abstract class HttpError extends WrappingError { - readonly instructions: string; - constructor(message: string, instructions: string, cause?: Error); - get name(): string; - abstract get errorCode(): number; -} -export declare class BadRequestError extends HttpError { - readonly url: string; - constructor(message: string, instructions: string, url: string, cause?: Error); - get errorCode(): number; -} -export declare class ForbiddenHttpError extends BadRequestError { - constructor(thing: string, url: string, cause?: Error); - get errorCode(): number; -} -export declare class NotFoundHttpError extends BadRequestError { - constructor(thing: string, url: string, cause?: Error); - get errorCode(): number; -} -export declare class ServerError extends HttpError { - constructor(message: string, cause?: Error); - get errorCode(): number; -} -export declare class ServiceUnavailableHttpError extends ServerError { - constructor(message: string, cause?: Error); - get errorCode(): number; -} diff --git a/dist/HttpError.js b/dist/HttpError.js deleted file mode 100644 index 26efec1..0000000 --- a/dist/HttpError.js +++ /dev/null @@ -1,52 +0,0 @@ -import { WrappingError } from "./Utils"; -export class HttpError extends WrappingError { - constructor(message, instructions, cause) { - super(message, cause); - this.instructions = instructions; - } - get name() { - return this.constructor.name; - } -} -export class BadRequestError extends HttpError { - constructor(message, instructions, url, cause) { - super(message, instructions, cause); - this.url = url; - } - get errorCode() { - return 400; - } -} -export class ForbiddenHttpError extends BadRequestError { - constructor(thing, url, cause) { - super(`You don't have access to this ${thing}.`, `${url} doesn't belong to *you*.`, url, cause); - } - get errorCode() { - return 403; - } -} -export class NotFoundHttpError extends BadRequestError { - constructor(thing, url, cause) { - super(`${thing.charAt(0).toUpperCase()}${thing.substr(1)} not found.`, `${url} doesn't exist or was deleted.`, url, cause); - } - get errorCode() { - return 404; - } -} -export class ServerError extends HttpError { - constructor(message, cause) { - super(message, `Maybe you should contact us; see instructions below.`, cause); - } - get errorCode() { - return 500; - } -} -export class ServiceUnavailableHttpError extends ServerError { - constructor(message, cause) { - super(message, cause); - } - get errorCode() { - return 503; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSHR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GNvbnN0cnVjdG9yKG1lc3NhZ2U6IHN0cmluZywgY2F1c2U/OiBFcnJvcikge1xuICAgICAgICBzdXBlcihtZXNzYWdlLCBjYXVzZSk7XG4gICAgfVxuXG4gICAgZ2V0IGVycm9yQ29kZSgpOiBudW1iZXIge1xuICAgICAgICByZXR1cm4gNTAzO1xuICAgIH1cbn0iXX0= \ No newline at end of file diff --git a/dist/Logger.d.ts b/dist/Logger.d.ts deleted file mode 100644 index 755ec36..0000000 --- a/dist/Logger.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -export default class Logger { - static silentError(error: Error, ...message: any[]): string; - static error(error: Error, ...message: any[]): string; - static warn(...message: any[]): void; - static info(...message: any[]): void; - static debug(...message: any[]): void; - static dev(...message: any[]): void; - private static log; - private constructor(); -} -export declare enum LogLevel { - ERROR = 0, - WARN = 1, - INFO = 2, - DEBUG = 3, - DEV = 4 -} -export declare type LogLevelKeys = keyof typeof LogLevel; diff --git a/dist/Logger.js b/dist/Logger.js deleted file mode 100644 index b9bef78..0000000 --- a/dist/Logger.js +++ /dev/null @@ -1,111 +0,0 @@ -import config from "config"; -import { v4 as uuid } from "uuid"; -import Log from "./models/Log"; -const LOG_LEVEL = config.get('log_level'); -const DB_LOG_LEVEL = config.get('db_log_level'); -export default class Logger { - static silentError(error, ...message) { - return this.log('ERROR', message, error, true) || ''; - } - static error(error, ...message) { - return this.log('ERROR', message, error) || ''; - } - static warn(...message) { - this.log('WARN', message); - } - static info(...message) { - this.log('INFO', message); - } - static debug(...message) { - this.log('DEBUG', message); - } - static dev(...message) { - this.log('DEV', message); - } - static log(level, message, error, silent = false) { - const levelIndex = LogLevel[level]; - if (levelIndex <= LogLevel[LOG_LEVEL]) { - if (error) { - if (levelIndex > LogLevel.ERROR) - this.warn(`Wrong log level ${level} with attached error.`); - } - else { - if (levelIndex <= LogLevel.ERROR) - this.warn(`No error attached with log level ${level}.`); - } - const computedMsg = message.map(v => { - if (typeof v === 'string') { - return v; - } - else { - return JSON.stringify(v, (key, value) => { - if (value instanceof Object) { - if (value.type === 'Buffer') { - return `Buffer<${Buffer.from(value.data).toString('hex')}>`; - } - else if (value !== v) { - return `[object Object]`; - } - } - if (typeof value === 'string' && value.length > 96) { - return value.substr(0, 96) + '...'; - } - return value; - }, 4); - } - }).join(' '); - const log = new Log({}); - log.setLevel(level); - log.message = computedMsg; - log.setError(error); - let logID = Buffer.alloc(16); - uuid({}, logID); - log.setLogID(logID); - let output = `[${level}] `; - let pad = output.length; - if (levelIndex <= LogLevel[DB_LOG_LEVEL]) - output += `${log.getLogID()} - `; - output += computedMsg.replace(/\n/g, '\n' + ' '.repeat(pad)); - switch (level) { - case "ERROR": - if (silent || !error) { - console.error(output); - } - else { - console.error(output, error); - } - break; - case "WARN": - console.warn(output); - break; - case "INFO": - console.info(output); - break; - case "DEBUG": - case "DEV": - console.debug(output); - break; - } - if (levelIndex <= LogLevel[DB_LOG_LEVEL]) { - log.save().catch(err => { - if (!silent && err.message.indexOf('ECONNREFUSED') < 0) { - console.error({ save_err: err, error }); - } - }); - } - return log.getLogID(); - } - return null; - } - constructor() { - } -} -export var LogLevel; -(function (LogLevel) { - LogLevel[LogLevel["ERROR"] = 0] = "ERROR"; - LogLevel[LogLevel["WARN"] = 1] = "WARN"; - LogLevel[LogLevel["INFO"] = 2] = "INFO"; - LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG"; - LogLevel[LogLevel["DEV"] = 4] = "DEV"; -})(LogLevel || (LogLevel = {})); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9nZ2VyLmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJMb2dnZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxNQUFNLE1BQU0sUUFBUSxDQUFDO0FBQzVCLE9BQU8sRUFBQyxFQUFFLElBQUksSUFBSSxFQUFDLE1BQU0sTUFBTSxDQUFDO0FBQ2hDLE9BQU8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B9IGVsc2Uge1xuICAgICAgICAgICAgICAgIGlmIChsZXZlbEluZGV4IDw9IExvZ0xldmVsLkVSUk9SKSB0aGlzLndhcm4oYE5vIGVycm9yIGF0dGFjaGVkIHdpdGggbG9nIGxldmVsICR7bGV2ZWx9LmApO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjb25zdCBjb21wdXRlZE1zZyA9IG1lc3NhZ2UubWFwKHYgPT4ge1xuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgdiA9PT0gJ3N0cmluZycpIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHY7XG4gICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIEpTT04uc3RyaW5naWZ5KHYsIChrZXk6IHN0cmluZywgdmFsdWU6IGFueSkgPT4ge1xuICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHZhbHVlIGluc3RhbmNlb2YgT2JqZWN0KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHZhbHVlLnR5cGUgPT09ICdCdWZmZXInKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiBgQnVmZmVyPCR7QnVmZmVyLmZyb20odmFsdWUuZGF0YSkudG9TdHJpbmcoJ2hleCcpfT5gO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAodmFsdWUgIT09IHYpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIGBbb2JqZWN0IE9iamVjdF1gO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgdmFsdWUgPT09ICdzdHJpbmcnICYmIHZhbHVlLmxlbmd0aCA+IDk2KSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHZhbHVlLnN1YnN0cigwLCA5NikgKyAnLi4uJztcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICAgICAgICAgICAgICAgICAgfSwgNCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSkuam9pbignICcpO1xuXG4gICAgICAgICAgICBjb25zdCBsb2cgPSBuZXcgTG9nKHt9KTtcbiAgICAgICAgICAgIGxvZy5zZXRMZXZlbChsZXZlbCk7XG4gICAgICAgICAgICBsb2cubWVzc2FnZSA9IGNvbXB1dGVkTXNnO1xuICAgICAgICAgICAgbG9nLnNldEVycm9yKGVycm9yKTtcblxuICAgICAgICAgICAgbGV0IGxvZ0lEID0gQnVmZmVyLmFsbG9jKDE2KTtcbiAgICAgICAgICAgIHV1aWQoe30sIGxvZ0lEKTtcbiAgICAgICAgICAgIGxvZy5zZXRMb2dJRChsb2dJRCk7XG5cblxuICAgICAgICAgICAgbGV0IG91dHB1dCA9IGBbJHtsZXZlbH1dIGA7XG4gICAgICAgICAgICBsZXQgcGFkID0gb3V0cHV0Lmxlbmd0aDtcbiAgICAgICAgICAgIGlmIChsZXZlbEluZGV4IDw9IExvZ0xldmVsW0RCX0xPR19MRVZFTF0pIG91dHB1dCArPSBgJHtsb2cuZ2V0TG9nSUQoKX0gLSBgO1xuICAgICAgICAgICAgb3V0cHV0ICs9IGNvbXB1dGVkTXNnLnJlcGxhY2UoL1xcbi9nLCAnXFxuJyArICcgJy5yZXBlYXQocGFkKSk7XG5cbiAgICAgICAgICAgIHN3aXRjaCAobGV2ZWwpIHtcbiAgICAgICAgICAgICAgICBjYXNlIFwiRVJST1JcIjpcbiAgICAgICAgICAgICAgICAgICAgaWYgKHNpbGVudCB8fCAhZXJyb3IpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3Iob3V0cHV0KTtcbiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3Iob3V0cHV0LCBlcnJvcik7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgY2FzZSBcIldBUk5cIjpcbiAgICAgICAgICAgICAgICAgICAgY29uc29sZS53YXJuKG91dHB1dCk7XG4gICAgICAgICAgICAgICAgICAgIGJyZWFrO1xuICAgICAgICAgICAgICAgIGNhc2UgXCJJTkZPXCI6XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuaW5mbyhvdXRwdXQpO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICBjYXNlIFwiREVCVUdcIjpcbiAgICAgICAgICAgICAgICBjYXNlIFwiREVWXCI6XG4gICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZGVidWcob3V0cHV0KTtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmIChsZXZlbEluZGV4IDw9IExvZ0xldmVsW0RCX0xPR19MRVZFTF0pIHtcbiAgICAgICAgICAgICAgICBsb2cuc2F2ZSgpLmNhdGNoKGVyciA9PiB7XG4gICAgICAgICAgICAgICAgICAgIGlmICghc2lsZW50ICYmIGVyci5tZXNzYWdlLmluZGV4T2YoJ0VDT05OUkVGVVNFRCcpIDwgMCkge1xuICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcih7c2F2ZV9lcnI6IGVyciwgZXJyb3J9KTtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIGxvZy5nZXRMb2dJRCgpO1xuICAgICAgICB9XG4gICAgICAgIHJldHVybiBudWxsO1xuICAgIH1cblxuICAgIHByaXZhdGUgY29uc3RydWN0b3IoKSB7XG4gICAgfVxufVxuXG5leHBvcnQgZW51bSBMb2dMZXZlbCB7XG4gICAgRVJST1IsXG4gICAgV0FSTixcbiAgICBJTkZPLFxuICAgIERFQlVHLFxuICAgIERFVixcbn1cblxuZXhwb3J0IHR5cGUgTG9nTGV2ZWxLZXlzID0ga2V5b2YgdHlwZW9mIExvZ0xldmVsO1xuIl19 \ No newline at end of file diff --git a/dist/Mail.d.ts b/dist/Mail.d.ts deleted file mode 100644 index 04bc02c..0000000 --- a/dist/Mail.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { SentMessageInfo } from "nodemailer"; -export declare function mailRoute(template: string): string; -export default class Mail { - private static transporter; - private static getTransporter; - static prepare(): Promise; - static end(): void; - static parse(template: string, data: any, textOnly: boolean): string; - private readonly template; - private readonly options; - private readonly data; - constructor(template: MailTemplate, data?: { - [p: string]: any; - }); - private verifyData; - send(...to: string[]): Promise; -} -export declare class MailTemplate { - private readonly _template; - private readonly subject; - constructor(template: string, subject: (data: any) => string); - get template(): string; - getSubject(data: any): string; -} diff --git a/dist/Mail.js b/dist/Mail.js deleted file mode 100644 index d10f620..0000000 --- a/dist/Mail.js +++ /dev/null @@ -1,122 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import nodemailer from "nodemailer"; -import config from "config"; -import nunjucks from 'nunjucks'; -import * as util from "util"; -import { WrappingError } from "./Utils"; -import mjml2html from "mjml"; -import * as querystring from "querystring"; -import Logger from "./Logger"; -export function mailRoute(template) { - return `/mail/${template}`; -} -export default class Mail { - constructor(template, data = {}) { - this.options = {}; - this.template = template; - this.data = data; - this.options.subject = this.template.getSubject(data); - this.verifyData(); - } - static getTransporter() { - if (!this.transporter) - throw new MailError('Mail system was not prepared.'); - return this.transporter; - } - static prepare() { - return __awaiter(this, void 0, void 0, function* () { - const transporter = nodemailer.createTransport({ - host: config.get('mail.host'), - port: config.get('mail.port'), - secure: config.get('mail.secure'), - auth: { - user: config.get('mail.username'), - pass: config.get('mail.password'), - }, - tls: { - rejectUnauthorized: !config.get('mail.allow_invalid_tls') - } - }); - try { - yield util.promisify(transporter.verify)(); - this.transporter = transporter; - } - catch (e) { - throw new MailError('Connection to mail service unsuccessful.', e); - } - Logger.info(`Mail ready to be distributed via ${config.get('mail.host')}:${config.get('mail.port')}`); - }); - } - static end() { - this.transporter.close(); - } - static parse(template, data, textOnly) { - data.text = textOnly; - const nunjucksResult = nunjucks.render(template, data); - if (textOnly) - return nunjucksResult; - const mjmlResult = mjml2html(nunjucksResult, {}); - if (mjmlResult.errors.length > 0) { - throw new MailError(`Error while parsing mail template ${template}: ${JSON.stringify(mjmlResult.errors, null, 4)}`); - } - return mjmlResult.html; - } - verifyData() { - for (const forbiddenField of [ - 'to', - ]) { - if (this.data[forbiddenField] !== undefined) { - throw new MailError(`Can't use reserved data.${forbiddenField}.`); - } - } - } - send(...to) { - return __awaiter(this, void 0, void 0, function* () { - const results = []; - for (const destEmail of to) { - // Reset options - this.options.html = this.options.text = undefined; - // Set options - this.options.to = destEmail; - // Set data - this.data.mail_subject = this.options.subject; - this.data.mail_to = this.options.to; - this.data.mail_link = `${config.get('public_url')}${mailRoute(this.template.template)}?${querystring.stringify(this.data)}`; - // Log - Logger.dev('Send mail', this.options); - // Render email - this.options.html = Mail.parse('mails/' + this.template.template + '.mjml.njk', this.data, false); - this.options.text = Mail.parse('mails/' + this.template.template + '.mjml.njk', this.data, true); - // Send email - results.push(yield Mail.getTransporter().sendMail(this.options)); - } - return results; - }); - } -} -export class MailTemplate { - constructor(template, subject) { - this._template = template; - this.subject = subject; - } - get template() { - return this._template; - } - getSubject(data) { - return 'Watch My Stream - ' + this.subject(data); - } -} -class MailError extends WrappingError { - constructor(message = 'An error occurred while sending mail.', cause) { - super(message, cause); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFpbC5qcyIsInNvdXJjZVJvb3QiOiIuLyIsInNvdXJjZXMiOlsiTWFpbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxPQUFPLFVBQTBDLE1BQU0sWUFBWSxDQUFDO0FBQ3BFLE9BQU8sTUFBTSxNQUFNLFFBQVEsQ0FBQztBQUU1QixPQUFPLFFBQVEsTUFBTSxVQUFVLENBQUM7QUFDaEMsT0FBTyxLQUFLLElBQUksTUFBTSxNQUFNLENBQUM7QUFDN0IsT0FBTyxFQUFDLGFBQWEsRUFBQyxNQUFNLFNBQVMsQ0FBQztBQUN0QyxPQUFPLFNBQVMsTUFBTSxNQUFNLENBQUM7QUFDN0IsT0FBTyxLQUFLLFdBQVcsTUFBTSxhQUFhLENBQUM7QUFDM0MsT0FBTyxNQUFNLE1BQU0sVUFBVSxDQUFDO0FBRTlCLE1BQU0sVUFBVSxTQUFTLENBQUMsUUFBZ0I7SUFDdEMsT0FBTyxTQUFTLFFBQVEsRUFBRSxDQUFDO0FBQy9CLENBQUM7QUFFRCxNQUFNLENBQUMsT0FBTyxPQUFPLElBQUk7SUFzRHJCLFlBQVksUUFBc0IsRUFBRSxPQUE2QixFQUFFO1FBSGxELFlBQU8sR0FBWSxFQUFFLENBQUM7UUFJbkMsSUFBSSxDQUFDLFFBQVEsR0FBRyxRQUFRLENBQUM7UUFDekIsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUM7UUFDakIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxPQUFPLEdBQUcsSUFBSSxDQUFDLFFBQVEsQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLENBQUM7UUFFdEQsSUFBSSxDQUFDLFVBQVUsRUFBRSxDQUFDO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dCA9IHN1YmplY3Q7XG4gICAgfVxuXG4gICAgcHVibGljIGdldCB0ZW1wbGF0ZSgpOiBzdHJpbmcge1xuICAgICAgICByZXR1cm4gdGhpcy5fdGVtcGxhdGU7XG4gICAgfVxuXG4gICAgcHVibGljIGdldFN1YmplY3QoZGF0YTogYW55KTogc3RyaW5nIHtcbiAgICAgICAgcmV0dXJuICdXYXRjaCBNeSBTdHJlYW0gLSAnICsgdGhpcy5zdWJqZWN0KGRhdGEpO1xuICAgIH1cbn1cblxuY2xhc3MgTWFpbEVycm9yIGV4dGVuZHMgV3JhcHBpbmdFcnJvciB7XG4gICAgY29uc3RydWN0b3IobWVzc2FnZTogc3RyaW5nID0gJ0FuIGVycm9yIG9jY3VycmVkIHdoaWxlIHNlbmRpbmcgbWFpbC4nLCBjYXVzZT86IEVycm9yKSB7XG4gICAgICAgIHN1cGVyKG1lc3NhZ2UsIGNhdXNlKTtcbiAgICB9XG59Il19 \ No newline at end of file diff --git a/dist/Pagination.d.ts b/dist/Pagination.d.ts deleted file mode 100644 index ee6c5c7..0000000 --- a/dist/Pagination.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import Model from "./db/Model"; -export default class Pagination { - private readonly models; - readonly page: number; - readonly perPage: number; - readonly totalCount: number; - constructor(models: T[], page: number, perPage: number, totalCount: number); - hasPrevious(): boolean; - hasNext(): boolean; -} diff --git a/dist/Pagination.js b/dist/Pagination.js deleted file mode 100644 index 42e59b8..0000000 --- a/dist/Pagination.js +++ /dev/null @@ -1,15 +0,0 @@ -export default class Pagination { - constructor(models, page, perPage, totalCount) { - this.models = models; - this.page = page; - this.perPage = perPage; - this.totalCount = totalCount; - } - hasPrevious() { - return this.page > 1; - } - hasNext() { - return this.models.length >= this.perPage && this.page * this.perPage < this.totalCount; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUGFnaW5hdGlvbi5qcyIsInNvdXJjZVJvb3QiOiIuLyIsInNvdXJjZXMiOl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tYmVyKSB7XG4gICAgICAgIHRoaXMubW9kZWxzID0gbW9kZWxzO1xuICAgICAgICB0aGlzLnBhZ2UgPSBwYWdlO1xuICAgICAgICB0aGlzLnBlclBhZ2UgPSBwZXJQYWdlO1xuICAgICAgICB0aGlzLnRvdGFsQ291bnQgPSB0b3RhbENvdW50O1xuICAgIH1cblxuICAgIHB1YmxpYyBoYXNQcmV2aW91cygpOiBib29sZWFuIHtcbiAgICAgICAgcmV0dXJuIHRoaXMucGFnZSA+IDE7XG4gICAgfVxuXG4gICAgcHVibGljIGhhc05leHQoKTogYm9vbGVhbiB7XG4gICAgICAgIHJldHVybiB0aGlzLm1vZGVscy5sZW5ndGggPj0gdGhpcy5wZXJQYWdlICYmIHRoaXMucGFnZSAqIHRoaXMucGVyUGFnZSA8IHRoaXMudG90YWxDb3VudDtcbiAgICB9XG5cbn0iXX0= \ No newline at end of file diff --git a/dist/Utils.d.ts b/dist/Utils.d.ts deleted file mode 100644 index 7d7c2b4..0000000 --- a/dist/Utils.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export declare function sleep(ms: number): Promise; -export declare abstract class WrappingError extends Error { - readonly cause?: Error; - protected constructor(message: string, cause?: Error); - get name(): string; -} -export declare function cryptoRandomDictionary(size: number, dictionary: string): string; diff --git a/dist/Utils.js b/dist/Utils.js deleted file mode 100644 index 18b3e25..0000000 --- a/dist/Utils.js +++ /dev/null @@ -1,38 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import * as crypto from "crypto"; -export function sleep(ms) { - return __awaiter(this, void 0, void 0, function* () { - return yield new Promise(resolve => { - setTimeout(() => resolve(), ms); - }); - }); -} -export class WrappingError extends Error { - constructor(message, cause) { - super(message); - this.cause = cause; - if (cause !== undefined) { - this.stack = (this.stack || '') + `\n> Caused by: ${cause.stack}`; - } - } - get name() { - return this.constructor.name; - } -} -export function cryptoRandomDictionary(size, dictionary) { - const randomBytes = crypto.randomBytes(size); - const output = new Array(size); - for (let i = 0; i < size; i++) { - output[i] = dictionary[Math.floor((randomBytes[i] / 255) * dictionary.length)]; - } - return output.join(''); -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVXRpbHMuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbIlV0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sS0FBSyxNQUFNLE1BQU0sUUFBUSxDQUFDO0FBRWpDLE1BQU0sVUFBZ0IsS0FBSyxDQUFDLEVBQVU7O1FBQ2xDLE9BQU8sTUFBTSxJQUFJLE9BQU8sQ0FBQyxPQUFPLENBQUMsRUFBRTtZQUMvQixVQUFVLENBQUMsR0FBRyxFQUFFLENBQUMsT0FBTyxFQUFFLEVBQUUsRUFBRSxDQUFDLENBQUM7UUFDcEMsQ0FBQyxDQUFDLENBQUM7SUFDUCxDQUFDO0NBQUE7QUFFRCxNQUFNLE9BQWdCLGFBQWMsU0FBUSxLQUFLO0lBRzdDLFlBQXNCLE9BQWUsRUFBRSxLQUFhO1FBQ2hELEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUNmLElBQUksQ0FBQyxLQUFLLEdBQUcsS0FBSyxDQUFDO1FBRW5CLElBQUksS0FBSyxLQUFLLFNBQVMsRUFBRTtZQUNyQixJQUFJLENBQUMsS0FBSyxHQUFHLENBQUMsSUFBSSxDQUFDLEtBQUssSUFBSSxFQUFFLENBQUMsR0FBRyxrQkFBa0IsS0FBSyxDQUFDLEt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HVibGljIHJlYWRvbmx5IGNhdXNlPzogRXJyb3I7XG5cbiAgICBwcm90ZWN0ZWQgY29uc3RydWN0b3IobWVzc2FnZTogc3RyaW5nLCBjYXVzZT86IEVycm9yKSB7XG4gICAgICAgIHN1cGVyKG1lc3NhZ2UpO1xuICAgICAgICB0aGlzLmNhdXNlID0gY2F1c2U7XG5cbiAgICAgICAgaWYgKGNhdXNlICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIHRoaXMuc3RhY2sgPSAodGhpcy5zdGFjayB8fCAnJykgKyBgXFxuPiBDYXVzZWQgYnk6ICR7Y2F1c2Uuc3RhY2t9YDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGdldCBuYW1lKCk6IHN0cmluZyB7XG4gICAgICAgIHJldHVybiB0aGlzLmNvbnN0cnVjdG9yLm5hbWU7XG4gICAgfVxufVxuXG5leHBvcnQgZnVuY3Rpb24gY3J5cHRvUmFuZG9tRGljdGlvbmFyeShzaXplOiBudW1iZXIsIGRpY3Rpb25hcnk6IHN0cmluZyk6IHN0cmluZyB7XG4gICAgY29uc3QgcmFuZG9tQnl0ZXMgPSBjcnlwdG8ucmFuZG9tQnl0ZXMoc2l6ZSk7XG4gICAgY29uc3Qgb3V0cHV0ID0gbmV3IEFycmF5KHNpemUpO1xuXG4gICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzaXplOyBpKyspIHtcbiAgICAgICAgb3V0cHV0W2ldID0gZGljdGlvbmFyeVtNYXRoLmZsb29yKChyYW5kb21CeXRlc1tpXSAvIDI1NSkgKiBkaWN0aW9uYXJ5Lmxlbmd0aCldO1xuICAgIH1cblxuICAgIHJldHVybiBvdXRwdXQuam9pbignJyk7XG59Il19 \ No newline at end of file diff --git a/dist/WebSocketListener.d.ts b/dist/WebSocketListener.d.ts deleted file mode 100644 index 0610621..0000000 --- a/dist/WebSocketListener.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -/// -/// -import WebSocket from "ws"; -import { IncomingMessage } from "http"; -export default abstract class WebSocketListener { - abstract path(): string; - abstract handle(socket: WebSocket, request: IncomingMessage, session: Express.SessionData): Promise; -} diff --git a/dist/WebSocketListener.js b/dist/WebSocketListener.js deleted file mode 100644 index 03ed92d..0000000 --- a/dist/WebSocketListener.js +++ /dev/null @@ -1,3 +0,0 @@ -export default class WebSocketListener { -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiV2ViU29ja2V0TGlzdGVuZXIuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbIldlYlNvY2tldExpc3RlbmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLE1BQU0sQ0FBQyxPQUFPLE9BQWdCLGlCQUFpQjtDQUk5QyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBXZWJTb2NrZXQgZnJvbSBcIndzXCI7XG5pbXBvcnQge0luY29taW5nTWVzc2FnZX0gZnJvbSBcImh0dHBcIjtcblxuZXhwb3J0IGRlZmF1bHQgYWJzdHJhY3QgY2xhc3MgV2ViU29ja2V0TGlzdGVuZXIge1xuICAgIHB1YmxpYyBhYnN0cmFjdCBwYXRoKCk6IHN0cmluZztcblxuICAgIHB1YmxpYyBhYnN0cmFjdCBhc3luYyBoYW5kbGUoc29ja2V0OiBXZWJTb2NrZXQsIHJlcXVlc3Q6IEluY29taW5nTWVzc2FnZSwgc2Vzc2lvbjogRXhwcmVzcy5TZXNzaW9uRGF0YSk6IFByb21pc2U8dm9pZD47XG59Il19 \ No newline at end of file diff --git a/dist/components/CsrfProtectionComponent.d.ts b/dist/components/CsrfProtectionComponent.d.ts deleted file mode 100644 index 9d9dd67..0000000 --- a/dist/components/CsrfProtectionComponent.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -export default class CsrfProtectionComponent extends ApplicationComponent { - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/CsrfProtectionComponent.js b/dist/components/CsrfProtectionComponent.js deleted file mode 100644 index 54d2ee1..0000000 --- a/dist/components/CsrfProtectionComponent.js +++ /dev/null @@ -1,57 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import crypto from "crypto"; -import { BadRequestError } from "../HttpError"; -export default class CsrfProtectionComponent extends ApplicationComponent { - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - router.use((req, res, next) => { - if (!req.session) { - throw new Error('Session is unavailable.'); - } - res.locals.getCSRFToken = () => { - if (typeof req.session.csrf !== 'string') { - req.session.csrf = crypto.randomBytes(64).toString('base64'); - } - return req.session.csrf; - }; - if (!['GET', 'HEAD', 'OPTIONS'].find(s => s === req.method)) { - if (req.session.csrf === undefined) { - throw new InvalidCsrfTokenError(req.baseUrl, `You weren't assigned any CSRF token.`); - } - else if (req.body.csrf === undefined) { - throw new InvalidCsrfTokenError(req.baseUrl, `You didn't provide any CSRF token.`); - } - else if (req.session.csrf !== req.body.csrf) { - throw new InvalidCsrfTokenError(req.baseUrl, `Tokens don't match.`); - } - } - next(); - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - }); - } -} -class InvalidCsrfTokenError extends BadRequestError { - constructor(url, details, cause) { - super(`Invalid CSRF token`, `${details} We can't process this request. Please try again.`, url, cause); - } - get name() { - return 'Invalid CSRF Token'; - } - get errorCode() { - return 401; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ3NyZlByb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AnSEVBRCcsICdPUFRJT05TJ10uZmluZChzID0+IHMgPT09IHJlcS5tZXRob2QpKSB7XG4gICAgICAgICAgICAgICAgaWYgKHJlcS5zZXNzaW9uLmNzcmYgPT09IHVuZGVmaW5lZCkge1xuICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgSW52YWxpZENzcmZUb2tlbkVycm9yKHJlcS5iYXNlVXJsLCBgWW91IHdlcmVuJ3QgYXNzaWduZWQgYW55IENTUkYgdG9rZW4uYCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmIChyZXEuYm9keS5jc3JmID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IEludmFsaWRDc3JmVG9rZW5FcnJvcihyZXEuYmFzZVVybCwgYFlvdSBkaWRuJ3QgcHJvdmlkZSBhbnkgQ1NSRiB0b2tlbi5gKTtcbiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHJlcS5zZXNzaW9uLmNzcmYgIT09IHJlcS5ib2R5LmNzcmYpIHtcbiAgICAgICAgICAgICAgICAgICAgdGhyb3cgbmV3IEludmFsaWRDc3JmVG9rZW5FcnJvcihyZXEuYmFzZVVybCwgYFRva2VucyBkb24ndCBtYXRjaC5gKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICBuZXh0KCk7XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIHB1YmxpYyBhc3luYyBzdG9wKCk6IFByb21pc2U8dm9pZD4ge1xuICAgIH1cbn1cblxuY2xhc3MgSW52YWxpZENzcmZUb2tlbkVycm9yIGV4dGVuZHMgQmFkUmVxdWVzdEVycm9yIHtcbiAgICBjb25zdHJ1Y3Rvcih1cmw6IHN0cmluZywgZGV0YWlsczogc3RyaW5nLCBjYXVzZT86IEVycm9yKSB7XG4gICAgICAgIHN1cGVyKFxuICAgICAgICAgICAgYEludmFsaWQgQ1NSRiB0b2tlbmAsXG4gICAgICAgICAgICBgJHtkZXRhaWxzfSBXZSBjYW4ndCBwcm9jZXNzIHRoaXMgcmVxdWVzdC4gUGxlYXNlIHRyeSBhZ2Fpbi5gLFxuICAgICAgICAgICAgdXJsLFxuICAgICAgICAgICAgY2F1c2VcbiAgICAgICAgKTtcbiAgICB9XG5cbiAgICBnZXQgbmFtZSgpOiBzdHJpbmcge1xuICAgICAgICByZXR1cm4gJ0ludmFsaWQgQ1NSRiBUb2tlbic7XG4gICAgfVxuXG4gICAgZ2V0IGVycm9yQ29kZSgpOiBudW1iZXIge1xuICAgICAgICByZXR1cm4gNDAxO1xuICAgIH1cbn1cbiJdfQ== \ No newline at end of file diff --git a/dist/components/ExpressAppComponent.d.ts b/dist/components/ExpressAppComponent.d.ts deleted file mode 100644 index 08f55bb..0000000 --- a/dist/components/ExpressAppComponent.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -import { Server } from "http"; -export default class ExpressAppComponent extends ApplicationComponent { - private readonly port; - private server?; - constructor(port: number); - start(app: Express, router: Router): Promise; - stop(): Promise; - getServer(): Server; -} diff --git a/dist/components/ExpressAppComponent.js b/dist/components/ExpressAppComponent.js deleted file mode 100644 index 63a63db..0000000 --- a/dist/components/ExpressAppComponent.js +++ /dev/null @@ -1,45 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import express from "express"; -import Logger from "../Logger"; -export default class ExpressAppComponent extends ApplicationComponent { - constructor(port) { - super(); - this.port = port; - } - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - this.server = app.listen(this.port, 'localhost', () => { - Logger.info(`Web server running on localhost:${this.port}.`); - }); - router.use(express.json()); - router.use(express.urlencoded()); - router.use((req, res, next) => { - req.models = {}; - req.modelCollections = {}; - next(); - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - if (this.server) { - yield this.close('Webserver', this.server, this.server.close); - } - }); - } - getServer() { - if (!this.server) - throw 'Server was not initialized.'; - return this.server; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRXhwcmVzc0FwcENvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIuLyIsInNvdXJjZXMiOlsiY29tcG9uZW50cy9FeHByZXNzQXBwQ29tcG9uZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sb0JBQW9CLE1BQU0seUJBQXlCLENBQUM7QUFDM0QsT0FBTyxPQUEwQixNQUFNLFNBQVMsQ0FBQztBQUNqRCxPQUFPLE1BQU0sTUFBTSxXQUFXLENBQUM7QUFHL0IsTUFBTSxDQUFDLE9BQU8sT0FBTyxtQkFBb0IsU0FBUSxvQkFBMEI7SUFJdkUsWUFBWSxJQUFZO1FBQ3BCLEtBQUssRUFBRSxDQUFDO1FBQ1IsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUM7SUFDckIsQ0FBQztJQUVZLEtBQUssQ0FBQyxHQUFZLEVBQUUsTUFBYzs7WUFDM0MsSUFBSSxDQUFDLE1BQU0sR0FBRyxHQUFHLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLEVBQUUsV0FBVyxFQUFFLEdBQUcsRUFBRTtnQkFDbEQsTUFBTSxDQUFDLElBQUksQ0FBQyxtQ0FBbUMsSUFBSSxDQUFDLElBQUksR0FBRyxDQUFDLENBQUM7WUFDakUsQ0FBQyxDQUFDLENBQUM7WUFFSCxNQU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c2UpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgcHVibGljIGdldFNlcnZlcigpOiBTZXJ2ZXIge1xuICAgICAgICBpZiAoIXRoaXMuc2VydmVyKSB0aHJvdyAnU2VydmVyIHdhcyBub3QgaW5pdGlhbGl6ZWQuJztcbiAgICAgICAgcmV0dXJuIHRoaXMuc2VydmVyO1xuICAgIH1cbn0iXX0= \ No newline at end of file diff --git a/dist/components/FormHelperComponent.d.ts b/dist/components/FormHelperComponent.d.ts deleted file mode 100644 index 2d69e20..0000000 --- a/dist/components/FormHelperComponent.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -export default class FormHelperComponent extends ApplicationComponent { - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/FormHelperComponent.js b/dist/components/FormHelperComponent.js deleted file mode 100644 index 3e207cd..0000000 --- a/dist/components/FormHelperComponent.js +++ /dev/null @@ -1,52 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -export default class FormHelperComponent extends ApplicationComponent { - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - router.use((req, res, next) => { - if (!req.session) { - throw new Error('Session is unavailable.'); - } - res.locals.query = req.query; - let _validation = null; - res.locals.validation = () => { - if (!_validation) { - const v = req.flash('validation'); - _validation = v.length > 0 ? v[0] : null; - } - return _validation; - }; - let _previousFormData = null; - res.locals.previousFormData = () => { - if (!_previousFormData) { - const v = req.flash('previousFormData'); - _previousFormData = v.length > 0 ? v[0] : null; - } - return _previousFormData; - }; - next(); - }); - router.use((req, res, next) => { - if (['GET', 'POST'].find(m => m === req.method)) { - if (typeof req.body === 'object') { - req.flash('previousFormData', req.body); - } - } - next(); - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRm9ybUhlbHBlckNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIuLyIsInNvdXJjZXMiOlsiY29tcG9uZW50cy9Gb3JtSGVscGVyQ29tcG9uZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sb0JBQW9CLE1BQU0seUJBQXlCLENBQUM7QUFHM0QsTUFBTSxDQUFDLE9BQU8sT0FBTyxtQkFBb0IsU0FBUSxvQkFBMEI7SUFDMUQsS0FBSyxDQUFDLEdBQVksRUFBRSxNQUFjOztZQUMzQyxNQUFNLENBQUMsR0FBRyxDQUFDLENBQUMsR0FBRyxFQUFFLEdBQUcsRUFBRSxJQUFJLEVBQUUsRUFBRTtnQkFDMUIsSUFBSSxDQUFDLEdBQUcsQ0FBQyxPQUFPLEVBQUU7b0JBQ2QsTUFBTSxJQUFJLEtBQUssQ0FBQyx5QkFBeUIsQ0FBQyxDQUFDO2lCQUM5QztnQkFFRCxHQUFHLENBQUMsTUFBTSxDQUFDLEtBQUssR0FBRyxHQUFHLENBQUMsS0FBSyxDQUFDO2dCQUU3QixJQUFJLFdBQVcsR0FBUSxJQUFJLENBQUM7Z0JBQzVCLEdBQUcsQ0FBQyxNQUFNLENBQUMsVUFBVSxHQUFHLEdBQUcsRUFBRTtvQkFDekIsSUFBSSxDQUFDLFdBQVcsRUFBRTt3QkFDZCxNQUFNLENBQUMsR0FBRyxHQUFHLENBQUMsS0FBSyxDQUFDLFlBQVksQ0FBQyxDQUFDO3dCQUNsQyxXQUFXLEdBQUcsQ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gICAgICAgICAgICAgIHJldHVybiBfdmFsaWRhdGlvbjtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgbGV0IF9wcmV2aW91c0Zvcm1EYXRhOiBhbnkgPSBudWxsO1xuICAgICAgICAgICAgcmVzLmxvY2Fscy5wcmV2aW91c0Zvcm1EYXRhID0gKCkgPT4ge1xuICAgICAgICAgICAgICAgIGlmICghX3ByZXZpb3VzRm9ybURhdGEpIHtcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgdiA9IHJlcS5mbGFzaCgncHJldmlvdXNGb3JtRGF0YScpO1xuICAgICAgICAgICAgICAgICAgICBfcHJldmlvdXNGb3JtRGF0YSA9IHYubGVuZ3RoID4gMCA/IHYgWzBdIDogbnVsbDtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICByZXR1cm4gX3ByZXZpb3VzRm9ybURhdGE7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgbmV4dCgpO1xuICAgICAgICB9KTtcblxuICAgICAgICByb3V0ZXIudXNlKChyZXEsIHJlcywgbmV4dCkgPT4ge1xuICAgICAgICAgICAgaWYgKFsnR0VUJywgJ1BPU1QnXS5maW5kKG0gPT4gbSA9PT0gcmVxLm1ldGhvZCkpIHtcbiAgICAgICAgICAgICAgICBpZiAodHlwZW9mIHJlcS5ib2R5ID09PSAnb2JqZWN0Jykge1xuICAgICAgICAgICAgICAgICAgICByZXEuZmxhc2goJ3ByZXZpb3VzRm9ybURhdGEnLCByZXEuYm9keSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgbmV4dCgpO1xuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBwdWJsaWMgYXN5bmMgc3RvcCgpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICB9XG5cbn0iXX0= \ No newline at end of file diff --git a/dist/components/LogRequestsComponent.d.ts b/dist/components/LogRequestsComponent.d.ts deleted file mode 100644 index c043dc4..0000000 --- a/dist/components/LogRequestsComponent.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -export default class LogRequestsComponent extends ApplicationComponent { - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/LogRequestsComponent.js b/dist/components/LogRequestsComponent.js deleted file mode 100644 index 2d5ea22..0000000 --- a/dist/components/LogRequestsComponent.js +++ /dev/null @@ -1,31 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import onFinished from "on-finished"; -import Logger from "../Logger"; -export default class LogRequestsComponent extends ApplicationComponent { - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - router.use((req, res, next) => { - onFinished(res, (err) => { - if (!err) { - Logger.info(`${req.method} ${req.originalUrl} - ${res.statusCode}`); - } - }); - next(); - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9nUmVxdWVzdHNDb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvTG9nUmVxdWVzdHNDb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxvQkFBb0IsTUFBTSx5QkFBeUIsQ0FBQztBQUMzRCxPQUFPLFVBQVUsTUFBTSxhQUFhLENBQUM7QUFDckMsT0FBTyxNQUFNLE1B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UHJvbWlzZTx2b2lkPiB7XG4gICAgICAgIHJvdXRlci51c2UoKHJlcSwgcmVzLCBuZXh0KSA9PiB7XG4gICAgICAgICAgICBvbkZpbmlzaGVkKHJlcywgKGVycikgPT4ge1xuICAgICAgICAgICAgICAgIGlmICghZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgIExvZ2dlci5pbmZvKGAke3JlcS5tZXRob2R9ICR7cmVxLm9yaWdpbmFsVXJsfSAtICR7cmVzLnN0YXR1c0NvZGV9YCk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICBuZXh0KCk7XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIHB1YmxpYyBhc3luYyBzdG9wKCk6IFByb21pc2U8dm9pZD4ge1xuICAgIH1cblxufSJdfQ== \ No newline at end of file diff --git a/dist/components/MailComponent.d.ts b/dist/components/MailComponent.d.ts deleted file mode 100644 index d708d33..0000000 --- a/dist/components/MailComponent.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -export default class MailComponent extends ApplicationComponent { - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/MailComponent.js b/dist/components/MailComponent.js deleted file mode 100644 index 1cd2a88..0000000 --- a/dist/components/MailComponent.js +++ /dev/null @@ -1,24 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import Mail from "../Mail"; -export default class MailComponent extends ApplicationComponent { - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - yield this.prepare('Mail connection', () => Mail.prepare()); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - Mail.end(); - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFpbENvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIuLyIsInNvdXJjZXMiOlsiY29tcG9uZW50cy9NYWlsQ29tcG9uZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sb0JBQW9CLE1BQU0seUJBQXlCLENBQUM7QUFFM0QsT0FBTyxJQUFJLE1BQU0sU0FBUyxDQUFDO0FBRTNCLE1BQU0sQ0FBQyxPQUFPLE9BQU8sYUFBYyxTQUFRLG9CQUEwQjtJQUNwRCxLQUFLLENBQUMsR0FBWSxFQUFFLE1BQWM7O1lBQzNDLE1BQU0sSUFBSSxDQUFDLE9BQU8sQ0FBQyxpQkFBaUIsRUFBRSxHQUFHLEVBQUUsQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FBQztRQUNoRSxDQUFDO0tBQUE7SUFFWSxJQUFJOztZQUNiLElBQUksQ0FBQyxHQUFHLEVBQUUsQ0FBQztRQUNmLENBQUM7S0FBQTtDQUVKIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IEFwcGxpY2F0aW9uQ29tcG9uZW50IGZyb20gXCIuLi9BcHBsaWNhdGlvbkNvbXBvbmVudFwiO1xuaW1wb3J0IHtFeHByZXNzLCBSb3V0ZXJ9IGZyb20gXCJleHByZXNzXCI7XG5pbXBvcnQgTWFpbCBmcm9tIFwiLi4vTWFpbFwiO1xuXG5leHBvcnQgZGVmYXVsdCBjbGFzcyBNYWlsQ29tcG9uZW50IGV4dGVuZHMgQXBwbGljYXRpb25Db21wb25lbnQ8dm9pZD4ge1xuICAgIHB1YmxpYyBhc3luYyBzdGFydChhcHA6IEV4cHJlc3MsIHJvdXRlcjogUm91dGVyKTogUHJvbWlzZTx2b2lkPiB7XG4gICAgICAgIGF3YWl0IHRoaXMucHJlcGFyZSgnTWFpbCBjb25uZWN0aW9uJywgKCkgPT4gTWFpbC5wcmVwYXJlKCkpO1xuICAgIH1cblxuICAgIHB1YmxpYyBhc3luYyBzdG9wKCk6IFByb21pc2U8dm9pZD4ge1xuICAgICAgICBNYWlsLmVuZCgpO1xuICAgIH1cblxufSJdfQ== \ No newline at end of file diff --git a/dist/components/MaintenanceComponent.d.ts b/dist/components/MaintenanceComponent.d.ts deleted file mode 100644 index 01fc5a7..0000000 --- a/dist/components/MaintenanceComponent.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -import Application from "../Application"; -export default class MaintenanceComponent extends ApplicationComponent { - private readonly application; - private readonly canServe; - constructor(application: Application, canServe: () => boolean); - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/MaintenanceComponent.js b/dist/components/MaintenanceComponent.js deleted file mode 100644 index b590313..0000000 --- a/dist/components/MaintenanceComponent.js +++ /dev/null @@ -1,42 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import { ServiceUnavailableHttpError } from "../HttpError"; -export default class MaintenanceComponent extends ApplicationComponent { - constructor(application, canServe) { - super(); - this.application = application; - this.canServe = canServe; - } - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - router.use((req, res, next) => { - if (res.headersSent) { - return next(); - } - if (!this.application.isReady()) { - res.header({ 'Retry-After': 60 }); - res.locals.refresh_after = 5; - throw new ServiceUnavailableHttpError('Watch My Stream is readying up. Please wait a few seconds...'); - } - if (!this.canServe()) { - res.locals.refresh_after = 30; - throw new ServiceUnavailableHttpError('Watch My Stream is unavailable due to failure of dependent services.'); - } - next(); - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFpbnRlbmFuY2VDb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvTWFpbnRlbmFuY2VDb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxvQkFBb0IsTUFBTSx5QkFBeUIsQ0FBQztBQUUzRCxPQUFPLEVBQUMsMkJBQTJCLEVBQUMsTUFBTSxjQUFjLENBQUM7QUFHekQsTUFBTSxDQUFDLE9BQU8sT0FBTyxvQkFBcUIsU0FBUSxvQkFBMEI7SUFJeEUsWUFBWSxXQUF3QixFQUFFLFFBQXVCO1FBQ3pELEtBQUssRUFBRSxDQUFDO1FBQ1IsSUFBSSxDQUFDLFdBQVcsR0FBRyxXQUFXLENBQUM7UUFDL0IsSUFBSSxDQUFDLFFBQVEsR0FBRyxRQUFRLENBQUM7SUFDN0IsQ0FBQztJQUVZLEtBQUssQ0FBQyxHQUFZLEVBQUUsTUFBYzs7WUFDM0MsTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFDLEdBQVksRUFBRSxHQUFhLEVBQUUsSUFBa0IsRUFBRSxFQUFFO2dCQUMzRCxJQUFJLEdBQUcsQ0FBQyxXQUFXLEVBQUU7b0JBQ2pCLE9BQU8sSUFBSSxFQUFFLENBQUM7aUJBQ2pCO2dCQUVELElBQUksQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLE9BQU8sRU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HRocm93IG5ldyBTZXJ2aWNlVW5hdmFpbGFibGVIdHRwRXJyb3IoJ1dhdGNoIE15IFN0cmVhbSBpcyB1bmF2YWlsYWJsZSBkdWUgdG8gZmFpbHVyZSBvZiBkZXBlbmRlbnQgc2VydmljZXMuJyk7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIG5leHQoKTtcbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgcHVibGljIGFzeW5jIHN0b3AoKTogUHJvbWlzZTx2b2lkPiB7XG4gICAgfVxuXG59Il19 \ No newline at end of file diff --git a/dist/components/MysqlComponent.d.ts b/dist/components/MysqlComponent.d.ts deleted file mode 100644 index 2b1fd92..0000000 --- a/dist/components/MysqlComponent.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -export default class MysqlComponent extends ApplicationComponent { - start(app: Express, router: Router): Promise; - stop(): Promise; - canServe(): boolean; -} diff --git a/dist/components/MysqlComponent.js b/dist/components/MysqlComponent.js deleted file mode 100644 index 7c7816d..0000000 --- a/dist/components/MysqlComponent.js +++ /dev/null @@ -1,27 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import MysqlConnectionManager from "../db/MysqlConnectionManager"; -export default class MysqlComponent extends ApplicationComponent { - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - yield this.prepare('Mysql connection', () => MysqlConnectionManager.prepare()); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - yield MysqlConnectionManager.endPool(); - }); - } - canServe() { - return MysqlConnectionManager.pool !== undefined; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTXlzcWxDb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvTXlzcWxDb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxvQkFBb0IsTUFBTSx5QkFBeUIsQ0FBQztBQUUzRCxPQUFPLHNCQUFzQixNQUFNLDhCQUE4QixDQUFDO0FBRWxFLE1BQU0sQ0FBQyxPQUFPLE9BQU8sY0FBZSxTQUFRLG9CQUEwQjtJQUNyRCxLQUFLLENBQUMsR0FBWSxFQUFFLE1BQWM7O1lBQzNDLE1BQU0sSUFBSSxDQUFDLE9BQU8sQ0FBQyxrQkFBa0IsRUFBRSxHQUFHLEVBQUUsQ0FBQyxzQkFBc0IsQ0FBQyxPQUFPLEVBQUUsQ0FBQyxDQUFDO1FBQ25GLENBQUM7S0FBQTtJQUVZLElBQUk7O1lBQ2IsTUFBTSxzQkFBc0IsQ0FBQyxPQUFPLEVBQUUsQ0FBQztRQUMzQyxDQUFDO0tBQUE7SUFFTSxRQUFRO1FBQ1gsT0FBTyxzQkFBc0IsQ0FBQyxJQUFJLEtBQUssU0FBUyxDQUFDO0lBQ3JELENBQUM7Q0FFSiIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBBcHBsaWNhdGlvbkNvbXBvbmVudCBmcm9tIFwiLi4vQXBwbGljYXRpb25Db21wb25lbnRcIjtcbmltcG9ydCB7RXhwcmVzcywgUm91dGVyfSBmcm9tIFwiZXhwcmVzc1wiO1xuaW1wb3J0IE15c3FsQ29ubmVjdGlvbk1hbmFnZXIgZnJvbSBcIi4uL2RiL015c3FsQ29ubmVjdGlvbk1hbmFnZXJcIjtcblxuZXhwb3J0IGRlZmF1bHQgY2xhc3MgTXlzcWxDb21wb25lbnQgZXh0ZW5kcyBBcHBsaWNhdGlvbkNvbXBvbmVudDx2b2lkPiB7XG4gICAgcHVibGljIGFzeW5jIHN0YXJ0KGFwcDogRXhwcmVzcywgcm91dGVyOiBSb3V0ZXIpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICAgICAgYXdhaXQgdGhpcy5wcmVwYXJlKCdNeXNxbCBjb25uZWN0aW9uJywgKCkgPT4gTXlzcWxDb25uZWN0aW9uTWFuYWdlci5wcmVwYXJlKCkpO1xuICAgIH1cblxuICAgIHB1YmxpYyBhc3luYyBzdG9wKCk6IFByb21pc2U8dm9pZD4ge1xuICAgICAgICBhd2FpdCBNeXNxbENvbm5lY3Rpb25NYW5hZ2VyLmVuZFBvb2woKTtcbiAgICB9XG5cbiAgICBwdWJsaWMgY2FuU2VydmUoKTogYm9vbGVhbiB7XG4gICAgICAgIHJldHVybiBNeXNxbENvbm5lY3Rpb25NYW5hZ2VyLnBvb2wgIT09IHVuZGVmaW5lZDtcbiAgICB9XG5cbn0iXX0= \ No newline at end of file diff --git a/dist/components/RedirectBackComponent.d.ts b/dist/components/RedirectBackComponent.d.ts deleted file mode 100644 index 1958ecb..0000000 --- a/dist/components/RedirectBackComponent.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -export default class RedirectBackComponent extends ApplicationComponent { - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/RedirectBackComponent.js b/dist/components/RedirectBackComponent.js deleted file mode 100644 index 20364e0..0000000 --- a/dist/components/RedirectBackComponent.js +++ /dev/null @@ -1,52 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import onFinished from "on-finished"; -import Logger from "../Logger"; -import { ServerError } from "../HttpError"; -export default class RedirectBackComponent extends ApplicationComponent { - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - router.use((req, res, next) => { - if (!req.session) { - throw new Error('Session is unavailable.'); - } - onFinished(res, (err) => { - if (!err && res.statusCode === 200) { - req.session.previousUrl = req.originalUrl; - Logger.debug('Prev url set to', req.session.previousUrl); - req.session.save((err) => { - if (err) { - Logger.error(err, 'Error while saving session'); - } - }); - } - }); - res.redirectBack = (defaultUrl) => { - if (req.session && typeof req.session.previousUrl === 'string') { - res.redirect(req.session.previousUrl); - } - else if (typeof defaultUrl === 'string') { - res.redirect(defaultUrl); - } - else { - throw new ServerError('There is no previous url and no default redirection url was provided.'); - } - }; - next(); - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVkaXJlY3RCYWNrQ29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJjb21wb25lbnRzL1JlZGlyZWN0QmFja0NvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxPQUFPLG9CQUFvQixNQUFNLHlCQUF5QixDQUFDO0FBRTNELE9BQU8sVUFBVSxNQUFNLGFBQWEsQ0FBQztBQUNyQyxPQUFPLE1BQU0sTUFBTSxXQUFXLENBQUM7QUFDL0IsT0FBTyxFQUFDLFdBQVcsRUFBQyxNQUFNLGNBQWMsQ0FBQztBQUV6QyxNQUFNLENBQUMsT0FBTyxPQUFPLHFCQUFzQixTQUFRLG9CQUEwQjtJQUM1RCxLQUFLLENBQUMsR0FBWSx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AgICBvbkZpbmlzaGVkKHJlcywgKGVycikgPT4ge1xuICAgICAgICAgICAgICAgIGlmICghZXJyICYmIHJlcy5zdGF0dXNDb2RlID09PSAyMDApIHtcbiAgICAgICAgICAgICAgICAgICAgcmVxLnNlc3Npb24hLnByZXZpb3VzVXJsID0gcmVxLm9yaWdpbmFsVXJsO1xuICAgICAgICAgICAgICAgICAgICBMb2dnZXIuZGVidWcoJ1ByZXYgdXJsIHNldCB0bycsIHJlcS5zZXNzaW9uIS5wcmV2aW91c1VybCk7XG4gICAgICAgICAgICAgICAgICAgIHJlcS5zZXNzaW9uIS5zYXZlKChlcnIpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBMb2dnZXIuZXJyb3IoZXJyLCAnRXJyb3Igd2hpbGUgc2F2aW5nIHNlc3Npb24nKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSk7XG5cbiAgICAgICAgICAgIHJlcy5yZWRpcmVjdEJhY2sgPSAoZGVmYXVsdFVybD86IHN0cmluZykgPT4ge1xuICAgICAgICAgICAgICAgIGlmIChyZXEuc2Vzc2lvbiAmJiB0eXBlb2YgcmVxLnNlc3Npb24ucHJldmlvdXNVcmwgPT09ICdzdHJpbmcnKSB7XG4gICAgICAgICAgICAgICAgICAgIHJlcy5yZWRpcmVjdChyZXEuc2Vzc2lvbi5wcmV2aW91c1VybCk7XG4gICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZGVmYXVsdFVybCA9PT0gJ3N0cmluZycpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVzLnJlZGlyZWN0KGRlZmF1bHRVcmwpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIHRocm93IG5ldyBTZXJ2ZXJFcnJvcignVGhlcmUgaXMgbm8gcHJldmlvdXMgdXJsIGFuZCBubyBkZWZhdWx0IHJlZGlyZWN0aW9uIHVybCB3YXMgcHJvdmlkZWQuJyk7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfTtcblxuICAgICAgICAgICAgbmV4dCgpO1xuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBwdWJsaWMgYXN5bmMgc3RvcCgpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICB9XG5cbn0iXX0= \ No newline at end of file diff --git a/dist/components/RedisComponent.d.ts b/dist/components/RedisComponent.d.ts deleted file mode 100644 index 4e16e68..0000000 --- a/dist/components/RedisComponent.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -import { Store } from "express-session"; -export default class RedisComponent extends ApplicationComponent { - private redisClient?; - private store?; - start(app: Express, router: Router): Promise; - stop(): Promise; - getStore(): Store; - canServe(): boolean; -} diff --git a/dist/components/RedisComponent.js b/dist/components/RedisComponent.js deleted file mode 100644 index a6a9d5f..0000000 --- a/dist/components/RedisComponent.js +++ /dev/null @@ -1,46 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import redis from "redis"; -import config from "config"; -import Logger from "../Logger"; -import session from "express-session"; -import connect_redis from "connect-redis"; -const RedisStore = connect_redis(session); -export default class RedisComponent extends ApplicationComponent { - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - this.redisClient = redis.createClient(config.get('redis.port'), config.get('redis.host'), {}); - this.redisClient.on('error', (err) => { - Logger.error(err, 'An error occurred with redis.'); - }); - this.store = new RedisStore({ - client: this.redisClient, - prefix: 'wms-sess:', - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - if (this.redisClient) { - yield this.close('Redis connection', this.redisClient, this.redisClient.quit); - } - }); - } - getStore() { - if (!this.store) - throw `Redis store was not initialized.`; - return this.store; - } - canServe() { - return this.redisClient !== undefined && this.redisClient.connected; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVkaXNDb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvUmVkaXNDb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxvQkFBb0IsTUFBTSx5QkFBeUIsQ0FBQztBQUUzRCxPQUFPLEtBQW9CLE1BQU0sT0FBTyxDQUFDO0FBQ3pDLE9BQU8sTUFBTSxNQUFNLFFBQVEsQ0FBQztBQUM1QixPQUFPLE1BQU0sTUFBTSxXQUFXLENBQUM7QUFDL0IsT0FBTyxPQUFnQixNQUFNLGlCQUFpQixDQUFDO0FBQy9DLE9BQU8sYUFBYSxNQUFNLGVBQWUsQ0FBQztBQUUxQyxNQUFNLFVBQVUsR0FBRyxhQUFhLENBQUMsT0FBTyxDQUFDLENBQUM7QUFFMUMsTUFBTSxDQUFDLE9BQU8sT0FBTyxjQUFlLFNBQVEsb0JBQTBCO0lBSXJELEtBQUssQ0FBQyxHQUFZLEVBQUUsTUFBYzs7WUFDM0MsSUFBSSxDQUFDLFdBQVcsR0FBRyxLQUFLLENBQUMsWUFBWSxDQUFDLE1BQU0sQ0FBQyxHQUFHLENBQUMsWUFBWSxDQUFDLEVBQUUsTUFBTSxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsRUFBRSxFQUFFLENBQUMsQ0FBQztZQUM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eW5jIHN0b3AoKTogUHJvbWlzZTx2b2lkPiB7XG4gICAgICAgIGlmICh0aGlzLnJlZGlzQ2xpZW50KSB7XG4gICAgICAgICAgICBhd2FpdCB0aGlzLmNsb3NlKCdSZWRpcyBjb25uZWN0aW9uJywgdGhpcy5yZWRpc0NsaWVudCwgdGhpcy5yZWRpc0NsaWVudC5xdWl0KTtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIHB1YmxpYyBnZXRTdG9yZSgpOiBTdG9yZSB7XG4gICAgICAgIGlmICghdGhpcy5zdG9yZSkgdGhyb3cgYFJlZGlzIHN0b3JlIHdhcyBub3QgaW5pdGlhbGl6ZWQuYDtcbiAgICAgICAgcmV0dXJuIHRoaXMuc3RvcmU7XG4gICAgfVxuXG4gICAgcHVibGljIGNhblNlcnZlKCk6IGJvb2xlYW4ge1xuICAgICAgICByZXR1cm4gdGhpcy5yZWRpc0NsaWVudCAhPT0gdW5kZWZpbmVkICYmIHRoaXMucmVkaXNDbGllbnQuY29ubmVjdGVkO1xuICAgIH1cbn0iXX0= \ No newline at end of file diff --git a/dist/components/ServeStaticDirectoryComponent.d.ts b/dist/components/ServeStaticDirectoryComponent.d.ts deleted file mode 100644 index ca770b3..0000000 --- a/dist/components/ServeStaticDirectoryComponent.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -import { PathParams } from "express-serve-static-core"; -export default class ServeStaticDirectoryComponent extends ApplicationComponent { - private readonly root; - private readonly path?; - constructor(root: string, routePath?: PathParams); - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/ServeStaticDirectoryComponent.js b/dist/components/ServeStaticDirectoryComponent.js deleted file mode 100644 index 2ead032..0000000 --- a/dist/components/ServeStaticDirectoryComponent.js +++ /dev/null @@ -1,33 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import express from "express"; -export default class ServeStaticDirectoryComponent extends ApplicationComponent { - constructor(root, routePath) { - super(); - this.root = root; - this.path = routePath; - } - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - if (typeof this.path !== 'undefined') { - router.use(this.path, express.static(this.root, { maxAge: 1000 * 3600 * 72 })); - } - else { - router.use(express.static(this.root, { maxAge: 1000 * 3600 * 72 })); - } - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VydmVTdGF0aWNEaXJlY3RvcnlDb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImNvbXBvbmVudHMvU2VydmVTdGF0aWNEaXJlY3RvcnlDb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxvQkFBb0IsTUFBTSx5QkFBeUIsQ0FBQztBQUMzRCxPQUFPLE9BQTBCLE1BQU0sU0FBUyxDQUFDO0FBR2pELE1BQU0sQ0FBQyxPQUFPLE9BQU8sNkJBQThCLFNBQVEsb0JBQTBCO0lBSWpGLFlBQVksSUFBWSxFQUFFLFNBQXNCO1FBQzVDLEtBQUssRUFBRSxDQUFDO1FBQ1IsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUM7UUFDakIsSUFBSSxDQUFDLElBQUksR0FBRyxTQUFTLENBQUM7SUFDMUIsQ0FBQztJQUVZLEtBQUssQ0FBQyxHQUFZLEVBQUUsTUFBYzs7WUFDM0M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ICAgICBzdXBlcigpO1xuICAgICAgICB0aGlzLnJvb3QgPSByb290O1xuICAgICAgICB0aGlzLnBhdGggPSByb3V0ZVBhdGg7XG4gICAgfVxuXG4gICAgcHVibGljIGFzeW5jIHN0YXJ0KGFwcDogRXhwcmVzcywgcm91dGVyOiBSb3V0ZXIpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICAgICAgaWYgKHR5cGVvZiB0aGlzLnBhdGggIT09ICd1bmRlZmluZWQnKSB7XG4gICAgICAgICAgICByb3V0ZXIudXNlKHRoaXMucGF0aCwgZXhwcmVzcy5zdGF0aWModGhpcy5yb290LCB7bWF4QWdlOiAxMDAwICogMzYwMCAqIDcyfSkpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgcm91dGVyLnVzZShleHByZXNzLnN0YXRpYyh0aGlzLnJvb3QsIHttYXhBZ2U6IDEwMDAgKiAzNjAwICogNzJ9KSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBwdWJsaWMgYXN5bmMgc3RvcCgpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICB9XG5cbn0iXX0= \ No newline at end of file diff --git a/dist/components/SessionComponent.d.ts b/dist/components/SessionComponent.d.ts deleted file mode 100644 index f2966f4..0000000 --- a/dist/components/SessionComponent.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import RedisComponent from "./RedisComponent"; -import { Express, Router } from "express"; -export default class SessionComponent extends ApplicationComponent { - private readonly storeComponent; - constructor(storeComponent: RedisComponent); - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/SessionComponent.js b/dist/components/SessionComponent.js deleted file mode 100644 index 591bbdf..0000000 --- a/dist/components/SessionComponent.js +++ /dev/null @@ -1,59 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import session from "express-session"; -import config from "config"; -import flash from "connect-flash"; -export default class SessionComponent extends ApplicationComponent { - constructor(storeComponent) { - super(); - this.storeComponent = storeComponent; - } - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - router.use(session({ - saveUninitialized: true, - secret: config.get('session.secret'), - store: this.storeComponent.getStore(), - resave: true, - cookie: { - httpOnly: true, - secure: config.get('session.cookie.secure'), - }, - rolling: true, - })); - router.use(flash()); - router.use((req, res, next) => { - if (!req.session) { - throw new Error('Session is unavailable.'); - } - res.locals.session = req.session; - let _flash = null; - res.locals.flash = () => { - if (!_flash) { - _flash = { - info: req.flash('info'), - success: req.flash('success'), - warning: req.flash('warning'), - error: req.flash('error'), - }; - } - return _flash; - }; - next(); - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2Vzc2lvbkNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIuLyIsInNvdXJjZXMiOlsiY29tcG9uZW50cy9TZXNzaW9uQ29tcG9uZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sb0JBQW9CLE1BQU0seUJBQXlCLENBQUM7QUFDM0QsT0FBTyxPQUFPLE1BQU0saUJBQWlCLENBQUM7QUFDdEMsT0FBTyxNQUFNLE1BQU0sUUFBUSxDQUFDO0FBRTVCLE9BQU8sS0FBSyxNQUFNLGVBQWUsQ0FBQztBQUdsQyxNQUFNLENBQUMsT0FBTyxPQUFPLGdCQUFpQixTQUFRLG9CQUEwQjtJQUlwRSxZQUF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RvcmVDb21wb25lbnQ6IFJlZGlzQ29tcG9uZW50KSB7XG4gICAgICAgIHN1cGVyKCk7XG4gICAgICAgIHRoaXMuc3RvcmVDb21wb25lbnQgPSBzdG9yZUNvbXBvbmVudDtcbiAgICB9XG5cbiAgICBwdWJsaWMgYXN5bmMgc3RhcnQoYXBwOiBFeHByZXNzLCByb3V0ZXI6IFJvdXRlcik6IFByb21pc2U8dm9pZD4ge1xuICAgICAgICByb3V0ZXIudXNlKHNlc3Npb24oe1xuICAgICAgICAgICAgc2F2ZVVuaW5pdGlhbGl6ZWQ6IHRydWUsXG4gICAgICAgICAgICBzZWNyZXQ6IGNvbmZpZy5nZXQoJ3Nlc3Npb24uc2VjcmV0JyksXG4gICAgICAgICAgICBzdG9yZTogdGhpcy5zdG9yZUNvbXBvbmVudC5nZXRTdG9yZSgpLFxuICAgICAgICAgICAgcmVzYXZlOiB0cnVlLFxuICAgICAgICAgICAgY29va2llOiB7XG4gICAgICAgICAgICAgICAgaHR0cE9ubHk6IHRydWUsXG4gICAgICAgICAgICAgICAgc2VjdXJlOiBjb25maWcuZ2V0KCdzZXNzaW9uLmNvb2tpZS5zZWN1cmUnKSxcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICByb2xsaW5nOiB0cnVlLFxuICAgICAgICB9KSk7XG5cbiAgICAgICAgcm91dGVyLnVzZShmbGFzaCgpKTtcblxuICAgICAgICByb3V0ZXIudXNlKChyZXEsIHJlcywgbmV4dCkgPT4ge1xuICAgICAgICAgICAgaWYgKCFyZXEuc2Vzc2lvbikge1xuICAgICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcignU2Vzc2lvbiBpcyB1bmF2YWlsYWJsZS4nKTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgcmVzLmxvY2Fscy5zZXNzaW9uID0gcmVxLnNlc3Npb247XG5cbiAgICAgICAgICAgIGxldCBfZmxhc2g6IGFueSA9IG51bGw7XG4gICAgICAgICAgICByZXMubG9jYWxzLmZsYXNoID0gKCkgPT4ge1xuICAgICAgICAgICAgICAgIGlmICghX2ZsYXNoKSB7XG4gICAgICAgICAgICAgICAgICAgIF9mbGFzaCA9IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGluZm86IHJlcS5mbGFzaCgnaW5mbycpLFxuICAgICAgICAgICAgICAgICAgICAgICAgc3VjY2VzczogcmVxLmZsYXNoKCdzdWNjZXNzJyksXG4gICAgICAgICAgICAgICAgICAgICAgICB3YXJuaW5nOiByZXEuZmxhc2goJ3dhcm5pbmcnKSxcbiAgICAgICAgICAgICAgICAgICAgICAgIGVycm9yOiByZXEuZmxhc2goJ2Vycm9yJyksXG4gICAgICAgICAgICAgICAgICAgIH07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybiBfZmxhc2g7XG4gICAgICAgICAgICB9O1xuICAgICAgICAgICAgbmV4dCgpO1xuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBwdWJsaWMgYXN5bmMgc3RvcCgpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICB9XG59Il19 \ No newline at end of file diff --git a/dist/components/WebSocketServerComponent.d.ts b/dist/components/WebSocketServerComponent.d.ts deleted file mode 100644 index 1393d47..0000000 --- a/dist/components/WebSocketServerComponent.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import ApplicationComponent from "../ApplicationComponent"; -import { Express, Router } from "express"; -import ExpressAppComponent from "./ExpressAppComponent"; -import Application from "../Application"; -import RedisComponent from "./RedisComponent"; -export default class WebSocketServerComponent extends ApplicationComponent { - private readonly application; - private readonly expressAppComponent; - private readonly storeComponent; - private wss?; - constructor(application: Application, expressAppComponent: ExpressAppComponent, storeComponent: RedisComponent); - start(app: Express, router: Router): Promise; - stop(): Promise; -} diff --git a/dist/components/WebSocketServerComponent.js b/dist/components/WebSocketServerComponent.js deleted file mode 100644 index ccd0926..0000000 --- a/dist/components/WebSocketServerComponent.js +++ /dev/null @@ -1,73 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import ApplicationComponent from "../ApplicationComponent"; -import { Server as WebSocketServer } from "ws"; -import Logger from "../Logger"; -import cookie from "cookie"; -import cookieParser from "cookie-parser"; -import config from "config"; -export default class WebSocketServerComponent extends ApplicationComponent { - constructor(application, expressAppComponent, storeComponent) { - super(); - this.expressAppComponent = expressAppComponent; - this.application = application; - this.storeComponent = storeComponent; - } - start(app, router) { - return __awaiter(this, void 0, void 0, function* () { - const listeners = this.application.getWebSocketListeners(); - this.wss = new WebSocketServer({ - server: this.expressAppComponent.getServer(), - }, () => { - Logger.info(`Websocket server started over webserver.`); - }).on('error', (err) => { - Logger.error(err, 'An error occurred in the websocket server.'); - }).on('connection', (socket, request) => { - const listener = request.url ? listeners[request.url] : null; - if (!listener) { - socket.close(1002, `Path not found ${request.url}`); - return; - } - else if (!request.headers.cookie) { - socket.close(1002, `Can't process request without cookies.`); - return; - } - Logger.debug(`Websocket on ${request.url}`); - const cookies = cookie.parse(request.headers.cookie); - const sid = cookieParser.signedCookie(cookies['connect.sid'], config.get('session.secret')); - if (!sid) { - socket.close(1002); - return; - } - const store = this.storeComponent.getStore(); - store.get(sid, (err, session) => { - if (err || !session) { - Logger.error(err, 'Error while initializing session in websocket.'); - socket.close(1011); - return; - } - session.id = sid; - store.createSession(request, session); - listener.handle(socket, request, session).catch(err => { - Logger.error(err, 'Error in websocket listener.'); - }); - }); - }); - }); - } - stop() { - return __awaiter(this, void 0, void 0, function* () { - if (this.wss) { - yield this.close('WebSocket server', this.wss, this.wss.close); - } - }); - } -} -//# sourceMapping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B7XG4gICAgICAgICAgICBMb2dnZXIuZXJyb3IoZXJyLCAnQW4gZXJyb3Igb2NjdXJyZWQgaW4gdGhlIHdlYnNvY2tldCBzZXJ2ZXIuJyk7XG4gICAgICAgIH0pLm9uKCdjb25uZWN0aW9uJywgKHNvY2tldCwgcmVxdWVzdCkgPT4ge1xuICAgICAgICAgICAgY29uc3QgbGlzdGVuZXIgPSByZXF1ZXN0LnVybCA/IGxpc3RlbmVyc1tyZXF1ZXN0LnVybF0gOiBudWxsO1xuXG4gICAgICAgICAgICBpZiAoIWxpc3RlbmVyKSB7XG4gICAgICAgICAgICAgICAgc29ja2V0LmNsb3NlKDEwMDIsIGBQYXRoIG5vdCBmb3VuZCAke3JlcXVlc3QudXJsfWApO1xuICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoIXJlcXVlc3QuaGVhZGVycy5jb29raWUpIHtcbiAgICAgICAgICAgICAgICBzb2NrZXQuY2xvc2UoMTAwMiwgYENhbid0IHByb2Nlc3MgcmVxdWVzdCB3aXRob3V0IGNvb2tpZXMuYCk7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBMb2dnZXIuZGVidWcoYFdlYnNvY2tldCBvbiAke3JlcXVlc3QudXJsfWApO1xuXG4gICAgICAgICAgICBjb25zdCBjb29raWVzID0gY29va2llLnBhcnNlKHJlcXVlc3QuaGVhZGVycy5jb29raWUpO1xuICAgICAgICAgICAgY29uc3Qgc2lkID0gY29va2llUGFyc2VyLnNpZ25lZENvb2tpZShjb29raWVzWydjb25uZWN0LnNpZCddLCBjb25maWcuZ2V0KCdzZXNzaW9uLnNlY3JldCcpKTtcblxuICAgICAgICAgICAgaWYgKCFzaWQpIHtcbiAgICAgICAgICAgICAgICBzb2NrZXQuY2xvc2UoMTAwMik7XG4gICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBjb25zdCBzdG9yZSA9IHRoaXMuc3RvcmVDb21wb25lbnQuZ2V0U3RvcmUoKTtcbiAgICAgICAgICAgIHN0b3JlLmdldChzaWQsIChlcnIsIHNlc3Npb24pID0+IHtcbiAgICAgICAgICAgICAgICBpZiAoZXJyIHx8ICFzZXNzaW9uKSB7XG4gICAgICAgICAgICAgICAgICAgIExvZ2dlci5lcnJvcihlcnIsICdFcnJvciB3aGlsZSBpbml0aWFsaXppbmcgc2Vzc2lvbiBpbiB3ZWJzb2NrZXQuJyk7XG4gICAgICAgICAgICAgICAgICAgIHNvY2tldC5jbG9zZSgxMDExKTtcbiAgICAgICAgICAgICAgICAgICAgcmV0dXJuO1xuICAgICAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgICAgIHNlc3Npb24uaWQgPSBzaWQ7XG5cbiAgICAgICAgICAgICAgICBzdG9yZS5jcmVhdGVTZXNzaW9uKDxSZXF1ZXN0PnJlcXVlc3QsIHNlc3Npb24pO1xuICAgICAgICAgICAgICAgIGxpc3RlbmVyLmhhbmRsZShzb2NrZXQsIHJlcXVlc3QsIHNlc3Npb24pLmNhdGNoKGVyciA9PiB7XG4gICAgICAgICAgICAgICAgICAgIExvZ2dlci5lcnJvcihlcnIsICdFcnJvciBpbiB3ZWJzb2NrZXQgbGlzdGVuZXIuJyk7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgcHVibGljIGFzeW5jIHN0b3AoKTogUHJvbWlzZTx2b2lkPiB7XG4gICAgICAgIGlmICh0aGlzLndzcykge1xuICAgICAgICAgICAgYXdhaXQgdGhpcy5jbG9zZSgnV2ViU29ja2V0IHNlcnZlcicsIHRoaXMud3NzLCB0aGlzLndzcy5jbG9zZSk7XG4gICAgICAgIH1cbiAgICB9XG59Il19 \ No newline at end of file diff --git a/dist/db/Migration.d.ts b/dist/db/Migration.d.ts deleted file mode 100644 index 9a8bc39..0000000 --- a/dist/db/Migration.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export default abstract class Migration { - readonly version: number; - constructor(version: number); - shouldRun(currentVersion: number): Promise; - abstract install(): Promise; - abstract rollback(): Promise; -} diff --git a/dist/db/Migration.js b/dist/db/Migration.js deleted file mode 100644 index a96fbf1..0000000 --- a/dist/db/Migration.js +++ /dev/null @@ -1,20 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -export default class Migration { - constructor(version) { - this.version = version; - } - shouldRun(currentVersion) { - return __awaiter(this, void 0, void 0, function* () { - return this.version > currentVersion; - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uLmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJkYi9NaWdyYXRpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsTUFBTSxDQUFDLE9BQU8sT0FBZ0IsU0FBUztJQUduQyxZQUFZLE9BQWU7UUFDdkIsSUFBSSxDQUFDLE9BQU8sR0FBRyxPQUFPLENBQUM7SUFDM0IsQ0FBQztJQUVLLFNBQVMsQ0FBQyxjQUFzQjs7WUFDbEMsT0FBTyxJQUFJLENBQUMsT0FBTyxHQUFHLGNBQWMsQ0FBQztRQUN6QyxDQUFDO0tBQUE7Q0FLSiIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IGFic3RyYWN0IGNsYXNzIE1pZ3JhdGlvbiB7XG4gICAgcHVibGljIHJlYWRvbmx5IHZlcnNpb246IG51bWJlcjtcblxuICAgIGNvbnN0cnVjdG9yKHZlcnNpb246IG51bWJlcikge1xuICAgICAgICB0aGlzLnZlcnNpb24gPSB2ZXJzaW9uO1xuICAgIH1cblxuICAgIGFzeW5jIHNob3VsZFJ1bihjdXJyZW50VmVyc2lvbjogbnVtYmVyKTogUHJvbWlzZTxib29sZWFuPiB7XG4gICAgICAgIHJldHVybiB0aGlzLnZlcnNpb24gPiBjdXJyZW50VmVyc2lvbjtcbiAgICB9XG5cbiAgICBhYnN0cmFjdCBhc3luYyBpbnN0YWxsKCk6IFByb21pc2U8dm9pZD47XG5cbiAgICBhYnN0cmFjdCBhc3luYyByb2xsYmFjaygpOiBQcm9taXNlPHZvaWQ+O1xufSJdfQ== \ No newline at end of file diff --git a/dist/db/Model.d.ts b/dist/db/Model.d.ts deleted file mode 100644 index 4f61055..0000000 --- a/dist/db/Model.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -import Validator from "./Validator"; -import { Connection } from "mysql"; -import Query from "./Query"; -import { Request } from "express"; -export default abstract class Model { - static getById(id: number): Promise; - static paginate(request: Request, perPage?: number): Promise; - protected static select(...fields: string[]): Query; - protected static update(data: { - [key: string]: any; - }): Query; - protected static delete(): Query; - protected static models(query: Query): Promise; - static loadRelation(models: T[], relation: string, model: Function, localField: string): Promise; - private static getFactory; - protected readonly properties: ModelProperty[]; - private readonly relations; - id?: number; - [key: string]: any; - constructor(data: any); - protected abstract defineProperties(): void; - protected defineProperty(name: string, validator?: Validator | RegExp): void; - private updateWithData; - protected beforeSave(exists: boolean, connection: Connection): Promise; - protected afterSave(): Promise; - save(connection?: Connection, postHook?: (callback: () => Promise) => void): Promise; - private saveTransaction; - static get table(): string; - get table(): string; - exists(): Promise; - delete(): Promise; - validate(onlyFormat?: boolean, connection?: Connection): Promise; - private cache; - protected relation(name: string): T | null; -} -export interface ModelFactory { - (data: any): T; -} -declare class ModelProperty { - readonly name: string; - private readonly validator; - private val?; - constructor(name: string, validator: Validator); - validate(onlyFormat: boolean, connection?: Connection): Promise; - get value(): T | undefined; - set value(val: T | undefined); -} -export declare class ModelCache { - private static readonly caches; - static cache(instance: Model): void; - static forget(instance: Model): void; - static all(table: string): { - [key: number]: Model; - } | undefined; - static get(table: string, id: number): Model | undefined; -} -export declare const EMAIL_REGEX: RegExp; -export {}; diff --git a/dist/db/Model.js b/dist/db/Model.js deleted file mode 100644 index cfa3221..0000000 --- a/dist/db/Model.js +++ /dev/null @@ -1,291 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import MysqlConnectionManager, { query } from "./MysqlConnectionManager"; -import Validator from "./Validator"; -import Query from "./Query"; -import Pagination from "../Pagination"; -export default class Model { - constructor(data) { - this.properties = []; - this.relations = {}; - this.defineProperty('id', new Validator()); - this.defineProperties(); - this.updateWithData(data); - } - static getById(id) { - return __awaiter(this, void 0, void 0, function* () { - const cachedModel = ModelCache.get(this.table, id); - if ((cachedModel === null || cachedModel === void 0 ? void 0 : cachedModel.constructor) === this) { - return cachedModel; - } - const models = yield this.models(this.select().where('id', id).first()); - return models.length > 0 ? models[0] : null; - }); - } - static paginate(request, perPage = 20) { - return __awaiter(this, void 0, void 0, function* () { - let page = request.params.page ? parseInt(request.params.page) : 1; - let query = this.select().limit(perPage, (page - 1) * perPage).withTotalRowCount(); - if (request.params.sortBy) { - const dir = request.params.sortDirection; - query = query.sortBy(request.params.sortBy, dir === 'ASC' || dir === 'DESC' ? dir : undefined); - } - else { - query = query.sortBy('id'); - } - const models = yield this.models(query); - // @ts-ignore - models.pagination = new Pagination(models, page, perPage, models.totalCount); - return models; - }); - } - static select(...fields) { - return Query.select(this.table, ...fields); - } - static update(data) { - return Query.update(this.table, data); - } - static delete() { - return Query.delete(this.table); - } - static models(query) { - return __awaiter(this, void 0, void 0, function* () { - const results = yield query.execute(); - const models = []; - const factory = this.getFactory(); - for (const result of results.results) { - const cachedModel = ModelCache.get(this.table, result.id); - if (cachedModel && cachedModel.constructor === this) { - cachedModel.updateWithData(result); - models.push(cachedModel); - } - else { - models.push(factory(result)); - } - } - // @ts-ignore - models.totalCount = results.foundRows; - return models; - }); - } - static loadRelation(models, relation, model, localField) { - return __awaiter(this, void 0, void 0, function* () { - const loadMap = {}; - const ids = models.map(m => { - m.relations[relation] = null; - if (m[localField]) - loadMap[m[localField]] = v => m.relations[relation] = v; - return m[localField]; - }).filter(id => id); - for (const v of yield model.models(model.select().whereIn('id', ids))) { - loadMap[v.id](v); - } - }); - } - static getFactory(factory) { - if (factory === undefined) { - factory = this.FACTORY; - if (factory === undefined) - factory = data => new this(data); - } - return factory; - } - defineProperty(name, validator) { - if (validator === undefined) - validator = new Validator(); - if (validator instanceof RegExp) { - const regexp = validator; - validator = new Validator().regexp(regexp); - } - const prop = new ModelProperty(name, validator); - this.properties.push(prop); - Object.defineProperty(this, name, { - get: () => prop.value, - set: (value) => prop.value = value, - }); - } - updateWithData(data) { - this.id = data['id']; - for (const prop of this.properties) { - if (data[prop.name] !== undefined) { - this[prop.name] = data[prop.name]; - } - } - } - beforeSave(exists, connection) { - return __awaiter(this, void 0, void 0, function* () { - }); - } - afterSave() { - return __awaiter(this, void 0, void 0, function* () { - }); - } - save(connection, postHook) { - return __awaiter(this, void 0, void 0, function* () { - yield this.validate(false, connection); - const exists = yield this.exists(); - let needs_full_update = false; - if (connection) { - needs_full_update = yield this.saveTransaction(connection, exists, needs_full_update); - } - else { - needs_full_update = yield MysqlConnectionManager.wrapTransaction((connection) => __awaiter(this, void 0, void 0, function* () { return this.saveTransaction(connection, exists, needs_full_update); })); - } - const callback = () => __awaiter(this, void 0, void 0, function* () { - if (needs_full_update) { - this.updateWithData((yield this.constructor.select().where('id', this.id).first().execute()).results[0]); - } - if (!exists) { - this.cache(); - } - yield this.afterSave(); - }); - if (connection) { - postHook(callback); - } - else { - yield callback(); - } - }); - } - saveTransaction(connection, exists, needs_full_update) { - return __awaiter(this, void 0, void 0, function* () { - // Before save - yield this.beforeSave(exists, connection); - if (exists && this.hasOwnProperty('updated_at')) { - this.updated_at = new Date(); - } - const props = []; - const values = []; - if (exists) { - for (const prop of this.properties) { - if (prop.value !== undefined) { - props.push(prop.name + '=?'); - values.push(prop.value); - } - else { - needs_full_update = true; - } - } - values.push(this.id); - yield query(`UPDATE ${this.table} SET ${props.join(',')} WHERE id=?`, values, connection); - } - else { - const props_holders = []; - for (const prop of this.properties) { - if (prop.value !== undefined) { - props.push(prop.name); - props_holders.push('?'); - values.push(prop.value); - } - else { - needs_full_update = true; - } - } - const result = yield query(`INSERT INTO ${this.table} (${props.join(', ')}) VALUES(${props_holders.join(', ')})`, values, connection); - this.id = result.other.insertId; - } - return needs_full_update; - }); - } - static get table() { - return this.name - .replace(/(?:^|\.?)([A-Z])/g, (x, y) => '_' + y.toLowerCase()) - .replace(/^_/, '') - + 's'; - } - get table() { - // @ts-ignore - return this.constructor.table; - } - exists() { - return __awaiter(this, void 0, void 0, function* () { - if (!this.id) - return false; - const result = yield query(`SELECT 1 FROM ${this.table} WHERE id=? LIMIT 1`, [ - this.id, - ]); - return result.results.length > 0; - }); - } - delete() { - return __awaiter(this, void 0, void 0, function* () { - if (!(yield this.exists())) - throw new Error('This model instance doesn\'t exist in DB.'); - yield query(`DELETE FROM ${this.table} WHERE id=?`, [ - this.id, - ]); - ModelCache.forget(this); - this.id = undefined; - }); - } - validate(onlyFormat = false, connection) { - return __awaiter(this, void 0, void 0, function* () { - return yield Promise.all(this.properties.map(prop => prop.validate(onlyFormat, connection))); - }); - } - cache() { - ModelCache.cache(this); - } - relation(name) { - if (this.relations[name] === undefined) - throw new Error('Model not loaded'); - return this.relations[name]; - } -} -class ModelProperty { - constructor(name, validator) { - this.name = name; - this.validator = validator; - } - validate(onlyFormat, connection) { - return __awaiter(this, void 0, void 0, function* () { - return yield this.validator.execute(this.name, this.value, onlyFormat, connection); - }); - } - get value() { - return this.val; - } - set value(val) { - this.val = val; - } -} -export class ModelCache { - static cache(instance) { - if (instance.id === undefined) - throw new Error('Cannot cache an instance with an undefined id.'); - let tableCache = this.caches[instance.table]; - if (!tableCache) - tableCache = this.caches[instance.table] = {}; - if (!tableCache[instance.id]) - tableCache[instance.id] = instance; - } - static forget(instance) { - if (instance.id === undefined) - throw new Error('Cannot forget an instance with an undefined id.'); - let tableCache = this.caches[instance.table]; - if (!tableCache) - return; - if (tableCache[instance.id]) - delete tableCache[instance.id]; - } - static all(table) { - return this.caches[table]; - } - static get(table, id) { - const tableCache = this.all(table); - if (!tableCache) - return undefined; - return tableCache[id]; - } -} -ModelCache.caches = {}; -export const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTW9kZWwuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImRiL01vZGVsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sc0JBQXNCLEVBQUUsRUFBQyxLQUFLLEVBQUMsTUFBTSwwQkFBMEIsQ0FBQztBQUN2RSxPQUFPLFNBQVMsTUFBTSxhQUFhLENBQUM7QUFFcEMsT0FBTyxLQUFLLE1BQU0sU0FBUyxDQUFDO0FBRTVCLE9BQU8sVUFBVSxNQUFNLGVBQWUsQ0FBQztBQUV2QyxNQUFNLENBQ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ICAgdGhpcy51cGRhdGVkX2F0ID0gbmV3IERhdGUoKTtcbiAgICAgICAgfVxuXG4gICAgICAgIGNvbnN0IHByb3BzID0gW107XG4gICAgICAgIGNvbnN0IHZhbHVlcyA9IFtdO1xuXG4gICAgICAgIGlmIChleGlzdHMpIHtcbiAgICAgICAgICAgIGZvciAoY29uc3QgcHJvcCBvZiB0aGlzLnByb3BlcnRpZXMpIHtcbiAgICAgICAgICAgICAgICBpZiAocHJvcC52YWx1ZSAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgICAgIHByb3BzLnB1c2gocHJvcC5uYW1lICsgJz0/Jyk7XG4gICAgICAgICAgICAgICAgICAgIHZhbHVlcy5wdXNoKHByb3AudmFsdWUpO1xuICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgIG5lZWRzX2Z1bGxfdXBkYXRlID0gdHJ1ZTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YWx1ZXMucHVzaCh0aGlzLmlkKTtcbiAgICAgICAgICAgIGF3YWl0IHF1ZXJ5KGBVUERBVEUgJHt0aGlzLnRhYmxlfSBTRVQgJHtwcm9wcy5qb2luKCcsJyl9IFdIRVJFIGlkPT9gLCB2YWx1ZXMsIGNvbm5lY3Rpb24pO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgY29uc3QgcHJvcHNfaG9sZGVycyA9IFtdO1xuICAgICAgICAgICAgZm9yIChjb25zdCBwcm9wIG9mIHRoaXMucHJvcGVydGllcykge1xuICAgICAgICAgICAgICAgIGlmIChwcm9wLnZhbHVlICE9PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgICAgICAgICAgcHJvcHMucHVzaChwcm9wLm5hbWUpO1xuICAgICAgICAgICAgICAgICAgICBwcm9wc19ob2xkZXJzLnB1c2goJz8nKTtcbiAgICAgICAgICAgICAgICAgICAgdmFsdWVzLnB1c2gocHJvcC52YWx1Z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6IHtcbiAgICAgICAgW2tleTogbnVtYmVyXTogTW9kZWxcbiAgICB9IHwgdW5kZWZpbmVkIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGVzW3RhYmxlXTtcbiAgICB9XG5cbiAgICBwdWJsaWMgc3RhdGljIGdldCh0YWJsZTogc3RyaW5nLCBpZDogbnVtYmVyKTogTW9kZWwgfCB1bmRlZmluZWQge1xuICAgICAgICBjb25zdCB0YWJsZUNhY2hlID0gdGhpcy5hbGwodGFibGUpO1xuICAgICAgICBpZiAoIXRhYmxlQ2FjaGUpIHJldHVybiB1bmRlZmluZWQ7XG4gICAgICAgIHJldHVybiB0YWJsZUNhY2hlW2lkXTtcbiAgICB9XG59XG5cbmV4cG9ydCBjb25zdCBFTUFJTF9SRUdFWCA9IC9eW2EtekEtWjAtOS4hIyQlJicqK1xcXFwvPT9eX2B7fH1+LV0rQFthLXpBLVowLTldKD86W2EtekEtWjAtOS1dezAsNjF9W2EtekEtWjAtOV0pPyg/OlxcLlthLXpBLVowLTldKD86W2EtekEtWjAtOS1dezAsNjF9W2EtekEtWjAtOV0pPykrJC87Il19 \ No newline at end of file diff --git a/dist/db/MysqlConnectionManager.d.ts b/dist/db/MysqlConnectionManager.d.ts deleted file mode 100644 index bc6eef0..0000000 --- a/dist/db/MysqlConnectionManager.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Connection, FieldInfo, Pool } from 'mysql'; -import Migration from "./Migration"; -export interface QueryResult { - readonly results: any[]; - readonly fields: FieldInfo[]; - readonly other?: any; - foundRows?: number; -} -export declare function query(queryString: string, values?: any, connection?: Connection): Promise; -export default class MysqlConnectionManager { - private static currentPool?; - private static databaseReady; - private static readonly migrations; - static registerMigration(migration: (version: number) => Migration): void; - static prepare(): Promise; - static get pool(): Pool; - private static createPool; - static endPool(): Promise; - static query(queryString: string, values?: any, connection?: Connection): Promise; - static wrapTransaction(transaction: (connection: Connection) => Promise): Promise; - private static rejectAndRollback; - private static handleMigrations; -} diff --git a/dist/db/MysqlConnectionManager.js b/dist/db/MysqlConnectionManager.js deleted file mode 100644 index 3353b4b..0000000 --- a/dist/db/MysqlConnectionManager.js +++ /dev/null @@ -1,168 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import mysql from 'mysql'; -import config from 'config'; -import Logger from "../Logger"; -export function query(queryString, values, connection) { - return __awaiter(this, void 0, void 0, function* () { - return yield MysqlConnectionManager.query(queryString, values, connection); - }); -} -export default class MysqlConnectionManager { - static registerMigration(migration) { - this.migrations.push(migration(this.migrations.length + 1)); - } - static prepare() { - return __awaiter(this, void 0, void 0, function* () { - if (config.get('mysql.create_database_automatically') === true) { - const dbName = config.get('mysql.database'); - Logger.info(`Creating database ${dbName}...`); - const connection = mysql.createConnection({ - host: config.get('mysql.host'), - user: config.get('mysql.user'), - password: config.get('mysql.password'), - }); - yield new Promise((resolve, reject) => { - connection.query(`CREATE DATABASE IF NOT EXISTS ${dbName}`, (error) => { - if (error !== null) { - reject(error); - } - else { - resolve(); - } - }); - }); - connection.end(); - Logger.info(`Database ${dbName} created!`); - } - this.databaseReady = true; - yield this.handleMigrations(); - }); - } - static get pool() { - if (this.currentPool === undefined) { - this.currentPool = this.createPool(); - } - return this.currentPool; - } - static createPool() { - return mysql.createPool({ - connectionLimit: config.get('mysql.connectionLimit'), - host: config.get('mysql.host'), - user: config.get('mysql.user'), - password: config.get('mysql.password'), - database: config.get('mysql.database'), - }); - } - static endPool() { - return __awaiter(this, void 0, void 0, function* () { - return new Promise(resolve => { - if (this.currentPool !== undefined) { - this.currentPool.end(() => { - Logger.info('Mysql connection pool ended.'); - resolve(); - }); - this.currentPool = undefined; - } - else { - resolve(); - } - }); - }); - } - static query(queryString, values, connection) { - return __awaiter(this, void 0, void 0, function* () { - return yield new Promise((resolve, reject) => { - Logger.dev('Mysql query:', queryString, '; values:', values); - (connection ? connection : this.pool).query(queryString, values, (error, results, fields) => { - if (error !== null) { - reject(error); - return; - } - resolve({ - results: Array.isArray(results) ? results : [], - fields: fields !== undefined ? fields : [], - other: Array.isArray(results) ? null : results - }); - }); - }); - }); - } - static wrapTransaction(transaction) { - return __awaiter(this, void 0, void 0, function* () { - return yield new Promise((resolve, reject) => { - this.pool.getConnection((err, connection) => { - if (err) { - reject(err); - return; - } - connection.beginTransaction((err) => { - if (err) { - reject(err); - this.pool.releaseConnection(connection); - return; - } - transaction(connection).then(val => { - connection.commit((err) => { - if (err) { - this.rejectAndRollback(connection, err, reject); - this.pool.releaseConnection(connection); - return; - } - this.pool.releaseConnection(connection); - resolve(val); - }); - }).catch(err => { - this.rejectAndRollback(connection, err, reject); - this.pool.releaseConnection(connection); - }); - }); - }); - }); - }); - } - static rejectAndRollback(connection, err, reject) { - connection.rollback((rollbackErr) => { - if (rollbackErr) { - reject(err + '\n' + rollbackErr); - } - else { - reject(err); - } - }); - } - static handleMigrations() { - return __awaiter(this, void 0, void 0, function* () { - let currentVersion = 0; - try { - const result = yield query('SELECT id FROM migrations ORDER BY id DESC LIMIT 1'); - currentVersion = result.results[0].id; - } - catch (e) { - if (e.code === 'ECONNREFUSED' || e.code !== 'ER_NO_SUCH_TABLE') { - throw new Error('Cannot run migrations: ' + e.code); - } - } - for (const migration of this.migrations) { - if (yield migration.shouldRun(currentVersion)) { - Logger.info('Running migration ', migration.version, migration.constructor.name); - yield migration.install(); - yield query('INSERT INTO migrations VALUES(?, ?, NOW())', [ - migration.version, - migration.constructor.name, - ]); - } - } - }); - } -} -MysqlConnectionManager.databaseReady = false; -MysqlConnectionManager.migrations = []; -//# sourceMappingURL=data:application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sLnVzZXInKSxcbiAgICAgICAgICAgICAgICBwYXNzd29yZDogY29uZmlnLmdldCgnbXlzcWwucGFzc3dvcmQnKSxcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgYXdhaXQgbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgICAgICAgICAgIGNvbm5lY3Rpb24ucXVlcnkoYENSRUFURSBEQVRBQkFTRSBJRiBOT1QgRVhJU1RTICR7ZGJOYW1lfWAsIChlcnJvcikgPT4ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoZXJyb3IgIT09IG51bGwpIHtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJlamVjdChlcnJvcik7XG4gICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXNvbHZlKCk7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgY29ubmVjdGlvbi5lbmQoKTtcbiAgICAgICAgICAgIExvZ2dlci5pbmZvKGBEYXRhYmFzZSAke2RiTmFtZX0gY3JlYXRlZCFgKTtcbiAgICAgICAgfVxuICAgICAgICB0aGlzLmRhdGFiYXNlUmVhZHkgPSB0cnVlO1xuXG4gICAgICAgIGF3YWl0IHRoaXMuaGFuZGxlTWlncmF0aW9ucygpO1xuICAgIH1cblxuICAgIHB1YmxpYyBzdGF0aWMgZ2V0IHBvb2woKTogUG9vbCB7XG4gICAgICAgIGlmICh0aGlzLmN1cnJlbnRQb29sID09PSB1bmRlZmluZWQpIHtcbiAgICAgICAgICAgIHRoaXMuY3VycmVudFBvb2wgPSB0aGlzLmNyZWF0ZVBvb2woKTtcbiAgICAgICAgfVxuICAgICAgICByZXR1cm4gdGhpcy5jdXJyZW50UG9vbDtcbiAgICB9XG5cbiAgICBwcml2YXRlIHN0YXRpYyBjcmVhdGVQb29sKCk6IFBvb2wge1xuICAgICAgICByZXR1cm4gbXlzcWwuY3JlYXRlUG9vbCh7XG4gICAgICAgICAgICBjb25uZWN0aW9uTGltaXQ6IGNvbmZpZy5nZXQoJ215c3FsLmNvbm5lY3Rpb25MaW1pdCcpLFxuICAgICAgICAgICAgaG9zdDogY29uZmlnLmdldCgnbXlzcWwuaG9zdCcpLFxuICAgICAgICAgICAgdXNlcjogY29uZmlnLmdldCgnbXlzcWwudXNlcicpLFxuICAgICAgICAgICAgcGFzc3dvcmQ6IGNvbmZpZy5nZXQoJ215c3FsLnBhc3N3b3JkJyksXG4gICAgICAgICAgICBkYXRhYmFzZTogY29uZmlnLmdldCgnbXlzcWwuZGF0YWJhc2UnKSxcbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgcHVibGljIHN0YXRpYyBhc3luYyBlbmRQb29sKCk6IFByb21pc2U8dm9pZD4ge1xuICAgICAgICByZXR1cm4gbmV3IFByb21pc2UocmVzb2x2ZSA9PiB7XG4gICAgICAgICAgICBpZiAodGhpcy5jdXJyZW50UG9vbCAhPT0gdW5kZWZpbmVkKSB7XG4gICAgICAgICAgICAgICAgdGhpcy5jdXJyZW50UG9vbC5lbmQoKCkgPT4ge1xuICAgICAgICAgICAgICAgICAgICBMb2dnZXIuaW5mbygnTXlzcWwgY29ubmVjdGlvbiBwb29sIGVuZGVkLicpO1xuICAgICAgICAgICAgICAgICAgICByZXNvbHZlKCk7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgdGhpcy5jdXJyZW50UG9vbCA9IHVuZGVmaW5lZDtcbiAgICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICAgICAgcmVzb2x2ZSgpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBwdWJsaWMgc3RhdGljIGFzeW5jIHF1ZXJ5KHF1ZXJ5U3RyaW5nOiBzdHJpbmcsIHZhbHVlcz86IGFueSwgY29ubmVjdGlvbj86IENvbm5lY3Rpb24pOiBQcm9taXNlPFF1ZXJ5UmVzdWx0PiB7XG4gICAgICAgIHJldHVybiBhd2FpdCBuZXcgUHJvbWlzZTxRdWVyeVJlc3VsdD4oKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgICAgICAgTG9nZ2VyLmRldignTXlzcWwgcXVlcnk6JywgcXVlcnlTdHJpbmcsICc7IHZhbHVlczonLCB2YWx1ZXMpO1xuICAgICAgICAgICAgKGNvbm5lY3Rpb24gPyBjb25uZWN0aW9uIDogdGhpcy5wb29sKS5xdWVyeShxdWVyeVN0cmluZywgdmFsdWVzLCAoZXJyb3IsIHJlc3VsdHMsIGZpZWxkcykgPT4ge1xuICAgICAgICAgICAgICAgIGlmIChlcnJvciAhPT0gbnVsbCkge1xuICAgICAgICAgICAgICAgICAgICByZWplY3QoZXJyb3IpO1xuICAgICAgICAgICAgICAgICAgICByZXR1cm47XG4gICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgcmVzb2x2ZSh7XG4gICAgICAgICAgICAgICAgICAgIHJlc3VsdHM6IEFycmF5LmlzQXJyYXkocmVzdWx0cykgPyByZXN1bHRzIDogW10sXG4gICAgICAgICAgICAgICAgICAgIGZpZWxkczogZmllbGRzICE9PSB1bmRlZmluZWQgPyBmaWVsZHMgOiBbXSxcbiAgICAgICAgICAgICAgICAgICAgb3RoZXI6IEFycmF5LmlzQXJyYXkocmVzdWx0cykgPyBudWxsIDogcmVzdWx0c1xuICAgICAgICAgICAgICAgIH0pO1xuICAgICAgICAgICAgfSk7XG4gICAgICAgIH0pO1xuICAgIH1cblxuICAgIHB1YmxpYyBzdGF0aWMgYXN5bmMgd3JhcFRyYW5zYWN0aW9uPFQ+KHRyYW5zYWN0aW9uOiAoY29ubmVjdGlvbjogQ29ubmVjdGlvbikgPT4gUHJvbWlzZTxUPik6IFByb21pc2U8VD4ge1xuICAgICAgICByZXR1cm4gYXdhaXQgbmV3IFByb21pc2U8VD4oKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgICAgICAgdGhpcy5wb29sLmdldENvbm5lY3Rpb24oKGVyciwgY29ubmVjdGlvbikgPT4ge1xuICAgICAgICAgICAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgICAgICAgICAgICAgcmVqZWN0KGVycik7XG4gICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICBjb25uZWN0aW9uLmJlZ2luVHJhbnNhY3Rpb24oKGVycikgPT4ge1xuICAgICAgICAgICAgICAgICAgICBpZiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZWplY3QoZXJyKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucG9vbC5yZWxlYXNlQ29ubmVjdGlvbihjb25uZWN0aW9uKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIHRyYW5zYWN0aW9uKGNvbm5lY3Rpb24pLnRoZW4odmFsID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgIGNvbm5lY3Rpb24uY29tbWl0KChlcnIpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZXJyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucmVqZWN0QW5kUm9sbGJhY2soY29ubmVjdGlvbiwgZXJyLCByZWplY3QpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnBvb2wucmVsZWFzZUNvbm5lY3Rpb24oY29ubmVjdGlvbik7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9XG5cbiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnBvb2wucmVsZWFzZUNvbm5lY3Rpb24oY29ubmVjdGlvbik7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzb2x2ZSh2YWwpO1xuICAgICAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgICAgIH0pLmNhdGNoKGVyciA9PiB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLnJlamVjdEFuZFJvbGxiYWNrKGNvbm5lY3Rpb24sIGVyciwgcmVqZWN0KTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucG9vbC5yZWxlYXNlQ29ubmVjdGlvbihjb25uZWN0aW9uKTtcbiAgICAgICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9KTtcbiAgICAgICAgfSk7XG4gICAgfVxuXG4gICAgcHJpdmF0ZSBzdGF0aWMgcmVqZWN0QW5kUm9sbGJhY2soY29ubmVjdGlvbjogQ29ubmVjdGlvbiwgZXJyOiBhbnksIHJlamVjdDogKGVycjogYW55KSA9PiB2b2lkKSB7XG4gICAgICAgIGNvbm5lY3Rpb24ucm9sbGJhY2soKHJvbGxiYWNrRXJyKSA9PiB7XG4gICAgICAgICAgICBpZiAocm9sbGJhY2tFcnIpIHtcbiAgICAgICAgICAgICAgICByZWplY3QoZXJyICsgJ1xcbicgKyByb2xsYmFja0Vycik7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgIHJlamVjdChlcnIpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICB9XG5cbiAgICBwcml2YXRlIHN0YXRpYyBhc3luYyBoYW5kbGVNaWdyYXRpb25zKCkge1xuICAgICAgICBsZXQgY3VycmVudFZlcnNpb24gPSAwO1xuXG4gICAgICAgIHRyeSB7XG4gICAgICAgICAgICBjb25zdCByZXN1bHQgPSBhd2FpdCBxdWVyeSgnU0VMRUNUIGlkIEZST00gbWlncmF0aW9ucyBPUkRFUiBCWSBpZCBERVNDIExJTUlUIDEnKTtcbiAgICAgICAgICAgIGN1cnJlbnRWZXJzaW9uID0gcmVzdWx0LnJlc3VsdHNbMF0uaWQ7XG4gICAgICAgIH0gY2F0Y2ggKGUpIHtcbiAgICAgICAgICAgIGlmIChlLmNvZGUgPT09ICdFQ09OTlJFRlVTRUQnIHx8IGUuY29kZSAhPT0gJ0VSX05PX1NVQ0hfVEFCTEUnKSB7XG4gICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCdDYW5ub3QgcnVuIG1pZ3JhdGlvbnM6ICcgKyBlLmNvZGUpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgZm9yIChjb25zdCBtaWdyYXRpb24gb2YgdGhpcy5taWdyYXRpb25zKSB7XG4gICAgICAgICAgICBpZiAoYXdhaXQgbWlncmF0aW9uLnNob3VsZFJ1bihjdXJyZW50VmVyc2lvbikpIHtcbiAgICAgICAgICAgICAgICBMb2dnZXIuaW5mbygnUnVubmluZyBtaWdyYXRpb24gJywgbWlncmF0aW9uLnZlcnNpb24sIG1pZ3JhdGlvbi5jb25zdHJ1Y3Rvci5uYW1lKTtcbiAgICAgICAgICAgICAgICBhd2FpdCBtaWdyYXRpb24uaW5zdGFsbCgpO1xuICAgICAgICAgICAgICAgIGF3YWl0IHF1ZXJ5KCdJTlNFUlQgSU5UTyBtaWdyYXRpb25zIFZBTFVFUyg/LCA/LCBOT1coKSknLCBbXG4gICAgICAgICAgICAgICAgICAgIG1pZ3JhdGlvbi52ZXJzaW9uLFxuICAgICAgICAgICAgICAgICAgICBtaWdyYXRpb24uY29uc3RydWN0b3IubmFtZSxcbiAgICAgICAgICAgICAgICBdKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cbn0iXX0= \ No newline at end of file diff --git a/dist/db/Query.d.ts b/dist/db/Query.d.ts deleted file mode 100644 index 72cd517..0000000 --- a/dist/db/Query.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { QueryResult } from "./MysqlConnectionManager"; -import { Connection } from "mysql"; -export default class Query { - static select(table: string, ...fields: string[]): Query; - static update(table: string, data: { - [key: string]: any; - }): Query; - static delete(table: string): Query; - private readonly type; - private readonly table; - private readonly fields; - private _where; - private _limit?; - private _offset?; - private _sortBy?; - private _sortDirection?; - private _foundRows; - private constructor(); - where(field: string, value: string | Date | Query | any, operator?: WhereOperator, test?: WhereTest): Query; - whereNot(field: string, value: string | Date | Query | any, operator?: WhereOperator): Query; - orWhere(field: string, value: string | Date | Query | any): Query; - whereIn(field: string, value: any[]): Query; - limit(limit: number, offset?: number): Query; - first(): Query; - sortBy(field: string, direction?: 'ASC' | 'DESC'): Query; - withTotalRowCount(): Query; - toString(final?: boolean): string; - build(): string; - get variables(): any[]; - isCacheable(): boolean; - execute(connection?: Connection): Promise; -} -export declare enum QueryType { - SELECT = 0, - UPDATE = 1, - DELETE = 2 -} -declare enum WhereOperator { - AND = "AND", - OR = "OR" -} -declare enum WhereTest { - EQUALS = "=", - DIFFERENT = "!=", - IN = " IN " -} -export {}; diff --git a/dist/db/Query.js b/dist/db/Query.js deleted file mode 100644 index ece3d18..0000000 --- a/dist/db/Query.js +++ /dev/null @@ -1,176 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import { query } from "./MysqlConnectionManager"; -export default class Query { - constructor(type, table, fields) { - this._where = []; - this._foundRows = false; - this.type = type; - this.table = table; - this.fields = fields || []; - } - static select(table, ...fields) { - return new Query(QueryType.SELECT, table, fields.length > 0 ? fields : ['*']); - } - static update(table, data) { - const fields = []; - for (let key in data) { - if (data.hasOwnProperty(key)) { - fields.push(new UpdateFieldValue(key, data[key])); - } - } - return new Query(QueryType.UPDATE, table, fields); - } - static delete(table) { - return new Query(QueryType.DELETE, table); - } - where(field, value, operator = WhereOperator.AND, test = WhereTest.EQUALS) { - this._where.push(new WhereFieldValue(field, value, operator, test)); - return this; - } - whereNot(field, value, operator = WhereOperator.AND) { - return this.where(field, value, operator, WhereTest.DIFFERENT); - } - orWhere(field, value) { - return this.where(field, value, WhereOperator.OR); - } - whereIn(field, value) { - return this.where(field, value, WhereOperator.AND, WhereTest.IN); - } - limit(limit, offset = 0) { - this._limit = limit; - this._offset = offset; - return this; - } - first() { - return this.limit(1); - } - sortBy(field, direction = 'ASC') { - this._sortBy = field; - this._sortDirection = direction; - return this; - } - withTotalRowCount() { - this._foundRows = true; - return this; - } - toString(final = false) { - var _a; - let query = ''; - let fields = (_a = this.fields) === null || _a === void 0 ? void 0 : _a.join(','); - let where = ''; - if (this._where.length > 0) { - where = `WHERE ${this._where[0]}`; - for (let i = 1; i < this._where.length; i++) { - where += this._where[i].toString(false); - } - } - let limit = ''; - if (typeof this._limit === 'number') { - limit = `LIMIT ${this._limit}`; - if (typeof this._offset === 'number' && this._offset !== 0) { - limit += ` OFFSET ${this._offset}`; - } - } - let orderBy = ''; - if (typeof this._sortBy === 'string') { - orderBy = `ORDER BY ${this._sortBy} ${this._sortDirection}`; - } - switch (this.type) { - case QueryType.SELECT: - query = `SELECT ${this._foundRows ? 'SQL_CALC_FOUND_ROWS' : ''} ${fields} FROM ${this.table} ${where} ${orderBy} ${limit}`; - break; - case QueryType.UPDATE: - query = `UPDATE ${this.table} SET ${fields} ${where} ${orderBy} ${limit}`; - break; - case QueryType.DELETE: - query = `DELETE FROM ${this.table} ${where} ${orderBy} ${limit}`; - break; - } - return final ? query : `(${query})`; - } - build() { - return this.toString(true); - } - get variables() { - var _a; - const variables = []; - (_a = this.fields) === null || _a === void 0 ? void 0 : _a.filter(v => v instanceof FieldValue).flatMap(v => v.variables).forEach(v => variables.push(v)); - this._where.flatMap(v => v.variables) - .forEach(v => variables.push(v)); - return variables; - } - isCacheable() { - return this.type === QueryType.SELECT && this.fields.length === 1 && this.fields[0] === '*'; - } - execute(connection) { - return __awaiter(this, void 0, void 0, function* () { - const queryResult = yield query(this.build(), this.variables, connection); - if (this._foundRows) { - const foundRows = yield query('SELECT FOUND_ROWS() as r', undefined, connection); - queryResult.foundRows = foundRows.results[0].r; - } - return queryResult; - }); - } -} -export var QueryType; -(function (QueryType) { - QueryType[QueryType["SELECT"] = 0] = "SELECT"; - QueryType[QueryType["UPDATE"] = 1] = "UPDATE"; - QueryType[QueryType["DELETE"] = 2] = "DELETE"; -})(QueryType || (QueryType = {})); -var WhereOperator; -(function (WhereOperator) { - WhereOperator["AND"] = "AND"; - WhereOperator["OR"] = "OR"; -})(WhereOperator || (WhereOperator = {})); -var WhereTest; -(function (WhereTest) { - WhereTest["EQUALS"] = "="; - WhereTest["DIFFERENT"] = "!="; - WhereTest["IN"] = " IN "; -})(WhereTest || (WhereTest = {})); -class FieldValue { - constructor(field, value) { - this.field = field; - this.value = value; - } - toString(first = true) { - return `${!first ? ',' : ''}${this.field}${this.test}${this.value instanceof Query ? this.value : (Array.isArray(this.value) ? '(?)' : '?')}`; - } - get test() { - return '='; - } - get variables() { - return this.value instanceof Query ? this.value.variables : [this.value]; - } -} -class SelectFieldValue extends FieldValue { - toString(first = true) { - return `(${this.value instanceof Query ? this.value : '?'}) AS ${this.field}`; - } -} -class UpdateFieldValue extends FieldValue { -} -class WhereFieldValue extends FieldValue { - constructor(field, value, operator, test) { - super(field, value); - this.operator = operator; - this._test = test; - } - toString(first = true) { - return (!first ? ` ${this.operator} ` : '') + super.toString(true); - } - get test() { - return this._test; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUXVlcnkuanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImRiL1F1ZXJ5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sRUFBQyxLQUFLLEVB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bignLCcpO1xuXG4gICAgICAgIGxldCB3aGVyZSA9ICcnO1xuICAgICAgICBpZiAodGhpcy5fd2hlcmUubGVuZ3RoID4gMCkge1xuICAgICAgICAgICAgd2hlcmUgPSBgV0hFUkUgJHt0aGlzLl93aGVyZVswXX1gO1xuICAgICAgICAgICAgZm9yIChsZXQgaSA9IDE7IGkgPCB0aGlzLl93aGVyZS5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgICAgIHdoZXJlICs9IHRoaXMuX3doZXJlW2ldLnRvU3RyaW5nKGZhbHNlKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIGxldCBsaW1pdCA9ICcnO1xuICAgICAgICBpZiAodHlwZW9mIHRoaXMuX2xpbWl0ID09PSAnbnVtYmVyJykge1xuICAgICAgICAgICAgbGltaXQgPSBgTElNSVQgJHt0aGlzLl9saW1pdH1gO1xuICAgICAgICAgICAgaWYgKHR5cGVvZiB0aGlzLl9vZmZzZXQgPT09ICdudW1iZXInICYmIHRoaXMuX29mZnNldCAhPT0gMCkge1xuICAgICAgICAgICAgICAgIGxpbWl0ICs9IGAgT0ZGU0VUICR7dGhpcy5fb2Zmc2V0fWA7XG4gICAgICAgICAgICB9XG4gICAgICAgIH1cblxuICAgICAgICBsZXQgb3JkZXJCeSA9ICcnO1xuICAgICAgICBpZiAodHlwZW9mIHRoaXMuX3NvcnRCeSA9PT0gJ3N0cmluZycpIHtcbiAgICAgICAgICAgIG9yZGVyQnkgPSBgT1JERVIgQlkgJHt0aGlzLl9zb3J0Qnl9ICR7dGhpcy5fc29ydERpcmVjdGlvbn1gO1xuICAgICAgICB9XG5cbiAgICAgICAgc3dpdGNoICh0aGlzLnR5cGUpIHtcbiAgICAgICAgICAgIGNhc2UgUXVlcnlUeXBlLlNFTEVDVDpcbiAgICAgICAgICAgICAgICBxdWVyeSA9IGBTRUxFQ1QgJHt0aGlzLl9mb3VuZFJvd3MgPyAnU1FMX0NBTENfRk9VTkRfUk9XUycg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kcyBGaWVsZFZhbHVlIHtcbn1cblxuY2xhc3MgV2hlcmVGaWVsZFZhbHVlIGV4dGVuZHMgRmllbGRWYWx1ZSB7XG4gICAgcHJpdmF0ZSByZWFkb25seSBvcGVyYXRvcjogV2hlcmVPcGVyYXRvcjtcbiAgICBwcml2YXRlIHJlYWRvbmx5IF90ZXN0OiBXaGVyZVRlc3Q7XG5cbiAgICBjb25zdHJ1Y3RvcihmaWVsZDogc3RyaW5nLCB2YWx1ZTogYW55LCBvcGVyYXRvcjogV2hlcmVPcGVyYXRvciwgdGVzdDogV2hlcmVUZXN0KSB7XG4gICAgICAgIHN1cGVyKGZpZWxkLCB2YWx1ZSk7XG4gICAgICAgIHRoaXMub3BlcmF0b3IgPSBvcGVyYXRvcjtcbiAgICAgICAgdGhpcy5fdGVzdCA9IHRlc3Q7XG4gICAgfVxuXG4gICAgcHVibGljIHRvU3RyaW5nKGZpcnN0OiBib29sZWFuID0gdHJ1ZSk6IHN0cmluZyB7XG4gICAgICAgIHJldHVybiAoIWZpcnN0ID8gYCAke3RoaXMub3BlcmF0b3J9IGAgOiAnJykgKyBzdXBlci50b1N0cmluZyh0cnVlKTtcbiAgICB9XG5cbiAgICBwcm90ZWN0ZWQgZ2V0IHRlc3QoKTogc3RyaW5nIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuX3Rlc3Q7XG4gICAgfVxufSJdfQ== \ No newline at end of file diff --git a/dist/db/Validator.d.ts b/dist/db/Validator.d.ts deleted file mode 100644 index e5a2edd..0000000 --- a/dist/db/Validator.d.ts +++ /dev/null @@ -1,86 +0,0 @@ -import Model from "./Model"; -import Query from "./Query"; -import { Connection } from "mysql"; -export default class Validator { - private readonly steps; - private readonly validationAttributes; - private _min?; - private _max?; - /** - * @param thingName The name of the thing to validate. - * @param value The value to verify. - * @param onlyFormat {@code true} to only validate format properties, {@code false} otherwise. - * @param connection A connection to use in case of wrapped transactions. - */ - execute(thingName: string, value: T | undefined, onlyFormat: boolean, connection?: Connection): Promise; - defined(): Validator; - acceptUndefined(): Validator; - equals(other?: T): Validator; - regexp(regexp: RegExp): Validator; - length(length: number): Validator; - /** - * @param minLength included - * @param maxLength included - */ - between(minLength: number, maxLength: number): Validator; - /** - * @param min included - */ - min(min: number): Validator; - /** - * @param max included - */ - max(max: number): Validator; - unique(model: Model, querySupplier?: () => Query): Validator; - exists(modelClass: Function, foreignKey?: string): Validator; - private addStep; - getValidationAttributes(): string[]; - step(step: number): Validator; -} -export declare class ValidationBag extends Error { - private readonly messages; - addMessage(err: ValidationError): void; - hasMessages(): boolean; - getMessages(): { - [p: string]: ValidationError; - }; -} -export declare abstract class ValidationError extends Error { - thingName?: string; - value?: any; - get name(): string; -} -export declare class BadLengthValidationError extends ValidationError { - private readonly expectedLength; - private readonly maxLength?; - constructor(expectedLength: number, maxLength?: number); - get message(): string; -} -export declare class BadValueValidationError extends ValidationError { - private readonly expectedValue; - constructor(expectedValue: any); - get message(): string; -} -export declare class OutOfRangeValidationError extends ValidationError { - private readonly min?; - private readonly max?; - constructor(min?: number, max?: number); - get message(): string; -} -export declare class InvalidFormatValidationError extends ValidationError { - get message(): string; -} -export declare class UndefinedValueValidationError extends ValidationError { - get message(): string; -} -export declare class AlreadyExistsValidationError extends ValidationError { - private readonly table; - constructor(table: string); - get message(): string; -} -export declare class UnknownRelationValidationError extends ValidationError { - private readonly table; - private readonly foreignKey?; - constructor(table: string, foreignKey?: string); - get message(): string; -} diff --git a/dist/db/Validator.js b/dist/db/Validator.js deleted file mode 100644 index 6766235..0000000 --- a/dist/db/Validator.js +++ /dev/null @@ -1,261 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -export default class Validator { - constructor() { - this.steps = []; - this.validationAttributes = []; - } - /** - * @param thingName The name of the thing to validate. - * @param value The value to verify. - * @param onlyFormat {@code true} to only validate format properties, {@code false} otherwise. - * @param connection A connection to use in case of wrapped transactions. - */ - execute(thingName, value, onlyFormat, connection) { - return __awaiter(this, void 0, void 0, function* () { - const bag = new ValidationBag(); - for (const step of this.steps) { - if (onlyFormat && !step.isFormat) - continue; - const result = step.verifyStep(value, thingName, connection); - if ((result === false || result instanceof Promise && (yield result) === false) && step.throw) { - const error = step.throw(); - error.thingName = thingName; - error.value = value; - bag.addMessage(error); - } - else if (step.interrupt !== undefined && step.interrupt(value)) { - break; - } - } - if (bag.hasMessages()) { - throw bag; - } - }); - } - defined() { - this.validationAttributes.push('required'); - this.addStep({ - verifyStep: val => val !== undefined, - throw: () => new UndefinedValueValidationError(), - isFormat: true, - }); - return this; - } - acceptUndefined() { - this.addStep({ - verifyStep: () => true, - throw: null, - interrupt: val => val === undefined || val === null, - isFormat: true, - }); - return this; - } - equals(other) { - this.addStep({ - verifyStep: val => val === other, - throw: () => new BadValueValidationError(other), - isFormat: true, - }); - return this; - } - regexp(regexp) { - this.validationAttributes.push(`pattern="${regexp}"`); - this.addStep({ - verifyStep: val => regexp.test(val), - throw: () => new InvalidFormatValidationError(), - isFormat: true, - }); - return this; - } - length(length) { - this.addStep({ - verifyStep: val => val.length === length, - throw: () => new BadLengthValidationError(length), - isFormat: true, - }); - return this; - } - /** - * @param minLength included - * @param maxLength included - */ - between(minLength, maxLength) { - this.addStep({ - verifyStep: val => { - const length = val.length; - return length >= minLength && length <= maxLength; - }, - throw: () => new BadLengthValidationError(minLength, maxLength), - isFormat: true, - }); - return this; - } - /** - * @param min included - */ - min(min) { - this.validationAttributes.push(`min="${min}"`); - this._min = min; - this.addStep({ - verifyStep: val => { - return val >= min; - }, - throw: () => new OutOfRangeValidationError(this._min, this._max), - isFormat: true, - }); - return this; - } - /** - * @param max included - */ - max(max) { - this.validationAttributes.push(`max="${max}"`); - this._max = max; - this.addStep({ - verifyStep: val => { - return val <= max; - }, - throw: () => new OutOfRangeValidationError(this._min, this._max), - isFormat: true, - }); - return this; - } - unique(model, querySupplier) { - this.addStep({ - verifyStep: (val, thingName, c) => __awaiter(this, void 0, void 0, function* () { - let query; - if (querySupplier) { - query = querySupplier().where(thingName, val); - } - else { - query = model.constructor.select('1').where(thingName, val); - } - if (typeof model.id === 'number') - query = query.whereNot('id', model.id); - return (yield query.execute(c)).results.length === 0; - }), - throw: () => new AlreadyExistsValidationError(model.table), - isFormat: false, - }); - return this; - } - exists(modelClass, foreignKey) { - this.addStep({ - verifyStep: (val, thingName, c) => __awaiter(this, void 0, void 0, function* () { return (yield modelClass.select('1').where(foreignKey !== undefined ? foreignKey : thingName, val).execute(c)).results.length >= 1; }), - throw: () => new UnknownRelationValidationError(modelClass.table, foreignKey), - isFormat: false, - }); - return this; - } - addStep(step) { - this.steps.push(step); - } - getValidationAttributes() { - return this.validationAttributes; - } - step(step) { - this.validationAttributes.push(`step="${step}"`); - return this; - } -} -export class ValidationBag extends Error { - constructor() { - super(...arguments); - this.messages = {}; - } - addMessage(err) { - if (!err.thingName) { - throw new Error('Null thing name'); - } - this.messages[err.thingName] = { - name: err.name, - message: err.message, - value: err.value, - }; - } - hasMessages() { - return Object.keys(this.messages).length > 0; - } - getMessages() { - return this.messages; - } -} -export class ValidationError extends Error { - get name() { - return this.constructor.name; - } -} -export class BadLengthValidationError extends ValidationError { - constructor(expectedLength, maxLength) { - super(); - this.expectedLength = expectedLength; - this.maxLength = maxLength; - } - get message() { - return `${this.thingName} expected length: ${this.expectedLength}${this.maxLength !== undefined ? ` to ${this.maxLength}` : ''}; ` + - `actual length: ${this.value.length}.`; - } -} -export class BadValueValidationError extends ValidationError { - constructor(expectedValue) { - super(); - this.expectedValue = expectedValue; - } - get message() { - return `Expected: ${this.expectedValue}; got: ${this.value}.`; - } -} -export class OutOfRangeValidationError extends ValidationError { - constructor(min, max) { - super(); - this.min = min; - this.max = max; - } - get message() { - if (this.min === undefined) { - return `${this.thingName} must be at most ${this.max}`; - } - else if (this.max === undefined) { - return `${this.thingName} must be at least ${this.min}`; - } - return `${this.thingName} must be between ${this.min} and ${this.max}.`; - } -} -export class InvalidFormatValidationError extends ValidationError { - get message() { - return `"${this.value}" is not a valid ${this.thingName}.`; - } -} -export class UndefinedValueValidationError extends ValidationError { - get message() { - return `${this.thingName} is required.`; - } -} -export class AlreadyExistsValidationError extends ValidationError { - constructor(table) { - super(); - this.table = table; - } - get message() { - return `${this.value} already exists in ${this.table}.${this.thingName}.`; - } -} -export class UnknownRelationValidationError extends ValidationError { - constructor(table, foreignKey) { - super(); - this.table = table; - this.foreignKey = foreignKey; - } - get message() { - return `${this.thingName}=${this.value} relation was not found in ${this.table}${this.foreignKey !== undefined ? `.${this.foreignKey}` : ''}.`; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVmFsaWRhdG9yLmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJkYi9WYWxpZGF0b3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBSUEsTUFBTSxDQUFDLE9BQU8sT0FBTyxTQUFTO0lBQTlCO1FBQ3FCLFVBQUssR0FBd0IsRUFBRSxDQUFDO1FBQ2hDLHlCQUFvQixHQUFhLEVBQUUsQ0FBQztJQXlLekQsQ0FBQztJQXBLRzs7Ozs7T0FLRztJQUNHLE9BQU8sQ0FBQyxTQUFpQixFQUFFLEtBQW9CLEVBQUUsVUFBbUIsRUFBRSxVQUF1Qjs7WUFDL0YsTUFBTSxHQUFHLEdBQUcsSUFBSSxhQUFhLEVBQUUsQ0FBQztZQUVoQyxLQUFLLE1BQU0sSUFBSSxJQUFJLElBQUksQ0FBQyxLQUFLLEVBQUU7Z0JBQzNCLElBQUksVUFBVSx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uc3RydWN0b3IodGFibGU6IHN0cmluZywgZm9yZWlnbktleT86IHN0cmluZykge1xuICAgICAgICBzdXBlcigpO1xuICAgICAgICB0aGlzLnRhYmxlID0gdGFibGU7XG4gICAgICAgIHRoaXMuZm9yZWlnbktleSA9IGZvcmVpZ25LZXk7XG4gICAgfVxuXG4gICAgcHVibGljIGdldCBtZXNzYWdlKCk6IHN0cmluZyB7XG4gICAgICAgIHJldHVybiBgJHt0aGlzLnRoaW5nTmFtZX09JHt0aGlzLnZhbHVlfSByZWxhdGlvbiB3YXMgbm90IGZvdW5kIGluICR7dGhpcy50YWJsZX0ke3RoaXMuZm9yZWlnbktleSAhPT0gdW5kZWZpbmVkID8gYC4ke3RoaXMuZm9yZWlnbktleX1gIDogJyd9LmA7XG4gICAgfVxufSJdfQ== \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index e69de29..0000000 diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2bb1323..0000000 --- a/dist/index.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiLi8iLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIiLCJzb3VyY2VzQ29udGVudCI6WyIiXX0= \ No newline at end of file diff --git a/dist/migrations/CreateLogsTable.d.ts b/dist/migrations/CreateLogsTable.d.ts deleted file mode 100644 index 1feed20..0000000 --- a/dist/migrations/CreateLogsTable.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import Migration from "../db/Migration"; -/** - * Must be the first migration - */ -export default class CreateLogsTable extends Migration { - install(): Promise; - rollback(): Promise; -} diff --git a/dist/migrations/CreateLogsTable.js b/dist/migrations/CreateLogsTable.js deleted file mode 100644 index 37b968a..0000000 --- a/dist/migrations/CreateLogsTable.js +++ /dev/null @@ -1,37 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import Migration from "../db/Migration"; -import { query } from "../db/MysqlConnectionManager"; -/** - * Must be the first migration - */ -export default class CreateLogsTable extends Migration { - install() { - return __awaiter(this, void 0, void 0, function* () { - yield query('CREATE TABLE logs(' + - 'id INT NOT NULL AUTO_INCREMENT,' + - 'level TINYINT UNSIGNED NOT NULL,' + - 'message TEXT NOT NULL,' + - 'log_id BINARY(16),' + - 'error_name VARCHAR(128),' + - 'error_message VARCHAR(512),' + - 'error_stack TEXT,' + - 'created_at DATETIME NOT NULL DEFAULT NOW(),' + - 'PRIMARY KEY (id)' + - ')'); - }); - } - rollback() { - return __awaiter(this, void 0, void 0, function* () { - yield query('DROP TABLE logs'); - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ3JlYXRlTG9nc1RhYmxlLmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJtaWdyYXRpb25zL0NyZWF0ZUxvZ3NUYWJsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxPQUFPLFNBQVMsTUFBTSxpQkFBaUIsQ0FBQztBQUN4QyxPQUFPLEVBQUMsS0FBSyxFQUFDLE1BQU0sOEJBQThCLENBQUM7QUFFbkQ7O0dBRUc7QUFDSCxNQUFNLENBQUMsT0FBTyxPQUFPLGVBQWdCLFNBQVEsU0FBUztJQUM1QyxPQUFPOztZQUNULE1BQU0sS0FBSyxDQUFDLG9CQUFvQjtn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AgICAgICAgICAgICdlcnJvcl9zdGFjayBURVhULCcgK1xuICAgICAgICAgICAgJ2NyZWF0ZWRfYXQgREFURVRJTUUgTk9UIE5VTEwgREVGQVVMVCBOT1coKSwnICtcbiAgICAgICAgICAgICdQUklNQVJZIEtFWSAoaWQpJyArXG4gICAgICAgICAgICAnKScpO1xuICAgIH1cblxuICAgIGFzeW5jIHJvbGxiYWNrKCk6IFByb21pc2U8dm9pZD4ge1xuICAgICAgICBhd2FpdCBxdWVyeSgnRFJPUCBUQUJMRSBsb2dzJyk7XG4gICAgfVxufSJdfQ== \ No newline at end of file diff --git a/dist/migrations/CreateMigrationsTable.d.ts b/dist/migrations/CreateMigrationsTable.d.ts deleted file mode 100644 index 9d00a58..0000000 --- a/dist/migrations/CreateMigrationsTable.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import Migration from "../db/Migration"; -/** - * Must be the first migration - */ -export default class CreateMigrationsTable extends Migration { - shouldRun(currentVersion: number): Promise; - install(): Promise; - rollback(): Promise; -} diff --git a/dist/migrations/CreateMigrationsTable.js b/dist/migrations/CreateMigrationsTable.js deleted file mode 100644 index cda8f45..0000000 --- a/dist/migrations/CreateMigrationsTable.js +++ /dev/null @@ -1,48 +0,0 @@ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -import Migration from "../db/Migration"; -import { query } from "../db/MysqlConnectionManager"; -/** - * Must be the first migration - */ -export default class CreateMigrationsTable extends Migration { - shouldRun(currentVersion) { - const _super = Object.create(null, { - shouldRun: { get: () => super.shouldRun } - }); - return __awaiter(this, void 0, void 0, function* () { - try { - yield query('SELECT 1 FROM migrations LIMIT 1'); - } - catch (e) { - if (e.code !== 'ER_NO_SUCH_TABLE') { - return false; - } - } - return yield _super.shouldRun.call(this, currentVersion); - }); - } - install() { - return __awaiter(this, void 0, void 0, function* () { - yield query('CREATE TABLE migrations(' + - 'id INT NOT NULL,' + - 'name VARCHAR(64) NOT NULL,' + - 'migration_date DATE,' + - 'PRIMARY KEY (id)' + - ')'); - }); - } - rollback() { - return __awaiter(this, void 0, void 0, function* () { - yield query('DROP TABLE migrations'); - }); - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ3JlYXRlTWlncmF0aW9uc1RhYmxlLmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJtaWdyYXRpb25zL0NyZWF0ZU1pZ3JhdGlvbnNUYWJsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxPQUFPLFNBQVMsTUFBTSxpQkFBaUIsQ0FBQztBQUN4QyxPQUFPLEVBQUMsS0FBSyxFQUFDLE1BQU0sOEJBQThCLENBQUM7QUFFbkQ7O0dBRUc7QUFDSCxNQUFNLENBQUMsT0FBTyxPQUFPLHFCQUFzQixTQUFRLFNBQVM7SUFDbEQsU0FBUyxDQUFDLGNBQXNCOzs7OztZQUNsQyxJQUFJO2dCQUNBLE1BQU0sS0FBSyxDQUFDLGtDQUFrQyxDQUFDLENBQUM7YUFDbkQ7WUFBQyxPQUFPLENBQUMsRUFBRTtnQkFDUixJQUFJLENBQUMsQ0FBQyxJQUFJLEtBQUssa0JBQWtCLEVBQUU7b0JBQy9CLE9BQU8sS0FBSyxDQUFDO2lCQUNoQjthQUNKO1lBRUQsT0FBTyxNQUFNLE9BQU0sU0FBUyxZQUFDLGNBQWMsQ0FBQyxDQUFDO1FBQ2pELENBQUM7S0FBQTtJQUVLLE9BQU87O1lBQ1QsTUFBTSxLQUFLLENBQUMsMEJBQ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yYXRpb25zKCcgK1xuICAgICAgICAgICAgJ2lkIElOVCBOT1QgTlVMTCwnICtcbiAgICAgICAgICAgICduYW1lIFZBUkNIQVIoNjQpIE5PVCBOVUxMLCcgK1xuICAgICAgICAgICAgJ21pZ3JhdGlvbl9kYXRlIERBVEUsJyArXG4gICAgICAgICAgICAnUFJJTUFSWSBLRVkgKGlkKScgK1xuICAgICAgICAgICAgJyknKTtcbiAgICB9XG5cbiAgICBhc3luYyByb2xsYmFjaygpOiBQcm9taXNlPHZvaWQ+IHtcbiAgICAgICAgYXdhaXQgcXVlcnkoJ0RST1AgVEFCTEUgbWlncmF0aW9ucycpO1xuICAgIH1cbn0iXX0= \ No newline at end of file diff --git a/dist/models/Log.d.ts b/dist/models/Log.d.ts deleted file mode 100644 index 46553bf..0000000 --- a/dist/models/Log.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/// -import Model from "../db/Model"; -import { LogLevelKeys } from "../Logger"; -export default class Log extends Model { - private level?; - message?: string; - private log_id?; - private error_name?; - private error_message?; - private error_stack?; - private created_at?; - protected defineProperties(): void; - getLevel(): LogLevelKeys; - setLevel(level: LogLevelKeys): void; - getLogID(): string | null; - setLogID(buffer: Buffer): void; - getErrorName(): string; - getErrorMessage(): string; - getErrorStack(): string; - setError(error?: Error): void; -} diff --git a/dist/models/Log.js b/dist/models/Log.js deleted file mode 100644 index e1929e2..0000000 --- a/dist/models/Log.js +++ /dev/null @@ -1,56 +0,0 @@ -import Model from "../db/Model"; -import { LogLevel } from "../Logger"; -import Validator from "../db/Validator"; -export default class Log extends Model { - defineProperties() { - this.defineProperty('level', new Validator().defined()); - this.defineProperty('message', new Validator().defined().between(0, 65535)); - this.defineProperty('log_id', new Validator().acceptUndefined().length(16)); - this.defineProperty('error_name', new Validator().acceptUndefined().between(0, 128)); - this.defineProperty('error_message', new Validator().acceptUndefined().between(0, 512)); - this.defineProperty('error_stack', new Validator().acceptUndefined().between(0, 65535)); - this.defineProperty('created_at', new Validator()); - } - getLevel() { - if (typeof this.level !== 'number') - return 'ERROR'; - return LogLevel[this.level]; - } - setLevel(level) { - this.level = LogLevel[level]; - } - getLogID() { - if (!this.log_id) - return null; - const chars = this.log_id.toString('hex'); - let out = ''; - let i = 0; - for (const l of [8, 4, 4, 4, 12]) { - if (i > 0) - out += '-'; - out += chars.substr(i, l); - i += l; - } - return out; - } - setLogID(buffer) { - this.log_id = buffer; - } - getErrorName() { - return this.error_name || ''; - } - getErrorMessage() { - return this.error_message || ''; - } - getErrorStack() { - return this.error_stack || ''; - } - setError(error) { - if (!error) - return; - this.error_name = error.name; - this.error_message = error.message; - this.error_stack = error.stack; - } -} -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9nLmpzIiwic291cmNlUm9vdCI6Ii4vIiwic291cmNlcyI6WyJtb2RlbHMvTG9nLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxNQUFNLGFBQWEsQ0FBQztBQUNoQyxPQUFPLEVBQUMsUUFBUSxFQUFlLE1BQU0sV0FBVyxDQUFDO0FBQ2pELE9BQU8sU0FBUyxNQUFNLGlCQUFpQixDQUFDO0FBRXhDLE1BQU0sQ0FBQyxPQUFPLE9BQU8sR0FBSSxTQUFRLEtBQUs7SUFTeEIsZ0JBQWdCO1FBQ3RCLElBQUksQ0FBQyxjQUFjLENBQVMsT0FBTyxFQUFFLElBQUksU0FBUyxFQUFVLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FBQztRQUN4RSxJQUFJLENBQUMsY0FBYyxDQUFTLFNBQVMsRUFBRSxJQUFJLFNBQVMsRUFBVSxDQUFDLE9BQU8sRUFBRSxDQUFDLE9BQU8sQ0FBQyxDQUFDLEVBQUUsS0FBSyxDQUFDLENBQUMsQ0FBQztRQUM1RixJQUFJLENBQUMsY0FBYyxDQUFTLFFBQVEsRUFBRSxJQUFJLFNBQVMsRUFBVSxDQUFDLGVBQWUsRUFBRSxDQUFDL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pID4gMCkgb3V0ICs9ICctJztcbiAgICAgICAgICAgIG91dCArPSBjaGFycy5zdWJzdHIoaSwgbCk7XG4gICAgICAgICAgICBpICs9IGw7XG4gICAgICAgIH1cbiAgICAgICAgcmV0dXJuIG91dDtcbiAgICB9XG5cbiAgICBwdWJsaWMgc2V0TG9nSUQoYnVmZmVyOiBCdWZmZXIpIHtcbiAgICAgICAgdGhpcy5sb2dfaWQgPSBidWZmZXI7XG4gICAgfVxuXG4gICAgcHVibGljIGdldEVycm9yTmFtZSgpOiBzdHJpbmcge1xuICAgICAgICByZXR1cm4gdGhpcy5lcnJvcl9uYW1lIHx8ICcnO1xuICAgIH1cblxuICAgIHB1YmxpYyBnZXRFcnJvck1lc3NhZ2UoKTogc3RyaW5nIHtcbiAgICAgICAgcmV0dXJuIHRoaXMuZXJyb3JfbWVzc2FnZSB8fCAnJztcbiAgICB9XG5cbiAgICBwdWJsaWMgZ2V0RXJyb3JTdGFjaygpOiBzdHJpbmcge1xuICAgICAgICByZXR1cm4gdGhpcy5lcnJvcl9zdGFjayB8fCAnJztcbiAgICB9XG5cbiAgICBwdWJsaWMgc2V0RXJyb3IoZXJyb3I/OiBFcnJvcikge1xuICAgICAgICBpZiAoIWVycm9yKSByZXR1cm47XG5cbiAgICAgICAgdGhpcy5lcnJvcl9uYW1lID0gZXJyb3IubmFtZTtcbiAgICAgICAgdGhpcy5lcnJvcl9tZXNzYWdlID0gZXJyb3IubWVzc2FnZTtcbiAgICAgICAgdGhpcy5lcnJvcl9zdGFjayA9IGVycm9yLnN0YWNrO1xuICAgIH1cbn1cbiJdfQ== \ No newline at end of file diff --git a/dist/package.json b/dist/package.json deleted file mode 100644 index 71516db..0000000 --- a/dist/package.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "name": "wms-core", - "version": "0.1.1", - "description": "Node web framework", - "repository": "git@gitlab.com:ArisuOngaku/wms-core.git", - "author": "Alice Gaudon ", - "license": "MIT", - "publishConfig": { - "registry": "http://127.0.0.1:4873", - "access": "restricted" - }, - "main": "dist/index.js", - "types": "dist/index.d.ts", - "scripts": { - "build": "rm -r dist && tsc && cp package.json dist/", - "publish_to_local": "yarn build && cd dist && yarn publish" - }, - "devDependencies": { - "@types/config": "^0.0.36", - "@types/connect-flash": "^0.0.35", - "@types/connect-redis": "^0.0.13", - "@types/cookie": "^0.3.3", - "@types/cookie-parser": "^1.4.2", - "@types/express": "^4.17.6", - "@types/mjml": "^4.0.4", - "@types/mysql": "^2.15.10", - "@types/nodemailer": "^6.4.0", - "@types/nunjucks": "^3.1.3", - "@types/on-finished": "^2.3.1", - "@types/uuid": "^7.0.2", - "@types/ws": "^7.2.4", - "typescript": "^3.8.3" - }, - "dependencies": { - "config": "^3.3.1", - "connect-flash": "^0.1.1", - "connect-redis": "^4.0.4", - "cookie": "^0.4.1", - "cookie-parser": "^1.4.5", - "express": "^4.17.1", - "mjml": "^4.6.2", - "mysql": "^2.18.1", - "nodemailer": "^6.4.6", - "nunjucks": "^3.2.1", - "on-finished": "^2.3.0", - "uuid": "^7.0.3", - "ws": "^7.2.3" - } -} diff --git a/package.json b/package.json index 8782916..6ae4403 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,21 @@ { "name": "wms-core", - "version": "0.1.0", + "version": "0.1.5", "description": "Node web framework", "repository": "git@gitlab.com:ArisuOngaku/wms-core.git", "author": "Alice Gaudon ", "license": "MIT", - "private": true, + "publishConfig": { + "registry": "http://127.0.0.1:4873", + "access": "restricted" + }, "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { - "build": "rm -r dist && tsc", - "prepublishOnly": "yarn build" + "build": "rm -r dist && tsc && cp package.json dist/ && mkdir dist/types && cp src/types/* dist/types/", + "publish_to_local": "yarn build && cd dist && yarn publish" }, "devDependencies": { - "typescript": "^3.8.3" - }, - "dependencies": { "@types/config": "^0.0.36", "@types/connect-flash": "^0.0.35", "@types/connect-redis": "^0.0.13", @@ -29,6 +29,9 @@ "@types/on-finished": "^2.3.1", "@types/uuid": "^7.0.2", "@types/ws": "^7.2.4", + "typescript": "^3.8.3" + }, + "dependencies": { "config": "^3.3.1", "connect-flash": "^0.1.1", "connect-redis": "^4.0.4", diff --git a/src/types/Express.d.ts b/src/types/Express.d.ts index 41a32b5..ce55917 100644 --- a/src/types/Express.d.ts +++ b/src/types/Express.d.ts @@ -1,20 +1,22 @@ import {Environment} from "nunjucks"; import Model from "../db/Model"; -declare module 'express-serve-static-core' { - export interface Request { - env: Environment; - models: { [p: string]: Model | null }; - modelCollections: { [p: string]: Model[] | null }; +declare global { + namespace Express { + export interface Request { + env: Environment; + models: { [p: string]: Model | null }; + modelCollections: { [p: string]: Model[] | null }; - flash(): { [key: string]: string[] }; + flash(): { [key: string]: string[] }; - flash(message: string): any; + flash(message: string): any; - flash(event: string, message: any): any; - } + flash(event: string, message: any): any; + } - export interface Response { - redirectBack(defaultUrl?: string): any; + export interface Response { + redirectBack(defaultUrl?: string): any; + } } } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 3f61cae..b3b5107 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { - "target": "ES6", + "target": "ES2020", + "module": "CommonJS", "declaration": true, "stripInternal": true, @@ -11,9 +12,10 @@ "allowSyntheticDefaultImports": true, "moduleResolution": "Node", - "baseUrl": ".", + "esModuleInterop": true, + "baseUrl": "dist", "rootDir": "src", - "sourceRoot": ".", + "sourceRoot": "src", "inlineSourceMap": true, "inlineSources": true, "outDir": "dist",