skyguard-js 1.0.0 → 1.0.2
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.
- package/README.md +63 -56
- package/dist/app.d.ts +2 -5
- package/dist/app.js +15 -17
- package/dist/exceptions/httpExceptions.d.ts +57 -0
- package/dist/exceptions/httpExceptions.js +108 -0
- package/dist/exceptions/index.d.ts +0 -4
- package/dist/exceptions/index.js +1 -10
- package/dist/http/nodeNativeHttp.js +6 -2
- package/dist/http/request.d.ts +3 -5
- package/dist/http/request.js +8 -12
- package/dist/http/response.js +2 -3
- package/dist/middlewares/index.d.ts +2 -0
- package/dist/middlewares/index.js +7 -0
- package/dist/middlewares/session.js +4 -4
- package/dist/parsers/contentParserManager.js +3 -3
- package/dist/parsers/jsonParser.js +2 -2
- package/dist/parsers/multipartParser.d.ts +1 -1
- package/dist/parsers/multipartParser.js +3 -3
- package/dist/parsers/xmlParser.d.ts +1 -1
- package/dist/parsers/xmlParser.js +13 -18
- package/dist/routing/buildFullPath.d.ts +8 -0
- package/dist/routing/buildFullPath.js +21 -0
- package/dist/routing/layer.js +1 -1
- package/dist/routing/router.d.ts +0 -8
- package/dist/routing/router.js +9 -29
- package/dist/routing/routerGroup.d.ts +5 -6
- package/dist/routing/routerGroup.js +7 -7
- package/dist/sessions/fileSessionStorage.d.ts +156 -0
- package/dist/sessions/fileSessionStorage.js +292 -0
- package/dist/sessions/index.d.ts +1 -0
- package/dist/sessions/index.js +3 -1
- package/dist/sessions/memorySessionStorage.d.ts +3 -3
- package/dist/sessions/memorySessionStorage.js +6 -8
- package/dist/sessions/session.d.ts +4 -4
- package/dist/sessions/session.js +4 -7
- package/dist/sessions/sessionStorage.d.ts +6 -26
- package/dist/static/contentDisposition.js +1 -1
- package/dist/static/fileDownload.js +10 -8
- package/package.json +15 -4
- package/dist/exceptions/contentParserException.d.ts +0 -10
- package/dist/exceptions/contentParserException.js +0 -21
- package/dist/exceptions/fileDownloadException.d.ts +0 -4
- package/dist/exceptions/fileDownloadException.js +0 -11
- package/dist/exceptions/httpNotFoundException.d.ts +0 -7
- package/dist/exceptions/httpNotFoundException.js +0 -14
- package/dist/exceptions/sessionException.d.ts +0 -4
- package/dist/exceptions/sessionException.js +0 -11
- package/dist/server/nodeNativeServer.d.ts +0 -29
- package/dist/server/nodeNativeServer.js +0 -42
- package/dist/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -10,24 +10,24 @@ At its current stage, the framework focuses on **routing**, **internal architect
|
|
|
10
10
|
|
|
11
11
|
## 🎯 Current Goals
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
- Provide a simple and expressive API to register and handle HTTP routes
|
|
14
|
+
- Maintain a clean, extensible, and framework-agnostic architecture
|
|
15
|
+
- Leverage TypeScript for strong typing and better developer experience
|
|
16
|
+
- Serve as a learning project with progressive evolution
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
20
|
## ✨ Current Features
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
- TypeScript-first design
|
|
23
|
+
- HTTP routing by method (GET, POST, PUT, PATCH, DELETE)
|
|
24
|
+
- Route groups with prefixes
|
|
25
|
+
- Global, group, and route-level middlewares
|
|
26
|
+
- Request / Response abstractions
|
|
27
|
+
- Declarative data validation
|
|
28
|
+
- Simple template engine with layouts and helpers
|
|
29
|
+
- Static file serving
|
|
30
|
+
- Session handling (via middleware)
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
@@ -42,8 +42,7 @@ npm install skyguard-js
|
|
|
42
42
|
## 🏁 Basic Usage
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
|
-
import { createApp } from "skyguard-js";
|
|
46
|
-
import { Response } from "skyguard-js/http";
|
|
45
|
+
import { createApp, Response } from "skyguard-js";
|
|
47
46
|
|
|
48
47
|
const app = createApp();
|
|
49
48
|
|
|
@@ -51,7 +50,9 @@ app.get("/health", () => {
|
|
|
51
50
|
return Response.json({ status: "ok" });
|
|
52
51
|
});
|
|
53
52
|
|
|
54
|
-
app.
|
|
53
|
+
app.run(3000, () => {
|
|
54
|
+
console.log(`Server running in port: http://localhost:${3000}`);
|
|
55
|
+
});
|
|
55
56
|
```
|
|
56
57
|
|
|
57
58
|
---
|
|
@@ -79,7 +80,7 @@ Internally, the framework maps HTTP methods to route layers using an optimized r
|
|
|
79
80
|
Route groups allow you to organize endpoints under a shared prefix.
|
|
80
81
|
|
|
81
82
|
```ts
|
|
82
|
-
app.group("/api",
|
|
83
|
+
app.group("/api", api => {
|
|
83
84
|
api.get("/users", () => Response.json({ message: "Users" }));
|
|
84
85
|
api.get("/products", () => Response.json({ message: "Products" }));
|
|
85
86
|
});
|
|
@@ -92,8 +93,7 @@ app.group("/api", (api) => {
|
|
|
92
93
|
Middlewares can be registered **globally**, **per group**, or **per route**.
|
|
93
94
|
|
|
94
95
|
```ts
|
|
95
|
-
import { Request, Response } from "skyguard-js
|
|
96
|
-
import { RouteHandler } from "skyguard-js/types";
|
|
96
|
+
import { Request, Response, RouteHandler } from "skyguard-js";
|
|
97
97
|
|
|
98
98
|
const authMiddleware = async (
|
|
99
99
|
request: Request,
|
|
@@ -110,17 +110,25 @@ const authMiddleware = async (
|
|
|
110
110
|
app.middlewares([authMiddleware]);
|
|
111
111
|
|
|
112
112
|
// Group middleware
|
|
113
|
-
app.group("/admin",
|
|
113
|
+
app.group("/admin", admin => {
|
|
114
114
|
admin.middlewares([authMiddleware]);
|
|
115
115
|
admin.get("/dashboard", () => Response.json({ ok: true }));
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
// Route-level middleware
|
|
119
|
-
app.get(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
app.get("/secure", () => Response.json({ secure: true }), [authMiddleware]);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Static Files
|
|
125
|
+
|
|
126
|
+
To serve static files, use the `static` method.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { join } from "node:path";
|
|
130
|
+
|
|
131
|
+
app.static(join(__dirname, "..", "static"));
|
|
124
132
|
```
|
|
125
133
|
|
|
126
134
|
---
|
|
@@ -134,15 +142,15 @@ import { ValidationSchema } from "skyguard-js/validation";
|
|
|
134
142
|
|
|
135
143
|
export const userSchema = ValidationSchema.create()
|
|
136
144
|
.field("name")
|
|
137
|
-
|
|
138
|
-
|
|
145
|
+
.required("Name is required")
|
|
146
|
+
.string({ maxLength: 60 })
|
|
139
147
|
.field("email")
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
.required()
|
|
149
|
+
.email()
|
|
142
150
|
.field("age")
|
|
143
|
-
|
|
151
|
+
.number({ min: 18, max: 99 })
|
|
144
152
|
.field("active")
|
|
145
|
-
|
|
153
|
+
.boolean()
|
|
146
154
|
.build();
|
|
147
155
|
|
|
148
156
|
app.post("/users", (request: Request) => {
|
|
@@ -157,10 +165,10 @@ app.post("/users", (request: Request) => {
|
|
|
157
165
|
|
|
158
166
|
Validation is:
|
|
159
167
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
- Fail-fast per field
|
|
169
|
+
- Fully typed
|
|
170
|
+
- Reusable
|
|
171
|
+
- Decoupled from transport layer
|
|
164
172
|
|
|
165
173
|
---
|
|
166
174
|
|
|
@@ -189,13 +197,13 @@ app.get("/home", () => {
|
|
|
189
197
|
|
|
190
198
|
### Supported features
|
|
191
199
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
200
|
+
- Variable interpolation (`{{ variable }}`)
|
|
201
|
+
- Conditionals (`{{#if}}`)
|
|
202
|
+
- Loops (`{{#each}}`)
|
|
203
|
+
- Layouts
|
|
204
|
+
- Partials
|
|
205
|
+
- Built-in helpers (`upper`, `lower`, `date`)
|
|
206
|
+
- Custom helpers
|
|
199
207
|
|
|
200
208
|
---
|
|
201
209
|
|
|
@@ -203,24 +211,23 @@ app.get("/home", () => {
|
|
|
203
211
|
|
|
204
212
|
⚠️ **Early-stage project**
|
|
205
213
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
214
|
+
- Not production-ready
|
|
215
|
+
- API may change
|
|
216
|
+
- Features are still evolving
|
|
217
|
+
- Intended primarily for learning and experimentation
|
|
210
218
|
|
|
211
219
|
---
|
|
212
220
|
|
|
213
221
|
## 🔮 Roadmap (Tentative)
|
|
214
222
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
* Plugin system
|
|
223
|
+
- Middleware system (✅)
|
|
224
|
+
- Template engine (✅)
|
|
225
|
+
- Request / Response abstraction (✅)
|
|
226
|
+
- Data validation (✅)
|
|
227
|
+
- Error handling improvements (✅)
|
|
228
|
+
- Sessions & cookies (in progress)
|
|
229
|
+
- Authentication & authorization
|
|
230
|
+
- Database & ORM integration
|
|
224
231
|
|
|
225
232
|
---
|
|
226
233
|
|
|
@@ -234,4 +241,4 @@ This project was created to deeply understand how frameworks like **Express**, *
|
|
|
234
241
|
|
|
235
242
|
MIT License
|
|
236
243
|
|
|
237
|
-
---
|
|
244
|
+
---
|
package/dist/app.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RouterGroup } from "./routing";
|
|
2
|
-
import { type HttpAdapter } from "./http";
|
|
3
2
|
import { type View } from "./views";
|
|
4
3
|
import type { Middleware, RouteHandler } from "./types";
|
|
5
4
|
/**
|
|
@@ -23,8 +22,6 @@ import type { Middleware, RouteHandler } from "./types";
|
|
|
23
22
|
export declare class App {
|
|
24
23
|
/** Main routing system */
|
|
25
24
|
private router;
|
|
26
|
-
/** Underlying HTTP server implementation */
|
|
27
|
-
private server;
|
|
28
25
|
/**
|
|
29
26
|
* View engine used to render templates.
|
|
30
27
|
*
|
|
@@ -57,7 +54,7 @@ export declare class App {
|
|
|
57
54
|
*
|
|
58
55
|
* @param adapter - HTTP adapter bridging the runtime with the framework
|
|
59
56
|
*/
|
|
60
|
-
handle
|
|
57
|
+
private handle;
|
|
61
58
|
/**
|
|
62
59
|
* Enables static file serving.
|
|
63
60
|
*
|
|
@@ -76,7 +73,7 @@ export declare class App {
|
|
|
76
73
|
*
|
|
77
74
|
* @param port - TCP port to listen on
|
|
78
75
|
*/
|
|
79
|
-
|
|
76
|
+
run(port: number, callback: VoidFunction, hostname?: string): void;
|
|
80
77
|
/**
|
|
81
78
|
* Sets a global prefix for all routes.
|
|
82
79
|
*
|
package/dist/app.js
CHANGED
|
@@ -4,11 +4,12 @@ exports.createApp = exports.App = void 0;
|
|
|
4
4
|
const routing_1 = require("./routing");
|
|
5
5
|
const http_1 = require("./http");
|
|
6
6
|
const exceptions_1 = require("./exceptions");
|
|
7
|
-
const nodeNativeServer_1 = require("./server/nodeNativeServer");
|
|
8
7
|
const views_1 = require("./views");
|
|
9
8
|
const node_path_1 = require("node:path");
|
|
10
9
|
const app_1 = require("./helpers/app");
|
|
11
10
|
const fileStaticHandler_1 = require("./static/fileStaticHandler");
|
|
11
|
+
const node_http_1 = require("node:http");
|
|
12
|
+
const httpExceptions_1 = require("./exceptions/httpExceptions");
|
|
12
13
|
/**
|
|
13
14
|
* The `App` class acts as the **execution kernel** and **lifecycle orchestrator**
|
|
14
15
|
* of the framework.
|
|
@@ -30,8 +31,6 @@ const fileStaticHandler_1 = require("./static/fileStaticHandler");
|
|
|
30
31
|
class App {
|
|
31
32
|
/** Main routing system */
|
|
32
33
|
router;
|
|
33
|
-
/** Underlying HTTP server implementation */
|
|
34
|
-
server;
|
|
35
34
|
/**
|
|
36
35
|
* View engine used to render templates.
|
|
37
36
|
*
|
|
@@ -52,7 +51,6 @@ class App {
|
|
|
52
51
|
static bootstrap() {
|
|
53
52
|
const app = (0, app_1.singleton)(App);
|
|
54
53
|
app.router = new routing_1.Router();
|
|
55
|
-
app.server = new nodeNativeServer_1.NodeServer(app);
|
|
56
54
|
app.view = new views_1.RaptorEngine((0, node_path_1.join)(__dirname, "..", "views"));
|
|
57
55
|
return app;
|
|
58
56
|
}
|
|
@@ -107,8 +105,13 @@ class App {
|
|
|
107
105
|
*
|
|
108
106
|
* @param port - TCP port to listen on
|
|
109
107
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
run(port, callback, hostname = "127.0.0.1") {
|
|
109
|
+
(0, node_http_1.createServer)((req, res) => {
|
|
110
|
+
const adapter = new http_1.NodeHttpAdapter(req, res);
|
|
111
|
+
void this.handle(adapter);
|
|
112
|
+
}).listen(port, hostname, () => {
|
|
113
|
+
callback();
|
|
114
|
+
});
|
|
112
115
|
}
|
|
113
116
|
/**
|
|
114
117
|
* Sets a global prefix for all routes.
|
|
@@ -168,16 +171,8 @@ class App {
|
|
|
168
171
|
* This method centralizes error handling and response mapping.
|
|
169
172
|
*/
|
|
170
173
|
handleError(error, adapter) {
|
|
171
|
-
if (error instanceof
|
|
172
|
-
adapter.sendResponse(http_1.Response.
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (error instanceof exceptions_1.ContentParserException) {
|
|
176
|
-
adapter.sendResponse(http_1.Response.json({ message: error.message }).setStatus(422));
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
if (error instanceof exceptions_1.SessionException) {
|
|
180
|
-
adapter.sendResponse(http_1.Response.json({ message: error.message }).setStatus(401));
|
|
174
|
+
if (error instanceof httpExceptions_1.HttpException) {
|
|
175
|
+
adapter.sendResponse(http_1.Response.json(error.toJSON()).setStatus(error.statusCode));
|
|
181
176
|
return;
|
|
182
177
|
}
|
|
183
178
|
if (error instanceof exceptions_1.ValidationException) {
|
|
@@ -187,7 +182,10 @@ class App {
|
|
|
187
182
|
}).setStatus(400));
|
|
188
183
|
return;
|
|
189
184
|
}
|
|
190
|
-
adapter.sendResponse(http_1.Response.
|
|
185
|
+
adapter.sendResponse(http_1.Response.json({
|
|
186
|
+
statusCode: 500,
|
|
187
|
+
message: "Internal Server Error",
|
|
188
|
+
}).setStatus(500));
|
|
191
189
|
console.error(error);
|
|
192
190
|
}
|
|
193
191
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface HttpExceptionOptions {
|
|
2
|
+
message?: string;
|
|
3
|
+
statusCode?: number;
|
|
4
|
+
code?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class HttpException extends Error {
|
|
7
|
+
readonly statusCode: number;
|
|
8
|
+
readonly code: string;
|
|
9
|
+
constructor(options: HttpExceptionOptions);
|
|
10
|
+
toJSON(): {
|
|
11
|
+
message: string;
|
|
12
|
+
statusCode: number;
|
|
13
|
+
code: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare class BadRequestError extends HttpException {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class UnauthorizedError extends HttpException {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class ForbiddenError extends HttpException {
|
|
23
|
+
constructor(message: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class NotFoundError extends HttpException {
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class RequestTimeoutError extends HttpException {
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class ConflictError extends HttpException {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
export declare class UnsopportedMediaTypeError extends HttpException {
|
|
35
|
+
constructor(message: string);
|
|
36
|
+
}
|
|
37
|
+
export declare class UnprocessableContentError extends HttpException {
|
|
38
|
+
constructor(message: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class TooManyRequestsError extends HttpException {
|
|
41
|
+
constructor(message: string);
|
|
42
|
+
}
|
|
43
|
+
export declare class InternalServerError extends HttpException {
|
|
44
|
+
constructor(message: string);
|
|
45
|
+
}
|
|
46
|
+
export declare class NotImplementedError extends HttpException {
|
|
47
|
+
constructor(message: string);
|
|
48
|
+
}
|
|
49
|
+
export declare class BadGatewayError extends HttpException {
|
|
50
|
+
constructor(message: string);
|
|
51
|
+
}
|
|
52
|
+
export declare class ServiceUnavailableError extends HttpException {
|
|
53
|
+
constructor(message: string);
|
|
54
|
+
}
|
|
55
|
+
export declare class GatewayTimeoutError extends HttpException {
|
|
56
|
+
constructor(message: string);
|
|
57
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GatewayTimeoutError = exports.ServiceUnavailableError = exports.BadGatewayError = exports.NotImplementedError = exports.InternalServerError = exports.TooManyRequestsError = exports.UnprocessableContentError = exports.UnsopportedMediaTypeError = exports.ConflictError = exports.RequestTimeoutError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.BadRequestError = exports.HttpException = void 0;
|
|
4
|
+
class HttpException extends Error {
|
|
5
|
+
statusCode;
|
|
6
|
+
code;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options.message ?? "Internal Server Error");
|
|
9
|
+
this.name = this.constructor.name;
|
|
10
|
+
this.statusCode = options.statusCode ?? 500;
|
|
11
|
+
this.code = options.code ?? "INTERNAL_SERVER_ERROR";
|
|
12
|
+
Error.captureStackTrace(this, this.constructor);
|
|
13
|
+
}
|
|
14
|
+
toJSON() {
|
|
15
|
+
return {
|
|
16
|
+
message: this.message,
|
|
17
|
+
statusCode: this.statusCode,
|
|
18
|
+
code: this.code,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.HttpException = HttpException;
|
|
23
|
+
// Errores 4xx - Client
|
|
24
|
+
class BadRequestError extends HttpException {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super({ message, statusCode: 400, code: "BAD_REQUEST" });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.BadRequestError = BadRequestError;
|
|
30
|
+
class UnauthorizedError extends HttpException {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super({ message, statusCode: 401, code: "UNAUTHORIZED" });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.UnauthorizedError = UnauthorizedError;
|
|
36
|
+
class ForbiddenError extends HttpException {
|
|
37
|
+
constructor(message) {
|
|
38
|
+
super({ message, statusCode: 403, code: "FORBIDDEN" });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ForbiddenError = ForbiddenError;
|
|
42
|
+
class NotFoundError extends HttpException {
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super({ message, statusCode: 404, code: "NOT_FOUND" });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.NotFoundError = NotFoundError;
|
|
48
|
+
class RequestTimeoutError extends HttpException {
|
|
49
|
+
constructor(message) {
|
|
50
|
+
super({ message, statusCode: 408, code: "REQUEST_TIMEOUT" });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.RequestTimeoutError = RequestTimeoutError;
|
|
54
|
+
class ConflictError extends HttpException {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super({ message, statusCode: 409, code: "CONFLICT" });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.ConflictError = ConflictError;
|
|
60
|
+
class UnsopportedMediaTypeError extends HttpException {
|
|
61
|
+
constructor(message) {
|
|
62
|
+
super({ message, statusCode: 415, code: "UNSOPPORTED_MEDIA_TYPE" });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.UnsopportedMediaTypeError = UnsopportedMediaTypeError;
|
|
66
|
+
class UnprocessableContentError extends HttpException {
|
|
67
|
+
constructor(message) {
|
|
68
|
+
super({ message, statusCode: 422, code: "UNPROCESSABLE_CONTENT" });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.UnprocessableContentError = UnprocessableContentError;
|
|
72
|
+
class TooManyRequestsError extends HttpException {
|
|
73
|
+
constructor(message) {
|
|
74
|
+
super({ message, statusCode: 429, code: "TOO_MANY_REQUESTS" });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.TooManyRequestsError = TooManyRequestsError;
|
|
78
|
+
// Errores 5xx - Servidor
|
|
79
|
+
class InternalServerError extends HttpException {
|
|
80
|
+
constructor(message) {
|
|
81
|
+
super({ message, statusCode: 500, code: "INTERNAL_SERVER_ERROR" });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.InternalServerError = InternalServerError;
|
|
85
|
+
class NotImplementedError extends HttpException {
|
|
86
|
+
constructor(message) {
|
|
87
|
+
super({ message, statusCode: 501, code: "NOT_IMPLEMENTED" });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.NotImplementedError = NotImplementedError;
|
|
91
|
+
class BadGatewayError extends HttpException {
|
|
92
|
+
constructor(message) {
|
|
93
|
+
super({ message, statusCode: 502, code: "BAD_GATEWAY" });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.BadGatewayError = BadGatewayError;
|
|
97
|
+
class ServiceUnavailableError extends HttpException {
|
|
98
|
+
constructor(message) {
|
|
99
|
+
super({ message, statusCode: 503, code: "SERVICE_UNAVAILABLE" });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
103
|
+
class GatewayTimeoutError extends HttpException {
|
|
104
|
+
constructor(message) {
|
|
105
|
+
super({ message, statusCode: 504, code: "GATEWAY_TIMEOUT" });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.GatewayTimeoutError = GatewayTimeoutError;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
export { ContentParserException, ReadBodyException, } from "./contentParserException";
|
|
2
1
|
export { FileNotExistsException } from "./fileExistsException";
|
|
3
|
-
export { HttpNotFoundException } from "./httpNotFoundException";
|
|
4
2
|
export { HelperExecutionException, HelperNotFoundException, HelperArgumentException, } from "./helperExceptions";
|
|
5
3
|
export { ValidationException, ValidatorFieldException, } from "./validationException";
|
|
6
4
|
export { ContentDispositionException } from "./contentDispositionException";
|
|
7
|
-
export { FileDownloadException } from "./fileDownloadException";
|
|
8
|
-
export { SessionException } from "./sessionException";
|
|
9
5
|
export { InvalidHttpStatusException } from "./invalidHttpStatusException";
|
package/dist/exceptions/index.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InvalidHttpStatusException = exports.
|
|
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; } });
|
|
3
|
+
exports.InvalidHttpStatusException = exports.ContentDispositionException = exports.ValidatorFieldException = exports.ValidationException = exports.HelperArgumentException = exports.HelperNotFoundException = exports.HelperExecutionException = exports.FileNotExistsException = void 0;
|
|
7
4
|
var fileExistsException_1 = require("./fileExistsException");
|
|
8
5
|
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
6
|
var helperExceptions_1 = require("./helperExceptions");
|
|
12
7
|
Object.defineProperty(exports, "HelperExecutionException", { enumerable: true, get: function () { return helperExceptions_1.HelperExecutionException; } });
|
|
13
8
|
Object.defineProperty(exports, "HelperNotFoundException", { enumerable: true, get: function () { return helperExceptions_1.HelperNotFoundException; } });
|
|
@@ -17,9 +12,5 @@ Object.defineProperty(exports, "ValidationException", { enumerable: true, get: f
|
|
|
17
12
|
Object.defineProperty(exports, "ValidatorFieldException", { enumerable: true, get: function () { return validationException_1.ValidatorFieldException; } });
|
|
18
13
|
var contentDispositionException_1 = require("./contentDispositionException");
|
|
19
14
|
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
15
|
var invalidHttpStatusException_1 = require("./invalidHttpStatusException");
|
|
25
16
|
Object.defineProperty(exports, "InvalidHttpStatusException", { enumerable: true, get: function () { return invalidHttpStatusException_1.InvalidHttpStatusException; } });
|
|
@@ -42,8 +42,12 @@ class NodeHttpAdapter {
|
|
|
42
42
|
.setMethod(this.req.method || httpMethods_1.HttpMethods.get)
|
|
43
43
|
.setQueryParams(Object.fromEntries(url.searchParams.entries()))
|
|
44
44
|
.setHeaders(this.req.headers);
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (request.getMethod === httpMethods_1.HttpMethods.post ||
|
|
46
|
+
request.getMethod === httpMethods_1.HttpMethods.put ||
|
|
47
|
+
request.getMethod === httpMethods_1.HttpMethods.patch) {
|
|
48
|
+
const parsedData = await this.contentParser.parse(this.req);
|
|
49
|
+
request.setData(parsedData);
|
|
50
|
+
}
|
|
47
51
|
return request;
|
|
48
52
|
}
|
|
49
53
|
/**
|
package/dist/http/request.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { HttpMethods } from "./httpMethods";
|
|
2
2
|
import type { Headers, HttpValue } from "../types";
|
|
3
|
-
import { Layer } from "../routing/layer";
|
|
4
3
|
import { FieldDefinition } from "../validators";
|
|
5
4
|
import { Session } from "../sessions";
|
|
6
5
|
/**
|
|
@@ -18,8 +17,6 @@ import { Session } from "../sessions";
|
|
|
18
17
|
export declare class Request {
|
|
19
18
|
/** Normalized request path (e.g. "/api/users/42") */
|
|
20
19
|
private url;
|
|
21
|
-
/** Routing layer that resolved this request */
|
|
22
|
-
private layer;
|
|
23
20
|
/** Incoming HTTP headers */
|
|
24
21
|
private headers;
|
|
25
22
|
/** Normalized HTTP method */
|
|
@@ -28,14 +25,14 @@ export declare class Request {
|
|
|
28
25
|
private data;
|
|
29
26
|
/** Query string parameters */
|
|
30
27
|
private query;
|
|
28
|
+
/** Dynamic route parameters (path params) */
|
|
29
|
+
private params;
|
|
31
30
|
/** Session associated with the request */
|
|
32
31
|
private session;
|
|
33
32
|
constructor(url: string);
|
|
34
33
|
get getUrl(): string;
|
|
35
34
|
get getMethod(): HttpMethods;
|
|
36
35
|
setMethod(method: HttpMethods): this;
|
|
37
|
-
get getLayer(): Layer;
|
|
38
|
-
setLayer(layer: Layer): this;
|
|
39
36
|
get getHeaders(): Headers;
|
|
40
37
|
setHeaders(headers: Headers): this;
|
|
41
38
|
/**
|
|
@@ -70,6 +67,7 @@ export declare class Request {
|
|
|
70
67
|
* request.getParams("id"); // "42"
|
|
71
68
|
*/
|
|
72
69
|
getParams(key?: string): HttpValue;
|
|
70
|
+
setParams(params: Record<string, string>): this;
|
|
73
71
|
getData(): Record<string, unknown>;
|
|
74
72
|
setData(data: Record<string, any>): this;
|
|
75
73
|
get getSession(): Session;
|
package/dist/http/request.js
CHANGED
|
@@ -17,8 +17,6 @@ const validators_1 = require("../validators");
|
|
|
17
17
|
class Request {
|
|
18
18
|
/** Normalized request path (e.g. "/api/users/42") */
|
|
19
19
|
url;
|
|
20
|
-
/** Routing layer that resolved this request */
|
|
21
|
-
layer;
|
|
22
20
|
/** Incoming HTTP headers */
|
|
23
21
|
headers;
|
|
24
22
|
/** Normalized HTTP method */
|
|
@@ -27,6 +25,8 @@ class Request {
|
|
|
27
25
|
data = {};
|
|
28
26
|
/** Query string parameters */
|
|
29
27
|
query = {};
|
|
28
|
+
/** Dynamic route parameters (path params) */
|
|
29
|
+
params = {};
|
|
30
30
|
/** Session associated with the request */
|
|
31
31
|
session;
|
|
32
32
|
constructor(url) {
|
|
@@ -42,13 +42,6 @@ class Request {
|
|
|
42
42
|
this.method = method;
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
45
|
-
get getLayer() {
|
|
46
|
-
return this.layer;
|
|
47
|
-
}
|
|
48
|
-
setLayer(layer) {
|
|
49
|
-
this.layer = layer;
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
45
|
get getHeaders() {
|
|
53
46
|
return this.headers;
|
|
54
47
|
}
|
|
@@ -95,10 +88,13 @@ class Request {
|
|
|
95
88
|
* request.getParams("id"); // "42"
|
|
96
89
|
*/
|
|
97
90
|
getParams(key = null) {
|
|
98
|
-
const parameters = this.layer.parseParameters(this.url);
|
|
99
91
|
if (key === null)
|
|
100
|
-
return
|
|
101
|
-
return
|
|
92
|
+
return this.params;
|
|
93
|
+
return this.params[key] ?? null;
|
|
94
|
+
}
|
|
95
|
+
setParams(params) {
|
|
96
|
+
this.params = params;
|
|
97
|
+
return this;
|
|
102
98
|
}
|
|
103
99
|
getData() {
|
|
104
100
|
return this.data;
|
package/dist/http/response.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Response = void 0;
|
|
4
|
-
const container_1 = require("../container/container");
|
|
5
|
-
const app_1 = require("../app");
|
|
6
4
|
const statusCodes_1 = require("./statusCodes");
|
|
7
5
|
const exceptions_1 = require("../exceptions");
|
|
6
|
+
const app_1 = require("../helpers/app");
|
|
8
7
|
/**
|
|
9
8
|
* Represents an outgoing response sent to the client.
|
|
10
9
|
*
|
|
@@ -172,7 +171,7 @@ class Response {
|
|
|
172
171
|
* return Response.render("auth/login", {}, "auth");
|
|
173
172
|
*/
|
|
174
173
|
static async render(view, params, layout = null) {
|
|
175
|
-
const content = await
|
|
174
|
+
const content = await (0, app_1.app)().view.render(view, params, layout);
|
|
176
175
|
return new this().setContentType("text/html").setContent(content);
|
|
177
176
|
}
|
|
178
177
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sessions = exports.cors = void 0;
|
|
4
|
+
var cors_1 = require("./cors");
|
|
5
|
+
Object.defineProperty(exports, "cors", { enumerable: true, get: function () { return cors_1.cors; } });
|
|
6
|
+
var session_1 = require("./session");
|
|
7
|
+
Object.defineProperty(exports, "sessions", { enumerable: true, get: function () { return session_1.sessions; } });
|