barejs 0.2.5 → 0.2.7

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
@@ -50,6 +50,23 @@ app.listen(3000);
50
50
 
51
51
  ## Installation & Quick Start
52
52
 
53
+ ### Official Starter CLI ([`create-barejs`](https://github.com/xarhang/create-barejs))
54
+
55
+ Scaffold a production-ready project (with JSON logging, `securityHeaders()`, `healthcheck()`, and OpenAPI 3.1 + Scalar `/docs`) in one command:
56
+
57
+ ```bash
58
+ # Interactive (prompts for Bun, Node.js, Node.js + uWebSockets.js, or Deno)
59
+ bun create barejs my-app
60
+
61
+ # Or choose a runtime directly:
62
+ bun create barejs my-bun-app --bun
63
+ bun create barejs my-node-app --node
64
+ bun create barejs my-uws-app --node-uws
65
+ bun create barejs my-deno-app --deno
66
+ ```
67
+
68
+ ### Manual Installation
69
+
53
70
  <details open>
54
71
  <summary><strong>Bun (&gt;= 1.1.0)</strong></summary>
55
72
 
@@ -110,7 +127,7 @@ Deno.serve({ port: 3000 }, (req, info) => app.fetch(req, info.remoteAddr.hostnam
110
127
  ```typescript
111
128
  import { BareJS, cors, securityHeaders } from 'barejs/edge';
112
129
 
113
- // Zero node:* imports (~195 KB bundle)
130
+ // Zero node:* imports (~50 KB bundle)
114
131
  const app = new BareJS<{ API_KEY: string }>()
115
132
  .use(securityHeaders())
116
133
  .use(cors({ origin: '*' }))
@@ -154,10 +171,10 @@ Measured in-process on **Bun** with [`mitata`](https://github.com/evanwash/mitat
154
171
 
155
172
  | Scenario | **BareJS** | **ElysiaJS** | **Hono** |
156
173
  | :--- | :---: | :---: | :---: |
157
- | **1. 100 Routes + Dynamic Params** | **`1.41 µs`**<br><sub>`p99: 7.67 µs`</sub> | `1.94 µs`<br><sub>`p99: 9.19 µs`</sub> | `3.76 µs`<br><sub>`p99: 14.06 µs`</sub> |
158
- | **2. 10 Middlewares + Deep Path** | **`1.54 µs`**<br><sub>`p99: 8.16 µs`</sub> | `2.03 µs`<br><sub>`p99: 9.06 µs`</sub> | `4.17 µs`<br><sub>`p99: 15.06 µs`</sub> |
159
- | **3. POST JSON + Schema Validation** | **`4.23 µs`**<br><sub>`p99: 14.34 µs`</sub> | `4.74 µs`<br><sub>`p99: 15.49 µs`</sub> | `4.68 µs`<br><sub>`p99: 16.31 µs`</sub> |
160
- | **4. Async Handler + Query Parsing** | `2.25 µs`<br><sub>`p99: 9.48 µs`</sub> | `2.46 µs`<br><sub>`p99: 10.30 µs`</sub> | `3.27 µs`<br><sub>`p99: 13.20 µs`</sub> |
174
+ | **1. 100 Routes + Dynamic Params** | **`1.31 µs`**<br><sub>`p99: 8.02 µs`</sub> | `1.82 µs`<br><sub>`p99: 8.54 µs`</sub> | `4.16 µs`<br><sub>`p99: 15.57 µs`</sub> |
175
+ | **2. 10 Middlewares + Deep Path** | **`1.13 µs`**<br><sub>`p99: 6.53 µs`</sub> | `2.02 µs`<br><sub>`p99: 9.29 µs`</sub> | `4.07 µs`<br><sub>`p99: 15.11 µs`</sub> |
176
+ | **3. POST JSON + Schema Validation** | **`3.54 µs`**<br><sub>`p99: 12.30 µs`</sub> | `4.53 µs`<br><sub>`p99: 14.47 µs`</sub> | `4.89 µs`<br><sub>`p99: 15.93 µs`</sub> |
177
+ | **4. Async Handler + Query Parsing** | **`2.11 µs`**<br><sub>`p99: 9.87 µs`</sub> | `2.44 µs`<br><sub>`p99: 10.52 µs`</sub> | `3.17 µs`<br><sub>`p99: 12.50 µs`</sub> |
161
178
 
162
179
  > Last Updated: 2026-11-30 (github action — `linux`, AMD EPYC 7763 64-Core Processor, Bun `1.4.5`, Elysia `1.4.21`, Hono `4.11.4`)
163
180
 
@@ -173,20 +190,21 @@ BareJS is a complete, zero-boilerplate backend platform—every module below shi
173
190
 
174
191
  | Category | Built-In Capabilities |
175
192
  | :--- | :--- |
176
- | **Core & Routing** | $O(1)$ static `switch` fast-path + radix jump-table (`:params`, `*` wildcards), Bun native `routes` fast-path, optional Node.js **`uWebSockets.js`** driver (`engine: 'uws'`), native **`tls`** option (Bun, `uWS.SSLApp`, Node `https`), zero-Node **`barejs/edge`** entrypoint (Cloudflare Workers, Vercel Edge, Deno Deploy), `app.listenCluster()` multi-core clustering, `BareRouter` sub-app mounting, lazy bounded LIFO `Context` pool (`0..65536`), `app.onRequest()`/`app.onResponse()` hooks, `app.request()` test helper |
177
- | **Validation & Serialization** | Unified `RouteSchemas` (`body`, `query`, `params`, `headers`, `response`, `maxBodySize`) supporting **Standard Schema v1** (Valibot, ArkType, Zod 4, Effect — async fail-closed), **TypeBox** (`Type`/`t`), **Zod** (`Z`/`z`), and **Native JSON Schema** (`native()`), automatic coercion, `413` streaming body limit, `stripUnknown` Mass-Assignment protection, recursive response secret-field stripping |
178
- | **Type-Safe RPC & Docs** | `bareClient(app \| url)` (with non-throwing `client.safe` Result union & typed `client.ws()`), chained proxy **`bareTreaty(app \| url)`** (`api.users({ id: 42 }).get()` & `.subscribe()` WebSocket in-memory or network), automatic **OpenAPI 3.1** spec (`/docs/json`) + Scalar UI (`/docs`), **JSON-RPC 2.0** (`app.rpc()`) |
179
- | **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(boolean \| string[])` CIDR allowlist |
193
+ | **Core & Routing** | $O(1)$ static `switch` + radix jump-table + $O(1)$ grouped sibling dispatch (`:params`, `*` wildcards), Bun native `routes` fast-path, optional Node.js **`uWebSockets.js`** driver (`engine: 'uws'`), native **`tls`** option (Bun, `uWS.SSLApp`, Node `https`), zero-Node **`barejs/edge`** entrypoint (`50 KB` bundle for Cloudflare Workers, Vercel Edge, Deno Deploy), `app.listenCluster()`, composable `app.use(plugin)` carrying routes + **`app.macro()`**, lazy bounded LIFO `Context` pool (`0..65536`), `app.onRequest()`/`app.onResponse()` hooks, `app.request()` test helper |
194
+ | **Validation & Serialization** | Unified `RouteSchemas` (`body`, `query`, `params`, `headers`, **`cookies`**, single or **per-status `response: { 200, 404 }`**, `maxBodySize`) supporting **Standard Schema v1** (Valibot, ArkType, Zod 4, Effect — async fail-closed), **TypeBox** (`Type`/`t`), **Zod** (`Z`/`z`), and **Native JSON Schema** (`native()`), automatic coercion, `413` streaming body limit, `stripUnknown` Mass-Assignment protection, recursive response secret-field stripping |
195
+ | **Type-Safe RPC & Docs** | `bareClient(app \| url)` (with non-throwing `client.safe` Result union & typed `client.ws()`), strict compile-time **`bareTreaty(app \| url)`** (`api.users({ id: 42 }).get()` & `.subscribe()` WebSocket in-memory or network with typed `data`/`error` unions), automatic **OpenAPI 3.1** spec (`/docs/json`, per-status responses & cookie params) + Scalar UI (`/docs`), **JSON-RPC 2.0** (`app.rpc()`) |
196
+ | **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, CRLF header/cookie/redirect guards, `cors()`, `csrf()`, `securityHeaders()`, `rateLimit()` (flood-resistant), `trustProxy(boolean \| string[])` CIDR allowlist |
180
197
  | **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()` |
181
- | **Real-Time, Files & Ops** | Parameterized WebSockets (`app.ws('/ws/:room')` with pub/sub on Bun & `uWebSockets.js`), Server-Sent Events (`ctx.sse()`), `ctx.upload()` & $O(\text{chunk})$ streaming `ctx.uploadStream()`, `staticFile()` (ETag, `304`, Range `206`, SPA fallback, LRU metadata cache), `compress()` (`zstd`/`br`/`gzip`), `useLog({ format: 'json' })` + `logger()`, `healthcheck()` (`/health` + `/ready`), `app.onDrain()` + IPC `DRAIN_REQUEST` |
198
+ | **Real-Time, Files & Ops** | Parameterized WebSockets (`app.ws('/ws/:room')` with fail-closed `body`/`query`/`headers` schemas & pub/sub on Bun / `uWebSockets.js`), **Generator Streaming** (`function*` / `async function*`), Server-Sent Events (`ctx.sse()`), **`file()` 1-liner** (root jail + download), `ctx.upload()` & $O(\text{chunk})$ streaming `ctx.uploadStream()`, `staticFile()` (ETag, `304`, Range `206`, SPA fallback, LRU cache), `compress()` (`zstd`/`br`/`gzip`), zero-dep W3C **`tracing()` / `serverTiming()`**, `useLog({ format: 'json' })`, `healthcheck()`, `app.onDrain()` + IPC `DRAIN_REQUEST` |
182
199
  | **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) |
183
200
 
184
201
  ---
185
202
 
186
203
  ## Documentation
187
204
 
188
- - **[Documentation Site](https://xarhang.github.io/bareJS/)** — Interactive docs, code examples, and live CI benchmark dashboard.
189
- - **[Comprehensive Guide](./docs/guide.md)** — Validation & auto-coercion, cookies & uploads, security suite, `app.derive()`, WebSockets, SSE, JSON-RPC 2.0, OpenAPI 3.1, `listenCluster()`, `uWebSockets.js`, native `tls`, `barejs/edge`, and `bareClient`/`bareTreaty`.
205
+ - **[Documentation Site](https://xarhang.github.io/bareJS/)** — Interactive docs with `Ctrl+K` instant search, sticky TOC, code examples, and live CI benchmark dashboard.
206
+ - **[`create-barejs` Starter CLI](https://github.com/xarhang/create-barejs)** — Official multi-runtime project scaffolding (`bun create barejs my-app --bun|--node|--node-uws|--deno`).
207
+ - **[Comprehensive Guide](./docs/guide.md)** — Scaffolding, validation & auto-coercion, cookies & uploads, `file()`, generator streaming, security suite, `app.derive()`, `app.macro()`, WebSockets, SSE, JSON-RPC 2.0, OpenAPI 3.1, `tracing()`/`serverTiming()`, `listenCluster()`, `uWebSockets.js`, native `tls`, `barejs/edge`, and `bareClient`/`bareTreaty`.
190
208
  - **[External Integrations](./docs/integrations.md)** — Ready-to-use recipes for Better-Auth, GraphQL Yoga, Auth0, Clerk, Sentry, and OpenTelemetry.
191
209
  - **[API & Configuration Reference](./docs/reference.md)** — Complete `Context` (`ctx`) & `BareJS` API tables, `poolSize`, `bare.config.ts`, and `NODE_ENV` settings.
192
210
  - **[Benchmarks](./BENCHMARKS.md)** — Full 7-scenario results and reproduction instructions.
@@ -198,7 +216,7 @@ BareJS is a complete, zero-boilerplate backend platform—every module below shi
198
216
 
199
217
  ## Status, Contributing & License
200
218
 
201
- - **Status:** Active `0.2.x` development (**483 tests / 6,740 assertions**). 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`).
219
+ - **Status:** Active `0.2.x` development (**493 tests across 35 files**). 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`).
202
220
  - **Security:** See [SECURITY.md](./SECURITY.md) for reporting vulnerabilities.
203
221
  - **Contributing:** See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and release workflows.
204
222
  - **License:** [MIT](./LICENSE) — Maintained by [xarhang](https://github.com/xarhang).