barejs 0.1.47 โ†’ 0.1.48

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 CHANGED
@@ -1,21 +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
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
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,184 +1,184 @@
1
- <div align="center">
2
- <br />
3
- <h1>Bare<span style="color: #F7DF1E;">JS</span></h1>
4
- <p><strong>The "Metal" of Web Frameworks</strong></p>
5
- <p><i>An ultra-high-performance web engine built for Bun, architected strictly for Mechanical Sympathy.</i></p>
6
-
7
- <p>
8
- <a href="https://www.npmjs.com/package/barejs">
9
- <img src="https://img.shields.io/npm/v/barejs?style=for-the-badge&logo=npm&color=CB3837" alt="NPM Version">
10
- </a>
11
- <a href="https://github.com/xarhang/barejs/actions/workflows/bench.yml">
12
- <img src="https://img.shields.io/github/actions/workflow/status/xarhang/barejs/bench.yml?branch=main&label=Performance&style=for-the-badge&logo=github" alt="Performance">
13
- </a>
14
- <a href="https://bun.sh">
15
- <img src="https://img.shields.io/badge/Bun-%3E%3D1.0.0-black?style=for-the-badge&logo=bun" alt="Bun Version">
16
- </a>
17
- <a href="https://github.com/xarhang/barejs/blob/main/LICENSE">
18
- <img src="https://img.shields.io/github/license/xarhang/barejs?style=for-the-badge&color=blue" alt="License">
19
- </a>
20
- </p>
21
- </div>
22
-
23
- ---
24
-
25
- </div>
26
-
27
- ## ๐Ÿ“Š Benchmarks: Real-World Performance
28
-
29
- BareJS leads in complex, real-world scenarios. We measure engine efficiency using a **stress test** involving **10+ middlewares** and **deep radix tree routing** to ensure performance holds under high concurrency.
30
- <!-- MARKER: PERFORMANCE_TABLE_START -->
31
-
32
- | Framework | Latency | Speed |
33
- | :--- | :--- | :--- |
34
- | **BareJS** | **1.79 ยตs** | **Baseline** |
35
- | Elysia | 2.44 ยตs | 1.36x slower |
36
- | Hono | 9.86 ยตs | 5.52x slower |
37
-
38
- > Last Updated: 2026-01-14 (github action)
39
-
40
- <!-- MARKER: PERFORMANCE_TABLE_END -->
41
-
42
- > [!TIP]
43
- > **View our [Continuous Benchmark Dashboard**](https://xarhang.github.io/bareJS/dev/benchmarks/) for historical data and detailed performance trends.
44
-
45
- ## ๐Ÿš€ Key Features
46
-
47
- * **JIT Pipeline Compilation**: Routes and middleware chains are flattened into a single function at runtime.
48
- * **Object Pooling**: Recycles `Context` objects via a circular buffer, drastically reducing GC pressure.
49
- * **Internal High-Performance Logger**: Zero-overhead logging integrated directly into the JIT engine.
50
- * **Precise Radix Router**: v0.1.46 introduces optimized segment matching for deep-nested paths.
51
- * **Mechanical Sympathy**: Intentionally designed to align with V8's optimization and Bun's I/O.
52
-
53
- ## ๐Ÿ› ๏ธ Installation
54
-
55
- ```bash
56
- bun add barejs
57
-
58
- ```
59
-
60
- ### The "Bare" Minimum
61
-
62
- ```typescript
63
- import { BareJS, type Context } from 'barejs';
64
-
65
- const app = new BareJS();
66
-
67
- // Enable Internal Logger
68
- app.useLog(true);
69
-
70
- app.get('/', (ctx: Context) => ctx.json({ hello: "world" }));
71
-
72
- app.listen(3000);
73
-
74
- ```
75
-
76
- ---
77
-
78
- ## ๐Ÿ“˜ Comprehensive Guide
79
-
80
- ### 1. โšก Standardized Response & Chaining
81
-
82
- BareJS v0.1.46 provides a fluent API for building responses.
83
-
84
- ```typescript
85
- app.get('/api/v1/health', (ctx: Context) => {
86
- // Chainable status and standardized send helper
87
- return ctx.status(200).send("System is healthy", {
88
- uptime: process.uptime()
89
- });
90
- });
91
-
92
- // Output: { "status": "success", "msg": "System is healthy", "uptime": ... }
93
-
94
- ```
95
-
96
- ### 2. ๐Ÿ›ก๏ธ Security & Authentication (Dual-API)
97
-
98
- ```typescript
99
- import { bareAuth, createToken, Password, Hash, type Context } from 'barejs';
100
-
101
- const SECRET = process.env.JWT_SECRET || "your-secret";
102
-
103
- app.post('/register', async (ctx: Context) => {
104
- const body = await ctx.jsonBody();
105
-
106
- // High-performance Argon2id Hashing (64MB default)
107
- const hash = await Password.make(body.password);
108
-
109
- // Verify with ease
110
- const isValid = await Hash.verify(body.password, hash);
111
-
112
- if (isValid) {
113
- const token = await createToken({ id: 1 }, SECRET);
114
- return { token };
115
- }
116
- });
117
-
118
- // Protect routes with built-in JWT middleware
119
- app.get('/me', bareAuth(SECRET), (ctx: Context) => {
120
- return ctx.send("Authenticated", { user: ctx.get('user') });
121
- });
122
-
123
- ```
124
-
125
- ### 3. โœ… Data Validation (3 Styles)
126
-
127
- BareJS is the only engine that offers JIT-optimized validation paths.
128
-
129
- ```typescript
130
- import { typebox, zod, native, t, type Context } from 'barejs';
131
- import { z } from 'zod';
132
-
133
- // Style A: TypeBox (JIT Optimized - Recommended)
134
- // Pre-compiled validation to outperform competitors by 55%
135
- const Schema = t.Object({ name: t.String() });
136
- app.post('/user', typebox(Schema), (ctx) => ctx.json(ctx.body));
137
-
138
- // Style B: Zod (Industry Standard)
139
- const ZodSchema = z.object({ age: z.number() });
140
- app.post('/age', zod(ZodSchema), (ctx) => ctx.json(ctx.body));
141
-
142
- // Style C: Native (Zero Dependency - Simple Checks)
143
- app.post('/native', native({ properties: { id: { type: 'number' } } }), (ctx) => ctx.json(ctx.body));
144
-
145
- ```
146
-
147
- ### 4. ๐Ÿ”Œ Essential Middleware
148
-
149
- ```typescript
150
- import { cors, staticFile } from 'barejs';
151
-
152
- app.use(cors());
153
- app.use(staticFile("public"));
154
-
155
- ```
156
-
157
- ---
158
-
159
- ## ๐Ÿง  Context API
160
-
161
- | Method / Property | Description |
162
- | --- | --- |
163
- | `ctx.req` | Raw incoming Bun `Request` object. |
164
- | `ctx.params` | Route parameters (e.g., `:id`). |
165
- | `ctx.jsonBody()` | **[Async]** Parses and caches JSON body for performance. |
166
- | `ctx.status(code)` | Sets the HTTP status code (**Chainable**). |
167
- | `ctx.send(msg, ext)` | Returns a standardized JSON response. |
168
- | `ctx.json(data)` | Returns an optimized raw JSON response. |
169
- | `ctx.setHeader(k, v)` | Sets a response header. |
170
- | `ctx.set / ctx.get` | Manual storage within the request lifecycle. |
171
-
172
- ---
173
-
174
- ## โš™๏ธ Performance Tuning
175
-
176
- | OS Variable / File | Default | Description |
177
- | --- | --- | --- |
178
- | `bare.config.ts` | - | Centralized config for Port and Hash algorithms. |
179
- | `BARE_POOL_SIZE` | `1024` | Context pool size (**Must be Power of 2**). |
180
- | `NODE_ENV` | `development` | Set to `production` to enable peak JIT optimizations. |
181
-
182
- ---
183
-
184
- **Maintained by [xarhang](https://github.com/xarhang) | License: MIT**
1
+ <div align="center">
2
+ <br />
3
+ <h1>Bare<span style="color: #F7DF1E;">JS</span></h1>
4
+ <p><strong>The "Metal" of Web Frameworks</strong></p>
5
+ <p><i>An ultra-high-performance web engine built for Bun, architected strictly for Mechanical Sympathy.</i></p>
6
+
7
+ <p>
8
+ <a href="https://www.npmjs.com/package/barejs">
9
+ <img src="https://img.shields.io/npm/v/barejs?style=for-the-badge&logo=npm&color=CB3837" alt="NPM Version">
10
+ </a>
11
+ <a href="https://github.com/xarhang/barejs/actions/workflows/bench.yml">
12
+ <img src="https://img.shields.io/github/actions/workflow/status/xarhang/barejs/bench.yml?branch=main&label=Performance&style=for-the-badge&logo=github" alt="Performance">
13
+ </a>
14
+ <a href="https://bun.sh">
15
+ <img src="https://img.shields.io/badge/Bun-%3E%3D1.0.0-black?style=for-the-badge&logo=bun" alt="Bun Version">
16
+ </a>
17
+ <a href="https://github.com/xarhang/barejs/blob/main/LICENSE">
18
+ <img src="https://img.shields.io/github/license/xarhang/barejs?style=for-the-badge&color=blue" alt="License">
19
+ </a>
20
+ </p>
21
+ </div>
22
+
23
+ ---
24
+
25
+ </div>
26
+
27
+ ## ๐Ÿ“Š Benchmarks: Real-World Performance
28
+
29
+ BareJS leads in complex, real-world scenarios. We measure engine efficiency using a **stress test** involving **10+ middlewares** and **deep radix tree routing** to ensure performance holds under high concurrency.
30
+ <!-- MARKER: PERFORMANCE_TABLE_START -->
31
+
32
+ | Framework | Latency | Speed |
33
+ | :--- | :--- | :--- |
34
+ | **BareJS** | **1.45 ยตs** | **Baseline** |
35
+ | Elysia | 1.94 ยตs | 1.34x slower |
36
+ | Hono | 5.62 ยตs | 3.87x slower |
37
+
38
+ > Last Updated: 2026-11-13 (github action)
39
+
40
+ <!-- MARKER: PERFORMANCE_TABLE_END -->
41
+
42
+ > [!TIP]
43
+ > **View our [Continuous Benchmark Dashboard**](https://xarhang.github.io/bareJS/dev/benchmarks/) for historical data and detailed performance trends.
44
+
45
+ ## ๐Ÿš€ Key Features
46
+
47
+ * **JIT Pipeline Compilation**: Routes and middleware chains are flattened into a single function at runtime.
48
+ * **Object Pooling**: Recycles `Context` objects via a circular buffer, drastically reducing GC pressure.
49
+ * **Internal High-Performance Logger**: Zero-overhead logging integrated directly into the JIT engine.
50
+ * **Precise Radix Router**: v0.1.46 introduces optimized segment matching for deep-nested paths.
51
+ * **Mechanical Sympathy**: Intentionally designed to align with V8's optimization and Bun's I/O.
52
+
53
+ ## ๐Ÿ› ๏ธ Installation
54
+
55
+ ```bash
56
+ bun add barejs
57
+
58
+ ```
59
+
60
+ ### The "Bare" Minimum
61
+
62
+ ```typescript
63
+ import { BareJS, type Context } from 'barejs';
64
+
65
+ const app = new BareJS();
66
+
67
+ // Enable Internal Logger
68
+ app.useLog(true);
69
+
70
+ app.get('/', (ctx: Context) => ctx.json({ hello: "world" }));
71
+
72
+ app.listen(3000);
73
+
74
+ ```
75
+
76
+ ---
77
+
78
+ ## ๐Ÿ“˜ Comprehensive Guide
79
+
80
+ ### 1. โšก Standardized Response & Chaining
81
+
82
+ BareJS v0.1.46 provides a fluent API for building responses.
83
+
84
+ ```typescript
85
+ app.get('/api/v1/health', (ctx: Context) => {
86
+ // Chainable status and standardized send helper
87
+ return ctx.status(200).send("System is healthy", {
88
+ uptime: process.uptime()
89
+ });
90
+ });
91
+
92
+ // Output: { "status": "success", "msg": "System is healthy", "uptime": ... }
93
+
94
+ ```
95
+
96
+ ### 2. ๐Ÿ›ก๏ธ Security & Authentication (Dual-API)
97
+
98
+ ```typescript
99
+ import { bareAuth, createToken, Password, Hash, type Context } from 'barejs';
100
+
101
+ const SECRET = process.env.JWT_SECRET || "your-secret";
102
+
103
+ app.post('/register', async (ctx: Context) => {
104
+ const body = await ctx.jsonBody();
105
+
106
+ // High-performance Argon2id Hashing (64MB default)
107
+ const hash = await Password.make(body.password);
108
+
109
+ // Verify with ease
110
+ const isValid = await Hash.verify(body.password, hash);
111
+
112
+ if (isValid) {
113
+ const token = await createToken({ id: 1 }, SECRET);
114
+ return { token };
115
+ }
116
+ });
117
+
118
+ // Protect routes with built-in JWT middleware
119
+ app.get('/me', bareAuth(SECRET), (ctx: Context) => {
120
+ return ctx.send("Authenticated", { user: ctx.get('user') });
121
+ });
122
+
123
+ ```
124
+
125
+ ### 3. โœ… Data Validation (3 Styles)
126
+
127
+ BareJS is the only engine that offers JIT-optimized validation paths.
128
+
129
+ ```typescript
130
+ import { typebox, zod, native, t, type Context } from 'barejs';
131
+ import { z } from 'zod';
132
+
133
+ // Style A: TypeBox (JIT Optimized - Recommended)
134
+ // Pre-compiled validation to outperform competitors by 55%
135
+ const Schema = t.Object({ name: t.String() });
136
+ app.post('/user', typebox(Schema), (ctx) => ctx.json(ctx.body));
137
+
138
+ // Style B: Zod (Industry Standard)
139
+ const ZodSchema = z.object({ age: z.number() });
140
+ app.post('/age', zod(ZodSchema), (ctx) => ctx.json(ctx.body));
141
+
142
+ // Style C: Native (Zero Dependency - Simple Checks)
143
+ app.post('/native', native({ properties: { id: { type: 'number' } } }), (ctx) => ctx.json(ctx.body));
144
+
145
+ ```
146
+
147
+ ### 4. ๐Ÿ”Œ Essential Middleware
148
+
149
+ ```typescript
150
+ import { cors, staticFile } from 'barejs';
151
+
152
+ app.use(cors());
153
+ app.use(staticFile("public"));
154
+
155
+ ```
156
+
157
+ ---
158
+
159
+ ## ๐Ÿง  Context API
160
+
161
+ | Method / Property | Description |
162
+ | --- | --- |
163
+ | `ctx.req` | Raw incoming Bun `Request` object. |
164
+ | `ctx.params` | Route parameters (e.g., `:id`). |
165
+ | `ctx.jsonBody()` | **[Async]** Parses and caches JSON body for performance. |
166
+ | `ctx.status(code)` | Sets the HTTP status code (**Chainable**). |
167
+ | `ctx.send(msg, ext)` | Returns a standardized JSON response. |
168
+ | `ctx.json(data)` | Returns an optimized raw JSON response. |
169
+ | `ctx.setHeader(k, v)` | Sets a response header. |
170
+ | `ctx.set / ctx.get` | Manual storage within the request lifecycle. |
171
+
172
+ ---
173
+
174
+ ## โš™๏ธ Performance Tuning
175
+
176
+ | OS Variable / File | Default | Description |
177
+ | --- | --- | --- |
178
+ | `bare.config.ts` | - | Centralized config for Port and Hash algorithms. |
179
+ | `BARE_POOL_SIZE` | `1024` | Context pool size (**Must be Power of 2**). |
180
+ | `NODE_ENV` | `development` | Set to `production` to enable peak JIT optimizations. |
181
+
182
+ ---
183
+
184
+ **Maintained by [xarhang](https://github.com/xarhang) | License: MIT**