barejs 0.1.50 → 0.1.51

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
@@ -37,17 +37,17 @@ BareJS is engineered to beat both **ElysiaJS** and **Hono** across routing, midd
37
37
  | **7. Live SQLite Report (`SUM`/`AVG`/`GROUP BY`)** | **`91.53 µs`** (`p99: 218 µs`) | — | `94.51 µs` (`p99: 277 µs`) | `103.66 µs` (`p99: 543 µs`) |
38
38
  | **8. Live SQLite Write (`POST` + Validate + `INSERT`)** | **`88.37 µs`** (`2.84 KB`) | — | `88.51 µs` (`2.95 KB`) | `103.73 µs` (`3.33 KB`) |
39
39
 
40
- > Verified with **209 Automated Tests (2,878 assertions)** and **100.00% Function & 100.00% Line Coverage**.
40
+ > Verified with **268 Automated Tests (5,634 assertions)** and **100.00% Function & 100.00% Line Coverage**.
41
41
 
42
42
  <!-- MARKER: PERFORMANCE_TABLE_START -->
43
43
 
44
44
  | Framework | Latency | Speed |
45
45
  | :--- | :--- | :--- |
46
- | **BareJS** | **0.95 µs** | **Baseline** |
47
- | Elysia | 1.17 µs | 1.23x slower |
48
- | Hono | 4.06 µs | 4.26x slower |
46
+ | **BareJS** | **0.87 µs** | **Baseline** |
47
+ | Elysia | 1.14 µs | 1.31x slower |
48
+ | Hono | 3.84 µs | 4.39x slower |
49
49
 
50
- > Last Updated: 2026-11-17 (github action)
50
+ > Last Updated: 2026-11-18 (github action)
51
51
 
52
52
  <!-- MARKER: PERFORMANCE_TABLE_END -->
53
53
 
@@ -60,13 +60,15 @@ BareJS is engineered to beat both **ElysiaJS** and **Hono** across routing, midd
60
60
 
61
61
  * **JIT Pipeline Compilation**: Flattens routes and middleware chains into direct JavaScript functions at startup, using `AsyncFunction` single-handler fast paths and conditional bytecode inlining.
62
62
  * **$O(1)$ Radix Jump-Table Router**: Compiles static branches, dynamic `:params`, and catch-all wildcards (`/*`) into inline `switch` jump-tables.
63
- * **Recursive JIT Response Projector (`compileProjector`)**: Compiles `response` schemas (**TypeBox**, **Zod**, or **Native**) into fixed-shape JS object literals that strip undeclared secret fields (`passwordHash`, `secretToken`) recursively at **`2.01 µs` (`653 B` RAM)**—19.4% faster and 27% lower memory than ElysiaJS.
64
- * **Built-In Payment Idempotency & Singleflight Coalescing**: Prevent double-charges and race conditions with `idempotency()` (`409 IDEMPOTENT_IN_FLIGHT` + `X-Idempotent-Replayed: true`), and eliminate cache-stampede / thundering-herd DB overload with `createSingleflight()`.
63
+ * **Recursive JIT Response Projector & Mass-Assignment Guard**: Compiles `response` schemas into fixed-shape JS object literals (`1.89 µs`, 28% faster than ElysiaJS), and supports `stripUnknown: true` on `body` to prevent Mass-Assignment attacks.
64
+ * **Built-In Resilience (`circuitBreaker`, `idempotency`, `createSingleflight`, `app.cron`)**: Prevent cascading failures (`503 Retry-After`), double-charges (`409 IDEMPOTENT_IN_FLIGHT`), cache stampedes (100 concurrent calls -> 1 DB hit), and overlapping background jobs.
65
+ * **Native Zero-Dep Gzip (`compress`)**: Compresses responses via Bun's native C/Zig `Bun.gzipSync` with `minSize` threshold and automatic SSE/204/304 bypass.
66
+ * **End-to-End Type Inference (`bareClient(app)`)**: Automatic compile-time inference of route paths (across all HTTP methods on shared paths), `params`, `query`, `headers`, `body`, and `response` types directly from your `BareJS` app or mounted `BareRouter`—with zero runtime overhead.
65
67
  * **Concurrency-Safe Object Pooling**: Recycles `Context` instances via a LIFO free-list stack with automatic cleanup on release—zero cross-request state leakage.
66
- * **Dual Response Ergonomics**: Return plain objects/strings directly (Elysia style) OR use chainable `ctx.json()`, `ctx.html()`, `ctx.text()`, `ctx.redirect()`, `ctx.send()` helpers (Hono/Express style).
68
+ * **Dual Response Ergonomics & Full HTTP Methods**: Return plain objects/strings directly (Elysia style) OR use `ctx.json()`, `ctx.html()`, `ctx.text()`, `ctx.redirect()`, `ctx.send()`, with `get`, `post`, `put`, `patch`, `delete`, `options`, `head`, and `all`.
67
69
  * **Unified Schema Validation & Auto-Coercion**: Validate `body`, `query`, `params`, `headers`, `response`, and `maxBodySize` (`413` DoS guard) in one object with **TypeBox**, **Zod**, or **Native JSON Schema**—with automatic `number`/`boolean` coercion on `query` and `params`.
68
- * **Batteries-Included Security Suite**: Built-in `securityHeaders()` (frozen zero-alloc), `cors()` (allowlist/predicate/credentials), `csrf()` (`Sec-Fetch-Site` + `Origin`/`Referer` + double-submit token), `timeout()` (`408`), `rateLimit()` (bounded LRU), `bareAuth()` (constant-time HS256 JWT), `Hash` (Argon2id), HMAC-signed `HttpOnly` cookies, and safe `ctx.upload()`.
69
- * **Real-Time, RPC, OpenAPI 3.1 & Zero-Network Client**: Native WebSocket (`app.ws`), Server-Sent Events (`ctx.sse`), JSON-RPC 2.0 (`app.rpc`), Scalar OpenAPI 3.1 UI (`app.docs`), and `bareClient(app | url)` (supports both in-memory zero-port execution and network HTTP).
70
+ * **Batteries-Included Zero-Trust Security Suite**: Built-in `securityHeaders()`, `cors()`, `csrf()`, `timeout()`, `rateLimit()`, `trustProxy(false)` anti-spoofing, `maxRequestBodySize` server cap, `bareAuth()` (constant-time HS256 JWT + `revokeToken()` / `isRevoked`), `Hash` (Argon2id), HMAC-signed cookies, `ctx.upload()`, and symlink-safe `staticFile()`.
71
+ * **Observability, Real-Time, RPC & OpenAPI 3.1**: Built-in `logger()` (`pretty`/`json` + `X-Request-Id`), `healthcheck()` (`/health` + `/ready`), parameterized WebSockets (`app.ws('/ws/:room')`), SSE (`ctx.sse`), JSON-RPC 2.0 (`app.rpc`), and OpenAPI 3.1 (`app.docs`) with `securitySchemes`, `servers`, and `tags`.
70
72
 
71
73
  ---
72
74
 
@@ -303,6 +305,41 @@ const remoteRes = await httpClient.get('/users/:id', { params: { id: 42 }, query
303
305
 
304
306
  ---
305
307
 
308
+ ### 6. 🛡️ Production Observability & Zero-Trust Hardening
309
+
310
+ ```typescript
311
+ import { BareJS, logger, healthcheck, bareAuth, revokeToken } from 'barejs';
312
+
313
+ const app = new BareJS()
314
+ .trustProxy(false) // Ignore spoofed X-Forwarded-For when directly exposed
315
+ .use(logger({ format: 'json' })) // Structured JSON logs + X-Request-Id
316
+ .use(healthcheck({
317
+ path: '/health',
318
+ readyPath: '/ready',
319
+ version: '1.0.0',
320
+ checks: { db: async () => true }
321
+ }))
322
+ .use(bareAuth({
323
+ secret: process.env.JWT_SECRET!,
324
+ isRevoked: async (payload) => isBlockedInRedis(payload.jti)
325
+ }));
326
+
327
+ // Revoke a compromised token or jti immediately
328
+ revokeToken('compromised-jti-123', 3600_000);
329
+
330
+ // OpenAPI 3.1 with Bearer JWT securitySchemes
331
+ app.docs('/docs', {
332
+ title: 'Production API',
333
+ securitySchemes: { bearerAuth: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' } },
334
+ security: [{ bearerAuth: [] }]
335
+ });
336
+
337
+ // Enforce server-level maxRequestBodySize (default: 10MB)
338
+ app.listen(3000, '0.0.0.0', true, { maxRequestBodySize: 2 * 1024 * 1024 });
339
+ ```
340
+
341
+ ---
342
+
306
343
  ## 🧠 Complete `Context` (`ctx`) Reference
307
344
 
308
345
  | Method / Property | Description |