skyguard-js 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +237 -0
  3. package/dist/app.d.ts +123 -0
  4. package/dist/app.js +198 -0
  5. package/dist/container/container.d.ts +60 -0
  6. package/dist/container/container.js +71 -0
  7. package/dist/exceptions/baseException.d.ts +6 -0
  8. package/dist/exceptions/baseException.js +15 -0
  9. package/dist/exceptions/contentDispositionException.d.ts +4 -0
  10. package/dist/exceptions/contentDispositionException.js +11 -0
  11. package/dist/exceptions/contentParserException.d.ts +10 -0
  12. package/dist/exceptions/contentParserException.js +21 -0
  13. package/dist/exceptions/fileDownloadException.d.ts +4 -0
  14. package/dist/exceptions/fileDownloadException.js +11 -0
  15. package/dist/exceptions/fileExistsException.d.ts +4 -0
  16. package/dist/exceptions/fileExistsException.js +11 -0
  17. package/dist/exceptions/helperExceptions.d.ts +10 -0
  18. package/dist/exceptions/helperExceptions.js +25 -0
  19. package/dist/exceptions/httpNotFoundException.d.ts +7 -0
  20. package/dist/exceptions/httpNotFoundException.js +14 -0
  21. package/dist/exceptions/index.d.ts +9 -0
  22. package/dist/exceptions/index.js +25 -0
  23. package/dist/exceptions/invalidHttpStatusException.d.ts +4 -0
  24. package/dist/exceptions/invalidHttpStatusException.js +11 -0
  25. package/dist/exceptions/sessionException.d.ts +4 -0
  26. package/dist/exceptions/sessionException.js +11 -0
  27. package/dist/exceptions/validationException.d.ts +13 -0
  28. package/dist/exceptions/validationException.js +32 -0
  29. package/dist/helpers/app.d.ts +4 -0
  30. package/dist/helpers/app.js +12 -0
  31. package/dist/helpers/http.d.ts +59 -0
  32. package/dist/helpers/http.js +77 -0
  33. package/dist/helpers/index.d.ts +1 -0
  34. package/dist/helpers/index.js +9 -0
  35. package/dist/http/httpAdapter.d.ts +26 -0
  36. package/dist/http/httpAdapter.js +2 -0
  37. package/dist/http/httpMethods.d.ts +14 -0
  38. package/dist/http/httpMethods.js +18 -0
  39. package/dist/http/index.d.ts +6 -0
  40. package/dist/http/index.js +13 -0
  41. package/dist/http/logger.d.ts +8 -0
  42. package/dist/http/logger.js +36 -0
  43. package/dist/http/nodeNativeHttp.d.ts +41 -0
  44. package/dist/http/nodeNativeHttp.js +73 -0
  45. package/dist/http/request.d.ts +85 -0
  46. package/dist/http/request.js +127 -0
  47. package/dist/http/response.d.ts +118 -0
  48. package/dist/http/response.js +179 -0
  49. package/dist/http/statusCodes.d.ts +1 -0
  50. package/dist/http/statusCodes.js +38 -0
  51. package/dist/index.d.ts +4 -0
  52. package/dist/index.js +10 -0
  53. package/dist/middlewares/cors.d.ts +103 -0
  54. package/dist/middlewares/cors.js +91 -0
  55. package/dist/middlewares/session.d.ts +26 -0
  56. package/dist/middlewares/session.js +88 -0
  57. package/dist/parsers/contentParser.d.ts +27 -0
  58. package/dist/parsers/contentParser.js +2 -0
  59. package/dist/parsers/contentParserManager.d.ts +50 -0
  60. package/dist/parsers/contentParserManager.js +91 -0
  61. package/dist/parsers/index.d.ts +8 -0
  62. package/dist/parsers/index.js +30 -0
  63. package/dist/parsers/jsonParser.d.ts +10 -0
  64. package/dist/parsers/jsonParser.js +24 -0
  65. package/dist/parsers/multipartParser.d.ts +35 -0
  66. package/dist/parsers/multipartParser.js +120 -0
  67. package/dist/parsers/parserInterface.d.ts +37 -0
  68. package/dist/parsers/parserInterface.js +2 -0
  69. package/dist/parsers/textParser.d.ts +11 -0
  70. package/dist/parsers/textParser.js +19 -0
  71. package/dist/parsers/urlEncodedParser.d.ts +10 -0
  72. package/dist/parsers/urlEncodedParser.js +19 -0
  73. package/dist/parsers/xmlParser.d.ts +47 -0
  74. package/dist/parsers/xmlParser.js +158 -0
  75. package/dist/routing/index.d.ts +3 -0
  76. package/dist/routing/index.js +9 -0
  77. package/dist/routing/layer.d.ts +85 -0
  78. package/dist/routing/layer.js +117 -0
  79. package/dist/routing/router.d.ts +143 -0
  80. package/dist/routing/router.js +210 -0
  81. package/dist/routing/routerGroup.d.ts +79 -0
  82. package/dist/routing/routerGroup.js +103 -0
  83. package/dist/server/nodeNativeServer.d.ts +29 -0
  84. package/dist/server/nodeNativeServer.js +42 -0
  85. package/dist/sessions/cookieOptions.d.ts +72 -0
  86. package/dist/sessions/cookieOptions.js +2 -0
  87. package/dist/sessions/index.d.ts +4 -0
  88. package/dist/sessions/index.js +7 -0
  89. package/dist/sessions/memorySessionStorage.d.ts +112 -0
  90. package/dist/sessions/memorySessionStorage.js +170 -0
  91. package/dist/sessions/session.d.ts +80 -0
  92. package/dist/sessions/session.js +101 -0
  93. package/dist/sessions/sessionStorage.d.ts +105 -0
  94. package/dist/sessions/sessionStorage.js +2 -0
  95. package/dist/static/contentDisposition.d.ts +71 -0
  96. package/dist/static/contentDisposition.js +159 -0
  97. package/dist/static/fileDownload.d.ts +44 -0
  98. package/dist/static/fileDownload.js +88 -0
  99. package/dist/static/fileStaticHandler.d.ts +61 -0
  100. package/dist/static/fileStaticHandler.js +110 -0
  101. package/dist/static/index.d.ts +4 -0
  102. package/dist/static/index.js +11 -0
  103. package/dist/static/mimeTypes.d.ts +1 -0
  104. package/dist/static/mimeTypes.js +40 -0
  105. package/dist/tsconfig.tsbuildinfo +1 -0
  106. package/dist/types/index.d.ts +122 -0
  107. package/dist/types/index.js +2 -0
  108. package/dist/validators/index.d.ts +5 -0
  109. package/dist/validators/index.js +22 -0
  110. package/dist/validators/rules/booleanRule.d.ts +11 -0
  111. package/dist/validators/rules/booleanRule.js +22 -0
  112. package/dist/validators/rules/dateRule.d.ts +16 -0
  113. package/dist/validators/rules/dateRule.js +44 -0
  114. package/dist/validators/rules/emailRule.d.ts +12 -0
  115. package/dist/validators/rules/emailRule.js +24 -0
  116. package/dist/validators/rules/index.d.ts +6 -0
  117. package/dist/validators/rules/index.js +15 -0
  118. package/dist/validators/rules/numberRule.d.ts +17 -0
  119. package/dist/validators/rules/numberRule.js +30 -0
  120. package/dist/validators/rules/requiredRule.d.ts +11 -0
  121. package/dist/validators/rules/requiredRule.js +21 -0
  122. package/dist/validators/rules/stringRule.d.ts +18 -0
  123. package/dist/validators/rules/stringRule.js +32 -0
  124. package/dist/validators/types.d.ts +55 -0
  125. package/dist/validators/types.js +2 -0
  126. package/dist/validators/validationRule.d.ts +53 -0
  127. package/dist/validators/validationRule.js +37 -0
  128. package/dist/validators/validationSchema.d.ts +145 -0
  129. package/dist/validators/validationSchema.js +198 -0
  130. package/dist/validators/validator.d.ts +58 -0
  131. package/dist/validators/validator.js +91 -0
  132. package/dist/views/helpersTemplate.d.ts +104 -0
  133. package/dist/views/helpersTemplate.js +186 -0
  134. package/dist/views/index.d.ts +4 -0
  135. package/dist/views/index.js +9 -0
  136. package/dist/views/raptorEngine.d.ts +127 -0
  137. package/dist/views/raptorEngine.js +165 -0
  138. package/dist/views/templateEngine.d.ts +80 -0
  139. package/dist/views/templateEngine.js +204 -0
  140. package/dist/views/view.d.ts +55 -0
  141. package/dist/views/view.js +2 -0
  142. package/package.json +79 -0
@@ -0,0 +1,6 @@
1
+ export declare abstract class BaseException extends Error {
2
+ readonly code: string;
3
+ readonly status?: number;
4
+ readonly meta?: Record<string, any>;
5
+ protected constructor(message: string, code: string, status?: number, meta?: Record<string, any>);
6
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseException = void 0;
4
+ class BaseException extends Error {
5
+ code;
6
+ status;
7
+ meta;
8
+ constructor(message, code, status, meta) {
9
+ super(message);
10
+ this.code = code;
11
+ this.status = status;
12
+ this.meta = meta;
13
+ }
14
+ }
15
+ exports.BaseException = BaseException;
@@ -0,0 +1,4 @@
1
+ import { BaseException } from "./baseException";
2
+ export declare class ContentDispositionException extends BaseException {
3
+ constructor();
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentDispositionException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ class ContentDispositionException extends baseException_1.BaseException {
6
+ constructor() {
7
+ super("filename must be a non-empty string", "CONTENT_DISPOSITION_ERROR");
8
+ this.name = "ContentDispositionException";
9
+ }
10
+ }
11
+ exports.ContentDispositionException = ContentDispositionException;
@@ -0,0 +1,10 @@
1
+ import { BaseException } from "./baseException";
2
+ /**
3
+ * Error personalizado para errores de parseo de contenido.
4
+ */
5
+ export declare class ContentParserException extends BaseException {
6
+ constructor(message: string);
7
+ }
8
+ export declare class ReadBodyException extends BaseException {
9
+ constructor();
10
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReadBodyException = exports.ContentParserException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ /**
6
+ * Error personalizado para errores de parseo de contenido.
7
+ */
8
+ class ContentParserException extends baseException_1.BaseException {
9
+ constructor(message) {
10
+ super(message, "CONTENT_PARSER_ERROR");
11
+ this.name = "ContentParserException";
12
+ }
13
+ }
14
+ exports.ContentParserException = ContentParserException;
15
+ class ReadBodyException extends baseException_1.BaseException {
16
+ constructor() {
17
+ super("Failed to read request body", "READ_BODY_REQUEST_ERROR");
18
+ this.name = "ReadBodyException";
19
+ }
20
+ }
21
+ exports.ReadBodyException = ReadBodyException;
@@ -0,0 +1,4 @@
1
+ import { BaseException } from "./baseException";
2
+ export declare class FileDownloadException extends BaseException {
3
+ constructor(message: string);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileDownloadException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ class FileDownloadException extends baseException_1.BaseException {
6
+ constructor(message) {
7
+ super(message, "FILE_DOWNLOAD_EXCEPTION");
8
+ this.name = "FileDownloadException";
9
+ }
10
+ }
11
+ exports.FileDownloadException = FileDownloadException;
@@ -0,0 +1,4 @@
1
+ import { BaseException } from "./baseException";
2
+ export declare class FileNotExistsException extends BaseException {
3
+ constructor(resource: string);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileNotExistsException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ class FileNotExistsException extends baseException_1.BaseException {
6
+ constructor(resource) {
7
+ super(`File not exists ${resource}`, "FILE_NOT_EXISTS_ERROR");
8
+ this.name = "FileNotExistsException";
9
+ }
10
+ }
11
+ exports.FileNotExistsException = FileNotExistsException;
@@ -0,0 +1,10 @@
1
+ import { BaseException } from "./baseException";
2
+ export declare class HelperNotFoundException extends BaseException {
3
+ constructor(helperName: string);
4
+ }
5
+ export declare class HelperExecutionException extends BaseException {
6
+ constructor(helperName: string);
7
+ }
8
+ export declare class HelperArgumentException extends BaseException {
9
+ constructor(helperName: string);
10
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HelperArgumentException = exports.HelperExecutionException = exports.HelperNotFoundException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ class HelperNotFoundException extends baseException_1.BaseException {
6
+ constructor(helperName) {
7
+ super(`Helper "${helperName}" is not registered`, "HELPER_NOT_FOUND_ERROR");
8
+ this.name = "HelperNotFoundException";
9
+ }
10
+ }
11
+ exports.HelperNotFoundException = HelperNotFoundException;
12
+ class HelperExecutionException extends baseException_1.BaseException {
13
+ constructor(helperName) {
14
+ super(`Error executing helper "${helperName}"`, "HELPER_EXECUTION_ERROR");
15
+ this.name = "HelperExecutionError";
16
+ }
17
+ }
18
+ exports.HelperExecutionException = HelperExecutionException;
19
+ class HelperArgumentException extends baseException_1.BaseException {
20
+ constructor(helperName) {
21
+ super(`Invalid argument for helper "${helperName}"`, "HELPER_ARGUMENT_ERROR");
22
+ this.name = "HelperArgumentError";
23
+ }
24
+ }
25
+ exports.HelperArgumentException = HelperArgumentException;
@@ -0,0 +1,7 @@
1
+ import { BaseException } from "./baseException";
2
+ /**
3
+ * HTTP exception not found hereda de Error
4
+ */
5
+ export declare class HttpNotFoundException extends BaseException {
6
+ constructor();
7
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpNotFoundException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ /**
6
+ * HTTP exception not found hereda de Error
7
+ */
8
+ class HttpNotFoundException extends baseException_1.BaseException {
9
+ constructor() {
10
+ super("Route not found", "HTTP_NOT_FOUND_ERROR");
11
+ this.name = "HttpNotFoundException";
12
+ }
13
+ }
14
+ exports.HttpNotFoundException = HttpNotFoundException;
@@ -0,0 +1,9 @@
1
+ export { ContentParserException, ReadBodyException, } from "./contentParserException";
2
+ export { FileNotExistsException } from "./fileExistsException";
3
+ export { HttpNotFoundException } from "./httpNotFoundException";
4
+ export { HelperExecutionException, HelperNotFoundException, HelperArgumentException, } from "./helperExceptions";
5
+ export { ValidationException, ValidatorFieldException, } from "./validationException";
6
+ export { ContentDispositionException } from "./contentDispositionException";
7
+ export { FileDownloadException } from "./fileDownloadException";
8
+ export { SessionException } from "./sessionException";
9
+ export { InvalidHttpStatusException } from "./invalidHttpStatusException";
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidHttpStatusException = exports.SessionException = exports.FileDownloadException = exports.ContentDispositionException = exports.ValidatorFieldException = exports.ValidationException = exports.HelperArgumentException = exports.HelperNotFoundException = exports.HelperExecutionException = exports.HttpNotFoundException = exports.FileNotExistsException = exports.ReadBodyException = exports.ContentParserException = void 0;
4
+ var contentParserException_1 = require("./contentParserException");
5
+ Object.defineProperty(exports, "ContentParserException", { enumerable: true, get: function () { return contentParserException_1.ContentParserException; } });
6
+ Object.defineProperty(exports, "ReadBodyException", { enumerable: true, get: function () { return contentParserException_1.ReadBodyException; } });
7
+ var fileExistsException_1 = require("./fileExistsException");
8
+ Object.defineProperty(exports, "FileNotExistsException", { enumerable: true, get: function () { return fileExistsException_1.FileNotExistsException; } });
9
+ var httpNotFoundException_1 = require("./httpNotFoundException");
10
+ Object.defineProperty(exports, "HttpNotFoundException", { enumerable: true, get: function () { return httpNotFoundException_1.HttpNotFoundException; } });
11
+ var helperExceptions_1 = require("./helperExceptions");
12
+ Object.defineProperty(exports, "HelperExecutionException", { enumerable: true, get: function () { return helperExceptions_1.HelperExecutionException; } });
13
+ Object.defineProperty(exports, "HelperNotFoundException", { enumerable: true, get: function () { return helperExceptions_1.HelperNotFoundException; } });
14
+ Object.defineProperty(exports, "HelperArgumentException", { enumerable: true, get: function () { return helperExceptions_1.HelperArgumentException; } });
15
+ var validationException_1 = require("./validationException");
16
+ Object.defineProperty(exports, "ValidationException", { enumerable: true, get: function () { return validationException_1.ValidationException; } });
17
+ Object.defineProperty(exports, "ValidatorFieldException", { enumerable: true, get: function () { return validationException_1.ValidatorFieldException; } });
18
+ var contentDispositionException_1 = require("./contentDispositionException");
19
+ Object.defineProperty(exports, "ContentDispositionException", { enumerable: true, get: function () { return contentDispositionException_1.ContentDispositionException; } });
20
+ var fileDownloadException_1 = require("./fileDownloadException");
21
+ Object.defineProperty(exports, "FileDownloadException", { enumerable: true, get: function () { return fileDownloadException_1.FileDownloadException; } });
22
+ var sessionException_1 = require("./sessionException");
23
+ Object.defineProperty(exports, "SessionException", { enumerable: true, get: function () { return sessionException_1.SessionException; } });
24
+ var invalidHttpStatusException_1 = require("./invalidHttpStatusException");
25
+ Object.defineProperty(exports, "InvalidHttpStatusException", { enumerable: true, get: function () { return invalidHttpStatusException_1.InvalidHttpStatusException; } });
@@ -0,0 +1,4 @@
1
+ import { BaseException } from "./baseException";
2
+ export declare class InvalidHttpStatusException extends BaseException {
3
+ constructor(status: number);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidHttpStatusException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ class InvalidHttpStatusException extends baseException_1.BaseException {
6
+ constructor(status) {
7
+ super(`Invalid HTTP status code: ${status}`, "INVALID_HTTP_STATUS_ERROR");
8
+ this.name = "InvalidHttpStatusException";
9
+ }
10
+ }
11
+ exports.InvalidHttpStatusException = InvalidHttpStatusException;
@@ -0,0 +1,4 @@
1
+ import { BaseException } from "./baseException";
2
+ export declare class SessionException extends BaseException {
3
+ constructor(message: string);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ class SessionException extends baseException_1.BaseException {
6
+ constructor(message) {
7
+ super(message, "SESSION_ERROR");
8
+ this.name = "SessionException";
9
+ }
10
+ }
11
+ exports.SessionException = SessionException;
@@ -0,0 +1,13 @@
1
+ import { ValidationError } from "../validators";
2
+ import { BaseException } from "./baseException";
3
+ export declare class ValidationException extends BaseException {
4
+ readonly errors: ValidationError[];
5
+ constructor(errors: ValidationError[]);
6
+ /**
7
+ * Obtiene los errores agrupados por campo.
8
+ */
9
+ getErrorsByField(): Record<string, string[]>;
10
+ }
11
+ export declare class ValidatorFieldException extends BaseException {
12
+ constructor();
13
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidatorFieldException = exports.ValidationException = void 0;
4
+ const baseException_1 = require("./baseException");
5
+ class ValidationException extends baseException_1.BaseException {
6
+ errors;
7
+ constructor(errors) {
8
+ super("Validation failed", "VALIDATION_ERROR");
9
+ this.errors = errors;
10
+ this.name = "ValidationException";
11
+ }
12
+ /**
13
+ * Obtiene los errores agrupados por campo.
14
+ */
15
+ getErrorsByField() {
16
+ const grouped = {};
17
+ for (const error of this.errors) {
18
+ if (!grouped[error.field])
19
+ grouped[error.field] = [];
20
+ grouped[error.field].push(error.message);
21
+ }
22
+ return grouped;
23
+ }
24
+ }
25
+ exports.ValidationException = ValidationException;
26
+ class ValidatorFieldException extends baseException_1.BaseException {
27
+ constructor() {
28
+ super("No field selected. Call field() first.", "VALIDATOR_FIELD_ERROR");
29
+ this.name = "ValidatorFieldException";
30
+ }
31
+ }
32
+ exports.ValidatorFieldException = ValidatorFieldException;
@@ -0,0 +1,4 @@
1
+ import { App } from "../app";
2
+ import type { Constructor } from "../types";
3
+ export declare function app(target?: Constructor<App>): App;
4
+ export declare function singleton<T>(target: Constructor<T>): T;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.app = app;
4
+ exports.singleton = singleton;
5
+ const app_1 = require("../app");
6
+ const container_1 = require("../container/container");
7
+ function app(target = app_1.App) {
8
+ return container_1.Container.resolve(target);
9
+ }
10
+ function singleton(target) {
11
+ return container_1.Container.singleton(target);
12
+ }
@@ -0,0 +1,59 @@
1
+ import type { TemplateContext } from "../types";
2
+ import { Response } from "../http/response";
3
+ /**
4
+ * Creates an HTTP response with a JSON body.
5
+ *
6
+ * @typeParam T - Type of the payload to be serialized.
7
+ * @param data - Data to be serialized as JSON.
8
+ * @returns A `Response` instance with `Content-Type: application/json`.
9
+ *
10
+ * @example
11
+ * return json({ ok: true, userId: 1 });
12
+ */
13
+ export declare function json<T>(data: T): Response;
14
+ /**
15
+ * Creates an HTTP response with a plain text body.
16
+ *
17
+ * @param data - Text to be sent as the response body.
18
+ * @returns A `Response` instance with a text-based `Content-Type`.
19
+ *
20
+ * @example
21
+ * return text("Hello world");
22
+ */
23
+ export declare function text(data: string): Response;
24
+ /**
25
+ * Creates an HTTP redirect response to the given URL.
26
+ *
27
+ * @param url - Target URL for the redirection (absolute or relative).
28
+ * @returns A `Response` instance configured as a redirect.
29
+ *
30
+ * @example
31
+ * return redirect("/login");
32
+ */
33
+ export declare function redirect(url: string): Response;
34
+ /**
35
+ * Returns a file as a downloadable response.
36
+ *
37
+ * @param path - File system path to the file (relative or absolute, depending on the runtime).
38
+ * @param filename - Optional filename suggested to the client for the download.
39
+ * @param headers - Optional additional headers to include in the response.
40
+ * @returns A `Promise<Response>` ready to be returned by a route handler.
41
+ *
42
+ * @example
43
+ * return await download("./storage/reports/sales.pdf", "report.pdf", {
44
+ * "Cache-Control": "no-store",
45
+ * });
46
+ */
47
+ export declare function download(path: string, filename?: string, headers?: Record<string, string>): Promise<Response>;
48
+ /**
49
+ * Renders a template/view and returns an HTTP response with the generated HTML.
50
+ *
51
+ * @param view - View identifier or template path, depending on the template system.
52
+ * @param params - Context variables available inside the template.
53
+ * @param layout - Optional layout name used to wrap the rendered view.
54
+ * @returns A `Promise<Response>` containing the rendered HTML.
55
+ *
56
+ * @example
57
+ * return await render("users/profile", { user }, "main");
58
+ */
59
+ export declare function render(view: string, params: TemplateContext, layout?: string): Promise<Response>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.json = json;
4
+ exports.text = text;
5
+ exports.redirect = redirect;
6
+ exports.download = download;
7
+ exports.render = render;
8
+ const response_1 = require("../http/response");
9
+ const fileDownload_1 = require("../static/fileDownload");
10
+ /**
11
+ * Creates an HTTP response with a JSON body.
12
+ *
13
+ * @typeParam T - Type of the payload to be serialized.
14
+ * @param data - Data to be serialized as JSON.
15
+ * @returns A `Response` instance with `Content-Type: application/json`.
16
+ *
17
+ * @example
18
+ * return json({ ok: true, userId: 1 });
19
+ */
20
+ function json(data) {
21
+ return response_1.Response.json(data);
22
+ }
23
+ /**
24
+ * Creates an HTTP response with a plain text body.
25
+ *
26
+ * @param data - Text to be sent as the response body.
27
+ * @returns A `Response` instance with a text-based `Content-Type`.
28
+ *
29
+ * @example
30
+ * return text("Hello world");
31
+ */
32
+ function text(data) {
33
+ return response_1.Response.text(data);
34
+ }
35
+ /**
36
+ * Creates an HTTP redirect response to the given URL.
37
+ *
38
+ * @param url - Target URL for the redirection (absolute or relative).
39
+ * @returns A `Response` instance configured as a redirect.
40
+ *
41
+ * @example
42
+ * return redirect("/login");
43
+ */
44
+ function redirect(url) {
45
+ return response_1.Response.redirect(url);
46
+ }
47
+ /**
48
+ * Returns a file as a downloadable response.
49
+ *
50
+ * @param path - File system path to the file (relative or absolute, depending on the runtime).
51
+ * @param filename - Optional filename suggested to the client for the download.
52
+ * @param headers - Optional additional headers to include in the response.
53
+ * @returns A `Promise<Response>` ready to be returned by a route handler.
54
+ *
55
+ * @example
56
+ * return await download("./storage/reports/sales.pdf", "report.pdf", {
57
+ * "Cache-Control": "no-store",
58
+ * });
59
+ */
60
+ async function download(path, filename, headers) {
61
+ const downloadClass = new fileDownload_1.FileDownloadHelper();
62
+ return await downloadClass.download(path, filename, headers);
63
+ }
64
+ /**
65
+ * Renders a template/view and returns an HTTP response with the generated HTML.
66
+ *
67
+ * @param view - View identifier or template path, depending on the template system.
68
+ * @param params - Context variables available inside the template.
69
+ * @param layout - Optional layout name used to wrap the rendered view.
70
+ * @returns A `Promise<Response>` containing the rendered HTML.
71
+ *
72
+ * @example
73
+ * return await render("users/profile", { user }, "main");
74
+ */
75
+ async function render(view, params, layout) {
76
+ return await response_1.Response.render(view, params, layout);
77
+ }
@@ -0,0 +1 @@
1
+ export { json, redirect, text, render, download } from "./http";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.download = exports.render = exports.text = exports.redirect = exports.json = void 0;
4
+ var http_1 = require("./http");
5
+ Object.defineProperty(exports, "json", { enumerable: true, get: function () { return http_1.json; } });
6
+ Object.defineProperty(exports, "redirect", { enumerable: true, get: function () { return http_1.redirect; } });
7
+ Object.defineProperty(exports, "text", { enumerable: true, get: function () { return http_1.text; } });
8
+ Object.defineProperty(exports, "render", { enumerable: true, get: function () { return http_1.render; } });
9
+ Object.defineProperty(exports, "download", { enumerable: true, get: function () { return http_1.download; } });
@@ -0,0 +1,26 @@
1
+ import { Request } from "./request";
2
+ import { Response } from "./response";
3
+ /**
4
+ * High-level contract that defines the framework entry port
5
+ * to the outside world (HTTP, sockets, runtimes, etc.).
6
+ *
7
+ * This interface allows the framework core to be fully decoupled
8
+ * from any concrete server implementation (Node.js, Bun, Deno, Cloudflare, etc.).
9
+ */
10
+ export interface HttpAdapter {
11
+ /**
12
+ * Builds and returns a {@link Request} instance from
13
+ * the current connection context.
14
+ *
15
+ * @returns A promise that resolves to a {@link Request} object
16
+ */
17
+ getRequest(): Promise<Request>;
18
+ /**
19
+ * Sends a {@link Response} to the client, mapping its status,
20
+ * headers, and body to the underlying runtime protocol.
21
+ *
22
+ * @param response - {@link Response} object containing
23
+ * the outgoing data defined by the application
24
+ */
25
+ sendResponse(response: Response): void;
26
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Enumeration of HTTP methods supported by the framework.
3
+ *
4
+ * Values follow the standard HTTP specification.
5
+ */
6
+ export declare enum HttpMethods {
7
+ get = "GET",
8
+ post = "POST",
9
+ put = "PUT",
10
+ patch = "PATCH",
11
+ delete = "DELETE",
12
+ options = "OPTIONS",
13
+ head = "HEAD"
14
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpMethods = void 0;
4
+ /**
5
+ * Enumeration of HTTP methods supported by the framework.
6
+ *
7
+ * Values follow the standard HTTP specification.
8
+ */
9
+ var HttpMethods;
10
+ (function (HttpMethods) {
11
+ HttpMethods["get"] = "GET";
12
+ HttpMethods["post"] = "POST";
13
+ HttpMethods["put"] = "PUT";
14
+ HttpMethods["patch"] = "PATCH";
15
+ HttpMethods["delete"] = "DELETE";
16
+ HttpMethods["options"] = "OPTIONS";
17
+ HttpMethods["head"] = "HEAD";
18
+ })(HttpMethods || (exports.HttpMethods = HttpMethods = {}));
@@ -0,0 +1,6 @@
1
+ export { Response } from "./response";
2
+ export { Request } from "./request";
3
+ export { NodeHttpAdapter } from "./nodeNativeHttp";
4
+ export { HttpMethods } from "./httpMethods";
5
+ export { HttpAdapter } from "./httpAdapter";
6
+ export { Logger } from "./logger";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = exports.HttpMethods = exports.NodeHttpAdapter = exports.Request = exports.Response = void 0;
4
+ var response_1 = require("./response");
5
+ Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return response_1.Response; } });
6
+ var request_1 = require("./request");
7
+ Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return request_1.Request; } });
8
+ var nodeNativeHttp_1 = require("./nodeNativeHttp");
9
+ Object.defineProperty(exports, "NodeHttpAdapter", { enumerable: true, get: function () { return nodeNativeHttp_1.NodeHttpAdapter; } });
10
+ var httpMethods_1 = require("./httpMethods");
11
+ Object.defineProperty(exports, "HttpMethods", { enumerable: true, get: function () { return httpMethods_1.HttpMethods; } });
12
+ var logger_1 = require("./logger");
13
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
@@ -0,0 +1,8 @@
1
+ import { IncomingMessage } from "node:http";
2
+ import { Response } from "./response";
3
+ export declare class Logger {
4
+ private stream;
5
+ constructor();
6
+ log(req: IncomingMessage, res: Response, startTime: bigint): void;
7
+ private colorizeStatus;
8
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Logger = void 0;
4
+ class Logger {
5
+ stream;
6
+ constructor() {
7
+ this.stream = process.stdout;
8
+ }
9
+ log(req, res, startTime) {
10
+ const method = req.method || "-";
11
+ const url = req.url || "-";
12
+ const contentLength = res.getHeaders["content-length"] || "-";
13
+ const diff = process.hrtime.bigint() - startTime;
14
+ const responseTime = (Number(diff) / 1_000_000).toFixed(3);
15
+ const coloredStatus = this.colorizeStatus(res.getStatus);
16
+ const logLine = `${method} ${url} ${coloredStatus} ${responseTime} ms - ${contentLength}`;
17
+ this.stream.write(logLine + "\n");
18
+ }
19
+ colorizeStatus(statusCode) {
20
+ const statusStr = String(statusCode);
21
+ if (statusCode >= 500) {
22
+ return `\x1b[31m${statusStr}\x1b[0m`;
23
+ }
24
+ else if (statusCode >= 400) {
25
+ return `\x1b[33m${statusStr}\x1b[0m`;
26
+ }
27
+ else if (statusCode >= 300) {
28
+ return `\x1b[36m${statusStr}\x1b[0m`;
29
+ }
30
+ else if (statusCode >= 200) {
31
+ return `\x1b[32m${statusStr}\x1b[0m`;
32
+ }
33
+ return statusStr;
34
+ }
35
+ }
36
+ exports.Logger = Logger;
@@ -0,0 +1,41 @@
1
+ import { IncomingMessage, ServerResponse } from "node:http";
2
+ import type { HttpAdapter } from "./httpAdapter";
3
+ import { Response } from "./response";
4
+ import { Request } from "./request";
5
+ /**
6
+ * Node.js HTTP adapter.
7
+ *
8
+ * Acts as a bridge between the native Node.js HTTP API and the
9
+ * internal framework abstractions.
10
+ *
11
+ * @implements {HttpAdapter}
12
+ */
13
+ export declare class NodeHttpAdapter implements HttpAdapter {
14
+ private readonly req;
15
+ private readonly res;
16
+ private contentParser;
17
+ private logger;
18
+ private readonly startTime;
19
+ /**
20
+ * @param req - Native Node.js incoming request
21
+ * @param res - Native Node.js server response
22
+ */
23
+ constructor(req: IncomingMessage, res: ServerResponse);
24
+ /**
25
+ * Builds and returns a {@link Request} instance from
26
+ * the incoming Node.js request.
27
+ *
28
+ * @returns A fully constructed {@link Request} instance
29
+ */
30
+ getRequest(): Promise<Request>;
31
+ /**
32
+ * Sends a framework {@link Response} to the client by mapping it
33
+ * to the native Node.js {@link ServerResponse}.
34
+ *
35
+ * This method represents the final step of the request lifecycle
36
+ * in a Node.js runtime.
37
+ *
38
+ * @param response - Framework response to be sent to the client
39
+ */
40
+ sendResponse(response: Response): void;
41
+ }