barejs 0.1.8 → 0.1.9
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/package.json +2 -2
- package/src/bare.ts +3 -0
- package/src/index.ts +4 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "barejs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"author": "xarhang",
|
|
5
5
|
"description": "High-performance JIT-specialized web framework for Bun",
|
|
6
6
|
"main": "./src/bare.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./src/bare.ts",
|
|
11
|
-
"./middleware": "./src/
|
|
11
|
+
"./middleware": "./src/validators.ts"
|
|
12
12
|
},
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"repository": {
|
package/src/bare.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,39 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const app = new BareJS();
|
|
7
|
-
|
|
8
|
-
// Create Schema with TypeBox
|
|
9
|
-
const UserSchema = TB.Type.Object({
|
|
10
|
-
name: TB.Type.String(),
|
|
11
|
-
age: TB.Type.Number()
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// ✅ Route 1: Using TypeBox Validator (Fastest for Bun)
|
|
15
|
-
app.post('/users-tb', typebox(UserSchema), (ctx: Context) => {
|
|
16
|
-
return ctx.json({ message: "Saved via TypeBox", user: ctx.body });
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// ✅ Route 2: Using Native Validator (Safe alternative if TypeBox has issues)
|
|
21
|
-
app.post('/users-native', native(UserSchema), (ctx: Context) => {
|
|
22
|
-
return ctx.json({ message: "Saved via Native", user: ctx.body });
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// ✅ Route 3: No Validator (Pure speed, 0 ns overhead)
|
|
26
|
-
app.get('/ping', (ctx: Context) => ctx.json({ message: "pong" }));
|
|
27
|
-
// Dynamic Path
|
|
28
|
-
app.get('/user/:id', (ctx: Context) => {
|
|
29
|
-
const userId = ctx.params.id;
|
|
30
|
-
return ctx.json({ user: userId, status: 'active' });
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Multiple Params
|
|
34
|
-
app.get('/post/:category/:id', (ctx: Context) => {
|
|
35
|
-
return ctx.json(ctx.params); // { category: 'tech', id: '1' }
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
app.listen('0.0.0.0', 3000);
|
|
1
|
+
export { BareJS } from './bare';
|
|
2
|
+
export { BareContext } from './context';
|
|
3
|
+
export type { Context, Middleware, Handler, Next } from './context';
|
|
4
|
+
export { typebox, native, zod } from './validators';
|