Browse Source

restructuring, dist

CrazyDoctor 1 year ago
parent
commit
98ad1f838e
100 changed files with 1068 additions and 44 deletions
  1. 0 2
      .gitignore
  2. 10 0
      dist/base/exceptions/IncorrectMethodException.js
  3. 10 0
      dist/base/exceptions/InvalidMiddlewareException.js
  4. 10 0
      dist/base/exceptions/InvalidRouteException.js
  5. 10 0
      dist/base/exceptions/RouteNotSetException.js
  6. 10 0
      dist/base/exceptions/ServerNotInitializedException.js
  7. 13 0
      dist/base/exceptions/index.js
  8. 25 0
      dist/base/http/HttpHandler.js
  9. 8 0
      dist/base/http/HttpMethod.js
  10. 7 0
      dist/base/http/Middleware.js
  11. 10 0
      dist/base/http/Route.js
  12. 46 0
      dist/base/http/StatusCodes.js
  13. 13 0
      dist/base/http/index.js
  14. 2 0
      dist/base/i18n/KeyParams.js
  15. 72 0
      dist/base/i18n/i18n.js
  16. 2 0
      dist/base/i18n/i18nMap.js
  17. 17 0
      dist/base/i18n/index.js
  18. 39 0
      dist/base/logger/Logger.js
  19. 2 0
      dist/base/logger/Message.js
  20. 9 0
      dist/base/logger/MessageTypes.js
  21. 7 0
      dist/base/logger/index.js
  22. 33 0
      dist/base/util/Guid.js
  23. 5 0
      dist/base/util/index.js
  24. 22 0
      dist/index.js
  25. 17 0
      dist/middlewares/ExpressJsonMiddleware.js
  26. 17 0
      dist/middlewares/ExpressUrlencodedMiddleware.js
  27. 16 0
      dist/middlewares/InternalServerErrorHandler.js
  28. 13 0
      dist/middlewares/LoggerMiddleware.js
  29. 16 0
      dist/middlewares/NotFoundErrorHandler.js
  30. 18 0
      dist/middlewares/SessionMiddleware.js
  31. 15 0
      dist/middlewares/index.js
  32. 0 0
      dist/resources/i18n.json
  33. 16 0
      dist/routes/GetIndex.js
  34. 5 0
      dist/routes/index.js
  35. 195 0
      dist/server/Server.js
  36. 2 0
      dist/server/ServerProperties.js
  37. 5 0
      dist/server/index.js
  38. 4 0
      dist/types/base/exceptions/IncorrectMethodException.d.ts
  39. 4 0
      dist/types/base/exceptions/InvalidMiddlewareException.d.ts
  40. 4 0
      dist/types/base/exceptions/InvalidRouteException.d.ts
  41. 4 0
      dist/types/base/exceptions/RouteNotSetException.d.ts
  42. 4 0
      dist/types/base/exceptions/ServerNotInitializedException.d.ts
  43. 5 0
      dist/types/base/exceptions/index.d.ts
  44. 13 0
      dist/types/base/http/HttpHandler.d.ts
  45. 5 0
      dist/types/base/http/HttpMethod.d.ts
  46. 5 0
      dist/types/base/http/Middleware.d.ts
  47. 9 0
      dist/types/base/http/Route.d.ts
  48. 43 0
      dist/types/base/http/StatusCodes.d.ts
  49. 5 0
      dist/types/base/http/index.d.ts
  50. 4 0
      dist/types/base/i18n/KeyParams.d.ts
  51. 16 0
      dist/types/base/i18n/i18n.d.ts
  52. 6 0
      dist/types/base/i18n/i18nMap.d.ts
  53. 3 0
      dist/types/base/i18n/index.d.ts
  54. 10 0
      dist/types/base/logger/Logger.d.ts
  55. 6 0
      dist/types/base/logger/Message.d.ts
  56. 6 0
      dist/types/base/logger/MessageTypes.d.ts
  57. 3 0
      dist/types/base/logger/index.d.ts
  58. 4 0
      dist/types/base/util/Guid.d.ts
  59. 1 0
      dist/types/base/util/index.d.ts
  60. 6 0
      dist/types/index.d.ts
  61. 8 0
      dist/types/middlewares/ExpressJsonMiddleware.d.ts
  62. 8 0
      dist/types/middlewares/ExpressUrlencodedMiddleware.d.ts
  63. 8 0
      dist/types/middlewares/InternalServerErrorHandler.d.ts
  64. 7 0
      dist/types/middlewares/LoggerMiddleware.d.ts
  65. 8 0
      dist/types/middlewares/NotFoundErrorHandler.d.ts
  66. 9 0
      dist/types/middlewares/SessionMiddleware.d.ts
  67. 6 0
      dist/types/middlewares/index.d.ts
  68. 9 0
      dist/types/routes/GetIndex.d.ts
  69. 1 0
      dist/types/routes/index.d.ts
  70. 36 0
      dist/types/server/Server.d.ts
  71. 8 0
      dist/types/server/ServerProperties.d.ts
  72. 2 0
      dist/types/server/index.d.ts
  73. 1 1
      lib/base/exceptions/IncorrectMethodException.ts
  74. 1 1
      lib/base/exceptions/InvalidMiddlewareException.ts
  75. 1 1
      lib/base/exceptions/InvalidRouteException.ts
  76. 1 1
      lib/base/exceptions/RouteNotSetException.ts
  77. 1 1
      lib/base/exceptions/ServerNotInitializedException.ts
  78. 5 0
      lib/base/exceptions/index.ts
  79. 1 1
      lib/base/http/HttpHandler.ts
  80. 1 1
      lib/base/http/HttpMethod.ts
  81. 2 2
      lib/base/http/Middleware.ts
  82. 4 4
      lib/base/http/Route.ts
  83. 1 1
      lib/base/http/StatusCodes.ts
  84. 5 0
      lib/base/http/index.ts
  85. 1 1
      lib/base/i18n/KeyParams.ts
  86. 5 5
      lib/base/i18n/i18n.ts
  87. 1 1
      lib/base/i18n/i18nMap.ts
  88. 3 0
      lib/base/i18n/index.ts
  89. 3 3
      lib/base/logger/Logger.ts
  90. 8 0
      lib/base/logger/Message.ts
  91. 1 1
      lib/base/logger/MessageTypes.ts
  92. 3 0
      lib/base/logger/index.ts
  93. 1 1
      lib/base/util/Guid.ts
  94. 1 0
      lib/base/util/index.ts
  95. 6 0
      lib/index.ts
  96. 2 2
      lib/middlewares/ExpressJsonMiddleware.ts
  97. 2 2
      lib/middlewares/ExpressUrlencodedMiddleware.ts
  98. 4 5
      lib/middlewares/InternalServerErrorHandler.ts
  99. 3 3
      lib/middlewares/LoggerMiddleware.ts
  100. 3 4
      lib/middlewares/NotFoundErrorHandler.ts

+ 0 - 2
.gitignore

@@ -1,6 +1,4 @@
 .idea/
 node_modules/
-dist/
 *.iml
-index.ts
 package-lock.json

+ 10 - 0
dist/base/exceptions/IncorrectMethodException.js

@@ -0,0 +1,10 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.IncorrectMethodException = void 0;
+class IncorrectMethodException extends Error {
+    constructor() {
+        super('Incorrect method');
+        this.name = 'IncorrectMethod';
+    }
+}
+exports.IncorrectMethodException = IncorrectMethodException;

+ 10 - 0
dist/base/exceptions/InvalidMiddlewareException.js

@@ -0,0 +1,10 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.InvalidMiddlewareException = void 0;
+class InvalidMiddlewareException extends Error {
+    constructor(file) {
+        super(`Invalid middleware: ${file}`);
+        this.name = 'InvalidMiddleware';
+    }
+}
+exports.InvalidMiddlewareException = InvalidMiddlewareException;

+ 10 - 0
dist/base/exceptions/InvalidRouteException.js

@@ -0,0 +1,10 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.InvalidRouteException = void 0;
+class InvalidRouteException extends Error {
+    constructor(file) {
+        super(`Invalid route: ${file}`);
+        this.name = 'InvalidRoute';
+    }
+}
+exports.InvalidRouteException = InvalidRouteException;

+ 10 - 0
dist/base/exceptions/RouteNotSetException.js

@@ -0,0 +1,10 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.RouteNotSetException = void 0;
+class RouteNotSetException extends Error {
+    constructor() {
+        super('Route was not set.');
+        this.name = 'RouteNotSet';
+    }
+}
+exports.RouteNotSetException = RouteNotSetException;

+ 10 - 0
dist/base/exceptions/ServerNotInitializedException.js

@@ -0,0 +1,10 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ServerNotInitializedException = void 0;
+class ServerNotInitializedException extends Error {
+    constructor() {
+        super('Server not initialized');
+        this.name = 'ServerNotInitialized';
+    }
+}
+exports.ServerNotInitializedException = ServerNotInitializedException;

+ 13 - 0
dist/base/exceptions/index.js

@@ -0,0 +1,13 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ServerNotInitializedException = exports.RouteNotSetException = exports.InvalidRouteException = exports.InvalidMiddlewareException = exports.IncorrectMethodException = void 0;
+var IncorrectMethodException_1 = require("./IncorrectMethodException");
+Object.defineProperty(exports, "IncorrectMethodException", { enumerable: true, get: function () { return IncorrectMethodException_1.IncorrectMethodException; } });
+var InvalidMiddlewareException_1 = require("./InvalidMiddlewareException");
+Object.defineProperty(exports, "InvalidMiddlewareException", { enumerable: true, get: function () { return InvalidMiddlewareException_1.InvalidMiddlewareException; } });
+var InvalidRouteException_1 = require("./InvalidRouteException");
+Object.defineProperty(exports, "InvalidRouteException", { enumerable: true, get: function () { return InvalidRouteException_1.InvalidRouteException; } });
+var RouteNotSetException_1 = require("./RouteNotSetException");
+Object.defineProperty(exports, "RouteNotSetException", { enumerable: true, get: function () { return RouteNotSetException_1.RouteNotSetException; } });
+var ServerNotInitializedException_1 = require("./ServerNotInitializedException");
+Object.defineProperty(exports, "ServerNotInitializedException", { enumerable: true, get: function () { return ServerNotInitializedException_1.ServerNotInitializedException; } });

+ 25 - 0
dist/base/http/HttpHandler.js

@@ -0,0 +1,25 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.HttpHandler = void 0;
+class HttpHandler {
+    constructor(context) {
+        this.context = context !== null && context !== void 0 ? context : null;
+    }
+    setContext(context) {
+        this.context = context;
+        return this;
+    }
+    getContext() {
+        return this.context;
+    }
+    getRoute() {
+        return this.route;
+    }
+    getAction() {
+        return this.action;
+    }
+    getOrder() {
+        return this.order;
+    }
+}
+exports.HttpHandler = HttpHandler;

+ 8 - 0
dist/base/http/HttpMethod.js

@@ -0,0 +1,8 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.HttpMethod = void 0;
+var HttpMethod;
+(function (HttpMethod) {
+    HttpMethod[HttpMethod["GET"] = 0] = "GET";
+    HttpMethod[HttpMethod["POST"] = 1] = "POST";
+})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));

+ 7 - 0
dist/base/http/Middleware.js

@@ -0,0 +1,7 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Middleware = void 0;
+const HttpHandler_1 = require("./HttpHandler");
+class Middleware extends HttpHandler_1.HttpHandler {
+}
+exports.Middleware = Middleware;

+ 10 - 0
dist/base/http/Route.js

@@ -0,0 +1,10 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Route = void 0;
+const HttpHandler_1 = require("./HttpHandler");
+class Route extends HttpHandler_1.HttpHandler {
+    getMethod() {
+        return this.method;
+    }
+}
+exports.Route = Route;

+ 46 - 0
dist/base/http/StatusCodes.js

@@ -0,0 +1,46 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.StatusCodes = void 0;
+var StatusCodes;
+(function (StatusCodes) {
+    StatusCodes[StatusCodes["CONTINUE"] = 100] = "CONTINUE";
+    StatusCodes[StatusCodes["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
+    StatusCodes[StatusCodes["OK"] = 200] = "OK";
+    StatusCodes[StatusCodes["CREATED"] = 201] = "CREATED";
+    StatusCodes[StatusCodes["ACCEPTED"] = 202] = "ACCEPTED";
+    StatusCodes[StatusCodes["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
+    StatusCodes[StatusCodes["NO_CONTENT"] = 204] = "NO_CONTENT";
+    StatusCodes[StatusCodes["RESET_CONTENT"] = 205] = "RESET_CONTENT";
+    StatusCodes[StatusCodes["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
+    StatusCodes[StatusCodes["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
+    StatusCodes[StatusCodes["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
+    StatusCodes[StatusCodes["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY";
+    StatusCodes[StatusCodes["SEE_OTHER"] = 303] = "SEE_OTHER";
+    StatusCodes[StatusCodes["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
+    StatusCodes[StatusCodes["USE_PROXY"] = 305] = "USE_PROXY";
+    StatusCodes[StatusCodes["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
+    StatusCodes[StatusCodes["BAD_REQUEST"] = 400] = "BAD_REQUEST";
+    StatusCodes[StatusCodes["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
+    StatusCodes[StatusCodes["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
+    StatusCodes[StatusCodes["FORBIDDEN"] = 403] = "FORBIDDEN";
+    StatusCodes[StatusCodes["NOT_FOUND"] = 404] = "NOT_FOUND";
+    StatusCodes[StatusCodes["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
+    StatusCodes[StatusCodes["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
+    StatusCodes[StatusCodes["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
+    StatusCodes[StatusCodes["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
+    StatusCodes[StatusCodes["CONFLICT"] = 409] = "CONFLICT";
+    StatusCodes[StatusCodes["GONE"] = 410] = "GONE";
+    StatusCodes[StatusCodes["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
+    StatusCodes[StatusCodes["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
+    StatusCodes[StatusCodes["REQUEST_ENTITY_TOO_LARGE"] = 413] = "REQUEST_ENTITY_TOO_LARGE";
+    StatusCodes[StatusCodes["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
+    StatusCodes[StatusCodes["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
+    StatusCodes[StatusCodes["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
+    StatusCodes[StatusCodes["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
+    StatusCodes[StatusCodes["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
+    StatusCodes[StatusCodes["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
+    StatusCodes[StatusCodes["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
+    StatusCodes[StatusCodes["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
+    StatusCodes[StatusCodes["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
+    StatusCodes[StatusCodes["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
+})(StatusCodes || (exports.StatusCodes = StatusCodes = {}));

+ 13 - 0
dist/base/http/index.js

@@ -0,0 +1,13 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.StatusCodes = exports.Route = exports.Middleware = exports.HttpMethod = exports.HttpHandler = void 0;
+var HttpHandler_1 = require("./HttpHandler");
+Object.defineProperty(exports, "HttpHandler", { enumerable: true, get: function () { return HttpHandler_1.HttpHandler; } });
+var HttpMethod_1 = require("./HttpMethod");
+Object.defineProperty(exports, "HttpMethod", { enumerable: true, get: function () { return HttpMethod_1.HttpMethod; } });
+var Middleware_1 = require("./Middleware");
+Object.defineProperty(exports, "Middleware", { enumerable: true, get: function () { return Middleware_1.Middleware; } });
+var Route_1 = require("./Route");
+Object.defineProperty(exports, "Route", { enumerable: true, get: function () { return Route_1.Route; } });
+var StatusCodes_1 = require("./StatusCodes");
+Object.defineProperty(exports, "StatusCodes", { enumerable: true, get: function () { return StatusCodes_1.StatusCodes; } });

+ 2 - 0
dist/base/i18n/KeyParams.js

@@ -0,0 +1,2 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });

+ 72 - 0
dist/base/i18n/i18n.js

@@ -0,0 +1,72 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.$$ = exports.i18nLoader = void 0;
+const fs_1 = __importDefault(require("fs"));
+class i18nLoader {
+    constructor(locale) {
+        this.locale = locale;
+        this.map = {};
+    }
+    static getInstance(locale) {
+        if (!i18nLoader.instance)
+            i18nLoader.instance = new i18nLoader(locale !== null && locale !== void 0 ? locale : i18nLoader.defaultLocale);
+        return i18nLoader.instance;
+    }
+    setLocale(locale) {
+        this.locale = locale;
+        return this;
+    }
+    load(...paths) {
+        for (const p of paths) {
+            try {
+                const data = fs_1.default.readFileSync(p).toString('utf8');
+                try {
+                    this.loadJson(JSON.parse(data));
+                }
+                catch (err) {
+                    console.error('JSON parsing error:', err);
+                }
+            }
+            catch (error) {
+                console.error(`i18n file '${p}' not found.`, error);
+            }
+        }
+        return this;
+    }
+    loadJson(obj) {
+        for (const locale of Object.keys(obj)) {
+            if (!this.map[locale])
+                this.map[locale] = {};
+            for (const key of Object.keys(obj[locale]))
+                this.map[locale][key] = obj[locale][key];
+        }
+        return this;
+    }
+    get(key) {
+        var _a;
+        let value;
+        if (!this.map[this.locale] && !this.map[i18nLoader.defaultLocale])
+            return key;
+        if (this.map[i18nLoader.defaultLocale])
+            value = this.map[i18nLoader.defaultLocale][key];
+        if (this.map[this.locale])
+            value = (_a = this.map[this.locale][key]) !== null && _a !== void 0 ? _a : value;
+        return value !== null && value !== void 0 ? value : key;
+    }
+}
+exports.i18nLoader = i18nLoader;
+i18nLoader.defaultLocale = 'en_US';
+const $$ = (key, params) => {
+    let text = i18nLoader.getInstance().get(key);
+    if (params) {
+        for (const param of Object.keys(params)) {
+            const regex = new RegExp(`\{${param}\}`, 'g');
+            text = text.replace(regex, params[param]);
+        }
+    }
+    return text;
+};
+exports.$$ = $$;

+ 2 - 0
dist/base/i18n/i18nMap.js

@@ -0,0 +1,2 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });

+ 17 - 0
dist/base/i18n/index.js

@@ -0,0 +1,17 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    var desc = Object.getOwnPropertyDescriptor(m, k);
+    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+      desc = { enumerable: true, get: function() { return m[k]; } };
+    }
+    Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    o[k2] = m[k];
+}));
+var __exportStar = (this && this.__exportStar) || function(m, exports) {
+    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+__exportStar(require("./i18n"), exports);

+ 39 - 0
dist/base/logger/Logger.js

@@ -0,0 +1,39 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Logger = void 0;
+const pino_1 = __importDefault(require("pino"));
+const pino_http_1 = __importDefault(require("pino-http"));
+const MessageTypes_1 = require("./MessageTypes");
+const http_1 = require("../http");
+class Logger {
+    constructor() {
+        this.logger = (0, pino_1.default)({
+            transport: {
+                target: 'pino-pretty',
+                options: {
+                    translateTime: 'yyyy-mm-dd HH:MM:ss.l o',
+                }
+            }
+        });
+        this.httpLogger = (0, pino_http_1.default)({
+            logger: this.logger,
+            customLogLevel: (req, res, err) => {
+                if (res.statusCode >= http_1.StatusCodes.INTERNAL_SERVER_ERROR || err)
+                    return MessageTypes_1.MessageTypes.ERROR;
+                if (res.statusCode >= http_1.StatusCodes.BAD_REQUEST)
+                    return MessageTypes_1.MessageTypes.WARNING;
+                return MessageTypes_1.MessageTypes.INFO;
+            },
+        });
+    }
+    getLogger() {
+        return this.logger;
+    }
+    getHttpLogger() {
+        return this.httpLogger;
+    }
+}
+exports.Logger = Logger;

+ 2 - 0
dist/base/logger/Message.js

@@ -0,0 +1,2 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });

+ 9 - 0
dist/base/logger/MessageTypes.js

@@ -0,0 +1,9 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.MessageTypes = void 0;
+var MessageTypes;
+(function (MessageTypes) {
+    MessageTypes["INFO"] = "info";
+    MessageTypes["WARNING"] = "warn";
+    MessageTypes["ERROR"] = "error";
+})(MessageTypes || (exports.MessageTypes = MessageTypes = {}));

+ 7 - 0
dist/base/logger/index.js

@@ -0,0 +1,7 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.MessageTypes = exports.Logger = void 0;
+var Logger_1 = require("./Logger");
+Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return Logger_1.Logger; } });
+var MessageTypes_1 = require("./MessageTypes");
+Object.defineProperty(exports, "MessageTypes", { enumerable: true, get: function () { return MessageTypes_1.MessageTypes; } });

+ 33 - 0
dist/base/util/Guid.js

@@ -0,0 +1,33 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    var desc = Object.getOwnPropertyDescriptor(m, k);
+    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+      desc = { enumerable: true, get: function() { return m[k]; } };
+    }
+    Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+    Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+    o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+    __setModuleDefault(result, mod);
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Guid = void 0;
+const crypto = __importStar(require("crypto"));
+class Guid {
+    static new() {
+        return crypto.randomUUID();
+    }
+}
+exports.Guid = Guid;

+ 5 - 0
dist/base/util/index.js

@@ -0,0 +1,5 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Guid = void 0;
+var Guid_1 = require("./Guid");
+Object.defineProperty(exports, "Guid", { enumerable: true, get: function () { return Guid_1.Guid; } });

+ 22 - 0
dist/index.js

@@ -0,0 +1,22 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    var desc = Object.getOwnPropertyDescriptor(m, k);
+    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+      desc = { enumerable: true, get: function() { return m[k]; } };
+    }
+    Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    o[k2] = m[k];
+}));
+var __exportStar = (this && this.__exportStar) || function(m, exports) {
+    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+__exportStar(require("./server"), exports);
+__exportStar(require("./base/exceptions"), exports);
+__exportStar(require("./base/http"), exports);
+__exportStar(require("./base/util"), exports);
+__exportStar(require("./base/logger"), exports);
+__exportStar(require("./base/i18n"), exports);

+ 17 - 0
dist/middlewares/ExpressJsonMiddleware.js

@@ -0,0 +1,17 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ExpressJsonMiddleware = void 0;
+const http_1 = require("../base/http");
+const express_1 = __importDefault(require("express"));
+class ExpressJsonMiddleware extends http_1.Middleware {
+    constructor() {
+        super(...arguments);
+        this.order = -100;
+        this.route = null;
+        this.action = express_1.default.json();
+    }
+}
+exports.ExpressJsonMiddleware = ExpressJsonMiddleware;

+ 17 - 0
dist/middlewares/ExpressUrlencodedMiddleware.js

@@ -0,0 +1,17 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.ExpressUrlencodedMiddleware = void 0;
+const http_1 = require("../base/http");
+const express_1 = __importDefault(require("express"));
+class ExpressUrlencodedMiddleware extends http_1.Middleware {
+    constructor() {
+        super(...arguments);
+        this.order = -99;
+        this.route = null;
+        this.action = express_1.default.urlencoded({ extended: false });
+    }
+}
+exports.ExpressUrlencodedMiddleware = ExpressUrlencodedMiddleware;

+ 16 - 0
dist/middlewares/InternalServerErrorHandler.js

@@ -0,0 +1,16 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.InternalServerErrorHandler = void 0;
+const http_1 = require("../base/http");
+const i18n_1 = require("../base/i18n");
+class InternalServerErrorHandler extends http_1.Middleware {
+    constructor() {
+        super(...arguments);
+        this.order = 10000;
+        this.route = null;
+        this.action = (err, req, res, next) => {
+            res.status(http_1.StatusCodes.INTERNAL_SERVER_ERROR).send((0, i18n_1.$$)('org.crazydoctor.expressts.httpError.500'));
+        };
+    }
+}
+exports.InternalServerErrorHandler = InternalServerErrorHandler;

+ 13 - 0
dist/middlewares/LoggerMiddleware.js

@@ -0,0 +1,13 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.LoggerMiddleware = void 0;
+const http_1 = require("../base/http");
+class LoggerMiddleware extends http_1.Middleware {
+    constructor() {
+        super(...arguments);
+        this.order = -97;
+        this.route = null;
+        this.action = this.context.getLogger().getHttpLogger();
+    }
+}
+exports.LoggerMiddleware = LoggerMiddleware;

+ 16 - 0
dist/middlewares/NotFoundErrorHandler.js

@@ -0,0 +1,16 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.NotFoundErrorHandler = void 0;
+const http_1 = require("../base/http");
+const i18n_1 = require("../base/i18n");
+class NotFoundErrorHandler extends http_1.Middleware {
+    constructor() {
+        super(...arguments);
+        this.order = 9999;
+        this.route = null;
+        this.action = (req, res, next) => {
+            res.status(http_1.StatusCodes.NOT_FOUND).send((0, i18n_1.$$)('org.crazydoctor.expressts.httpError.404', { url: req.url }));
+        };
+    }
+}
+exports.NotFoundErrorHandler = NotFoundErrorHandler;

+ 18 - 0
dist/middlewares/SessionMiddleware.js

@@ -0,0 +1,18 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.SessionMiddleware = void 0;
+const http_1 = require("../base/http");
+const express_session_1 = __importDefault(require("express-session"));
+const util_1 = require("../base/util");
+class SessionMiddleware extends http_1.Middleware {
+    constructor() {
+        super(...arguments);
+        this.order = -98;
+        this.route = null;
+        this.action = (0, express_session_1.default)({ secret: util_1.Guid.new(), resave: false, saveUninitialized: false });
+    }
+}
+exports.SessionMiddleware = SessionMiddleware;

+ 15 - 0
dist/middlewares/index.js

@@ -0,0 +1,15 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.SessionMiddleware = exports.NotFoundErrorHandler = exports.LoggerMiddleware = exports.InternalServerErrorHandler = exports.ExpressUrlencodedMiddleware = exports.ExpressJsonMiddleware = void 0;
+var ExpressJsonMiddleware_1 = require("./ExpressJsonMiddleware");
+Object.defineProperty(exports, "ExpressJsonMiddleware", { enumerable: true, get: function () { return ExpressJsonMiddleware_1.ExpressJsonMiddleware; } });
+var ExpressUrlencodedMiddleware_1 = require("./ExpressUrlencodedMiddleware");
+Object.defineProperty(exports, "ExpressUrlencodedMiddleware", { enumerable: true, get: function () { return ExpressUrlencodedMiddleware_1.ExpressUrlencodedMiddleware; } });
+var InternalServerErrorHandler_1 = require("./InternalServerErrorHandler");
+Object.defineProperty(exports, "InternalServerErrorHandler", { enumerable: true, get: function () { return InternalServerErrorHandler_1.InternalServerErrorHandler; } });
+var LoggerMiddleware_1 = require("./LoggerMiddleware");
+Object.defineProperty(exports, "LoggerMiddleware", { enumerable: true, get: function () { return LoggerMiddleware_1.LoggerMiddleware; } });
+var NotFoundErrorHandler_1 = require("./NotFoundErrorHandler");
+Object.defineProperty(exports, "NotFoundErrorHandler", { enumerable: true, get: function () { return NotFoundErrorHandler_1.NotFoundErrorHandler; } });
+var SessionMiddleware_1 = require("./SessionMiddleware");
+Object.defineProperty(exports, "SessionMiddleware", { enumerable: true, get: function () { return SessionMiddleware_1.SessionMiddleware; } });

+ 0 - 0
src/resources/i18n.json → dist/resources/i18n.json


+ 16 - 0
dist/routes/GetIndex.js

@@ -0,0 +1,16 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.GetIndex = void 0;
+const http_1 = require("../base/http");
+class GetIndex extends http_1.Route {
+    constructor() {
+        super(...arguments);
+        this.order = 0;
+        this.method = http_1.HttpMethod.GET;
+        this.route = '/';
+        this.action = (req, res) => {
+            res.status(http_1.StatusCodes.OK).send('org.crazydoctor.expressts server sample page');
+        };
+    }
+}
+exports.GetIndex = GetIndex;

+ 5 - 0
dist/routes/index.js

@@ -0,0 +1,5 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.GetIndex = void 0;
+var GetIndex_1 = require("./GetIndex");
+Object.defineProperty(exports, "GetIndex", { enumerable: true, get: function () { return GetIndex_1.GetIndex; } });

+ 195 - 0
dist/server/Server.js

@@ -0,0 +1,195 @@
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    var desc = Object.getOwnPropertyDescriptor(m, k);
+    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
+      desc = { enumerable: true, get: function() { return m[k]; } };
+    }
+    Object.defineProperty(o, k2, desc);
+}) : (function(o, m, k, k2) {
+    if (k2 === undefined) k2 = k;
+    o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+    Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+    o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+    __setModuleDefault(result, mod);
+    return result;
+};
+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());
+    });
+};
+var __importDefault = (this && this.__importDefault) || function (mod) {
+    return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Server = void 0;
+const express_1 = __importDefault(require("express"));
+const http_1 = require("../base/http");
+const exceptions_1 = require("../base/exceptions");
+const exceptions_2 = require("../base/exceptions");
+const logger_1 = require("../base/logger");
+const i18n_1 = require("../base/i18n");
+const path_1 = __importDefault(require("path"));
+const fs_1 = __importDefault(require("fs"));
+const exceptions_3 = require("../base/exceptions");
+const exceptions_4 = require("../base/exceptions");
+const exceptions_5 = require("../base/exceptions");
+/** @sealed */
+class Server {
+    constructor(properties) {
+        this.instance = (0, express_1.default)();
+        this.port = properties.port;
+        this.i18n = i18n_1.i18nLoader.getInstance().setLocale(properties.locale);
+        this.logger = new logger_1.Logger();
+        this.httpHandlers = {};
+        this.i18nPath = properties.i18nPath;
+        this.middlewaresPath = properties.middlewaresPath;
+        this.routesPath = properties.routesPath;
+        this.initialized = false;
+    }
+    init() {
+        return __awaiter(this, void 0, void 0, function* () {
+            this.i18n.load(path_1.default.resolve(__dirname, Server.i18nDefaultPath));
+            yield this.registerMiddlewares(path_1.default.resolve(__dirname, Server.defaultMiddlewaresPath));
+            yield this.registerRoutes(path_1.default.resolve(__dirname, Server.defaultRoutesPath));
+            yield this.postInit();
+            this.initialized = true;
+            return this;
+        });
+    }
+    postInit() {
+        return __awaiter(this, void 0, void 0, function* () {
+            if (this.i18nPath)
+                this.i18n.load(this.i18nPath);
+            if (this.middlewaresPath)
+                yield this.registerMiddlewares(this.middlewaresPath);
+            if (this.routesPath)
+                yield this.registerRoutes(this.routesPath);
+        });
+    }
+    processHttpHandlers() {
+        const handlers = [];
+        for (const key in this.httpHandlers)
+            handlers.push(this.httpHandlers[key]);
+        handlers.sort((a, b) => a.getOrder() - b.getOrder());
+        for (const handler of handlers) {
+            if (handler instanceof http_1.Middleware)
+                this.addMiddleware(handler);
+            else if (handler instanceof http_1.Route)
+                this.addRoute(handler);
+        }
+    }
+    addMiddleware(middleware) {
+        if (middleware.getRoute() != null)
+            this.instance.use(middleware.getRoute(), middleware.getAction());
+        else
+            this.instance.use(middleware.getAction());
+        return this;
+    }
+    addRoute(route) {
+        if (route.getRoute() == null)
+            throw new exceptions_1.RouteNotSetException();
+        switch (route.getMethod()) {
+            case http_1.HttpMethod.GET:
+                return this.get(route);
+            case http_1.HttpMethod.POST:
+                return this.post(route);
+            default:
+                throw new exceptions_2.IncorrectMethodException();
+        }
+    }
+    logInfo(message) {
+        this.logger.getLogger().info(message);
+    }
+    logError(message) {
+        this.logger.getLogger().error(message);
+    }
+    logWarn(message) {
+        this.logger.getLogger().warn(message);
+    }
+    log(message) {
+        switch (message.type) {
+            case logger_1.MessageTypes.WARNING:
+                return this.logWarn(message.text);
+            case logger_1.MessageTypes.ERROR:
+                return this.logError(message.text);
+            default:
+                return this.logInfo(message.text);
+        }
+    }
+    get(route) {
+        this.instance.get(route.getRoute(), route.getAction());
+        return this;
+    }
+    post(route) {
+        this.instance.post(route.getRoute(), route.getAction());
+        return this;
+    }
+    registerRoutes(dir) {
+        return __awaiter(this, void 0, void 0, function* () {
+            const files = fs_1.default.readdirSync(dir);
+            for (const file of files) {
+                if (/\.(ts|js)$/.test(file)) {
+                    const { default: RouteClass } = yield Promise.resolve(`${path_1.default.join(dir, file)}`).then(s => __importStar(require(s)));
+                    if (RouteClass.prototype instanceof http_1.Route) {
+                        this.httpHandlers[RouteClass.name] = new RouteClass(this);
+                    }
+                    else
+                        throw new exceptions_4.InvalidRouteException(file);
+                }
+            }
+            return this;
+        });
+    }
+    registerMiddlewares(dir) {
+        return __awaiter(this, void 0, void 0, function* () {
+            const files = fs_1.default.readdirSync(dir);
+            for (const file of files) {
+                if (/\.(ts|js)$/.test(file)) {
+                    const { default: MiddlewareClass } = yield Promise.resolve(`${path_1.default.join(dir, file)}`).then(s => __importStar(require(s)));
+                    if (MiddlewareClass.prototype instanceof http_1.Middleware) {
+                        this.httpHandlers[MiddlewareClass.name] = new MiddlewareClass(this);
+                    }
+                    else
+                        throw new exceptions_3.InvalidMiddlewareException(file);
+                }
+            }
+            return this;
+        });
+    }
+    getLogger() {
+        return this.logger;
+    }
+    i18nLoad(path) {
+        this.i18n.load(path);
+        return this;
+    }
+    start(callback) {
+        if (!this.initialized)
+            throw new exceptions_5.ServerNotInitializedException();
+        this.processHttpHandlers();
+        const cb = () => {
+            this.logInfo((0, i18n_1.$$)('org.crazydoctor.expressts.start', { 'port': this.port }));
+            if (callback)
+                callback();
+        };
+        this.instance.listen(this.port, cb);
+    }
+}
+exports.Server = Server;
+Server.i18nDefaultPath = '../resources/i18n.json';
+Server.defaultMiddlewaresPath = '../middlewares';
+Server.defaultRoutesPath = '../routes';

+ 2 - 0
dist/server/ServerProperties.js

@@ -0,0 +1,2 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });

+ 5 - 0
dist/server/index.js

@@ -0,0 +1,5 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.Server = void 0;
+var Server_1 = require("./Server");
+Object.defineProperty(exports, "Server", { enumerable: true, get: function () { return Server_1.Server; } });

+ 4 - 0
dist/types/base/exceptions/IncorrectMethodException.d.ts

@@ -0,0 +1,4 @@
+declare class IncorrectMethodException extends Error {
+    constructor();
+}
+export { IncorrectMethodException };

+ 4 - 0
dist/types/base/exceptions/InvalidMiddlewareException.d.ts

@@ -0,0 +1,4 @@
+declare class InvalidMiddlewareException extends Error {
+    constructor(file: string);
+}
+export { InvalidMiddlewareException };

+ 4 - 0
dist/types/base/exceptions/InvalidRouteException.d.ts

@@ -0,0 +1,4 @@
+declare class InvalidRouteException extends Error {
+    constructor(file: string);
+}
+export { InvalidRouteException };

+ 4 - 0
dist/types/base/exceptions/RouteNotSetException.d.ts

@@ -0,0 +1,4 @@
+declare class RouteNotSetException extends Error {
+    constructor();
+}
+export { RouteNotSetException };

+ 4 - 0
dist/types/base/exceptions/ServerNotInitializedException.d.ts

@@ -0,0 +1,4 @@
+declare class ServerNotInitializedException extends Error {
+    constructor();
+}
+export { ServerNotInitializedException };

+ 5 - 0
dist/types/base/exceptions/index.d.ts

@@ -0,0 +1,5 @@
+export { IncorrectMethodException } from './IncorrectMethodException';
+export { InvalidMiddlewareException } from './InvalidMiddlewareException';
+export { InvalidRouteException } from './InvalidRouteException';
+export { RouteNotSetException } from './RouteNotSetException';
+export { ServerNotInitializedException } from './ServerNotInitializedException';

+ 13 - 0
dist/types/base/http/HttpHandler.d.ts

@@ -0,0 +1,13 @@
+declare abstract class HttpHandler {
+    protected abstract order: number;
+    protected abstract route: string | null;
+    protected abstract action: (...any: any[]) => any;
+    protected context: any;
+    constructor(context: Record<string, any>);
+    setContext(context: Record<string, any>): HttpHandler;
+    getContext(): Record<string, any>;
+    getRoute(): string | null;
+    getAction(): (...any: any[]) => any;
+    getOrder(): number;
+}
+export { HttpHandler };

+ 5 - 0
dist/types/base/http/HttpMethod.d.ts

@@ -0,0 +1,5 @@
+declare enum HttpMethod {
+    GET = 0,
+    POST = 1
+}
+export { HttpMethod };

+ 5 - 0
dist/types/base/http/Middleware.d.ts

@@ -0,0 +1,5 @@
+import { HttpHandler } from './HttpHandler';
+declare abstract class Middleware extends HttpHandler {
+    protected abstract action: (...any: any[]) => any;
+}
+export { Middleware };

+ 9 - 0
dist/types/base/http/Route.d.ts

@@ -0,0 +1,9 @@
+import { Request, Response } from 'express';
+import { HttpMethod } from './HttpMethod';
+import { HttpHandler } from './HttpHandler';
+declare abstract class Route extends HttpHandler {
+    protected abstract method: HttpMethod;
+    protected abstract action: (req: Request, res: Response) => any;
+    getMethod(): HttpMethod;
+}
+export { Route };

+ 43 - 0
dist/types/base/http/StatusCodes.d.ts

@@ -0,0 +1,43 @@
+declare enum StatusCodes {
+    CONTINUE = 100,
+    SWITCHING_PROTOCOLS = 101,
+    OK = 200,
+    CREATED = 201,
+    ACCEPTED = 202,
+    NON_AUTHORITATIVE_INFORMATION = 203,
+    NO_CONTENT = 204,
+    RESET_CONTENT = 205,
+    PARTIAL_CONTENT = 206,
+    MULTIPLE_CHOICES = 300,
+    MOVED_PERMANENTLY = 301,
+    MOVED_TEMPORARILY = 302,
+    SEE_OTHER = 303,
+    NOT_MODIFIED = 304,
+    USE_PROXY = 305,
+    TEMPORARY_REDIRECT = 307,
+    BAD_REQUEST = 400,
+    UNAUTHORIZED = 401,
+    PAYMENT_REQUIRED = 402,
+    FORBIDDEN = 403,
+    NOT_FOUND = 404,
+    METHOD_NOT_ALLOWED = 405,
+    NOT_ACCEPTABLE = 406,
+    PROXY_AUTHENTICATION_REQUIRED = 407,
+    REQUEST_TIMEOUT = 408,
+    CONFLICT = 409,
+    GONE = 410,
+    LENGTH_REQUIRED = 411,
+    PRECONDITION_FAILED = 412,
+    REQUEST_ENTITY_TOO_LARGE = 413,
+    REQUEST_URI_TOO_LONG = 414,
+    UNSUPPORTED_MEDIA_TYPE = 415,
+    REQUESTED_RANGE_NOT_SATISFIABLE = 416,
+    EXPECTATION_FAILED = 417,
+    INTERNAL_SERVER_ERROR = 500,
+    NOT_IMPLEMENTED = 501,
+    BAD_GATEWAY = 502,
+    SERVICE_UNAVAILABLE = 503,
+    GATEWAY_TIMEOUT = 504,
+    HTTP_VERSION_NOT_SUPPORTED = 505
+}
+export { StatusCodes };

+ 5 - 0
dist/types/base/http/index.d.ts

@@ -0,0 +1,5 @@
+export { HttpHandler } from './HttpHandler';
+export { HttpMethod } from './HttpMethod';
+export { Middleware } from './Middleware';
+export { Route } from './Route';
+export { StatusCodes } from './StatusCodes';

+ 4 - 0
dist/types/base/i18n/KeyParams.d.ts

@@ -0,0 +1,4 @@
+type KeyParams = {
+    [key: string]: any;
+};
+export { KeyParams };

+ 16 - 0
dist/types/base/i18n/i18n.d.ts

@@ -0,0 +1,16 @@
+import { i18nMap } from './i18nMap';
+import { KeyParams } from './KeyParams';
+declare class i18nLoader {
+    private static instance;
+    private readonly map;
+    private locale;
+    static defaultLocale: string;
+    constructor(locale: string);
+    static getInstance(locale?: string): i18nLoader;
+    setLocale(locale: string): i18nLoader;
+    load(...paths: string[]): i18nLoader;
+    loadJson(obj: i18nMap): i18nLoader;
+    get(key: string): string;
+}
+declare const $$: (key: string, params?: KeyParams) => string;
+export { i18nLoader, $$ };

+ 6 - 0
dist/types/base/i18n/i18nMap.d.ts

@@ -0,0 +1,6 @@
+type i18nMap = {
+    [key: string]: {
+        [key: string]: string;
+    };
+};
+export { i18nMap };

+ 3 - 0
dist/types/base/i18n/index.d.ts

@@ -0,0 +1,3 @@
+export * from './i18n';
+export { i18nMap } from './i18nMap';
+export { KeyParams } from './KeyParams';

+ 10 - 0
dist/types/base/logger/Logger.d.ts

@@ -0,0 +1,10 @@
+import pino from 'pino';
+import { HttpLogger } from 'pino-http';
+declare class Logger {
+    private readonly logger;
+    private readonly httpLogger;
+    constructor();
+    getLogger(): pino.Logger;
+    getHttpLogger(): HttpLogger;
+}
+export { Logger };

+ 6 - 0
dist/types/base/logger/Message.d.ts

@@ -0,0 +1,6 @@
+import { MessageTypes } from './MessageTypes';
+type Message = {
+    type: MessageTypes;
+    text: string;
+};
+export { Message };

+ 6 - 0
dist/types/base/logger/MessageTypes.d.ts

@@ -0,0 +1,6 @@
+declare enum MessageTypes {
+    INFO = "info",
+    WARNING = "warn",
+    ERROR = "error"
+}
+export { MessageTypes };

+ 3 - 0
dist/types/base/logger/index.d.ts

@@ -0,0 +1,3 @@
+export { Logger } from './Logger';
+export { Message } from './Message';
+export { MessageTypes } from './MessageTypes';

+ 4 - 0
dist/types/base/util/Guid.d.ts

@@ -0,0 +1,4 @@
+declare class Guid {
+    static new(): string;
+}
+export { Guid };

+ 1 - 0
dist/types/base/util/index.d.ts

@@ -0,0 +1 @@
+export { Guid } from './Guid';

+ 6 - 0
dist/types/index.d.ts

@@ -0,0 +1,6 @@
+export * from './server';
+export * from './base/exceptions';
+export * from './base/http';
+export * from './base/util';
+export * from './base/logger';
+export * from './base/i18n';

+ 8 - 0
dist/types/middlewares/ExpressJsonMiddleware.d.ts

@@ -0,0 +1,8 @@
+/// <reference types="connect" />
+import { Middleware } from '../base/http';
+declare class ExpressJsonMiddleware extends Middleware {
+    protected order: number;
+    protected route: null;
+    protected action: import("connect").NextHandleFunction;
+}
+export { ExpressJsonMiddleware };

+ 8 - 0
dist/types/middlewares/ExpressUrlencodedMiddleware.d.ts

@@ -0,0 +1,8 @@
+/// <reference types="connect" />
+import { Middleware } from '../base/http';
+declare class ExpressUrlencodedMiddleware extends Middleware {
+    protected order: number;
+    protected route: null;
+    protected action: import("connect").NextHandleFunction;
+}
+export { ExpressUrlencodedMiddleware };

+ 8 - 0
dist/types/middlewares/InternalServerErrorHandler.d.ts

@@ -0,0 +1,8 @@
+import { Middleware } from '../base/http';
+import { NextFunction, Request, Response } from 'express';
+declare class InternalServerErrorHandler extends Middleware {
+    protected order: number;
+    protected route: null;
+    protected action: (err: Error, req: Request, res: Response, next: NextFunction) => any;
+}
+export { InternalServerErrorHandler };

+ 7 - 0
dist/types/middlewares/LoggerMiddleware.d.ts

@@ -0,0 +1,7 @@
+import { Middleware } from '../base/http';
+declare class LoggerMiddleware extends Middleware {
+    protected order: number;
+    protected route: null;
+    protected action: import("pino-http").HttpLogger;
+}
+export { LoggerMiddleware };

+ 8 - 0
dist/types/middlewares/NotFoundErrorHandler.d.ts

@@ -0,0 +1,8 @@
+import { Middleware } from '../base/http';
+import { NextFunction, Request, Response } from 'express';
+declare class NotFoundErrorHandler extends Middleware {
+    protected order: number;
+    protected route: null;
+    protected action: (req: Request, res: Response, next: NextFunction) => any;
+}
+export { NotFoundErrorHandler };

+ 9 - 0
dist/types/middlewares/SessionMiddleware.d.ts

@@ -0,0 +1,9 @@
+/// <reference types="qs" />
+/// <reference types="express" />
+import { Middleware } from '../base/http';
+declare class SessionMiddleware extends Middleware {
+    protected order: number;
+    protected route: null;
+    protected action: import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
+}
+export { SessionMiddleware };

+ 6 - 0
dist/types/middlewares/index.d.ts

@@ -0,0 +1,6 @@
+export { ExpressJsonMiddleware } from './ExpressJsonMiddleware';
+export { ExpressUrlencodedMiddleware } from './ExpressUrlencodedMiddleware';
+export { InternalServerErrorHandler } from './InternalServerErrorHandler';
+export { LoggerMiddleware } from './LoggerMiddleware';
+export { NotFoundErrorHandler } from './NotFoundErrorHandler';
+export { SessionMiddleware } from './SessionMiddleware';

+ 9 - 0
dist/types/routes/GetIndex.d.ts

@@ -0,0 +1,9 @@
+import { Request, Response } from 'express';
+import { Route, HttpMethod } from '../base/http';
+declare class GetIndex extends Route {
+    protected order: number;
+    protected method: HttpMethod;
+    protected route: string;
+    protected action: (req: Request, res: Response) => any;
+}
+export { GetIndex };

+ 1 - 0
dist/types/routes/index.d.ts

@@ -0,0 +1 @@
+export { GetIndex } from './GetIndex';

+ 36 - 0
dist/types/server/Server.d.ts

@@ -0,0 +1,36 @@
+import { Middleware, Route } from '../base/http';
+import { Logger, Message } from '../base/logger';
+import { ServerProperties } from './ServerProperties';
+/** @sealed */
+declare class Server {
+    private instance;
+    private readonly port;
+    private readonly logger;
+    private i18n;
+    static readonly i18nDefaultPath = "../resources/i18n.json";
+    static readonly defaultMiddlewaresPath = "../middlewares";
+    static readonly defaultRoutesPath = "../routes";
+    private readonly httpHandlers;
+    private initialized;
+    private readonly i18nPath?;
+    private readonly middlewaresPath?;
+    private readonly routesPath?;
+    constructor(properties: ServerProperties);
+    init(): Promise<Server>;
+    private postInit;
+    private processHttpHandlers;
+    addMiddleware(middleware: Middleware): Server;
+    addRoute(route: Route): Server;
+    logInfo(message: string): void;
+    logError(message: string): void;
+    logWarn(message: string): void;
+    log(message: Message): void;
+    private get;
+    private post;
+    registerRoutes(dir: string): Promise<Server>;
+    registerMiddlewares(dir: string): Promise<Server>;
+    getLogger(): Logger;
+    i18nLoad(path: string): Server;
+    start(callback?: () => any): void;
+}
+export { Server };

+ 8 - 0
dist/types/server/ServerProperties.d.ts

@@ -0,0 +1,8 @@
+type ServerProperties = {
+    port: number;
+    locale: string;
+    i18nPath?: string;
+    middlewaresPath?: string;
+    routesPath?: string;
+};
+export { ServerProperties };

+ 2 - 0
dist/types/server/index.d.ts

@@ -0,0 +1,2 @@
+export { Server } from './Server';
+export { ServerProperties } from './ServerProperties';

+ 1 - 1
src/base/exceptions/IncorrectMethodException.ts → lib/base/exceptions/IncorrectMethodException.ts

@@ -5,4 +5,4 @@ class IncorrectMethodException extends Error {
 	}
 }
 
-export default IncorrectMethodException;
+export { IncorrectMethodException };

+ 1 - 1
src/base/exceptions/InvalidMiddlewareException.ts → lib/base/exceptions/InvalidMiddlewareException.ts

@@ -5,4 +5,4 @@ class InvalidMiddlewareException extends Error {
 	}
 }
 
-export default InvalidMiddlewareException;
+export { InvalidMiddlewareException };

+ 1 - 1
src/base/exceptions/InvalidRouteException.ts → lib/base/exceptions/InvalidRouteException.ts

@@ -5,4 +5,4 @@ class InvalidRouteException extends Error {
 	}
 }
 
-export default InvalidRouteException;
+export { InvalidRouteException };

+ 1 - 1
src/base/exceptions/RouteNotSetException.ts → lib/base/exceptions/RouteNotSetException.ts

@@ -5,4 +5,4 @@ class RouteNotSetException extends Error {
 	}
 }
 
-export default RouteNotSetException;
+export { RouteNotSetException };

+ 1 - 1
src/base/exceptions/ServerNotInitializedException.ts → lib/base/exceptions/ServerNotInitializedException.ts

@@ -5,4 +5,4 @@ class ServerNotInitializedException extends Error {
 	}
 }
 
-export default ServerNotInitializedException;
+export { ServerNotInitializedException };

+ 5 - 0
lib/base/exceptions/index.ts

@@ -0,0 +1,5 @@
+export { IncorrectMethodException } from './IncorrectMethodException';
+export { InvalidMiddlewareException } from './InvalidMiddlewareException';
+export { InvalidRouteException } from './InvalidRouteException';
+export { RouteNotSetException } from './RouteNotSetException';
+export { ServerNotInitializedException } from './ServerNotInitializedException';

+ 1 - 1
src/base/http/HttpHandler.ts → lib/base/http/HttpHandler.ts

@@ -30,4 +30,4 @@ abstract class HttpHandler {
 	}
 }
 
-export default HttpHandler;
+export { HttpHandler };

+ 1 - 1
src/base/http/HttpMethod.ts → lib/base/http/HttpMethod.ts

@@ -3,4 +3,4 @@ enum HttpMethod {
     POST
 }
 
-export default HttpMethod;
+export { HttpMethod };

+ 2 - 2
src/base/http/Middleware.ts → lib/base/http/Middleware.ts

@@ -1,7 +1,7 @@
-import HttpHandler from './HttpHandler';
+import { HttpHandler } from './HttpHandler';
 
 abstract class Middleware extends HttpHandler {
 	protected abstract action: (...any: any[]) => any;
 }
 
-export default Middleware;
+export { Middleware };

+ 4 - 4
src/base/http/Route.ts → lib/base/http/Route.ts

@@ -1,6 +1,6 @@
-import {Request, Response} from 'express';
-import HttpMethod from './HttpMethod';
-import HttpHandler from './HttpHandler';
+import { Request, Response } from 'express';
+import { HttpMethod } from './HttpMethod';
+import { HttpHandler } from './HttpHandler';
 
 abstract class Route extends HttpHandler {
 	protected abstract method: HttpMethod;
@@ -11,4 +11,4 @@ abstract class Route extends HttpHandler {
 	}
 }
 
-export default Route;
+export { Route };

+ 1 - 1
src/base/http/StatusCodes.ts → lib/base/http/StatusCodes.ts

@@ -41,4 +41,4 @@ enum StatusCodes {
 	HTTP_VERSION_NOT_SUPPORTED = 505
 }
 
-export default StatusCodes;
+export { StatusCodes };

+ 5 - 0
lib/base/http/index.ts

@@ -0,0 +1,5 @@
+export { HttpHandler } from './HttpHandler';
+export { HttpMethod } from './HttpMethod';
+export { Middleware } from './Middleware';
+export { Route } from './Route';
+export { StatusCodes } from './StatusCodes';

+ 1 - 1
src/base/i18n/KeyParams.ts → lib/base/i18n/KeyParams.ts

@@ -2,4 +2,4 @@ type KeyParams = {
 	[key: string]: any
 };
 
-export default KeyParams;
+export { KeyParams };

+ 5 - 5
src/base/i18n/i18n.ts → lib/base/i18n/i18n.ts

@@ -1,8 +1,8 @@
 import fs from 'fs';
-import i18nMap from './i18nMap';
-import KeyParams from './KeyParams';
+import { i18nMap } from './i18nMap';
+import { KeyParams } from './KeyParams';
 
-export class i18nLoader {
+class i18nLoader {
 	private static instance: i18nLoader;
 	private readonly map: i18nMap;
 	private locale: string;
@@ -64,7 +64,7 @@ export class i18nLoader {
 	}
 }
 
-export const $$ = (key: string, params?: KeyParams): string => {
+const $$ = (key: string, params?: KeyParams): string => {
 	let text = i18nLoader.getInstance().get(key);
 
 	if(params) {
@@ -77,4 +77,4 @@ export const $$ = (key: string, params?: KeyParams): string => {
 	return text;
 };
 
-export default {i18nLoader, $$};
+export { i18nLoader, $$ };

+ 1 - 1
src/base/i18n/i18nMap.ts → lib/base/i18n/i18nMap.ts

@@ -4,4 +4,4 @@ type i18nMap = {
 	}
 }
 
-export default i18nMap;
+export { i18nMap };

+ 3 - 0
lib/base/i18n/index.ts

@@ -0,0 +1,3 @@
+export * from './i18n';
+export { i18nMap } from './i18nMap';
+export { KeyParams } from './KeyParams';

+ 3 - 3
src/base/logger/Logger.ts → lib/base/logger/Logger.ts

@@ -1,7 +1,7 @@
 import pino from 'pino';
 import expressPino, {HttpLogger} from 'pino-http';
-import MessageTypes from './MessageTypes';
-import StatusCodes from '../http/StatusCodes';
+import { MessageTypes } from './MessageTypes';
+import { StatusCodes } from '../http';
 
 class Logger {
 	private readonly logger: pino.Logger;
@@ -37,4 +37,4 @@ class Logger {
 	}
 }
 
-export default Logger;
+export { Logger };

+ 8 - 0
lib/base/logger/Message.ts

@@ -0,0 +1,8 @@
+import { MessageTypes } from './MessageTypes';
+
+type Message = {
+	type: MessageTypes,
+	text: string
+};
+
+export { Message };

+ 1 - 1
src/base/logger/MessageTypes.ts → lib/base/logger/MessageTypes.ts

@@ -4,4 +4,4 @@ enum MessageTypes {
 	ERROR = 'error'
 }
 
-export default MessageTypes;
+export { MessageTypes };

+ 3 - 0
lib/base/logger/index.ts

@@ -0,0 +1,3 @@
+export { Logger } from './Logger';
+export { Message } from './Message';
+export { MessageTypes } from './MessageTypes';

+ 1 - 1
src/base/util/Guid.ts → lib/base/util/Guid.ts

@@ -6,4 +6,4 @@ class Guid {
 	}
 }
 
-export default Guid;
+export { Guid };

+ 1 - 0
lib/base/util/index.ts

@@ -0,0 +1 @@
+export { Guid } from './Guid';

+ 6 - 0
lib/index.ts

@@ -0,0 +1,6 @@
+export * from './server';
+export * from './base/exceptions';
+export * from './base/http';
+export * from './base/util';
+export * from './base/logger';
+export * from './base/i18n';

+ 2 - 2
src/middlewares/ExpressJsonMiddleware.ts → lib/middlewares/ExpressJsonMiddleware.ts

@@ -1,4 +1,4 @@
-import Middleware from '../base/http/Middleware';
+import { Middleware } from '../base/http';
 import express from 'express';
 
 class ExpressJsonMiddleware extends Middleware {
@@ -7,4 +7,4 @@ class ExpressJsonMiddleware extends Middleware {
 	protected action = express.json();
 }
 
-export default ExpressJsonMiddleware;
+export { ExpressJsonMiddleware };

+ 2 - 2
src/middlewares/ExpressUrlencodedMiddleware.ts → lib/middlewares/ExpressUrlencodedMiddleware.ts

@@ -1,4 +1,4 @@
-import Middleware from '../base/http/Middleware';
+import { Middleware } from '../base/http';
 import express from 'express';
 
 class ExpressUrlencodedMiddleware extends Middleware {
@@ -7,4 +7,4 @@ class ExpressUrlencodedMiddleware extends Middleware {
 	protected action = express.urlencoded({ extended: false });
 }
 
-export default ExpressUrlencodedMiddleware;
+export { ExpressUrlencodedMiddleware };

+ 4 - 5
src/middlewares/InternalServerErrorHandler.ts → lib/middlewares/InternalServerErrorHandler.ts

@@ -1,7 +1,6 @@
-import Middleware from '../base/http/Middleware';
-import {NextFunction, Request, Response} from 'express';
-import {$$} from '../base/i18n/i18n';
-import StatusCodes from '../base/http/StatusCodes';
+import { Middleware, StatusCodes } from '../base/http';
+import { NextFunction, Request, Response } from 'express';
+import { $$ } from '../base/i18n';
 
 class InternalServerErrorHandler extends Middleware {
 	protected order = 10000;
@@ -11,4 +10,4 @@ class InternalServerErrorHandler extends Middleware {
 	};
 }
 
-export default InternalServerErrorHandler;
+export { InternalServerErrorHandler };

+ 3 - 3
src/middlewares/LoggerMiddleware.ts → lib/middlewares/LoggerMiddleware.ts

@@ -1,5 +1,5 @@
-import Middleware from '../base/http/Middleware';
-import Logger from '../base/logger/Logger';
+import { Middleware } from '../base/http';
+import { Logger } from '../base/logger';
 
 class LoggerMiddleware extends Middleware {
 	protected order = -97;
@@ -7,4 +7,4 @@ class LoggerMiddleware extends Middleware {
 	protected action = (<Logger>this.context.getLogger()).getHttpLogger();
 }
 
-export default LoggerMiddleware;
+export { LoggerMiddleware };

+ 3 - 4
src/middlewares/NotFoundErrorHandler.ts → lib/middlewares/NotFoundErrorHandler.ts

@@ -1,7 +1,6 @@
-import Middleware from '../base/http/Middleware';
+import { Middleware, StatusCodes } from '../base/http';
 import {NextFunction, Request, Response} from 'express';
-import {$$} from '../base/i18n/i18n';
-import StatusCodes from '../base/http/StatusCodes';
+import { $$ } from '../base/i18n';
 
 class NotFoundErrorHandler extends Middleware {
 	protected order = 9999;
@@ -11,4 +10,4 @@ class NotFoundErrorHandler extends Middleware {
 	};
 }
 
-export default NotFoundErrorHandler;
+export { NotFoundErrorHandler };

Some files were not shown because too many files changed in this diff