hyperttp 0.1.8 → 0.2.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.
- package/dist/Hyperttp/Core/CacheManager.d.ts +13 -54
- package/dist/Hyperttp/Core/CacheManager.d.ts.map +1 -1
- package/dist/Hyperttp/Core/CacheManager.js +28 -50
- package/dist/Hyperttp/Core/CacheManager.js.map +1 -1
- package/dist/Hyperttp/Core/HttpClientImproved.d.ts +64 -285
- package/dist/Hyperttp/Core/HttpClientImproved.d.ts.map +1 -1
- package/dist/Hyperttp/Core/HttpClientImproved.js +282 -584
- package/dist/Hyperttp/Core/HttpClientImproved.js.map +1 -1
- package/dist/Hyperttp/Core/QueueManager.d.ts.map +1 -1
- package/dist/Hyperttp/Core/QueueManager.js.map +1 -1
- package/dist/Hyperttp/Core/RateLimiter.d.ts.map +1 -1
- package/dist/Hyperttp/Core/RateLimiter.js.map +1 -1
- package/dist/Hyperttp/Core/RequestBuilder.d.ts +97 -0
- package/dist/Hyperttp/Core/RequestBuilder.d.ts.map +1 -0
- package/dist/Hyperttp/Core/RequestBuilder.js +174 -0
- package/dist/Hyperttp/Core/RequestBuilder.js.map +1 -0
- package/dist/Hyperttp/Core/index.d.ts +1 -0
- package/dist/Hyperttp/Core/index.d.ts.map +1 -1
- package/dist/Hyperttp/Core/index.js +3 -1
- package/dist/Hyperttp/Core/index.js.map +1 -1
- package/dist/Hyperttp/Request.d.ts.map +1 -1
- package/dist/Hyperttp/Request.js.map +1 -1
- package/dist/Hyperttp/UrlExtractor.d.ts.map +1 -1
- package/dist/Hyperttp/UrlExtractor.js.map +1 -1
- package/dist/Hyperttp/index.d.ts +1 -1
- package/dist/Hyperttp/index.d.ts.map +1 -1
- package/dist/Hyperttp/index.js +2 -1
- package/dist/Hyperttp/index.js.map +1 -1
- package/dist/Types/index.d.ts.map +1 -1
- package/dist/Types/index.js.map +1 -1
- package/dist/Types/request.d.ts.map +1 -1
- package/dist/Types/request.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,65 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration options for the CacheManager
|
|
3
|
-
*/
|
|
4
1
|
export interface CacheManagerOptions {
|
|
5
|
-
/**
|
|
2
|
+
/** TTL для элементов в миллисекундах (по умолчанию 5 минут) */
|
|
6
3
|
cacheTTL?: number;
|
|
7
|
-
/**
|
|
4
|
+
/** Максимальное количество элементов в кэше (по умолчанию 500) */
|
|
8
5
|
cacheMaxSize?: number;
|
|
9
6
|
}
|
|
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
7
|
export declare class CacheManager {
|
|
22
8
|
private cache;
|
|
23
9
|
private ttl;
|
|
24
|
-
/**
|
|
25
|
-
* Creates a new CacheManager instance
|
|
26
|
-
* @param options - Configuration options for cache behavior
|
|
27
|
-
*/
|
|
28
10
|
constructor(options?: CacheManagerOptions);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
*/
|
|
11
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
12
|
+
set<T>(key: string, value: T): Promise<void>;
|
|
13
|
+
has(key: string): Promise<boolean>;
|
|
14
|
+
delete(key: string): Promise<boolean>;
|
|
15
|
+
clear(): Promise<void>;
|
|
16
|
+
getSync<T>(key: string): T | undefined;
|
|
17
|
+
setSync<T>(key: string, value: T): void;
|
|
18
|
+
hasSync(key: string): boolean;
|
|
19
|
+
deleteSync(key: string): boolean;
|
|
20
|
+
clearSync(): void;
|
|
21
|
+
/** Количество элементов в кэше */
|
|
63
22
|
get size(): number;
|
|
64
23
|
}
|
|
65
24
|
//# sourceMappingURL=CacheManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheManager.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"CacheManager.d.ts","sourceRoot":"","sources":["../../../../src/Hyperttp/Core/CacheManager.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,GAAG,CAAS;gBAER,OAAO,CAAC,EAAE,mBAAmB;IAYnC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAI3C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIrC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAItC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAIvC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI7B,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIhC,SAAS,IAAI,IAAI;IAIjB,kCAAkC;IAClC,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -2,24 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CacheManager = void 0;
|
|
4
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
5
|
class CacheManager {
|
|
17
6
|
cache;
|
|
18
7
|
ttl;
|
|
19
|
-
/**
|
|
20
|
-
* Creates a new CacheManager instance
|
|
21
|
-
* @param options - Configuration options for cache behavior
|
|
22
|
-
*/
|
|
23
8
|
constructor(options) {
|
|
24
9
|
this.ttl = options?.cacheTTL ?? 300_000;
|
|
25
10
|
this.cache = new lru_cache_1.LRUCache({
|
|
@@ -28,50 +13,43 @@ class CacheManager {
|
|
|
28
13
|
updateAgeOnGet: true,
|
|
29
14
|
});
|
|
30
15
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*/
|
|
37
|
-
get(key) {
|
|
38
|
-
return this.cache.get(key) ?? null;
|
|
16
|
+
// ----------------------
|
|
17
|
+
// Async API
|
|
18
|
+
// ----------------------
|
|
19
|
+
async get(key) {
|
|
20
|
+
return this.cache.get(key);
|
|
39
21
|
}
|
|
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) {
|
|
22
|
+
async set(key, value) {
|
|
47
23
|
this.cache.set(key, value);
|
|
48
24
|
}
|
|
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) {
|
|
25
|
+
async has(key) {
|
|
55
26
|
return this.cache.has(key);
|
|
56
27
|
}
|
|
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) {
|
|
28
|
+
async delete(key) {
|
|
63
29
|
return this.cache.delete(key);
|
|
64
30
|
}
|
|
65
|
-
|
|
66
|
-
* Clears all entries from the cache
|
|
67
|
-
*/
|
|
68
|
-
clear() {
|
|
31
|
+
async clear() {
|
|
69
32
|
this.cache.clear();
|
|
70
33
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
34
|
+
// ----------------------
|
|
35
|
+
// Sync API (супербыстрый)
|
|
36
|
+
// ----------------------
|
|
37
|
+
getSync(key) {
|
|
38
|
+
return this.cache.get(key);
|
|
39
|
+
}
|
|
40
|
+
setSync(key, value) {
|
|
41
|
+
this.cache.set(key, value);
|
|
42
|
+
}
|
|
43
|
+
hasSync(key) {
|
|
44
|
+
return this.cache.has(key);
|
|
45
|
+
}
|
|
46
|
+
deleteSync(key) {
|
|
47
|
+
return this.cache.delete(key);
|
|
48
|
+
}
|
|
49
|
+
clearSync() {
|
|
50
|
+
this.cache.clear();
|
|
51
|
+
}
|
|
52
|
+
/** Количество элементов в кэше */
|
|
75
53
|
get size() {
|
|
76
54
|
return this.cache.size;
|
|
77
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CacheManager.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"CacheManager.js","sourceRoot":"","sources":["../../../../src/Hyperttp/Core/CacheManager.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AASrC,MAAa,YAAY;IACf,KAAK,CAAwB;IAC7B,GAAG,CAAS;IAEpB,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,yBAAyB;IACzB,YAAY;IACZ,yBAAyB;IACzB,KAAK,CAAC,GAAG,CAAI,GAAW;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAkB,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,GAAG,CAAI,GAAW,EAAE,KAAQ;QAChC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,yBAAyB;IACzB,0BAA0B;IAC1B,yBAAyB;IACzB,OAAO,CAAI,GAAW;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAkB,CAAC;IAC9C,CAAC;IAED,OAAO,CAAI,GAAW,EAAE,KAAQ;QAC9B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,GAAW;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,SAAS;QACP,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,kCAAkC;IAClC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;CACF;AA/DD,oCA+DC"}
|
|
@@ -1,57 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CookieJar } from "tough-cookie";
|
|
2
|
+
import { HttpClientInterface, HttpClientOptions, RequestInterceptor, RequestInterface, RequestMetrics, ResponseInterceptor, ResponseType, StreamResponse } from "../../Types";
|
|
3
|
+
import { RequestBuilder } from "./RequestBuilder";
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Предоставляет надежный интерфейс для выполнения HTTP-запросов с автоматической обработкой
|
|
6
|
-
* распространенных паттернов, таких как повторные попытки, кэширование и перехват запросов/ответов.
|
|
7
|
-
* @en
|
|
8
|
-
* Enhanced HTTP client with caching, rate limiting, retry logic, and advanced features.
|
|
9
|
-
* Provides a robust interface for making HTTP requests with automatic handling of
|
|
10
|
-
* common patterns like retries, caching, and request/response interception.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const client = new HttpClientImproved({
|
|
15
|
-
* timeout: 10000,
|
|
16
|
-
* maxRetries: 3,
|
|
17
|
-
* cacheTTL: 300000,
|
|
18
|
-
* rateLimit: { maxRequests: 100, windowMs: 60000 }
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
* const response = await client.get('https://api.example.com/data');
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* // Using the fluent request builder
|
|
27
|
-
* const client = new HttpClientImproved();
|
|
28
|
-
* const response = await client.request('https://api.example.com/data')
|
|
29
|
-
* .headers({ 'Authorization': 'Bearer token' })
|
|
30
|
-
* .json()
|
|
31
|
-
* .send();
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* // Using RequestInterface for complex requests
|
|
37
|
-
* import { RequestInterface } from './src';
|
|
38
|
-
*
|
|
39
|
-
* class ApiRequest implements RequestInterface {
|
|
40
|
-
* constructor(
|
|
41
|
-
* private url: string,
|
|
42
|
-
* private headers: Record<string, string> = {},
|
|
43
|
-
* private body?: any
|
|
44
|
-
* ) {}
|
|
45
|
-
*
|
|
46
|
-
* getURL(): string { return this.url; }
|
|
47
|
-
* getHeaders(): Record<string, string> { return this.headers; }
|
|
48
|
-
* getBodyData(): any { return this.body; }
|
|
49
|
-
* }
|
|
50
|
-
*
|
|
51
|
-
* const client = new HttpClientImproved();
|
|
52
|
-
* const request = new ApiRequest('https://api.example.com/data');
|
|
53
|
-
* const response = await client.get(request);
|
|
54
|
-
* ```
|
|
5
|
+
* Advanced HTTP client with built-in caching, rate limiting, request queuing,
|
|
6
|
+
* automatic retries, cookie management, and response decompression.
|
|
55
7
|
*/
|
|
56
8
|
export default class HttpClientImproved implements HttpClientInterface {
|
|
57
9
|
private cookieJar;
|
|
@@ -66,179 +18,105 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
66
18
|
private requestInterceptors;
|
|
67
19
|
private responseInterceptors;
|
|
68
20
|
private requestMetrics;
|
|
69
|
-
constructor(options?: HttpClientOptions);
|
|
70
|
-
private log;
|
|
71
21
|
/**
|
|
72
|
-
* Creates a
|
|
73
|
-
* @param
|
|
74
|
-
* @returns SHA1 hash of the body, truncated to 8 characters
|
|
22
|
+
* Creates a new instance of HttpClientImproved.
|
|
23
|
+
* @param options Optional configuration options for the HTTP client
|
|
75
24
|
*/
|
|
76
|
-
|
|
25
|
+
constructor(options?: HttpClientOptions);
|
|
77
26
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param
|
|
80
|
-
* @returns Delay in milliseconds
|
|
27
|
+
* Sets default headers that will be applied to all outgoing requests.
|
|
28
|
+
* @param headers An object containing header names and values
|
|
81
29
|
*/
|
|
82
|
-
|
|
30
|
+
setDefaultHeaders(headers: Record<string, string>): void;
|
|
83
31
|
/**
|
|
84
|
-
*
|
|
85
|
-
* @
|
|
86
|
-
* @returns Promise that resolves after the delay
|
|
32
|
+
* Returns the cookie jar used for managing HTTP cookies.
|
|
33
|
+
* @returns The CookieJar instance
|
|
87
34
|
*/
|
|
88
|
-
|
|
35
|
+
getCookieJar(): CookieJar;
|
|
89
36
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* @param config - Original request configuration
|
|
93
|
-
* @returns Modified request configuration
|
|
37
|
+
* Adds a request interceptor to modify requests before they are sent.
|
|
38
|
+
* @param interceptor The interceptor function to add
|
|
94
39
|
*/
|
|
95
|
-
|
|
40
|
+
addRequestInterceptor(interceptor: RequestInterceptor): void;
|
|
96
41
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @param response - Original response data
|
|
100
|
-
* @returns Modified response data
|
|
42
|
+
* Adds a response interceptor to modify responses after they are received.
|
|
43
|
+
* @param interceptor The interceptor function to add
|
|
101
44
|
*/
|
|
45
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): void;
|
|
46
|
+
/** Closes the HTTP agent to properly terminate keep-alive connections. */
|
|
47
|
+
close(): void;
|
|
48
|
+
private log;
|
|
49
|
+
private decompress;
|
|
50
|
+
private calcDelay;
|
|
51
|
+
private sleep;
|
|
52
|
+
private applyRequestInterceptors;
|
|
102
53
|
private applyResponseInterceptors;
|
|
103
|
-
/**
|
|
104
|
-
* Resolves a redirect location relative to the base URL.
|
|
105
|
-
* Handles both absolute and relative redirect URLs.
|
|
106
|
-
* @param location - The redirect location from the response
|
|
107
|
-
* @param baseUrl - The original request URL
|
|
108
|
-
* @returns The resolved absolute URL
|
|
109
|
-
*/
|
|
110
54
|
private resolveRedirect;
|
|
111
|
-
/**
|
|
112
|
-
* Parses the Retry-After header to determine when to retry a request.
|
|
113
|
-
* Supports both seconds and HTTP date formats.
|
|
114
|
-
* @param retryAfterHeader - The Retry-After header value
|
|
115
|
-
* @returns Delay in milliseconds, or undefined if not parseable
|
|
116
|
-
*/
|
|
117
55
|
private parseRetryAfterMs;
|
|
118
|
-
/**
|
|
119
|
-
* Reads response body with size limit enforcement.
|
|
120
|
-
* Collects chunks until the response is complete or the limit is exceeded.
|
|
121
|
-
* @param body - Async iterable of response chunks
|
|
122
|
-
* @returns Complete response body as a Buffer
|
|
123
|
-
*/
|
|
124
56
|
private readBodyWithLimit;
|
|
125
|
-
/**
|
|
126
|
-
* Removes old metrics entries to prevent memory leaks.
|
|
127
|
-
* Keeps only metrics from the last 24 hours.
|
|
128
|
-
*/
|
|
129
|
-
private trimMetrics;
|
|
130
|
-
/**
|
|
131
|
-
* Sends an HTTP request with retry logic and rate limiting.
|
|
132
|
-
* Handles timeouts, redirects, and various retry scenarios.
|
|
133
|
-
* @param method - HTTP method (GET, POST, etc.)
|
|
134
|
-
* @param url - Target URL
|
|
135
|
-
* @param headers - HTTP headers
|
|
136
|
-
* @param body - Request body (optional)
|
|
137
|
-
* @param metrics - Optional metrics object to track request details
|
|
138
|
-
* @param redirects - Number of redirects followed so far
|
|
139
|
-
* @returns Promise resolving to the response data
|
|
140
|
-
*/
|
|
141
57
|
private sendWithRetry;
|
|
142
|
-
/**
|
|
143
|
-
* Parses the Content-Type header to extract MIME type and character encoding.
|
|
144
|
-
* @param contentType - Content-Type header value
|
|
145
|
-
* @returns Object containing type and charset information
|
|
146
|
-
*/
|
|
147
58
|
private parseContentType;
|
|
148
|
-
|
|
149
|
-
* Parses the HTTP response body based on content type and requested response type.
|
|
150
|
-
* Handles JSON, XML, text, and buffer responses with fallback parsing.
|
|
151
|
-
* @param res - HTTP response object
|
|
152
|
-
* @param responseType - Desired response type
|
|
153
|
-
* @returns Parsed response data
|
|
154
|
-
*/
|
|
59
|
+
private xmlParser;
|
|
155
60
|
private parseResponse;
|
|
156
|
-
/**
|
|
157
|
-
* Makes an HTTP request without using the cache.
|
|
158
|
-
* Used for methods that shouldn't be cached or when caching is disabled.
|
|
159
|
-
* @param method - HTTP method
|
|
160
|
-
* @param req - Request configuration
|
|
161
|
-
* @param responseType - Expected response type
|
|
162
|
-
* @returns Promise resolving to the response data
|
|
163
|
-
*/
|
|
164
|
-
private requestInternalWithoutCache;
|
|
165
|
-
/**
|
|
166
|
-
* Makes an HTTP request with caching support.
|
|
167
|
-
* Handles cache lookups, request deduplication, and automatic cache storage.
|
|
168
|
-
* @param method - HTTP method
|
|
169
|
-
* @param req - Request configuration
|
|
170
|
-
* @param useCache - Whether to use caching (default: true)
|
|
171
|
-
* @param responseType - Expected response type
|
|
172
|
-
* @returns Promise resolving to the response data
|
|
173
|
-
*/
|
|
174
61
|
private requestInternal;
|
|
175
62
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* @
|
|
180
|
-
* @
|
|
181
|
-
* @returns Promise resolving to the response data
|
|
63
|
+
* Performs an HTTP GET request.
|
|
64
|
+
* @param req The request object containing URL and headers
|
|
65
|
+
* @param responseType Optional response parsing type
|
|
66
|
+
* @returns A promise that resolves to the parsed response
|
|
67
|
+
* @template T The expected response type
|
|
182
68
|
*/
|
|
183
69
|
get<T = any>(req: RequestInterface | string, responseType?: ResponseType): Promise<T>;
|
|
184
70
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* @
|
|
189
|
-
* @
|
|
190
|
-
* @param responseType - Expected response type (default: "json")
|
|
191
|
-
* @returns Promise resolving to the response data
|
|
71
|
+
* Performs an HTTP POST request.
|
|
72
|
+
* @param req The request object containing URL, body, and headers
|
|
73
|
+
* @param responseType Optional response parsing type
|
|
74
|
+
* @returns A promise that resolves to the parsed response
|
|
75
|
+
* @template T The expected response type
|
|
192
76
|
*/
|
|
193
77
|
post<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
194
78
|
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* @
|
|
199
|
-
* @
|
|
200
|
-
* @param responseType - Expected response type (default: "json")
|
|
201
|
-
* @returns Promise resolving to the response data
|
|
79
|
+
* Performs an HTTP PUT request.
|
|
80
|
+
* @param req The request object containing URL, body, and headers
|
|
81
|
+
* @param responseType Optional response parsing type
|
|
82
|
+
* @returns A promise that resolves to the parsed response
|
|
83
|
+
* @template T The expected response type
|
|
202
84
|
*/
|
|
203
85
|
put<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
204
86
|
/**
|
|
205
|
-
*
|
|
206
|
-
* @
|
|
87
|
+
* Performs an HTTP DELETE request.
|
|
88
|
+
* @param req The request object containing URL and headers
|
|
89
|
+
* @param responseType Optional response parsing type
|
|
90
|
+
* @returns A promise that resolves to the parsed response
|
|
91
|
+
* @template T The expected response type
|
|
207
92
|
*/
|
|
208
|
-
|
|
93
|
+
delete<T = any>(req: RequestInterface | string, responseType?: ResponseType): Promise<T>;
|
|
209
94
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* @
|
|
214
|
-
* @
|
|
215
|
-
* @returns Promise resolving to the response data
|
|
95
|
+
* Performs an HTTP PATCH request.
|
|
96
|
+
* @param req The request object containing URL, body, and headers
|
|
97
|
+
* @param responseType Optional response parsing type
|
|
98
|
+
* @returns A promise that resolves to the parsed response
|
|
99
|
+
* @template T The expected response type
|
|
216
100
|
*/
|
|
217
|
-
|
|
101
|
+
patch<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
218
102
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* @param req - Request configuration
|
|
222
|
-
* @param responseType - Expected response type (default: "json")
|
|
223
|
-
* @returns Promise resolving to the response data
|
|
103
|
+
* @ru Получает потоковый ответ (для SSE, больших файлов).
|
|
104
|
+
* @en Gets streaming response (for SSE, large files).
|
|
224
105
|
*/
|
|
225
|
-
|
|
106
|
+
stream(req: RequestInterface | string): Promise<StreamResponse>;
|
|
226
107
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* @param req - Request configuration or URL string
|
|
231
|
-
* @returns Promise resolving to status and headers
|
|
108
|
+
* Performs an HTTP HEAD request.
|
|
109
|
+
* @param req The request object containing URL and headers
|
|
110
|
+
* @returns A promise that resolves when the request completes
|
|
232
111
|
*/
|
|
233
112
|
head(req: RequestInterface | string): Promise<{
|
|
234
113
|
status: number;
|
|
235
114
|
headers: Record<string, any>;
|
|
236
115
|
}>;
|
|
237
116
|
/**
|
|
238
|
-
* Clears the
|
|
239
|
-
* Removes all cached responses and resets the cache state.
|
|
117
|
+
* Clears the request cache.
|
|
240
118
|
*/
|
|
241
|
-
clearCache(): void
|
|
119
|
+
clearCache(): Promise<void>;
|
|
242
120
|
/**
|
|
243
121
|
* Clears all collected request metrics.
|
|
244
122
|
* Removes performance and timing data from memory.
|
|
@@ -264,8 +142,7 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
264
142
|
request<T = any>(url: string): RequestBuilder<T>;
|
|
265
143
|
/**
|
|
266
144
|
* Returns current statistics about the HTTP client's state.
|
|
267
|
-
*
|
|
268
|
-
* @returns Object containing various client statistics
|
|
145
|
+
* @returns An object containing cache size, request counts, and rate limit information
|
|
269
146
|
*/
|
|
270
147
|
getStats(): {
|
|
271
148
|
cacheSize: number;
|
|
@@ -273,104 +150,6 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
273
150
|
queuedRequests: number;
|
|
274
151
|
activeRequests: number;
|
|
275
152
|
currentRateLimit: number;
|
|
276
|
-
metricsSize: number;
|
|
277
153
|
};
|
|
278
154
|
}
|
|
279
|
-
/**
|
|
280
|
-
* Fluent request builder for making HTTP requests with a chainable API.
|
|
281
|
-
* Provides a convenient way to build and send HTTP requests with various options.
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```ts
|
|
285
|
-
* const client = new HttpClientImproved();
|
|
286
|
-
* const response = await client.request('https://api.example.com/data')
|
|
287
|
-
* .headers({ 'Authorization': 'Bearer token' })
|
|
288
|
-
* .query({ limit: 10, offset: 0 })
|
|
289
|
-
* .json()
|
|
290
|
-
* .send();
|
|
291
|
-
* ```
|
|
292
|
-
*/
|
|
293
|
-
declare class RequestBuilder<T = any> {
|
|
294
|
-
private _url;
|
|
295
|
-
private _method;
|
|
296
|
-
private _headers;
|
|
297
|
-
private _body?;
|
|
298
|
-
private _responseType;
|
|
299
|
-
/**
|
|
300
|
-
* Creates a new request builder for the specified URL.
|
|
301
|
-
* @param url - The target URL for the request
|
|
302
|
-
*/
|
|
303
|
-
constructor(url: string);
|
|
304
|
-
/**
|
|
305
|
-
* Sets HTTP headers for the request.
|
|
306
|
-
* @param headers - Object containing header key-value pairs
|
|
307
|
-
* @returns The builder instance for chaining
|
|
308
|
-
*/
|
|
309
|
-
headers(headers: Record<string, string>): this;
|
|
310
|
-
/**
|
|
311
|
-
* Sets the request body data.
|
|
312
|
-
* @param bodyData - The body data to send with the request
|
|
313
|
-
* @returns The builder instance for chaining
|
|
314
|
-
*/
|
|
315
|
-
body(bodyData: any): this;
|
|
316
|
-
/**
|
|
317
|
-
* Sets the response type to JSON.
|
|
318
|
-
* @returns The builder instance for chaining
|
|
319
|
-
*/
|
|
320
|
-
json(): this;
|
|
321
|
-
/**
|
|
322
|
-
* Sets the response type to plain text.
|
|
323
|
-
* @returns The builder instance for chaining
|
|
324
|
-
*/
|
|
325
|
-
text(): this;
|
|
326
|
-
/**
|
|
327
|
-
* Sets the response type to XML.
|
|
328
|
-
* @returns The builder instance for chaining
|
|
329
|
-
*/
|
|
330
|
-
xml(): this;
|
|
331
|
-
/**
|
|
332
|
-
* Sets the HTTP method to POST.
|
|
333
|
-
* @returns The builder instance for chaining
|
|
334
|
-
*/
|
|
335
|
-
post(): this;
|
|
336
|
-
/**
|
|
337
|
-
* @ru Устанавливает потоковый режим ответа.
|
|
338
|
-
* @en Sets streaming response mode.
|
|
339
|
-
*/
|
|
340
|
-
stream(): this;
|
|
341
|
-
/**
|
|
342
|
-
* Sets the HTTP method to PUT.
|
|
343
|
-
* @returns The builder instance for chaining
|
|
344
|
-
*/
|
|
345
|
-
put(): this;
|
|
346
|
-
/**
|
|
347
|
-
* Sets the HTTP method to PATCH.
|
|
348
|
-
* @returns The builder instance for chaining
|
|
349
|
-
*/
|
|
350
|
-
patch(): this;
|
|
351
|
-
/**
|
|
352
|
-
* Sets the HTTP method to DELETE.
|
|
353
|
-
* @returns The builder instance for chaining
|
|
354
|
-
*/
|
|
355
|
-
delete(): this;
|
|
356
|
-
/**
|
|
357
|
-
* Adds query parameters to the URL.
|
|
358
|
-
* @param params - Object containing query parameter key-value pairs
|
|
359
|
-
* @returns The builder instance for chaining
|
|
360
|
-
*/
|
|
361
|
-
query(params: Record<string, string | number | boolean>): this;
|
|
362
|
-
/**
|
|
363
|
-
* Sets a JSON body for the request.
|
|
364
|
-
* Automatically sets the Content-Type header to application/json.
|
|
365
|
-
* @param body - The JSON body data
|
|
366
|
-
* @returns The builder instance for chaining
|
|
367
|
-
*/
|
|
368
|
-
jsonBody<T>(body: T): this;
|
|
369
|
-
/**
|
|
370
|
-
* Sends the HTTP request and returns the response.
|
|
371
|
-
* @returns Promise resolving to the response data
|
|
372
|
-
*/
|
|
373
|
-
send(): Promise<T>;
|
|
374
|
-
}
|
|
375
|
-
export {};
|
|
376
155
|
//# sourceMappingURL=HttpClientImproved.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClientImproved.d.ts","sourceRoot":"","sources":["
|
|
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,EAEL,mBAAmB,EACnB,iBAAiB,EAGjB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,YAAY,EAEZ,cAAc,EAEf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAMlD;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,mBAAmB;IACpE,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,KAAK,CAAQ;IAErB,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAc;IAE9B,OAAO,CAAC,QAAQ,CAAmC;IAEnD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