barejs 0.1.3 → 0.1.4

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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +78 -16
  3. package/package.json +3 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xarhang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  # 🚀 BareJS
2
-
3
2
  BareJS is an ultra-high-performance web engine built on the Bun runtime, designed for minimalism and the lowest possible latency.
4
3
 
5
4
  ![Benchmark Status](https://github.com/xarhang/bareJS/actions/workflows/bench.yml/badge.svg)
@@ -18,7 +17,7 @@ Performance comparison between **BareJS**, **Elysia**, and **Hono**.
18
17
  <!-- MARKER: PERFORMANCE_TABLE_START -->
19
18
  | Framework | Latency (Avg) | Speed Ratio |
20
19
  | :--- | :--- | :--- |
21
- | **BareJS (Your Engine)** | **-- ns/iter** | **Baseline (1.0x)** |
20
+ | **BareJS** | **-- ns/iter** | **Baseline (1.0x)** |
22
21
  | Elysia | -- ns/iter | --x slower |
23
22
  | Hono | -- ns/iter | --x slower |
24
23
  <!-- MARKER: PERFORMANCE_TABLE_END -->
@@ -27,39 +26,102 @@ Performance comparison between **BareJS**, **Elysia**, and **Hono**.
27
26
 
28
27
  ---
29
28
 
30
- ## ✨ Features
29
+ **Features**
30
+
31
+ * **Ultra Low Latency:** Optimized to minimize processing overhead.
32
+ * **Zero Dependency:** Built natively for security and raw speed.
33
+ * **Optimized for Bun:** Leverages native Bun APIs for maximum performance.
34
+ * **Memory Efficient:** Minimal heap usage and clean garbage collection.
35
+
36
+ ---
37
+
38
+ ## 📖 Documentation
39
+
40
+ ### ⚡ The Core Engine
41
+
42
+ BareJS uses a **Static Route Compiler**. When you call `app.listen()`, BareJS transforms your routes into an optimized lookup table. This ensures routing complexity, meaning your app stays fast whether you have 10 routes or 10,000.
43
+
44
+ ### 🏗️ Request Context
45
+
46
+ Every handler receives a `Context` object:
47
+
48
+ * `ctx.req`: The native Bun `Request`.
49
+ * `ctx.params`: Route parameters (e.g., `/user/:id`).
50
+ * `ctx.json(data)`: High-speed JSON response helper.
51
+ * `ctx.body`: The validated JSON payload (available when using validators).
52
+
53
+ ---
54
+
55
+ ## 🛠 Usage Examples
56
+
57
+ ### 1. Basic Server
58
+
59
+ ```typescript
60
+ import { BareJS } from 'barejs';
61
+
62
+ const app = new BareJS();
63
+
64
+ app.get('/ping', (ctx) => ctx.json({ message: 'pong' }));
65
+
66
+ app.listen('0.0.0.0', 3000);
31
67
 
32
- - **Ultra Low Latency:** Optimized to minimize processing overhead.
33
- - **Zero Dependency:** Built natively for security and raw speed.
34
- - **Optimized for Bun:** Leverages native Bun APIs for maximum performance.
35
- - **Memory Efficient:** Minimal heap usage and clean garbage collection.
68
+ ```
69
+
70
+ ### 2. Validation (Choose Your Weapon)
71
+
72
+ BareJS allows you to use different validators for different routes.
73
+
74
+ ```typescript
75
+ import { BareJS } from 'barejs';
76
+ import { typebox, zod, native } from 'barejs/middleware';
77
+ import { Type } from '@sinclair/typebox';
78
+ import { z } from 'zod';
79
+
80
+ const app = new BareJS();
81
+
82
+ // High Performance: TypeBox
83
+ const UserSchema = Type.Object({ name: Type.String() });
84
+ app.post('/tb', typebox(UserSchema), (ctx) => ctx.json(ctx.body));
85
+
86
+ // Popular Choice: Zod
87
+ const ZodSchema = z.object({ age: z.number() });
88
+ app.post('/zod', zod(ZodSchema), (ctx) => ctx.json(ctx.body));
89
+
90
+ // No Dependencies: Native
91
+ app.post('/native', native({ properties: { id: { type: 'number' } } }), (ctx) => ctx.json(ctx.body));
92
+
93
+ ```
94
+
95
+ ---
36
96
 
37
97
  ## 🛠 Getting Started
38
98
 
39
99
  ### Prerequisites
40
- - [Bun](https://bun.sh) v1.0.0 or higher
100
+
101
+ * **Bun** v1.0.0 or higher
41
102
 
42
103
  ### Installation
104
+
43
105
  ```bash
44
- bun install
106
+ bun install barejs
107
+
45
108
  ```
46
109
 
47
110
  ### Running Benchmarks Locally
48
111
 
49
112
  ```bash
50
- bun run benchmarks/index.ts
113
+ bun run bench
51
114
 
52
115
  ```
53
116
 
54
- ---
55
-
56
117
  ## 🏗 Roadmap
57
118
 
58
119
  * [x] Middleware Pattern Support (Chain Execution)
59
- * [x] High-Speed Static Routing (O(1) Lookup Table)
120
+ * [x] High-Speed Static Routing ( Lookup Table)
60
121
  * [x] Schema Validation Integration
61
- * [ ] Full Documentation
122
+ * [x] Modular Validator Support (TypeBox, Zod, Native)
123
+ * [ ] Full Plugin System
62
124
 
63
- ---
125
+ **Maintained by xarhang**
64
126
 
65
- *Maintained by xarhang*
127
+ ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barejs",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "author": "xarhang",
5
5
  "description": "High-performance JIT-specialized web framework for Bun",
6
6
  "main": "src/bare.ts",
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "files": [
38
38
  "src",
39
- "README.md"
39
+ "README.md",
40
+ "LICENSE"
40
41
  ]
41
42
  }