@wxn0brp/falcon-frame 0.8.2 → 0.8.3
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/LICENSE +1 -1
- package/README.md +16 -17
- package/dist/req.js +7 -0
- package/dist/sse.d.ts +4 -1
- package/dist/sse.js +8 -8
- package/dist/types.d.ts +1 -0
- package/package.json +4 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
# FalconFrame
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A minimal, modular TypeScript web library.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Zero-dependency routing engine
|
|
8
|
+
- Middleware chaining
|
|
9
|
+
- Static file serving
|
|
10
|
+
- Request validation via inline schemas
|
|
11
|
+
- OpenAPI document generation
|
|
12
|
+
- Cookie management
|
|
13
|
+
- Debuggable logger
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
- 🧱 Middleware chaining
|
|
11
|
-
- 📁 Static file serving
|
|
12
|
-
- 📦 Request validation via inline schemas
|
|
13
|
-
- 🍪 Cookie management
|
|
14
|
-
- 🔍 Debuggable logger
|
|
15
|
-
|
|
16
|
-
## 📦 Installation
|
|
15
|
+
## Installation
|
|
17
16
|
|
|
18
17
|
```bash
|
|
19
|
-
|
|
18
|
+
bun add @wxn0brp/falcon-frame
|
|
20
19
|
```
|
|
21
20
|
|
|
22
|
-
##
|
|
21
|
+
## Usage Example
|
|
23
22
|
|
|
24
23
|
```ts
|
|
25
24
|
import FalconFrame, { validateBody } from "@wxn0brp/falcon-frame";
|
|
@@ -83,13 +82,13 @@ app.post(
|
|
|
83
82
|
// Protected route
|
|
84
83
|
app.get("/dashboard", requireAuth, (req, res) => {
|
|
85
84
|
return {
|
|
86
|
-
message:
|
|
85
|
+
message: `Welcome to the dashboard, ${req.cookies.session}`,
|
|
87
86
|
});
|
|
88
87
|
});
|
|
89
88
|
|
|
90
89
|
app.post("/logout", (req, res) => {
|
|
91
90
|
res.cookie("session", "", { maxAge: 0 });
|
|
92
|
-
res.json({ message: "
|
|
91
|
+
res.json({ message: "Logged out" });
|
|
93
92
|
});
|
|
94
93
|
|
|
95
94
|
// if no route matches
|
|
@@ -101,6 +100,6 @@ app.set404((req, res) => {
|
|
|
101
100
|
app.l(3000);
|
|
102
101
|
```
|
|
103
102
|
|
|
104
|
-
##
|
|
103
|
+
## License
|
|
105
104
|
|
|
106
|
-
Published under the MIT license
|
|
105
|
+
Published under the MIT license.
|
package/dist/req.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from "crypto";
|
|
1
2
|
import { URL } from "url";
|
|
2
3
|
import { parseCookies } from "./helpers.js";
|
|
3
4
|
import { getMiddlewares, matchMiddleware } from "./middleware.js";
|
|
@@ -34,6 +35,12 @@ export function handleRequest(req, res, FF, reRoute = false) {
|
|
|
34
35
|
fn(req);
|
|
35
36
|
handleRequest(req, res, FF, true);
|
|
36
37
|
};
|
|
38
|
+
if (FF.opts.xRequestId !== "disable") {
|
|
39
|
+
if (req.headers["x-request-id"])
|
|
40
|
+
res.setHeader("x-request-id", req.headers["x-request-id"]);
|
|
41
|
+
else if (FF.opts.xRequestId === "auto")
|
|
42
|
+
res.setHeader("x-request-id", randomUUID());
|
|
43
|
+
}
|
|
37
44
|
logger.info(`Incoming request: ${req.method} ${req.url}`);
|
|
38
45
|
const middlewaresPath = req.path + "/";
|
|
39
46
|
const middlewares = getMiddlewares(FF.middlewares, middlewaresPath.replace(/\/+/g, "/"));
|
package/dist/sse.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { FFResponse } from "./res.js";
|
|
2
2
|
import type { FFRequest, RouteHandler } from "./types.js";
|
|
3
3
|
export declare class SSEManager {
|
|
4
|
-
|
|
4
|
+
_clients: Map<string, {
|
|
5
|
+
req: FFRequest;
|
|
6
|
+
res: FFResponse;
|
|
7
|
+
}>;
|
|
5
8
|
getMiddleware(lastHandler?: RouteHandler): RouteHandler;
|
|
6
9
|
getClients(): Map<string, {
|
|
7
10
|
req: FFRequest;
|
package/dist/sse.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
export class SSEManager {
|
|
3
|
-
|
|
3
|
+
_clients = new Map();
|
|
4
4
|
getMiddleware(lastHandler) {
|
|
5
5
|
return (req, res, next) => {
|
|
6
6
|
res.sseInit();
|
|
7
7
|
const id = randomUUID();
|
|
8
|
-
this.
|
|
8
|
+
this._clients.set(id, { req, res });
|
|
9
9
|
req.on("close", () => {
|
|
10
|
-
this.
|
|
10
|
+
this._clients.delete(id);
|
|
11
11
|
});
|
|
12
12
|
req.sseId = id;
|
|
13
13
|
lastHandler?.(req, res, next);
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
getClients() {
|
|
17
|
-
return this.
|
|
17
|
+
return this._clients;
|
|
18
18
|
}
|
|
19
19
|
sendAll(data) {
|
|
20
|
-
for (const { res } of this.
|
|
20
|
+
for (const { res } of this._clients.values()) {
|
|
21
21
|
res.sseSend(data);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
sendTo(id, data) {
|
|
25
|
-
const client = this.
|
|
25
|
+
const client = this._clients.get(id);
|
|
26
26
|
if (client) {
|
|
27
27
|
client.res.sseSend(data);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
disconnect(id) {
|
|
31
|
-
const client = this.
|
|
31
|
+
const client = this._clients.get(id);
|
|
32
32
|
if (client) {
|
|
33
33
|
client.res.end();
|
|
34
|
-
this.
|
|
34
|
+
this._clients.delete(id);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/falcon-frame",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "wxn0brP",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"type": "module",
|
|
9
|
-
"description": "Lightweight modular TypeScript web
|
|
9
|
+
"description": "Lightweight modular TypeScript web library",
|
|
10
10
|
"homepage": "https://github.com/wxn0brP/FalconFrame",
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"keywords": [
|
|
16
16
|
"http",
|
|
17
17
|
"web",
|
|
18
|
-
"framework",
|
|
19
18
|
"typescript",
|
|
20
19
|
"modular",
|
|
21
20
|
"lightweight",
|
|
@@ -26,10 +25,10 @@
|
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"@types/node": "*",
|
|
28
27
|
"tsc-alias": "*",
|
|
29
|
-
"typescript": "^
|
|
28
|
+
"typescript": "^7"
|
|
30
29
|
},
|
|
31
30
|
"dependencies": {
|
|
32
|
-
"@wxn0brp/lucerna-log": "^0.2.
|
|
31
|
+
"@wxn0brp/lucerna-log": "^0.2.4"
|
|
33
32
|
},
|
|
34
33
|
"files": [
|
|
35
34
|
"dist"
|