barejs 0.1.34 → 0.1.35

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 CHANGED
@@ -39,11 +39,11 @@ BareJS leads in complex, real-world scenarios. We test using a **"Real-World" St
39
39
 
40
40
  | Framework | Latency | Speed |
41
41
  | :--- | :--- | :--- |
42
- | **BareJS** | **1.67 µs** | **Baseline** |
43
- | Elysia | 2.40 µs | 1.44x slower |
44
- | Hono | 9.93 µs | 5.94x slower |
42
+ | **BareJS** | **1.61 µs** | **Baseline** |
43
+ | Elysia | 1.90 µs | 1.18x slower |
44
+ | Hono | 8.69 µs | 5.39x slower |
45
45
 
46
- > Last Updated: Thu, 08 Jan 2026 17:04:12 GMT
46
+ > Last Updated: 2026-01-09 (BareJS Ultra-Accuracy Suite)
47
47
 
48
48
  <!-- MARKER: PERFORMANCE_TABLE_END -->
49
49
  > [!TIP]
@@ -82,9 +82,16 @@ Use `BareRouter` for modularity and nesting.
82
82
  import { BareJS, BareRouter } from 'barejs';
83
83
 
84
84
  const app = new BareJS();
85
- const api = new BareRouter("/api/v1");
85
+ const api = new BareRouter("/api");
86
86
 
87
- api.get("/status", (ctx) => ({ status: "ok" }));
87
+ // New: Simplified Nested Groups (Auto-Inferred Types)
88
+ api.group("/v1", (v1) => {
89
+ v1.get("/status", (ctx) => ({ status: "ok" }));
90
+
91
+ v1.group("/auth", (auth) => {
92
+ auth.post("/login", (ctx) => "OK");
93
+ });
94
+ });
88
95
 
89
96
  app.use(api); // Result: /api/v1/status
90
97
  ```
@@ -93,7 +100,7 @@ app.use(api); // Result: /api/v1/status
93
100
  Full RFC 7515 compliant JWT support and secure password utilities.
94
101
 
95
102
  ```typescript
96
- import { bareAuth, createToken, Password, type Context } from 'barejs';
103
+ import { bareAuth, createToken, Password } from 'barejs';
97
104
 
98
105
  const SECRET = "your-secret";
99
106
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- var c8=Object.defineProperty;var y1=(Q,W)=>{for(var G in W)c8(Q,G,{get:W[G],enumerable:!0,configurable:!0,set:(Y)=>W[G]=()=>Y})};class n0{prefix;groupMiddleware;routes=[];constructor(Q="",W=[]){this.prefix=Q;this.groupMiddleware=W}_add(Q,W,G){let Y=(this.prefix+W).replace(/\/+/g,"/")||"/";return this.routes.push({method:Q.toUpperCase(),path:Y,handlers:[...this.groupMiddleware,...G]}),this}get=(Q,...W)=>this._add("GET",Q,W);post=(Q,...W)=>this._add("POST",Q,W);put=(Q,...W)=>this._add("PUT",Q,W);patch=(Q,...W)=>this._add("PATCH",Q,W);delete=(Q,...W)=>this._add("DELETE",Q,W);group=(Q,...W)=>{let G=W.pop(),Y=W,Z=new n0((this.prefix+Q).replace(/\/+/g,"/"),[...this.groupMiddleware,...Y]);return G(Z),this.routes.push(...Z.routes),this};use(Q){if(Q&&Q.routes&&Array.isArray(Q.routes)){let W=Q.routes.map((G)=>({...G,path:(this.prefix+G.path).replace(/\/+/g,"/")||"/",handlers:[...this.groupMiddleware,...G.handlers]}));this.routes.push(...W)}else this.groupMiddleware.push(Q);return this}}class x0{children={};staticKeys=[];paramNode=null;paramName=null;handlers={};insert(Q,W,G){let Y=this,Z=Q.split("/").filter(Boolean);for(let X of Z)if(X.startsWith(":")){if(!Y.paramNode)Y.paramNode=new x0;Y.paramName=X.slice(1),Y=Y.paramNode}else{if(!Y.children[X])Y.children[X]=new x0,Y.staticKeys.push(X);Y=Y.children[X]}Y.handlers[W]=G}lookup(Q,W,G,Y){let Z=this,X=G===-1?0:G,z=W.length;if(W[X]==="/")X++;for(let H in Y.params)delete Y.params[H];while(X<z){let H=W.indexOf("/",X);if(H===-1)H=z;let j=H-X,B=!1,L=Z.staticKeys,w=L.length;if(w===1){let E=L[0];if(E.length===j){let G0=!0;for(let X0=0;X0<j;X0++)if(E[X0]!==W[X+X0]){G0=!1;break}if(G0)Z=Z.children[E],B=!0}}else for(let E=0;E<w;E++){let G0=L[E];if(G0.length===j){let X0=!0;for(let j0=0;j0<j;j0++)if(G0[j0]!==W[X+j0]){X0=!1;break}if(X0){Z=Z.children[G0],B=!0;break}}}if(!B)if(Z.paramNode)Y.params[Z.paramName]=W.slice(X,H),Z=Z.paramNode;else return null;X=H+1}return Z.handlers[Q]||null}jitCompile(Q,W=0,G="url",Y="s",Z=[]){let X="",z=" ".repeat(W);if(this.staticKeys.length>0)if(this.staticKeys.length===1){let H=this.staticKeys[0],j=H.length;X+=`${z}if (${G}.startsWith("${H}", ${Y})) {
2
+ var c8=Object.defineProperty;var y1=(Q,W)=>{for(var G in W)c8(Q,G,{get:W[G],enumerable:!0,configurable:!0,set:(Y)=>W[G]=()=>Y})};class n0{prefix;groupMiddleware;routes=[];constructor(Q="",W=[]){this.prefix=Q;this.groupMiddleware=W}_add(Q,W,G){let Y=(this.prefix+W).replace(/\/+/g,"/")||"/";return this.routes.push({method:Q.toUpperCase(),path:Y,handlers:[...this.groupMiddleware,...G]}),this}get(Q,...W){return this._add("GET",Q,W)}post(Q,...W){return this._add("POST",Q,W)}put(Q,...W){return this._add("PUT",Q,W)}patch(Q,...W){return this._add("PATCH",Q,W)}delete(Q,...W){return this._add("DELETE",Q,W)}group(Q,...W){let G=W.pop(),Y=W,Z=new n0((this.prefix+Q).replace(/\/+/g,"/"),[...this.groupMiddleware,...Y]);return G(Z),this.routes.push(...Z.routes),this}use(Q){if(Q&&Q.routes&&Array.isArray(Q.routes)){let W=Q.routes.map((G)=>({...G,path:(this.prefix+G.path).replace(/\/+/g,"/")||"/",handlers:[...this.groupMiddleware,...G.handlers]}));this.routes.push(...W)}else this.groupMiddleware.push(Q);return this}}class x0{children={};staticKeys=[];paramNode=null;paramName=null;handlers={};insert(Q,W,G){let Y=this,Z=Q.split("/").filter(Boolean);for(let X of Z)if(X.startsWith(":")){if(!Y.paramNode)Y.paramNode=new x0;Y.paramName=X.slice(1),Y=Y.paramNode}else{if(!Y.children[X])Y.children[X]=new x0,Y.staticKeys.push(X);Y=Y.children[X]}Y.handlers[W]=G}lookup(Q,W,G,Y){let Z=this,X=G===-1?0:G,z=W.length;if(W[X]==="/")X++;for(let H in Y.params)delete Y.params[H];while(X<z){let H=W.indexOf("/",X);if(H===-1)H=z;let j=H-X,B=!1,L=Z.staticKeys,w=L.length;if(w===1){let E=L[0];if(E.length===j){let G0=!0;for(let X0=0;X0<j;X0++)if(E[X0]!==W[X+X0]){G0=!1;break}if(G0)Z=Z.children[E],B=!0}}else for(let E=0;E<w;E++){let G0=L[E];if(G0.length===j){let X0=!0;for(let j0=0;j0<j;j0++)if(G0[j0]!==W[X+j0]){X0=!1;break}if(X0){Z=Z.children[G0],B=!0;break}}}if(!B)if(Z.paramNode)Y.params[Z.paramName]=W.slice(X,H),Z=Z.paramNode;else return null;X=H+1}return Z.handlers[Q]||null}jitCompile(Q,W=0,G="url",Y="s",Z=[]){let X="",z=" ".repeat(W);if(this.staticKeys.length>0)if(this.staticKeys.length===1){let H=this.staticKeys[0],j=H.length;X+=`${z}if (${G}.startsWith("${H}", ${Y})) {
3
3
  `,X+=`${z} const nextChar = ${G}.charCodeAt(${Y} + ${j});
4
4
  `,X+=`${z} if (isNaN(nextChar) || nextChar === 47) {
5
5
  `;let B=this.children[H],L=`newIdx${W}`;if(X+=`${z} const ${L} = isNaN(nextChar) ? ${G}.length : (${Y} + ${j} + 1);
@@ -2,7 +2,6 @@ export type Params = Record<string, string>;
2
2
  export type Next = () => Promise<any> | any;
3
3
  export type Middleware = (ctx: Context, next: Next) => Promise<any> | any;
4
4
  export type Handler = (ctx: Context) => Promise<any> | any;
5
- export type GroupCallback = (router: any) => void;
6
5
  export type AuthUser = Record<string, any>;
7
6
  export declare class Context {
8
7
  req: Request;
@@ -1,4 +1,5 @@
1
1
  import { type Middleware, type Handler } from './context';
2
+ export type GroupCallback = (router: BareRouter) => void;
2
3
  type HandlersChain = (Middleware | Handler)[];
3
4
  export declare class BareRouter {
4
5
  prefix: string;
@@ -10,12 +11,24 @@ export declare class BareRouter {
10
11
  }[];
11
12
  constructor(prefix?: string, groupMiddleware?: any[]);
12
13
  private _add;
13
- get: (path: string, ...h: HandlersChain) => this;
14
- post: (path: string, ...h: HandlersChain) => this;
15
- put: (path: string, ...h: HandlersChain) => this;
16
- patch: (path: string, ...h: HandlersChain) => this;
17
- delete: (path: string, ...h: HandlersChain) => this;
18
- group: (path: string, ...args: any[]) => this;
14
+ get(path: string, handler: Handler): this;
15
+ get(path: string, middleware: Middleware, handler: Handler): this;
16
+ get(path: string, ...h: HandlersChain): this;
17
+ post(path: string, handler: Handler): this;
18
+ post(path: string, middleware: Middleware, handler: Handler): this;
19
+ post(path: string, ...h: HandlersChain): this;
20
+ put(path: string, handler: Handler): this;
21
+ put(path: string, middleware: Middleware, handler: Handler): this;
22
+ put(path: string, ...h: HandlersChain): this;
23
+ patch(path: string, handler: Handler): this;
24
+ patch(path: string, middleware: Middleware, handler: Handler): this;
25
+ patch(path: string, ...h: HandlersChain): this;
26
+ delete(path: string, handler: Handler): this;
27
+ delete(path: string, middleware: Middleware, handler: Handler): this;
28
+ delete(path: string, ...h: HandlersChain): this;
29
+ group(path: string, callback: GroupCallback): this;
30
+ group(path: string, middleware: Middleware, callback: GroupCallback): this;
31
+ group(path: string, ...args: any[]): this;
19
32
  /**
20
33
  * 🔗 Use: Mounts a router or middleware
21
34
  * Supports nested routers with automatic path prefixing
package/package.json CHANGED
@@ -1,68 +1,71 @@
1
- {
2
- "name": "barejs",
3
- "version": "0.1.34",
4
- "author": "xarhang",
5
- "description": "High-performance JIT-specialized web framework for Bun",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
- "types": "./dist/types/index.d.ts",
9
- "type": "module",
10
- "exports": {
11
- ".": {
12
- "import": "./dist/index.js",
13
- "types": "./dist/types/index.d.ts"
14
- }
15
- },
16
- "sideEffects": false,
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/xarhang/barejs.git"
20
- },
21
- "scripts": {
22
- "test": "bun test",
23
- "benchs": "bun run benchmarks/index.ts",
24
- "bench": "bun run benchmarks/head-to-head.ts",
25
- "dev": "bun --watch src/index.ts",
26
- "build": "bun ./scripts/build.ts",
27
- "prepublishOnly": "bun run build",
28
- "release": "bun run build && npm version patch && npm publish --access public"
29
- },
30
- "keywords": [
31
- "bun",
32
- "framework",
33
- "fastest",
34
- "jit",
35
- "typebox",
36
- "zod",
37
- "barejs",
38
- "http-server"
39
- ],
40
- "license": "MIT",
41
- "peerDependencies": {
42
- "@sinclair/typebox": "^0.34.46",
43
- "zod": "^3.0.0"
44
- },
45
- "peerDependenciesMeta": {
46
- "@sinclair/typebox": {
47
- "optional": true
48
- },
49
- "zod": {
50
- "optional": true
51
- }
52
- },
53
- "devDependencies": {
54
- "@sinclair/typebox": "^0.34.46",
55
- "zod": "^3.23.8",
56
- "@types/bun": "latest",
57
- "typescript": "latest",
58
- "mitata": "^1.0.34",
59
- "elysia": "latest",
60
- "hono": "latest"
61
- },
62
- "files": [
63
- "dist",
64
- "src",
65
- "README.md",
66
- "LICENSE"
67
- ]
68
- }
1
+ {
2
+ "name": "barejs",
3
+ "version": "0.1.35",
4
+ "author": "xarhang",
5
+ "description": "High-performance JIT-specialized web framework for Bun",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/types/index.d.ts",
9
+ "type": "module",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/types/index.d.ts"
14
+ }
15
+ },
16
+ "sideEffects": false,
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/xarhang/barejs.git"
20
+ },
21
+ "scripts": {
22
+ "test": "bun run tests/core.test.ts",
23
+ "benchs": "bun run benchmarks/index.ts",
24
+ "bench": "bun run benchmarks/head-to-head.ts",
25
+ "dev": "bun --watch src/index.ts",
26
+ "build": "bun ./scripts/build.ts",
27
+ "prepublishOnly": "bun run build",
28
+ "release": "bun run build && npm version patch && npm publish --access public"
29
+ },
30
+ "keywords": [
31
+ "bun",
32
+ "framework",
33
+ "fastest",
34
+ "jit",
35
+ "typebox",
36
+ "zod",
37
+ "barejs",
38
+ "http-server"
39
+ ],
40
+ "license": "MIT",
41
+ "peerDependencies": {
42
+ "@sinclair/typebox": "^0.34.46",
43
+ "zod": "^3.0.0"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "@sinclair/typebox": {
47
+ "optional": true
48
+ },
49
+ "zod": {
50
+ "optional": true
51
+ }
52
+ },
53
+ "devDependencies": {
54
+ "@sinclair/typebox": "^0.34.46",
55
+ "zod": "^3.23.8",
56
+ "@types/bun": "latest",
57
+ "typescript": "latest",
58
+ "mitata": "^1.0.34",
59
+ "elysia": "latest",
60
+ "hono": "latest"
61
+ },
62
+ "files": [
63
+ "dist",
64
+ "src",
65
+ "README.md",
66
+ "LICENSE"
67
+ ],
68
+ "dependencies": {
69
+ "barejs": "."
70
+ }
71
+ }
package/src/context.ts CHANGED
@@ -2,7 +2,6 @@ export type Params = Record<string, string>;
2
2
  export type Next = () => Promise<any> | any;
3
3
  export type Middleware = (ctx: Context, next: Next) => Promise<any> | any;
4
4
  export type Handler = (ctx: Context) => Promise<any> | any;
5
- export type GroupCallback = (router: any) => void;
6
5
  export type AuthUser = Record<string, any>;
7
6
 
8
7
  export class Context {
package/src/router.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  type Middleware,
3
- type Handler,
4
- type GroupCallback
3
+ type Handler
5
4
  } from './context';
6
5
 
6
+ export type GroupCallback = (router: BareRouter) => void;
7
+
7
8
  type HandlersChain = (Middleware | Handler)[];
8
9
 
9
10
  export class BareRouter {
@@ -25,13 +26,35 @@ export class BareRouter {
25
26
  return this;
26
27
  }
27
28
 
28
- public get = (path: string, ...h: HandlersChain) => this._add("GET", path, h);
29
- public post = (path: string, ...h: HandlersChain) => this._add("POST", path, h);
30
- public put = (path: string, ...h: HandlersChain) => this._add("PUT", path, h);
31
- public patch = (path: string, ...h: HandlersChain) => this._add("PATCH", path, h);
32
- public delete = (path: string, ...h: HandlersChain) => this._add("DELETE", path, h);
29
+ public get(path: string, handler: Handler): this;
30
+ public get(path: string, middleware: Middleware, handler: Handler): this;
31
+ public get(path: string, ...h: HandlersChain): this;
32
+ public get(path: string, ...h: HandlersChain) { return this._add("GET", path, h); }
33
+
34
+ public post(path: string, handler: Handler): this;
35
+ public post(path: string, middleware: Middleware, handler: Handler): this;
36
+ public post(path: string, ...h: HandlersChain): this;
37
+ public post(path: string, ...h: HandlersChain) { return this._add("POST", path, h); }
38
+
39
+ public put(path: string, handler: Handler): this;
40
+ public put(path: string, middleware: Middleware, handler: Handler): this;
41
+ public put(path: string, ...h: HandlersChain): this;
42
+ public put(path: string, ...h: HandlersChain) { return this._add("PUT", path, h); }
33
43
 
34
- public group = (path: string, ...args: any[]) => {
44
+ public patch(path: string, handler: Handler): this;
45
+ public patch(path: string, middleware: Middleware, handler: Handler): this;
46
+ public patch(path: string, ...h: HandlersChain): this;
47
+ public patch(path: string, ...h: HandlersChain) { return this._add("PATCH", path, h); }
48
+
49
+ public delete(path: string, handler: Handler): this;
50
+ public delete(path: string, middleware: Middleware, handler: Handler): this;
51
+ public delete(path: string, ...h: HandlersChain): this;
52
+ public delete(path: string, ...h: HandlersChain) { return this._add("DELETE", path, h); }
53
+
54
+ public group(path: string, callback: GroupCallback): this;
55
+ public group(path: string, middleware: Middleware, callback: GroupCallback): this;
56
+ public group(path: string, ...args: any[]): this;
57
+ public group(path: string, ...args: any[]): this {
35
58
  const callback = args.pop() as GroupCallback;
36
59
  const middleware = args;
37
60
 
@@ -43,7 +66,7 @@ export class BareRouter {
43
66
  callback(subRouter);
44
67
  this.routes.push(...subRouter.routes);
45
68
  return this;
46
- };
69
+ }
47
70
 
48
71
  /**
49
72
  * 🔗 Use: Mounts a router or middleware