hyperttp 0.1.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -0
  3. package/dist/Hyperttp/Core/CacheManager.d.ts +65 -0
  4. package/dist/Hyperttp/Core/CacheManager.d.ts.map +1 -0
  5. package/dist/Hyperttp/Core/CacheManager.js +80 -0
  6. package/dist/Hyperttp/Core/CacheManager.js.map +1 -0
  7. package/dist/Hyperttp/Core/HttpClientImproved.d.ts +280 -0
  8. package/dist/Hyperttp/Core/HttpClientImproved.d.ts.map +1 -0
  9. package/dist/Hyperttp/Core/HttpClientImproved.js +611 -0
  10. package/dist/Hyperttp/Core/HttpClientImproved.js.map +1 -0
  11. package/dist/Hyperttp/Core/QueueManager.d.ts +49 -0
  12. package/dist/Hyperttp/Core/QueueManager.d.ts.map +1 -0
  13. package/dist/Hyperttp/Core/QueueManager.js +75 -0
  14. package/dist/Hyperttp/Core/QueueManager.js.map +1 -0
  15. package/dist/Hyperttp/Core/RateLimiter.d.ts +53 -0
  16. package/dist/Hyperttp/Core/RateLimiter.d.ts.map +1 -0
  17. package/dist/Hyperttp/Core/RateLimiter.js +70 -0
  18. package/dist/Hyperttp/Core/RateLimiter.js.map +1 -0
  19. package/dist/Hyperttp/Core/index.d.ts +22 -0
  20. package/dist/Hyperttp/Core/index.d.ts.map +1 -0
  21. package/dist/Hyperttp/Core/index.js +29 -0
  22. package/dist/Hyperttp/Core/index.js.map +1 -0
  23. package/dist/Hyperttp/Request.d.ts +78 -0
  24. package/dist/Hyperttp/Request.d.ts.map +1 -0
  25. package/dist/Hyperttp/Request.js +234 -0
  26. package/dist/Hyperttp/Request.js.map +1 -0
  27. package/dist/Hyperttp/UrlExtractor.d.ts +87 -0
  28. package/dist/Hyperttp/UrlExtractor.d.ts.map +1 -0
  29. package/dist/Hyperttp/UrlExtractor.js +127 -0
  30. package/dist/Hyperttp/UrlExtractor.js.map +1 -0
  31. package/dist/Hyperttp/index.d.ts +5 -0
  32. package/dist/Hyperttp/index.d.ts.map +1 -0
  33. package/dist/Hyperttp/index.js +18 -0
  34. package/dist/Hyperttp/index.js.map +1 -0
  35. package/dist/Types/index.d.ts +32 -0
  36. package/dist/Types/index.d.ts.map +1 -0
  37. package/dist/Types/index.js +18 -0
  38. package/dist/Types/index.js.map +1 -0
  39. package/dist/Types/request.d.ts +136 -0
  40. package/dist/Types/request.d.ts.map +1 -0
  41. package/dist/Types/request.js +3 -0
  42. package/dist/Types/request.js.map +1 -0
  43. package/dist/index.d.ts +3 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +12 -0
  46. package/dist/index.js.map +1 -0
  47. package/package.json +32 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 [Your Name or Organization]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Hyperttp
2
+
3
+ Advanced HTTP client for Node.js with caching, rate limiting, request queuing, automatic retries, cookie management, and response decompression.
4
+
5
+ ## Features
6
+
7
+ * Automatic request deduplication
8
+ * LRU caching with TTL
9
+ * Configurable rate limiting
10
+ * Concurrent request management
11
+ * Exponential backoff with jitter
12
+ * Cookie jar support
13
+ * Automatic response parsing (JSON/XML)
14
+ * Compression support (gzip, deflate, brotli)
15
+
16
+ ---
17
+
18
+ ## Buttons to Switch Language
19
+
20
+ [English](#english-version) | [Русский](#russian-version)
21
+
22
+ ---
23
+
24
+ ## Russian Version
25
+
26
+ ### Описание
27
+
28
+ Расширенный HTTP клиент для Node.js с кэшированием, ограничением запросов, очередями запросов, автоматическими повторными попытками, управлением cookie и декомпрессией ответов.
29
+
30
+ ### Возможности
31
+
32
+ * Автоматическое предотвращение дублирования запросов
33
+ * LRU кэширование с TTL
34
+ * Настраиваемое ограничение запросов
35
+ * Управление конкурентными запросами
36
+ * Экспоненциальная задержка с джиттером
37
+ * Поддержка cookie jar
38
+ * Автопарсинг JSON/XML
39
+ * Поддержка сжатия (gzip, deflate, brotli)
40
+
41
+ ### Пример использования
42
+
43
+ ```ts
44
+ import HttpClientImproved from './src/Hyperttp/Core/HttpClientImproved';
45
+ import Request from './src/Hyperttp/Request';
46
+
47
+ const client = new HttpClientImproved({
48
+ timeout: 10000,
49
+ maxConcurrent: 10,
50
+ logger: (level, msg) => console.log(`[${level}] ${msg}`),
51
+ });
52
+
53
+ const req = new Request({ scheme: 'https', host: 'example.com', port: 443 });
54
+ const data = await client.get(req);
55
+ console.log(data);
56
+ ```
57
+
58
+ ---
59
+
60
+ ## English Version
61
+
62
+ ### Description
63
+
64
+ Advanced HTTP client for Node.js with caching, rate limiting, request queuing, automatic retries, cookie management, and response decompression.
65
+
66
+ ### Features
67
+
68
+ * Automatic request deduplication
69
+ * LRU caching with TTL
70
+ * Configurable rate limiting
71
+ * Concurrent request management
72
+ * Exponential backoff with jitter
73
+ * Cookie jar support
74
+ * Automatic response parsing (JSON/XML)
75
+ * Compression support (gzip, deflate, brotli)
76
+
77
+ ### Usage Example
78
+
79
+ ```ts
80
+ import HttpClientImproved from './src/Hyperttp/Core/HttpClientImproved';
81
+ import Request from './src/Hyperttp/Request';
82
+
83
+ const client = new HttpClientImproved({
84
+ timeout: 10000,
85
+ maxConcurrent: 10,
86
+ logger: (level, msg) => console.log(`[${level}] ${msg}`),
87
+ });
88
+
89
+ const req = new Request({ scheme: 'https', host: 'example.com', port: 443 });
90
+ const data = await client.get(req);
91
+ console.log(data);
92
+ ```
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Configuration options for the CacheManager
3
+ */
4
+ export interface CacheManagerOptions {
5
+ /** Time-to-live for cached items in milliseconds (default: 300000ms / 5 minutes) */
6
+ cacheTTL?: number;
7
+ /** Maximum number of items to store in cache (default: 500) */
8
+ cacheMaxSize?: number;
9
+ }
10
+ /**
11
+ * LRU (Least Recently Used) cache manager with TTL support.
12
+ * Provides a simple key-value storage with automatic eviction of old entries.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const cache = new CacheManager({ cacheTTL: 60000, cacheMaxSize: 100 });
17
+ * cache.set('key', { data: 'value' });
18
+ * const value = cache.get<{ data: string }>('key');
19
+ * ```
20
+ */
21
+ export declare class CacheManager {
22
+ private cache;
23
+ private ttl;
24
+ /**
25
+ * Creates a new CacheManager instance
26
+ * @param options - Configuration options for cache behavior
27
+ */
28
+ constructor(options?: CacheManagerOptions);
29
+ /**
30
+ * Retrieves a value from the cache
31
+ * @template T - The type of the cached value
32
+ * @param key - The cache key to retrieve
33
+ * @returns The cached value or null if not found or expired
34
+ */
35
+ get<T>(key: string): T | null;
36
+ /**
37
+ * Stores a value in the cache
38
+ * @template T - The type of the value to cache
39
+ * @param key - The cache key
40
+ * @param value - The value to store
41
+ */
42
+ set<T>(key: string, value: T): void;
43
+ /**
44
+ * Checks if a key exists in the cache
45
+ * @param key - The cache key to check
46
+ * @returns True if the key exists and hasn't expired
47
+ */
48
+ has(key: string): boolean;
49
+ /**
50
+ * Removes a specific key from the cache
51
+ * @param key - The cache key to delete
52
+ * @returns True if the key was deleted, false if it didn't exist
53
+ */
54
+ delete(key: string): boolean;
55
+ /**
56
+ * Clears all entries from the cache
57
+ */
58
+ clear(): void;
59
+ /**
60
+ * Gets the current number of items in the cache
61
+ * @returns The number of cached items
62
+ */
63
+ get size(): number;
64
+ }
65
+ //# sourceMappingURL=CacheManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheManager.d.ts","sourceRoot":"","sources":["../../../src/Hyperttp/Core/CacheManager.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,GAAG,CAAS;IAEpB;;;OAGG;gBACS,OAAO,CAAC,EAAE,mBAAmB;IASzC;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAI7B;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAInC;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CacheManager = void 0;
4
+ const lru_cache_1 = require("lru-cache");
5
+ /**
6
+ * LRU (Least Recently Used) cache manager with TTL support.
7
+ * Provides a simple key-value storage with automatic eviction of old entries.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const cache = new CacheManager({ cacheTTL: 60000, cacheMaxSize: 100 });
12
+ * cache.set('key', { data: 'value' });
13
+ * const value = cache.get<{ data: string }>('key');
14
+ * ```
15
+ */
16
+ class CacheManager {
17
+ cache;
18
+ ttl;
19
+ /**
20
+ * Creates a new CacheManager instance
21
+ * @param options - Configuration options for cache behavior
22
+ */
23
+ constructor(options) {
24
+ this.ttl = options?.cacheTTL ?? 300_000;
25
+ this.cache = new lru_cache_1.LRUCache({
26
+ max: options?.cacheMaxSize ?? 500,
27
+ ttl: this.ttl,
28
+ updateAgeOnGet: true,
29
+ });
30
+ }
31
+ /**
32
+ * Retrieves a value from the cache
33
+ * @template T - The type of the cached value
34
+ * @param key - The cache key to retrieve
35
+ * @returns The cached value or null if not found or expired
36
+ */
37
+ get(key) {
38
+ return this.cache.get(key) ?? null;
39
+ }
40
+ /**
41
+ * Stores a value in the cache
42
+ * @template T - The type of the value to cache
43
+ * @param key - The cache key
44
+ * @param value - The value to store
45
+ */
46
+ set(key, value) {
47
+ this.cache.set(key, value);
48
+ }
49
+ /**
50
+ * Checks if a key exists in the cache
51
+ * @param key - The cache key to check
52
+ * @returns True if the key exists and hasn't expired
53
+ */
54
+ has(key) {
55
+ return this.cache.has(key);
56
+ }
57
+ /**
58
+ * Removes a specific key from the cache
59
+ * @param key - The cache key to delete
60
+ * @returns True if the key was deleted, false if it didn't exist
61
+ */
62
+ delete(key) {
63
+ return this.cache.delete(key);
64
+ }
65
+ /**
66
+ * Clears all entries from the cache
67
+ */
68
+ clear() {
69
+ this.cache.clear();
70
+ }
71
+ /**
72
+ * Gets the current number of items in the cache
73
+ * @returns The number of cached items
74
+ */
75
+ get size() {
76
+ return this.cache.size;
77
+ }
78
+ }
79
+ exports.CacheManager = CacheManager;
80
+ //# sourceMappingURL=CacheManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheManager.js","sourceRoot":"","sources":["../../../src/Hyperttp/Core/CacheManager.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AAYrC;;;;;;;;;;GAUG;AACH,MAAa,YAAY;IACf,KAAK,CAAwB;IAC7B,GAAG,CAAS;IAEpB;;;OAGG;IACH,YAAY,OAA6B;QACvC,IAAI,CAAC,GAAG,GAAG,OAAO,EAAE,QAAQ,IAAI,OAAO,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,oBAAQ,CAAC;YACxB,GAAG,EAAE,OAAO,EAAE,YAAY,IAAI,GAAG;YACjC,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,cAAc,EAAE,IAAI;SACrB,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAI,GAAW;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAI,GAAW,EAAE,KAAQ;QAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;CACF;AArED,oCAqEC"}
@@ -0,0 +1,280 @@
1
+ import { CookieJar } from "tough-cookie";
2
+ import { type RateLimiterConfig } from "./RateLimiter";
3
+ import { ResponseType } from "../../Types";
4
+ /**
5
+ * Custom error classes for better error handling
6
+ */
7
+ export declare class HttpClientError extends Error {
8
+ statusCode?: number | undefined;
9
+ originalError?: Error | undefined;
10
+ url?: string | undefined;
11
+ method?: string | undefined;
12
+ /**
13
+ * Creates a new HttpClientError instance.
14
+ * @param message The error message
15
+ * @param statusCode Optional HTTP status code
16
+ * @param originalError Optional original error that caused this error
17
+ * @param url Optional request URL
18
+ * @param method Optional HTTP method
19
+ */
20
+ constructor(message: string, statusCode?: number | undefined, originalError?: Error | undefined, url?: string | undefined, method?: string | undefined);
21
+ }
22
+ export declare class TimeoutError extends HttpClientError {
23
+ /**
24
+ * Creates a new TimeoutError instance.
25
+ * @param url The request URL that timed out
26
+ * @param timeout The timeout duration in milliseconds
27
+ */
28
+ constructor(url: string, timeout: number);
29
+ }
30
+ export declare class RateLimitError extends HttpClientError {
31
+ retryAfter?: number | undefined;
32
+ /**
33
+ * Creates a new RateLimitError instance.
34
+ * @param url The request URL that was rate limited
35
+ * @param retryAfter Optional retry after duration in milliseconds
36
+ */
37
+ constructor(url: string, retryAfter?: number | undefined);
38
+ }
39
+ /**
40
+ * Log levels for the HTTP client logger
41
+ */
42
+ export type LogLevel = "debug" | "info" | "warn" | "error";
43
+ /**
44
+ * Logger function type for HTTP client operations
45
+ */
46
+ export type LoggerFunction = (level: LogLevel, message: string, meta?: any) => void;
47
+ /**
48
+ * Configuration options for retry behavior
49
+ */
50
+ export interface RetryOptions {
51
+ /** Maximum number of retry attempts (default: 3) */
52
+ maxRetries: number;
53
+ /** Base delay in milliseconds before first retry (default: 1000) */
54
+ baseDelay: number;
55
+ /** Maximum delay in milliseconds between retries (default: 30000) */
56
+ maxDelay: number;
57
+ /** HTTP status codes that should trigger a retry */
58
+ retryStatusCodes: number[];
59
+ /** Whether to add random jitter to retry delays (default: true) */
60
+ jitter: boolean;
61
+ }
62
+ /**
63
+ * Request interceptor type
64
+ */
65
+ export type RequestInterceptor = (config: {
66
+ url: string;
67
+ method: string;
68
+ headers: Record<string, string>;
69
+ body?: string | Buffer;
70
+ }) => Promise<{
71
+ url: string;
72
+ method: string;
73
+ headers: Record<string, string>;
74
+ body?: string | Buffer;
75
+ }>;
76
+ /**
77
+ * Response interceptor type
78
+ */
79
+ export type ResponseInterceptor = (response: {
80
+ status: number;
81
+ headers: Record<string, any>;
82
+ body: Buffer;
83
+ url: string;
84
+ }) => Promise<{
85
+ status: number;
86
+ headers: Record<string, any>;
87
+ body: Buffer;
88
+ url: string;
89
+ }>;
90
+ /**
91
+ * Configuration options for the HttpClient
92
+ */
93
+ export interface HttpClientOptions {
94
+ /** Request timeout in milliseconds (default: 15000) */
95
+ timeout?: number;
96
+ /** Maximum number of concurrent requests (default: 50) */
97
+ maxConcurrent?: number;
98
+ /** Maximum number of retry attempts (default: 3) */
99
+ maxRetries?: number;
100
+ /** Cache time-to-live in milliseconds (default: 300000) */
101
+ cacheTTL?: number;
102
+ /** Maximum cache size (default: 500) */
103
+ cacheMaxSize?: number;
104
+ /** Rate limiting configuration */
105
+ rateLimit?: RateLimiterConfig;
106
+ /** Custom User-Agent header */
107
+ userAgent?: string;
108
+ /** Logger function for debugging and monitoring */
109
+ logger?: LoggerFunction;
110
+ /** Custom retry options */
111
+ retryOptions?: Partial<RetryOptions>;
112
+ /** Follow redirects (default: true) */
113
+ followRedirects?: boolean;
114
+ /** Maximum redirects to follow (default: 5) */
115
+ maxRedirects?: number;
116
+ /** Optional: limit response body size in bytes (protects memory) */
117
+ maxResponseBytes?: number;
118
+ }
119
+ /**
120
+ * Interface for request objects
121
+ */
122
+ export interface RequestInterface {
123
+ getURL(): string;
124
+ getBodyData(): any;
125
+ getHeaders(): Record<string, string>;
126
+ }
127
+ /**
128
+ * Interface for HTTP client implementations
129
+ */
130
+ export interface HttpClientInterface {
131
+ get<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
132
+ post<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
133
+ put<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
134
+ delete<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
135
+ patch<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
136
+ head(req: RequestInterface): Promise<void>;
137
+ clearCache(): void;
138
+ }
139
+ /**
140
+ * Interface for request performance metrics
141
+ */
142
+ export interface RequestMetrics {
143
+ startTime: number;
144
+ endTime: number;
145
+ duration: number;
146
+ statusCode?: number;
147
+ bytesReceived: number;
148
+ bytesSent: number;
149
+ retries: number;
150
+ cached: boolean;
151
+ url: string;
152
+ method: string;
153
+ }
154
+ /**
155
+ * Advanced HTTP client with built-in caching, rate limiting, request queuing,
156
+ * automatic retries, cookie management, and response decompression.
157
+ */
158
+ export default class HttpClientImproved implements HttpClientInterface {
159
+ private cookieJar;
160
+ private agent;
161
+ private cache;
162
+ private queue;
163
+ private limiter;
164
+ private inflight;
165
+ private retryOptions;
166
+ private defaultHeaders;
167
+ private options;
168
+ private requestInterceptors;
169
+ private responseInterceptors;
170
+ private requestMetrics;
171
+ /**
172
+ * Creates a new instance of HttpClientImproved.
173
+ * @param options Optional configuration options for the HTTP client
174
+ */
175
+ constructor(options?: HttpClientOptions);
176
+ /**
177
+ * Sets default headers that will be applied to all outgoing requests.
178
+ * @param headers An object containing header names and values
179
+ */
180
+ setDefaultHeaders(headers: Record<string, string>): void;
181
+ /**
182
+ * Returns the cookie jar used for managing HTTP cookies.
183
+ * @returns The CookieJar instance
184
+ */
185
+ getCookieJar(): CookieJar;
186
+ /**
187
+ * Adds a request interceptor to modify requests before they are sent.
188
+ * @param interceptor The interceptor function to add
189
+ */
190
+ addRequestInterceptor(interceptor: RequestInterceptor): void;
191
+ /**
192
+ * Adds a response interceptor to modify responses after they are received.
193
+ * @param interceptor The interceptor function to add
194
+ */
195
+ addResponseInterceptor(interceptor: ResponseInterceptor): void;
196
+ /** Closes the HTTP agent to properly terminate keep-alive connections. */
197
+ close(): void;
198
+ private log;
199
+ private decompress;
200
+ private calcDelay;
201
+ private sleep;
202
+ private applyRequestInterceptors;
203
+ private applyResponseInterceptors;
204
+ private resolveRedirect;
205
+ private parseRetryAfterMs;
206
+ private readBodyWithLimit;
207
+ private sendWithRetry;
208
+ private parseContentType;
209
+ private parseResponse;
210
+ private requestInternal;
211
+ /**
212
+ * Performs an HTTP GET request.
213
+ * @param req The request object containing URL and headers
214
+ * @param responseType Optional response parsing type
215
+ * @returns A promise that resolves to the parsed response
216
+ * @template T The expected response type
217
+ */
218
+ get<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
219
+ /**
220
+ * Performs an HTTP POST request.
221
+ * @param req The request object containing URL, body, and headers
222
+ * @param responseType Optional response parsing type
223
+ * @returns A promise that resolves to the parsed response
224
+ * @template T The expected response type
225
+ */
226
+ post<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
227
+ /**
228
+ * Performs an HTTP PUT request.
229
+ * @param req The request object containing URL, body, and headers
230
+ * @param responseType Optional response parsing type
231
+ * @returns A promise that resolves to the parsed response
232
+ * @template T The expected response type
233
+ */
234
+ put<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
235
+ /**
236
+ * Performs an HTTP DELETE request.
237
+ * @param req The request object containing URL and headers
238
+ * @param responseType Optional response parsing type
239
+ * @returns A promise that resolves to the parsed response
240
+ * @template T The expected response type
241
+ */
242
+ delete<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
243
+ /**
244
+ * Performs an HTTP PATCH request.
245
+ * @param req The request object containing URL, body, and headers
246
+ * @param responseType Optional response parsing type
247
+ * @returns A promise that resolves to the parsed response
248
+ * @template T The expected response type
249
+ */
250
+ patch<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
251
+ /**
252
+ * Performs an HTTP HEAD request.
253
+ * @param req The request object containing URL and headers
254
+ * @returns A promise that resolves when the request completes
255
+ */
256
+ head(req: RequestInterface): Promise<void>;
257
+ /**
258
+ * Clears the request cache.
259
+ */
260
+ clearCache(): void;
261
+ /**
262
+ * Retrieves performance metrics for a specific request.
263
+ * @param url The request URL
264
+ * @param method The HTTP method
265
+ * @returns The request metrics if available, undefined otherwise
266
+ */
267
+ getMetrics(url: string, method: string): RequestMetrics | undefined;
268
+ /**
269
+ * Returns current statistics about the HTTP client's state.
270
+ * @returns An object containing cache size, request counts, and rate limit information
271
+ */
272
+ getStats(): {
273
+ cacheSize: number;
274
+ inflightRequests: number;
275
+ queuedRequests: number;
276
+ activeRequests: number;
277
+ currentRateLimit: number;
278
+ };
279
+ }
280
+ //# sourceMappingURL=HttpClientImproved.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpClientImproved.d.ts","sourceRoot":"","sources":["../../../src/Hyperttp/Core/HttpClientImproved.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAUzC,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IAW/B,UAAU,CAAC,EAAE,MAAM;IACnB,aAAa,CAAC,EAAE,KAAK;IACrB,GAAG,CAAC,EAAE,MAAM;IACZ,MAAM,CAAC,EAAE,MAAM;IAbxB;;;;;;;OAOG;gBAED,OAAO,EAAE,MAAM,EACR,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,aAAa,CAAC,EAAE,KAAK,YAAA,EACrB,GAAG,CAAC,EAAE,MAAM,YAAA,EACZ,MAAM,CAAC,EAAE,MAAM,YAAA;CAMzB;AAED,qBAAa,YAAa,SAAQ,eAAe;IAC/C;;;;OAIG;gBACS,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAKzC;AAED,qBAAa,cAAe,SAAQ,eAAe;IAQxC,UAAU,CAAC,EAAE,MAAM;IAP5B;;;;OAIG;gBAED,GAAG,EAAE,MAAM,EACJ,UAAU,CA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