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 +47 -10
- package/dist/index.js +92 -91
- package/dist/types/client/index.d.ts +23 -23
- package/dist/types/core/bare.d.ts +74 -4
- package/dist/types/core/context.d.ts +2 -0
- package/dist/types/core/router.d.ts +19 -9
- package/dist/types/index.d.ts +8 -4
- package/dist/types/security/auth.d.ts +10 -3
- package/dist/types/security/resilience.d.ts +17 -0
- package/dist/types/security/validators.d.ts +2 -0
- package/dist/types/utils/compress.d.ts +12 -0
- package/dist/types/utils/health.d.ts +17 -0
- package/dist/types/utils/logger.d.ts +22 -0
- package/dist/types/utils/openapi.d.ts +23 -1
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/src/client/index.ts +58 -17
- package/src/core/bare.ts +216 -20
- package/src/core/context.ts +12 -7
- package/src/core/router.ts +27 -11
- package/src/index.ts +8 -4
- package/src/security/auth.ts +67 -11
- package/src/security/hash.ts +8 -2
- package/src/security/idempotency.ts +22 -3
- package/src/security/rateLimit.ts +1 -6
- package/src/security/resilience.ts +91 -0
- package/src/security/validators.ts +4 -1
- package/src/utils/compress.ts +49 -0
- package/src/utils/health.ts +65 -0
- package/src/utils/logger.ts +66 -0
- package/src/utils/openapi.ts +10 -0
- package/src/utils/static.ts +11 -2
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 **
|
|
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.
|
|
47
|
-
| Elysia | 1.
|
|
48
|
-
| Hono |
|
|
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-
|
|
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
|
|
64
|
-
* **Built-In
|
|
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
|
|
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()
|
|
69
|
-
* **Real-Time, RPC
|
|
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 |
|