barejs 0.1.5 → 0.1.6
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 +27 -8
- package/src/bare.ts +28 -3
- package/src/index.ts +26 -0
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "barejs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"author": "xarhang",
|
|
5
5
|
"description": "High-performance JIT-specialized web framework for Bun",
|
|
6
|
-
"main": "src/bare.ts",
|
|
7
|
-
"types": "src/bare.ts",
|
|
6
|
+
"main": "./src/bare.ts",
|
|
7
|
+
"types": "./src/bare.ts",
|
|
8
8
|
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/bare.ts",
|
|
11
|
+
"./middleware": "./src/middleware/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"sideEffects": false,
|
|
9
14
|
"repository": {
|
|
10
15
|
"type": "git",
|
|
11
16
|
"url": "git+https://github.com/xarhang/barejs.git"
|
|
@@ -13,7 +18,9 @@
|
|
|
13
18
|
"scripts": {
|
|
14
19
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
15
20
|
"bench": "bun run benchmarks/index.ts",
|
|
16
|
-
"dev": "bun --watch src/bare.ts"
|
|
21
|
+
"dev": "bun --watch src/bare.ts",
|
|
22
|
+
"build": "bun ./scripts/build.ts",
|
|
23
|
+
"release": "bun run build && npm version patch && npm publish --access public"
|
|
17
24
|
},
|
|
18
25
|
"keywords": [
|
|
19
26
|
"bun",
|
|
@@ -24,19 +31,31 @@
|
|
|
24
31
|
"zod"
|
|
25
32
|
],
|
|
26
33
|
"license": "MIT",
|
|
27
|
-
"
|
|
34
|
+
"peerDependencies": {
|
|
28
35
|
"@sinclair/typebox": "^0.34.46",
|
|
29
|
-
"zod": "^
|
|
36
|
+
"zod": "^3.0.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"@sinclair/typebox": {
|
|
40
|
+
"optional": true
|
|
41
|
+
},
|
|
42
|
+
"zod": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
30
45
|
},
|
|
31
46
|
"devDependencies": {
|
|
47
|
+
"@sinclair/typebox": "^0.34.46",
|
|
48
|
+
"zod": "^3.23.8",
|
|
32
49
|
"@types/bun": "latest",
|
|
33
50
|
"elysia": "^1.4.21",
|
|
34
51
|
"hono": "^4.11.3",
|
|
35
|
-
"mitata": "^1.0.34"
|
|
52
|
+
"mitata": "^1.0.34",
|
|
53
|
+
"typescript": "latest"
|
|
36
54
|
},
|
|
37
55
|
"files": [
|
|
38
56
|
"src",
|
|
57
|
+
"dist",
|
|
39
58
|
"README.md",
|
|
40
59
|
"LICENSE"
|
|
41
60
|
]
|
|
42
|
-
}
|
|
61
|
+
}
|
package/src/bare.ts
CHANGED
|
@@ -55,8 +55,8 @@ export class BareJS {
|
|
|
55
55
|
const handler = middlewares[idx++];
|
|
56
56
|
if (!handler) return;
|
|
57
57
|
// Support both async and sync handlers
|
|
58
|
-
return await (handler.length > 1
|
|
59
|
-
? (handler as Middleware)(ctx, next)
|
|
58
|
+
return await (handler.length > 1
|
|
59
|
+
? (handler as Middleware)(ctx, next)
|
|
60
60
|
: (handler as Handler)(ctx));
|
|
61
61
|
};
|
|
62
62
|
return await next();
|
|
@@ -93,7 +93,32 @@ export class BareJS {
|
|
|
93
93
|
|
|
94
94
|
public listen(ip: string = '0.0.0.0', port: number = 3000) {
|
|
95
95
|
this.compile();
|
|
96
|
-
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
const reset = "\x1b[0m";
|
|
101
|
+
const cyan = "\x1b[36m";
|
|
102
|
+
const yellow = "\x1b[33m";
|
|
103
|
+
const gray = "\x1b[90m";
|
|
104
|
+
const bold = "\x1b[1m";
|
|
105
|
+
if (process.env.NODE_ENV !== 'production' && process.env.BARE_SILENT !== 'true') {
|
|
106
|
+
console.log(`
|
|
107
|
+
${cyan}${bold} ____ _ ____
|
|
108
|
+
| __ ) __ _ _ __ ___ | / ___|
|
|
109
|
+
| _ \\ / _\` | '__/ _ \\ _ | \\___ \\
|
|
110
|
+
| |_) | (_| | | | __/| |_| |___) |
|
|
111
|
+
|____/ \\__,_|_| \\___| \\___/|____/
|
|
112
|
+
${reset}
|
|
113
|
+
${yellow}BareJS${reset} ${gray}${reset}
|
|
114
|
+
${gray}-----------------------------------${reset}
|
|
115
|
+
🚀 Running at: ${cyan}http://${ip}:${port}${reset}
|
|
116
|
+
${gray}Ready to build everything awesome!${reset}
|
|
117
|
+
`);
|
|
118
|
+
} else {
|
|
119
|
+
|
|
120
|
+
console.log(`🚀 BareJS running at http://${ip}:${port}`);
|
|
121
|
+
}
|
|
97
122
|
return Bun.serve({
|
|
98
123
|
hostname: ip,
|
|
99
124
|
port,
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BareJS, type Context } from './bare';
|
|
2
|
+
import { typebox, native } from './middleware/validators';
|
|
3
|
+
import * as TB from '@sinclair/typebox';
|
|
4
|
+
|
|
5
|
+
const app = new BareJS();
|
|
6
|
+
|
|
7
|
+
// Create Schema with TypeBox
|
|
8
|
+
const UserSchema = TB.Type.Object({
|
|
9
|
+
name: TB.Type.String(),
|
|
10
|
+
age: TB.Type.Number()
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// ✅ Route 1: Using TypeBox Validator (Fastest for Bun)
|
|
14
|
+
app.post('/users-tb', typebox(UserSchema), (ctx: Context) => {
|
|
15
|
+
return ctx.json({ message: "Saved via TypeBox", user: ctx.body });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// ✅ Route 2: Using Native Validator (Safe alternative if TypeBox has issues)
|
|
19
|
+
app.post('/users-native', native(UserSchema), (ctx: Context) => {
|
|
20
|
+
return ctx.json({ message: "Saved via Native", user: ctx.body });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// ✅ Route 3: No Validator (Pure speed, 0 ns overhead)
|
|
24
|
+
app.get('/ping', (ctx: Context) => ctx.json({ message: "pong" }));
|
|
25
|
+
|
|
26
|
+
app.listen('0.0.0.0', 3000);
|