barejs 0.1.60 → 0.1.62
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 +39 -18
- package/dist/index.js +136 -129
- package/dist/node.js +136 -129
- package/llms.txt +3 -2
- package/package.json +7 -2
- package/src/runtime/node.ts +216 -19
- package/src/security/hash.ts +4 -0
package/README.md
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
<br />
|
|
3
3
|
<h1>Bare<span style="color: #F7DF1E;">JS</span></h1>
|
|
4
4
|
<p><strong>The batteries-included web framework for Bun, Node.js, and Deno, engineered for minimal overhead.</strong></p>
|
|
5
|
-
<p><i>Built-in TypeBox &
|
|
5
|
+
<p><i>Built-in TypeBox, Zod & JSON Schema validation, end-to-end RPC client inference, OpenAPI 3.1, WebSockets, SSE, Streaming Uploads, JSON-RPC 2.0, Cron, Resilience, and Zero-Trust Security — powered by a JIT-compiled O(1) radix router and LIFO context pooling.</i></p>
|
|
6
6
|
|
|
7
7
|
<p>
|
|
8
8
|
<a href="https://www.npmjs.com/package/barejs"><img src="https://img.shields.io/npm/v/barejs?style=for-the-badge&logo=npm&color=CB3837" alt="NPM Version"></a>
|
|
9
|
-
<a href="https://github.com/xarhang/bareJS/actions/workflows/
|
|
9
|
+
<a href="https://github.com/xarhang/bareJS/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/xarhang/bareJS/ci.yml?branch=main&label=CI&style=for-the-badge&logo=github" alt="CI"></a>
|
|
10
|
+
<a href="https://github.com/xarhang/bareJS/actions/workflows/bench.yml"><img src="https://img.shields.io/github/actions/workflow/status/xarhang/bareJS/bench.yml?branch=main&label=Benchmarks&style=for-the-badge&logo=github" alt="Benchmarks"></a>
|
|
10
11
|
<a href="https://bun.sh"><img src="https://img.shields.io/badge/Bun-%3E%3D1.1.0-black?style=for-the-badge&logo=bun" alt="Bun"></a>
|
|
11
12
|
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node.js-%3E%3D20.0.0-339933?style=for-the-badge&logo=nodedotjs" alt="Node.js"></a>
|
|
12
13
|
<a href="https://deno.com"><img src="https://img.shields.io/badge/Deno-%3E%3D2.0-000000?style=for-the-badge&logo=deno" alt="Deno"></a>
|
|
@@ -36,12 +37,12 @@ app.listen(3000);
|
|
|
36
37
|
|
|
37
38
|
## Why BareJS?
|
|
38
39
|
|
|
39
|
-
- **O(1) JIT Router & Pooling:** Compiles static routes into an inline `switch` fast-path and dynamic routes into a radix jump-table with a lazy LIFO `Context` pool (`0..65536`) and dev-mode Use-After-Free Proxy guard.
|
|
40
|
-
- **Unified Schema Validation:** Declarative `body`, `query`, `params`, `headers`, and `response` schemas with **TypeBox**, **Zod**, or **Native JSON Schema** — including auto-coercion, `413` `maxBodySize` guards, and automatic secret-field stripping.
|
|
40
|
+
- **O(1) JIT Router, Sub-Routing & Pooling:** Compiles static routes into an inline `switch` fast-path and dynamic routes into a radix jump-table (`:params`, `*` wildcards, `BareRouter` sub-app mounting) with a lazy LIFO `Context` pool (`0..65536`) and dev-mode Use-After-Free Proxy guard.
|
|
41
|
+
- **Unified Schema Validation:** Declarative `body`, `query`, `params`, `headers`, and `response` schemas with **TypeBox**, **Zod**, or **Native JSON Schema** — including auto-coercion, `stripUnknown` Mass-Assignment protection, `413` `maxBodySize` guards, and automatic secret-field stripping.
|
|
41
42
|
- **End-to-End Type Safety:** `bareClient(app)` provides compile-time route, param, query, body, and response inference over HTTP or zero-network in-memory calls.
|
|
42
|
-
- **Batteries Included:** Auto-generated **OpenAPI 3.1** + Scalar UI (`app.docs`), **JSON-RPC 2.0** (`app.rpc`), **WebSockets** (`app.ws`), **SSE** (`ctx.sse`), **Compression** (`compress`),
|
|
43
|
-
- **Zero-Trust Security & Resilience:** Built-in `bareAuth` (HS256/RS256/ES256/JWKS), `Hash` (Argon2id/bcrypt), HMAC-signed cookies, `cors`, `csrf`, `rateLimit`, `idempotency`, `circuitBreaker`, `createSingleflight`, and `app.onDrain`.
|
|
44
|
-
- **Multi-Runtime
|
|
43
|
+
- **Batteries Included:** Auto-generated **OpenAPI 3.1** + Scalar UI (`app.docs`), **JSON-RPC 2.0** (`app.rpc`), **WebSockets** (`app.ws`), **SSE** (`ctx.sse`), **Streaming Uploads** (`ctx.upload` / `ctx.uploadStream`), **Compression** (`compress` — `zstd`/`br`/`gzip`), **Static Files** (`staticFile` with ETag/`304`/Range `206`), `app.derive`, `app.cron`, `logger`, and `healthcheck`.
|
|
44
|
+
- **Zero-Trust Security & Resilience:** Built-in `bareAuth` (HS256/RS256/ES256/JWKS + `revokeToken`), `basicAuth`, `hasRole`, `Hash` (Argon2id/bcrypt/scrypt), HMAC-signed cookies, `cors`, `csrf`, `rateLimit`, `idempotency`, `circuitBreaker`, `createSingleflight`, `timeout`, `redisStore`, and `app.onDrain`.
|
|
45
|
+
- **Multi-Runtime & Web Standard Interop:** Zero-dep native drivers for **Bun**, **Node.js >= 20** (`barejs/node` with built-in RFC 6455 WebSockets & `scrypt`), and **Deno >= 2.0** (`Deno.upgradeWebSocket`). Standard `Request`/`Response` (`ctx.req`) works directly with **Better-Auth**, **Auth0**, **Clerk**, **GraphQL Yoga**, **Sentry**, and **OpenTelemetry**.
|
|
45
46
|
|
|
46
47
|
---
|
|
47
48
|
|
|
@@ -69,7 +70,8 @@ app.listen(3000);
|
|
|
69
70
|
|
|
70
71
|
```bash
|
|
71
72
|
npm install barejs
|
|
72
|
-
#
|
|
73
|
+
# Zero-dep native WebSockets (RFC 6455) & scrypt hashing work out of the box!
|
|
74
|
+
# Optional peer dependencies only if you prefer `ws` or Argon2id:
|
|
73
75
|
npm install ws @node-rs/argon2
|
|
74
76
|
```
|
|
75
77
|
|
|
@@ -110,38 +112,56 @@ Deno.serve({ port: 3000 }, (req, info) => app.fetch(req, info.remoteAddr.hostnam
|
|
|
110
112
|
| **Security Middlewares (`cors`, `csrf`, `rateLimit`, `bareAuth`, `idempotency`)** | ✅ | ✅ | ✅ |
|
|
111
113
|
| **Streaming (`ctx.sse`, `ctx.upload`, `ctx.uploadStream`)** | ✅ | ✅ | ✅ |
|
|
112
114
|
| **Static Files (`staticFile`)** | ✅ | ✅ | ✅ |
|
|
113
|
-
| **Compression (`compress` — `gzip` / `br` / `zstd`)** | ✅ | ✅ (`gzip` / `br`) | ✅ (`gzip` / `br`) |
|
|
114
|
-
| **WebSockets (`app.ws`)** | ✅ Native |
|
|
115
|
+
| **Compression (`compress` — `gzip` / `br` / `zstd`)** | ✅ | ✅ (`gzip` / `br`, + `zstd` on Node >= 22.15) | ✅ (`gzip` / `br`) |
|
|
116
|
+
| **WebSockets (`app.ws`)** | ✅ Native | ✅ Native (RFC 6455) · Optional `ws` | ✅ Native (`Deno.upgradeWebSocket`) |
|
|
115
117
|
| **Password Hashing (`Hash`)** | ✅ Native (`Argon2id` / `bcrypt`) | ✅ Native (`scrypt`) · Optional `Argon2id` | ✅ Native (`scrypt`) · Optional `Argon2id` |
|
|
116
118
|
|
|
117
119
|
---
|
|
118
120
|
|
|
119
121
|
## Benchmarks (Bun)
|
|
120
122
|
|
|
121
|
-
Measured in-process on **Bun** with [`mitata`](https://github.com/evanwash/mitata) (`benchmarks/fair-suite.ts`). Bold values indicate
|
|
123
|
+
Measured in-process on **Bun** with [`mitata`](https://github.com/evanwash/mitata) (`benchmarks/fair-suite.ts`). Bold values indicate a **mean** latency more than 10% faster than the runner-up; differences under ~10% vary between GitHub Actions runs and are left unbolded (treated as ties). These micro-benchmarks measure framework overhead rather than end-to-end network HTTP throughput, and do not represent Node.js or Deno latency.
|
|
122
124
|
|
|
123
125
|
<!-- MARKER: MULTI_BENCH_SUMMARY_START -->
|
|
124
126
|
|
|
125
127
|
| Scenario | **BareJS** | **ElysiaJS** | **Hono** |
|
|
126
128
|
| :--- | :---: | :---: | :---: |
|
|
127
|
-
| **1. 100 Routes + Dynamic Params** | **`
|
|
128
|
-
| **2. 10 Middlewares + Deep Path** | **`1.
|
|
129
|
-
| **3. POST JSON + Schema Validation** | **`
|
|
130
|
-
| **4. Async Handler + Query Parsing** |
|
|
129
|
+
| **1. 100 Routes + Dynamic Params** | **`979 ns`**<br><sub>`p99: 5.87 µs`</sub> | `1.32 µs`<br><sub>`p99: 6.64 µs`</sub> | `2.80 µs`<br><sub>`p99: 11.53 µs`</sub> |
|
|
130
|
+
| **2. 10 Middlewares + Deep Path** | **`1.00 µs`**<br><sub>`p99: 5.58 µs`</sub> | `1.34 µs`<br><sub>`p99: 6.62 µs`</sub> | `3.12 µs`<br><sub>`p99: 12.05 µs`</sub> |
|
|
131
|
+
| **3. POST JSON + Schema Validation** | **`2.55 µs`**<br><sub>`p99: 9.91 µs`</sub> | `3.14 µs`<br><sub>`p99: 10.48 µs`</sub> | `3.27 µs`<br><sub>`p99: 12.28 µs`</sub> |
|
|
132
|
+
| **4. Async Handler + Query Parsing** | `1.55 µs`<br><sub>`p99: 7.22 µs`</sub> | `1.63 µs`<br><sub>`p99: 7.34 µs`</sub> | `2.15 µs`<br><sub>`p99: 9.11 µs`</sub> |
|
|
131
133
|
|
|
132
|
-
> Last Updated: 2026-11-
|
|
134
|
+
> Last Updated: 2026-11-25 (github action — `linux`, AMD EPYC 9V74 80-Core Processor, Bun `1.4.5`, Elysia `1.4.21`, Hono `4.11.4`)
|
|
133
135
|
|
|
134
136
|
<!-- MARKER: MULTI_BENCH_SUMMARY_END -->
|
|
135
137
|
|
|
136
|
-
See **[BENCHMARKS.md](./BENCHMARKS.md)** for all 7 scenarios (including SQLite
|
|
138
|
+
See **[BENCHMARKS.md](./BENCHMARKS.md)** for all 7 scenarios (including the SQLite Report scenario where Elysia is slightly faster, plus SQLite Write and response secret stripping), methodology, notes, and local reproduction steps, or view the [Continuous Benchmark Dashboard](https://xarhang.github.io/bareJS/dev/benchmarks/).
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Full Capabilities & Built-In Modules
|
|
143
|
+
|
|
144
|
+
BareJS is a complete, zero-boilerplate backend platform—every module below ships in the core package with TypeScript types:
|
|
145
|
+
|
|
146
|
+
| Category | Built-In Capabilities |
|
|
147
|
+
| :--- | :--- |
|
|
148
|
+
| **Core & Routing** | $O(1)$ static `switch` fast-path + radix jump-table (`:params`, `*` wildcards), `BareRouter` sub-app mounting (`app.route()`, `app.use(prefix, router)`), lazy bounded LIFO `Context` pool (`0..65536`), dev-mode Use-After-Free Proxy guard, `app.request()` in-memory test helper |
|
|
149
|
+
| **Validation & Serialization** | Unified `RouteSchemas` (`body`, `query`, `params`, `headers`, `response`, `maxBodySize`) supporting **TypeBox** (`Type`/`t`), **Zod** (`Z`/`z`), and **Native JSON Schema** (`native()`), automatic `number`/`integer`/`boolean`/repeated-array coercion, `413` streaming body limit, `stripUnknown` Mass-Assignment protection, recursive response secret-field stripping |
|
|
150
|
+
| **Type-Safe RPC & Docs** | End-to-end compile-time type inference via `bareClient(app \| url)`, automatic **OpenAPI 3.1** spec (`/docs/json`) + Scalar UI (`/docs`) with `securitySchemes` & `tags`, **JSON-RPC 2.0** (`app.rpc()` with single, batch & notifications) |
|
|
151
|
+
| **Zero-Trust Security** | `bareAuth()` (constant-time HS256 JWT + asymmetric RS256/ES256/JWKS + `revokeToken()`/`isRevoked`), `basicAuth()`, `hasRole()`, `Hash` (Argon2id/bcrypt on Bun; zero-dep `scrypt` fallback on Node/Deno), HMAC-SHA256 signed `HttpOnly` cookies, `cors()`, `csrf()`, `securityHeaders()`, `rateLimit()` (flood-resistant), `trustProxy(false)` |
|
|
152
|
+
| **Resilience & State** | `idempotency()` (`409 IDEMPOTENT_IN_FLIGHT` + `X-Idempotent-Replayed`, caller-scoped), `createSingleflight()` cache-stampede coalescing, `circuitBreaker()` (`503 Retry-After`), `timeout()` (`408`), pluggable `redisStore()` (`Bun.redis` / `ioredis`), overlap-safe `app.cron()` |
|
|
153
|
+
| **Real-Time, Files & Ops** | Parameterized WebSockets (`app.ws('/ws/:room')`), Server-Sent Events (`ctx.sse()`), `ctx.upload()` & $O(\text{chunk})$ streaming `ctx.uploadStream()`, `staticFile()` (ETag, `304`, Range `206`, LRU metadata cache), `compress()` (`zstd`/`br`/`gzip`), `logger()` (`pretty`/`json` + `X-Request-Id`), `healthcheck()` (`/health` + `/ready`), `app.onDrain()` + IPC `DRAIN_REQUEST` |
|
|
154
|
+
| **External Integrations** | Web Standard `ctx.req`/`Response` works out of the box with **Better-Auth**, **GraphQL Yoga**, **Auth0** (JWKS), **Clerk**, **Sentry**, and **OpenTelemetry** — see [docs/integrations.md](./docs/integrations.md) |
|
|
137
155
|
|
|
138
156
|
---
|
|
139
157
|
|
|
140
158
|
## Documentation
|
|
141
159
|
|
|
142
160
|
- **[Comprehensive Guide](./docs/guide.md)** — Validation & auto-coercion, cookies & uploads, security suite, `app.derive()`, WebSockets, SSE, JSON-RPC 2.0, OpenAPI 3.1, and `bareClient`.
|
|
161
|
+
- **[External Integrations](./docs/integrations.md)** — Ready-to-use recipes for Better-Auth, GraphQL Yoga, Auth0, Clerk, Sentry, and OpenTelemetry.
|
|
143
162
|
- **[API & Configuration Reference](./docs/reference.md)** — Complete `Context` (`ctx`) API table, `poolSize`, `bare.config.ts`, and `NODE_ENV` settings.
|
|
144
163
|
- **[Benchmarks](./BENCHMARKS.md)** — Full 7-scenario results and reproduction instructions.
|
|
164
|
+
- **[Security Policy](./SECURITY.md)** — Vulnerability reporting and security hardening guidelines.
|
|
145
165
|
- **[Changelog](./CHANGELOG.md)** — Release history and migration notes.
|
|
146
166
|
- **[`llms.txt`](./llms.txt)** — Token-efficient API reference for AI coding assistants (Cursor, Copilot, Claude, Windsurf).
|
|
147
167
|
|
|
@@ -149,6 +169,7 @@ See **[BENCHMARKS.md](./BENCHMARKS.md)** for all 7 scenarios (including SQLite r
|
|
|
149
169
|
|
|
150
170
|
## Status, Contributing & License
|
|
151
171
|
|
|
152
|
-
- **Status:** Active `0.1.x` development.
|
|
172
|
+
- **Status:** Active `0.1.x` development. The test suite is verified in [CI](./.github/workflows/ci.yml) across **Bun** (`bun test`), **Node.js 20 & 22** (`vitest run` + `tests/node-smoke.mjs`; Node 20 skips `production-db.test.ts` which requires `node:sqlite`), and **Deno 2** (`deno test` + `tests/deno-smoke.ts`; skips `playwright.test.ts` and `production-db.test.ts`).
|
|
173
|
+
- **Security:** See [SECURITY.md](./SECURITY.md) for reporting vulnerabilities.
|
|
153
174
|
- **Contributing:** See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and release workflows.
|
|
154
175
|
- **License:** [MIT](./LICENSE) — Maintained by [xarhang](https://github.com/xarhang).
|