jiren 1.5.5 → 1.6.0

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.
Files changed (44) hide show
  1. package/README.md +77 -21
  2. package/components/cache.ts +1 -1
  3. package/components/client-node-native.ts +497 -159
  4. package/components/client.ts +51 -29
  5. package/components/metrics.ts +1 -4
  6. package/components/native-node.ts +7 -3
  7. package/components/native.ts +29 -0
  8. package/components/persistent-worker.ts +73 -0
  9. package/components/subprocess-worker.ts +65 -0
  10. package/components/worker-pool.ts +169 -0
  11. package/components/worker.ts +39 -23
  12. package/dist/components/cache.d.ts +76 -0
  13. package/dist/components/cache.d.ts.map +1 -0
  14. package/dist/components/cache.js +439 -0
  15. package/dist/components/cache.js.map +1 -0
  16. package/dist/components/client-node-native.d.ts +114 -0
  17. package/dist/components/client-node-native.d.ts.map +1 -0
  18. package/dist/components/client-node-native.js +744 -0
  19. package/dist/components/client-node-native.js.map +1 -0
  20. package/dist/components/metrics.d.ts +104 -0
  21. package/dist/components/metrics.d.ts.map +1 -0
  22. package/dist/components/metrics.js +296 -0
  23. package/dist/components/metrics.js.map +1 -0
  24. package/dist/components/native-node.d.ts +60 -0
  25. package/dist/components/native-node.d.ts.map +1 -0
  26. package/dist/components/native-node.js +108 -0
  27. package/dist/components/native-node.js.map +1 -0
  28. package/dist/components/types.d.ts +250 -0
  29. package/dist/components/types.d.ts.map +1 -0
  30. package/dist/components/types.js +5 -0
  31. package/dist/components/types.js.map +1 -0
  32. package/dist/index-node.d.ts +10 -0
  33. package/dist/index-node.d.ts.map +1 -0
  34. package/dist/index-node.js +12 -0
  35. package/dist/index-node.js.map +1 -0
  36. package/dist/types/index.d.ts +63 -0
  37. package/dist/types/index.d.ts.map +1 -0
  38. package/dist/types/index.js +6 -0
  39. package/dist/types/index.js.map +1 -0
  40. package/index-node.ts +6 -6
  41. package/index.ts +4 -3
  42. package/lib/libhttpclient.dylib +0 -0
  43. package/package.json +13 -5
  44. package/types/index.ts +0 -68
package/README.md CHANGED
@@ -7,16 +7,30 @@
7
7
 
8
8
  ---
9
9
 
10
+ ## ⚡ Performance: Fastest in the World
11
+
12
+ Jiren outperforms top clients in every metric—throughput, latency, and stability.
13
+
14
+ | Client | Avg Latency | P99 Latency | Throughput | Relative Speed |
15
+ | --------- | ----------- | ----------- | ------------ | -------------- |
16
+ | **Jiren** | **21.6 µs** | **46.0 µs** | **46,000/s** | **🚀 Fastest** |
17
+ | Bun Fetch | 30.7 µs | 58.5 µs | 32,500/s | 1.4x Slower |
18
+ | Undici | 34.1 µs | 76.5 µs | 29,300/s | 1.6x Slower |
19
+ | Ky | 37.2 µs | 57.0 µs | 26,900/s | 1.7x Slower |
20
+ | Axios | 59.6 µs | 122.1 µs | 16,700/s | 2.8x Slower |
21
+
22
+ ---
23
+
10
24
  ## ✨ Why Jiren?
11
25
 
12
- | Feature | Benefit |
13
- | ------------------------ | ------------------------------------------------- |
14
- | ⚡ **Blazing Fast** | 2-3x faster than native `fetch` |
15
- | **HTTP/3 Support** | Automatic protocol upgrade for faster connections |
16
- | �💾 **Built-in Caching** | Automatic response caching with zero config |
17
- | 📝 **Type-Safe** | Full TypeScript support with autocomplete |
18
- | 🔒 **Anti-Bot Ready** | Bypass common bot protections easily |
19
- | 📊 **Built-in Metrics** | Track performance out of the box |
26
+ | Feature | Benefit |
27
+ | ----------------------- | ------------------------------------------------- |
28
+ | ⚡ **Blazing Fast** | Proven to be the fastest JS HTTP client |
29
+ | **HTTP/3 Support** | Automatic protocol upgrade for faster connections |
30
+ | 💾 **Built-in Caching** | Automatic response caching with zero config |
31
+ | 📝 **Type-Safe** | Full TypeScript support with autocomplete |
32
+ | 🔒 **Anti-Bot Ready** | Bypass common bot protections easily |
33
+ | 📊 **Built-in Metrics** | Track performance out of the box |
20
34
 
21
35
  ---
22
36
 
@@ -36,7 +50,7 @@ bun add jiren
36
50
  import { JirenClient } from "jiren";
37
51
 
38
52
  const client = new JirenClient({
39
- warmup: {
53
+ targets: {
40
54
  api: "https://api.example.com",
41
55
  github: "https://api.github.com",
42
56
  },
@@ -173,7 +187,7 @@ Enable caching for instant responses on repeated requests:
173
187
 
174
188
  ```typescript
175
189
  const client = new JirenClient({
176
- warmup: {
190
+ targets: {
177
191
  api: {
178
192
  url: "https://api.example.com",
179
193
  cache: true, // ← Enable caching (60s default)
@@ -186,7 +200,7 @@ const client = new JirenClient({
186
200
 
187
201
  ```typescript
188
202
  const client = new JirenClient({
189
- warmup: {
203
+ targets: {
190
204
  api: {
191
205
  url: "https://api.example.com",
192
206
  cache: { ttl: 300000 }, // 5 minutes
@@ -206,6 +220,10 @@ const client = new JirenClient({
206
220
  | First request | ~150ms | - |
207
221
  | Cached request | ~1-2ms | **100x faster** ⚡ |
208
222
 
223
+ ### 🚀 Performance Benchmark
224
+
225
+ See the [top of this README](#-performance-fastest-in-the-world) for detailed benchmark results. Jiren consistently wins on throughput and tail latency.
226
+
209
227
  ### Refresh Cache
210
228
 
211
229
  ```typescript
@@ -223,7 +241,7 @@ Bypass Cloudflare and other bot protections:
223
241
 
224
242
  ```typescript
225
243
  const client = new JirenClient({
226
- warmup: {
244
+ targets: {
227
245
  protected: "https://protected-site.com",
228
246
  },
229
247
  antibot: true,
@@ -242,7 +260,7 @@ Add middleware to modify requests/responses:
242
260
 
243
261
  ```typescript
244
262
  const client = new JirenClient({
245
- warmup: { api: "https://api.example.com" },
263
+ targets: { api: "https://api.example.com" },
246
264
  interceptors: {
247
265
  request: [
248
266
  (ctx) => ({
@@ -261,7 +279,7 @@ const client = new JirenClient({
261
279
 
262
280
  ```typescript
263
281
  const client = new JirenClient({
264
- warmup: { api: "https://api.example.com" },
282
+ targets: { api: "https://api.example.com" },
265
283
  interceptors: {
266
284
  response: [
267
285
  (ctx) => {
@@ -277,7 +295,7 @@ const client = new JirenClient({
277
295
 
278
296
  ```typescript
279
297
  const client = new JirenClient({
280
- warmup: { api: "https://api.example.com" },
298
+ targets: { api: "https://api.example.com" },
281
299
  interceptors: {
282
300
  error: [
283
301
  (error, ctx) => {
@@ -360,7 +378,7 @@ console.log(user.name); // ✅ Autocomplete works!
360
378
 
361
379
  ```typescript
362
380
  const client = new JirenClient({
363
- warmup: {
381
+ targets: {
364
382
  api: "https://api.example.com",
365
383
  cdn: "https://cdn.example.com",
366
384
  },
@@ -379,7 +397,7 @@ client.url.foo.get(); // ❌ TypeScript error!
379
397
 
380
398
  ```typescript
381
399
  new JirenClient({
382
- warmup: {
400
+ targets: {
383
401
  // Simple URL
384
402
  api: "https://api.example.com",
385
403
 
@@ -451,7 +469,7 @@ new JirenClient({
451
469
  import { JirenClient } from "jiren";
452
470
 
453
471
  export const api = new JirenClient({
454
- warmup: {
472
+ targets: {
455
473
  backend: {
456
474
  url: process.env.API_URL!,
457
475
  cache: { ttl: 30000 },
@@ -511,15 +529,53 @@ function UserList() {
511
529
 
512
530
  ---
513
531
 
532
+ ## 🏗️ Framework Integration
533
+
534
+ ### Next.js (App Router)
535
+
536
+ To use Jiren in Next.js, add it to `serverExternalPackages` in `next.config.ts`:
537
+
538
+ ```typescript
539
+ import type { NextConfig } from "next";
540
+
541
+ const nextConfig: NextConfig = {
542
+ // Required: Treat Jiren and Koffi as external native packages
543
+ serverExternalPackages: ["jiren", "koffi"],
544
+ };
545
+
546
+ export default nextConfig;
547
+ ```
548
+
549
+ **Usage in API Routes:**
550
+
551
+ ```typescript
552
+ // app/api/data/route.ts
553
+ import { JirenClient } from "jiren";
554
+
555
+ const client = new JirenClient({
556
+ targets: [{ key: "api", url: "https://api.example.com" }],
557
+ });
558
+
559
+ export async function GET() {
560
+ const response = await client.url.api.get({ path: "/users" });
561
+ return Response.json(await response.body.json());
562
+ }
563
+ ```
564
+
565
+ ---
566
+
514
567
  ## 📋 Requirements
515
568
 
516
- - **Bun** v1.0.0+
569
+ - **Runtime**:
570
+ - **Bun** v1.0.0+
571
+ - **Node.js** v18.0.0+ (macOS/Linux)
572
+ - **OS**: macOS (ARM64/x64) or Linux (x64)
517
573
 
518
574
  ---
519
575
 
520
576
  ## 📄 License
521
577
 
522
- MIT © Vikash Khati
578
+ MIT © VK
523
579
 
524
580
  ---
525
581
 
@@ -538,5 +594,5 @@ Contributions welcome! Please open an issue or submit a pull request.
538
594
  ---
539
595
 
540
596
  <p align="center">
541
- <strong>Made with ⚡ by Vikash Khati</strong>
597
+ <strong>Made with ⚡ by VK</strong>
542
598
  </p>
@@ -10,7 +10,7 @@ import {
10
10
  import { gzipSync, gunzipSync } from "zlib";
11
11
  import { createHash } from "crypto";
12
12
  import { join } from "path";
13
- import type { JirenResponse, JirenResponseBody } from "./types";
13
+ import type { JirenResponse, JirenResponseBody } from "./types.js";
14
14
 
15
15
  /**
16
16
  * Serializable cache entry - stores raw body data for reconstruction