princejs 1.7.2 → 1.7.5
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 +41 -10
- package/dist/create.js +1 -1
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 👑 **PrinceJS**
|
|
2
2
|
|
|
3
|
-
### ⚡ Ultra-clean, modern & minimal Bun web framework
|
|
3
|
+
### ⚡ Ultra-clean, modern & minimal Bun web framework. Among the top three in performance.
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|

|
|
@@ -86,14 +86,28 @@ import { cron, openapi } from "princejs/scheduler";
|
|
|
86
86
|
|
|
87
87
|
---
|
|
88
88
|
|
|
89
|
+
## Performance With Oha (oha -c 100 -z 30s)
|
|
90
|
+
|
|
91
|
+
| Framework | Req/s | Total |
|
|
92
|
+
|-----------|----------------|--------|
|
|
93
|
+
| Elysia | 25,312 req/s | 759k |
|
|
94
|
+
| Hono | 22,124 req/s | 664k |
|
|
95
|
+
| PrinceJS | 21,748 req/s | 653k |
|
|
96
|
+
| Express | 9,325 req/s | 280k |
|
|
97
|
+
|
|
98
|
+
### Among the top three
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
89
102
|
## 🎯 Full Example
|
|
90
103
|
|
|
91
104
|
```ts
|
|
92
105
|
import { prince } from "princejs";
|
|
93
106
|
import { cors, logger, rateLimit } from "princejs/middleware";
|
|
94
107
|
import { validate } from "princejs/validation";
|
|
95
|
-
import { cache,
|
|
108
|
+
import { cache, upload } from "princejs/helpers";
|
|
96
109
|
import { cron } from "princejs/scheduler";
|
|
110
|
+
import { Html, Head, Body, H1, P, render } from "princejs/jsx"
|
|
97
111
|
import { z } from "zod";
|
|
98
112
|
|
|
99
113
|
const app = prince(true);
|
|
@@ -104,23 +118,40 @@ app.use(rateLimit({ max: 100, window: 60 }));
|
|
|
104
118
|
|
|
105
119
|
app.use(validate(z.object({ name: z.string() })));
|
|
106
120
|
|
|
121
|
+
const Page = () => (
|
|
122
|
+
Html({
|
|
123
|
+
children: [
|
|
124
|
+
Head({
|
|
125
|
+
children: [
|
|
126
|
+
"Test Page"
|
|
127
|
+
]
|
|
128
|
+
}),
|
|
129
|
+
Body({
|
|
130
|
+
children: [
|
|
131
|
+
H1({
|
|
132
|
+
children: "Hello World"
|
|
133
|
+
}),
|
|
134
|
+
P({
|
|
135
|
+
children: "This is a test"
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
})
|
|
139
|
+
]
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
|
|
107
143
|
app.get("/", () => ({ message: "Welcome to PrinceJS" }));
|
|
108
144
|
|
|
109
145
|
app.get("/users/:id", (req) => ({ id: req.params.id }));
|
|
110
146
|
|
|
111
|
-
app.get("/
|
|
147
|
+
app.get("/jsx", () => render(Page()));
|
|
112
148
|
|
|
113
|
-
app.
|
|
149
|
+
app.get("/data", cache(60)(() => ({ time: Date.now() })));
|
|
114
150
|
|
|
115
151
|
app.post("/upload", upload(), (req) => ({ files: Object.keys(req.files || {}) }));
|
|
116
152
|
|
|
117
153
|
cron("*/1 * * * *", () => console.log("PrinceJS heartbeat"));
|
|
118
154
|
|
|
119
|
-
app.ws("/chat", {
|
|
120
|
-
open: (ws) => ws.send("Welcome!"),
|
|
121
|
-
message: (ws, msg) => ws.send(`Echo: ${msg}`)
|
|
122
|
-
});
|
|
123
|
-
|
|
124
155
|
app.listen(3000);
|
|
125
156
|
```
|
|
126
157
|
|
package/dist/create.js
CHANGED
|
@@ -7,7 +7,7 @@ import { join } from "path";
|
|
|
7
7
|
var name = Bun.argv[2];
|
|
8
8
|
if (!name) {
|
|
9
9
|
console.error("\u274C Error: Please provide a project name");
|
|
10
|
-
console.log("Usage:
|
|
10
|
+
console.log("Usage: bun create-princejs <project-name>");
|
|
11
11
|
process.exit(1);
|
|
12
12
|
}
|
|
13
13
|
if (existsSync(name)) {
|