hyperttp 0.4.2 → 0.4.5

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
@@ -1,15 +1,39 @@
1
1
  # Hyperttp ⚡
2
2
 
3
- [English](https://github.com/Dirold2/hyperttp) • [Русский](https://github.com/Dirold2/hyperttp/tree/main/lang/ru)
3
+ > English | [Русский](https://github.com/Dirold2/hyperttp/tree/main/lang/ru)
4
4
 
5
- An advanced, high-performance HTTP client for Node.js and Bun featuring built-in caching, rate limiting,
6
- request queuing, inflight request deduplication, performance metrics, and a fluent chainable API.
7
- Built as a feature-rich, production-ready extension over the optimized `@hyperttp/core` engine.
5
+ [![npm version](https://img.shields.io/npm/v/hyperttp)](https://www.npmjs.com/package/hyperttp)
6
+ [![npm downloads](https://img.shields.io/npm/dm/hyperttp)](https://www.npmjs.com/package/hyperttp)
7
+ [![license](https://img.shields.io/npm/l/hyperttp)](./LICENSE)
8
+ [![typescript](https://img.shields.io/badge/TypeScript-strict-blue)](https://www.typescriptlang.org/)
9
+
10
+ ---
11
+
12
+ ## 🌐 Language
13
+
14
+ - 🇺🇸 English
15
+ - 🇷🇺 [Русский](https://github.com/Dirold2/hyperttp/tree/main/lang/ru)
16
+
17
+ ---
18
+
19
+ ## 🔗 Quick Links
20
+
21
+ - 🏢 **Organization:** [github.com/IT-IF-OR](https://github.com/IT-IF-OR)
22
+ - 👤 **Author:** [github.com/dirold2](https://github.com/dirold2)
23
+ - 📦 **npm:** [npmjs.com/org/hyperttp](https://www.npmjs.com/org/hyperttp)
24
+ - ⚙️ **Core engine:** [`@hyperttp/core`](https://www.npmjs.com/package/@hyperttp/core)
25
+
26
+ ---
27
+
28
+ **Hyperttp** is a batteries-included, high-performance HTTP client for Node.js, Bun, Deno, and Browser environments.
29
+ It is a feature-rich, production-ready extension over the optimized [`@hyperttp/core`](https://www.npmjs.com/package/@hyperttp/core) engine,
30
+ shipping with caching, rate limiting, request queuing, inflight deduplication, performance metrics, and a fluent chainable API — all pre-wired and ready to use.
8
31
 
9
32
  ---
10
33
 
11
34
  ## 🔥 Key Features
12
35
 
36
+ - **🎯 Smart Response Parsing:** Automatically parses responses based on `responseType` (`json`, `text`, `xml`, `html`, `buffer`, `blob`, `stream`).
13
37
  - **🔀 Concurrency Management:** Built-in queue plugin (`withQueue`) to strictly enforce concurrent request limits.
14
38
  - **💾 Smart LRU Caching:** Dedicated caching layer (`withCache`) with TTL support to prevent redundant network drift.
15
39
  - **🚦 Rate Limiting:** Built-in Token Bucket algorithm to protect against external API blocks and rate limits.
@@ -17,6 +41,33 @@ Built as a feature-rich, production-ready extension over the optimized `@hypertt
17
41
  - **📈 Real-Time Metrics:** Out-of-the-box telemetry tracking latencies, RPS, cache hits, and overall client health.
18
42
  - **🔌 Modular Architecture:** Clean pipeline approach allowing custom plugins, serialization layers, and interceptors.
19
43
  - **💎 Fluent Request Builder API:** Clean, chainable API syntax to compose and configure requests with ease.
44
+ - **🗜️ Transparent Decompression:** Automatic handling of `gzip`, `deflate`, and `br` (Brotli) out of the box.
45
+
46
+ ---
47
+
48
+ ## 📦 Ecosystem Packages
49
+
50
+ | Package | Description | Repository |
51
+ | ---------------------------------------------------------------------------------------- | -------------------------------------------- | --------------------------------------------------------------- |
52
+ | **`hyperttp`** (you are here) | High-level client with all plugins pre-wired | [GitHub](https://github.com/dirold2/hyperttp) |
53
+ | [`@hyperttp/core`](https://www.npmjs.com/package/@hyperttp/core) | Low-level core with transport pipeline | [GitHub](https://github.com/IT-IF-OR/hyperttp-core) |
54
+ | [`@hyperttp/types`](https://www.npmjs.com/package/@hyperttp/types) | Shared TypeScript type definitions | [GitHub](https://github.com/dirold2/hyperttp-types) |
55
+ | [`@hyperttp/transport-bun`](https://www.npmjs.com/package/@hyperttp/transport-bun) | Native Bun transport | [GitHub](https://github.com/IT-IF-OR/hyperttp-transport-bun) |
56
+ | [`@hyperttp/transport-undici`](https://www.npmjs.com/package/@hyperttp/transport-undici) | Undici transport for Node.js | [GitHub](https://github.com/IT-IF-OR/hyperttp-transport-undici) |
57
+ | [`@hyperttp/parser`](https://www.npmjs.com/package/@hyperttp/parser) | Response body parser (JSON/XML/HTML) | [GitHub](https://github.com/IT-IF-OR/hyperttp-parser) |
58
+ | [`@hyperttp/serializer`](https://www.npmjs.com/package/@hyperttp/serializer) | Request body serializer | [GitHub](https://github.com/IT-IF-OR/hyperttp-serializer) |
59
+ | [`@hyperttp/cache`](https://www.npmjs.com/package/@hyperttp/cache) | HTTP response caching | [GitHub](https://github.com/IT-IF-OR/hyperttp-cache) |
60
+ | [`@hyperttp/queue`](https://www.npmjs.com/package/@hyperttp/queue) | Request queueing | [GitHub](https://github.com/IT-IF-OR/hyperttp-queue) |
61
+ | [`@hyperttp/ratelimit`](https://www.npmjs.com/package/@hyperttp/ratelimit) | Rate limiting | [GitHub](https://github.com/IT-IF-OR/hyperttp-ratelimit) |
62
+ | [`@hyperttp/inflight`](https://www.npmjs.com/package/@hyperttp/inflight) | In-flight request deduplication | [GitHub](https://github.com/IT-IF-OR/hyperttp-inflight) |
63
+ | [`@hyperttp/interceptors`](https://www.npmjs.com/package/@hyperttp/interceptors) | Request/response interceptors | [GitHub](https://github.com/IT-IF-OR/hyperttp-interceptors) |
64
+ | [`@hyperttp/metrics`](https://www.npmjs.com/package/@hyperttp/metrics) | Performance metrics | [GitHub](https://github.com/IT-IF-OR/hyperttp-metrics) |
65
+
66
+ ### Which package should I use?
67
+
68
+ - **Just need HTTP requests with caching, retries, and parsing?** → Use `hyperttp` (this package)
69
+ - **Need full control over the pipeline?** → Use `@hyperttp/core`
70
+ - **Building a custom transport or plugin?** → Use `@hyperttp/types`
20
71
 
21
72
  ---
22
73
 
@@ -25,13 +76,16 @@ Built as a feature-rich, production-ready extension over the optimized `@hypertt
25
76
  ```bash
26
77
  npm install hyperttp
27
78
 
79
+ # Optional: install a specific transport
80
+ npm install @hyperttp/transport-bun # for Bun
81
+ npm install @hyperttp/transport-undici # for Node.js
28
82
  ```
29
83
 
30
84
  ---
31
85
 
32
86
  ## 📦 Quick Start
33
87
 
34
- Simply import `HyperClient` and start dispatched requests. Core features like caching, queue management,
88
+ Simply import `HyperClient` and start dispatching requests. Core features like caching, queue management,
35
89
  and rate limiting are instantly preconfigured and active out of the box.
36
90
 
37
91
  ```typescript
@@ -43,9 +97,35 @@ const client = new HyperClient();
43
97
  const data = await client.get<MyDataType>("https://api.example.com/data");
44
98
 
45
99
  // POST request specifying expected response type alongside body payload
46
- const newItem = await client.post("https://api.example.com/items", "json", {
100
+ const newItem = await client.post<Item>("https://api.example.com/items", "json", {
47
101
  name: "New Item Structure",
48
102
  });
103
+
104
+ // Explicit response type
105
+ const html = await client.get<string>("https://example.com", "text");
106
+ const xml = await client.get<XmlDoc>("https://api.example.com/feed.xml", "xml");
107
+
108
+ // Streaming responses (e.g., LLM completions)
109
+ const chatStream = await client.stream("https://api.openai.com/v1/chat/completions");
110
+ const reader = chatStream.body.getReader();
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 💎 Fluent Builder API
116
+
117
+ Invoke the `.request(url)` chain to programmatically craft highly specific request structures on the fly:
118
+
119
+ ```typescript
120
+ const user = await client
121
+ .request("https://api.example.com/users")
122
+ .post() // Specify HTTP Method (Defaults to GET)
123
+ .query({ include: "profile" }) // Safely append and encode Query Parameters
124
+ .headers({ "X-Request-ID": crypto.randomUUID() })
125
+ .jsonBody({ name: "John", email: "john@example.com" }) // Automatically serializes and sets Content-Type header
126
+ .json<User>() // Asserts expected response format (.text(), .buffer(), .stream())
127
+ .timeout(5000) // Instantiates a contextual, request-scoped AbortSignal timeout
128
+ .send();
49
129
  ```
50
130
 
51
131
  ---
@@ -93,9 +173,6 @@ const client = new HyperClient({
93
173
  console.log(`[${level}] ${message}`, meta ?? "");
94
174
  },
95
175
 
96
- // 🔌 Plugin Registration
97
- plugins: [], // Inline custom plugin instances or absolute module paths
98
-
99
176
  // 💾 Extended Plugin Configurations (Injected via HyperttpPluginsExtension)
100
177
  cache: {
101
178
  enabled: true,
@@ -115,23 +192,99 @@ const client = new HyperClient({
115
192
 
116
193
  ---
117
194
 
118
- ## 🛠️ Advanced Features
195
+ ## 🔌 Pre-Wired Plugins
119
196
 
120
- ### Fluent Builder API
197
+ When using `HyperClient`, the following plugins are automatically registered:
121
198
 
122
- Invoke the `.request(url)` chain to programmatically craft highly specific request structures on the fly:
199
+ | Plugin | Purpose |
200
+ | ------------------ | ----------------------------------------------------------- |
201
+ | `withSerializer` | Serializes request bodies (JSON, FormData, URLSearchParams) |
202
+ | `withParser` | Parses response bodies based on `responseType` |
203
+ | `withQueue` | Queues requests when concurrency limit is reached |
204
+ | `withRateLimit` | Enforces rate limits |
205
+ | `withInflight` | Deduplicates in-flight requests |
206
+ | `withCache` | Caches responses based on HTTP headers |
207
+ | `withInterceptors` | Request/response interceptors |
208
+ | `withMetrics` | Collects performance metrics |
209
+
210
+ ### Custom Plugins
211
+
212
+ Extend the client with your own hooks:
123
213
 
124
214
  ```typescript
125
- const result = await client
126
- .request("https://api.example.com/search")
127
- .post() // Specify HTTP Method (Defaults to GET)
128
- .query({ q: "hyperttp", p: 1 }) // Safely append and encode Query Parameters
129
- .headers({ Authorization: "Bearer TOKEN" })
130
- .jsonBody({ activeOnly: true }) // Automatically serializes and sets Content-Type header
131
- .json() // Asserts expected response format (.text(), .buffer(), .stream())
132
- .timeout(5000) // Instantiates a contextual, request-scoped AbortSignal timeout
133
- .send();
215
+ client.use({
216
+ name: "performance-logger",
217
+ priority: 100, // Sorted execution priority (higher runs first)
218
+ mode: "background", // Forces onResponse to run as a non-blocking side-effect
219
+
220
+ setup: (ctx) => {
221
+ ctx.config.logger?.info?.("Plugin active");
222
+ },
223
+
224
+ onRequest: async (req, ctx) => {
225
+ req.meta.startTime = performance.now();
226
+ },
227
+
228
+ onResponse: async (res, req, ctx) => {
229
+ const duration = performance.now() - (req.meta.startTime as number);
230
+ console.log(`[${req.method}] ${req.url} -> ${res.status} (${duration.toFixed(2)}ms)`);
231
+ },
232
+
233
+ onError: async (error, req, ctx) => {
234
+ console.error(`Request failed to ${req.url}: ${error.message}`);
235
+ // Return a response object here to bypass/recover from the failure
236
+ },
237
+ });
238
+ ```
239
+
240
+ ### Plugin Phases
241
+
242
+ | Phase | Hook | Description |
243
+ | ----------- | ---------------- | ------------------------------------------------------- |
244
+ | **REQUEST** | `onRequest` | Intercepts before execution. Supports short-circuiting. |
245
+ | **DATA** | `onResponseData` | Transforms raw transport responses before mapping. |
246
+ | **FORMAT** | `onResponse` | Modifies client-facing responses. |
247
+ | **ERROR** | `onError` | Catches and recovers from errors. |
248
+
249
+ ---
250
+
251
+ ## 🏗️ Architecture Pipeline
252
+
253
+ `HyperClient` structures outbound and inbound requests across a sequential pipeline composed of granular plugins:
254
+
134
255
  ```
256
+ ┌─────────────────────────────────────────────────────────────────┐
257
+ │ HyperClient │
258
+ │ (Auto-wires: Serializer → Parser → Queue → RateLimit → │
259
+ │ Inflight → Cache → Interceptors → Metrics) │
260
+ └──────────────────────────┬──────────────────────────────────────┘
261
+ │
262
+ ▼
263
+ ┌─────────────────────────────────────────────────────────────────┐
264
+ │ HyperCore │
265
+ │ │
266
+ │ 1. Request Pipeline (onRequest) ─── short-circuit capable │
267
+ │ │ │
268
+ │ 2. Transport Execution (HyperTransport) │
269
+ │ ├─ BunTransport (native Bun fetch) │
270
+ │ ├─ UndiciTransport (Node.js) │
271
+ │ └─ NodeTransport (global fetch) │
272
+ │ │ │
273
+ │ 3. Response Data Pipeline (onResponseData) │
274
+ │ │ │
275
+ │ 4. Internal Processing (decompression, mapping) │
276
+ │ │ │
277
+ │ 5. Response Pipeline (onResponse) │
278
+ │ ├─ Mutators (sync/async modification) │
279
+ │ └─ Side Effects (background, non-blocking) │
280
+ │ │ │
281
+ │ 6. Error Pipeline (onError) ─── recovery capable │
282
+ └─────────────────────────────────────────────────────────────────┘
283
+ ```
284
+
285
+ ---
286
+
287
+ ## 🛠️ Advanced Features
135
288
 
136
289
  ### Statistics, Cache, and Metrics Engine
137
290
 
@@ -159,28 +312,58 @@ await client.destroy();
159
312
 
160
313
  ```typescript
161
314
  // Returns an HttpResponse interface carrying a custom ReadableStream with clone() support
162
- const streamResponse = await client.stream(
163
- "https://stream.example.com/audio.mp3",
164
- );
315
+ const streamResponse = await client.stream("https://stream.example.com/audio.mp3");
165
316
  const reader = streamResponse.body.getReader();
166
317
  ```
167
318
 
319
+ ### Extending Configuration
320
+
321
+ Create derived clients with merged configuration:
322
+
323
+ ```typescript
324
+ const authenticatedClient = client.extend({
325
+ network: { headers: { Authorization: "Bearer token_abc" } },
326
+ });
327
+ ```
328
+
168
329
  ---
169
330
 
170
- ## 🏗️ Architecture Pipeline
331
+ ## 🔄 Migration from axios
171
332
 
172
- `HyperClient` structures outbound and inbound requests across a sequential pipeline composed of granular plugins:
333
+ If you're migrating from axios, Hyperttp provides a familiar API:
334
+
335
+ ```typescript
336
+ // axios
337
+ import axios from "axios";
338
+ const { data } = await axios.get("/users/123");
339
+
340
+ // hyperttp (drop-in replacement)
341
+ import { HyperClient } from "hyperttp";
342
+ const client = new HyperClient();
343
+ const data = await client.get("/users/123");
344
+ ```
345
+
346
+ ---
347
+
348
+ ## 📊 Benchmarks
173
349
 
174
- 1. **withSerializer / withParser:** Manages automated runtime type transformations, payload normalization, and safe serialization.
175
- 2. **withCache:** Intercepts identical outgoing target operations, returning data directly from the LRU cache when matching.
176
- 3. **withInflight:** Identifies matching parallel operations and merges them into a single flight path, avoiding race conditions.
177
- 4. **withRateLimit & withQueue:** Sorts requests into a coordinated FIFO pattern,
178
- enforcing strict window boundaries and capacity bounds.
179
- 5. **withInterceptors:** Exposes direct developer lifecycle hooks to capture requests and responses before execution steps.
180
- 6. **withMetrics:** Records execution metrics across the entire lifecycle to offer real-time health telemetry.
350
+ For detailed benchmarks across Bun and Node.js runtimes with various transports, see the [`@hyperttp/core` benchmarks](https://github.com/IT-IF-OR/hyperttp-core#-benchmarks).
351
+
352
+ **Key takeaways:**
353
+
354
+ - **Bun + BunTransport**: ~15.22K RPS with all plugins enabled
355
+ - **Node.js + UndiciTransport**: ~10.82K RPS with all plugins enabled
356
+ - **Plugin Overhead**: Only ~9-14% compared to the bare `@hyperttp/core`
357
+ - **Zero Error Rate**: 0% errors across all benchmark scenarios
181
358
 
182
359
  ---
183
360
 
184
361
  ## 📄 License
185
362
 
186
363
  MIT
364
+
365
+ ---
366
+
367
+ <p align="center">
368
+ <a href="https://github.com/dirold2">dirold2</a>
369
+ </p>
package/index.d.ts CHANGED
@@ -1,12 +1,4 @@
1
1
  export { HyperClient } from "./Hyperttp/index.js";
2
2
  export { Request, PreparedRequest, UrlExtractor } from "./Hyperttp/index.js";
3
3
  export type * from "./Types/index.js";
4
- export * from "@hyperttp/cache";
5
- export * from "@hyperttp/queue";
6
- export * from "@hyperttp/ratelimit";
7
- export * from "@hyperttp/interceptors";
8
- export * from "@hyperttp/metrics";
9
- export * from "@hyperttp/inflight";
10
- export * from "@hyperttp/parser";
11
- export * from "@hyperttp/serializer";
12
4
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE7E,mBAAmB,kBAAkB,CAAC;AAEtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE7E,mBAAmB,kBAAkB,CAAC"}
package/index.js CHANGED
@@ -1,11 +1,3 @@
1
1
  export { HyperClient } from "./Hyperttp/index.js";
2
2
  export { Request, PreparedRequest, UrlExtractor } from "./Hyperttp/index.js";
3
- export * from "@hyperttp/cache";
4
- export * from "@hyperttp/queue";
5
- export * from "@hyperttp/ratelimit";
6
- export * from "@hyperttp/interceptors";
7
- export * from "@hyperttp/metrics";
8
- export * from "@hyperttp/inflight";
9
- export * from "@hyperttp/parser";
10
- export * from "@hyperttp/serializer";
11
3
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAI7E,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,28 +1,17 @@
1
1
  {
2
2
  "name": "hyperttp",
3
- "version": "0.4.2",
4
- "description": "A high-performance, universal HTTP client for Node.js with caching, retries, queueing, rate limiting, cookies and logging.",
3
+ "version": "0.4.5",
4
+ "description": "A high-performance, universal HTTP client for Node.js, Bun, Deno and Browser with caching, retries, queueing, rate limiting, cookies and logging.",
5
5
  "type": "module",
6
+ "sideEffects": false,
6
7
  "main": "./index.js",
7
8
  "types": "./index.d.ts",
8
- "author": "dirold2",
9
- "license": "MIT",
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/dirold2/hyperttp.git"
13
- },
14
9
  "exports": {
15
10
  ".": {
16
11
  "types": "./index.d.ts",
17
- "import": "./index.js",
18
- "require": "./index.js"
19
- },
20
- "./package.json": "./package.json"
12
+ "import": "./index.js"
13
+ }
21
14
  },
22
- "sideEffects": [
23
- "./index.js",
24
- "./index.d.ts"
25
- ],
26
15
  "keywords": [
27
16
  "http",
28
17
  "client",
@@ -33,19 +22,29 @@
33
22
  "queue",
34
23
  "retry",
35
24
  "cookies",
36
- "logger"
25
+ "logger",
26
+ "bun",
27
+ "deno",
28
+ "isomorphic",
29
+ "hyperttp"
37
30
  ],
31
+ "author": "dirold2",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/dirold2/hyperttp.git"
36
+ },
38
37
  "dependencies": {
39
38
  "@hyperttp/cache": "^1.1.6",
40
- "@hyperttp/core": "^1.3.3",
39
+ "@hyperttp/core": "^1.4.5",
41
40
  "@hyperttp/inflight": "^1.1.6",
42
41
  "@hyperttp/interceptors": "^1.1.5",
43
- "@hyperttp/metrics": "^1.1.5",
42
+ "@hyperttp/metrics": "^1.2.0",
44
43
  "@hyperttp/parser": "^1.1.8",
45
44
  "@hyperttp/queue": "^1.1.5",
46
45
  "@hyperttp/ratelimit": "^1.1.5",
47
- "@hyperttp/serializer": "^1.1.5",
48
- "@hyperttp/types": "^0.2.0"
46
+ "@hyperttp/serializer": "^1.2.0",
47
+ "@hyperttp/types": "^0.2.1"
49
48
  },
50
49
  "private": false
51
50
  }