hyperttp 0.1.7 → 0.1.9
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 +19 -249
- package/dist/Hyperttp/Core/HttpClientImproved.d.ts.map +1 -1
- package/dist/Hyperttp/Core/HttpClientImproved.js +393 -173
- 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 +0 -2
- 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/index.d.ts +7 -7
- package/dist/Hyperttp/Core/index.d.ts.map +1 -1
- package/dist/Hyperttp/Core/index.js +8 -8
- package/dist/Hyperttp/Core/index.js.map +1 -1
- package/dist/Hyperttp/Request.d.ts.map +1 -1
- package/dist/Hyperttp/Request.js +0 -1
- package/dist/Hyperttp/Request.js.map +1 -1
- package/dist/Hyperttp/UrlExtractor.d.ts.map +1 -1
- package/dist/Hyperttp/UrlExtractor.js +0 -1
- package/dist/Hyperttp/UrlExtractor.js.map +1 -1
- package/dist/Hyperttp/index.d.ts +4 -4
- package/dist/Hyperttp/index.d.ts.map +1 -1
- package/dist/Hyperttp/index.js +11 -11
- package/dist/Hyperttp/index.js.map +1 -1
- package/dist/Types/index.d.ts +256 -0
- package/dist/Types/index.d.ts.map +1 -1
- package/dist/Types/index.js +47 -0
- package/dist/Types/index.js.map +1 -1
- package/dist/Types/request.d.ts +1 -1
- package/dist/Types/request.d.ts.map +1 -1
- package/dist/Types/request.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -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,246 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ResponseType } from "../../Types";
|
|
3
|
-
/**
|
|
4
|
-
* Base error class for HTTP client operations.
|
|
5
|
-
* Contains additional context about the failed request including status code, URL, and method.
|
|
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
|
-
constructor(message: string, statusCode?: number | undefined, originalError?: Error | undefined, url?: string | undefined, method?: string | undefined);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Error thrown when an HTTP request exceeds the configured timeout duration.
|
|
16
|
-
* Contains information about the URL and timeout value that caused the failure.
|
|
17
|
-
*/
|
|
18
|
-
export declare class TimeoutError extends HttpClientError {
|
|
19
|
-
constructor(url: string, timeout: number);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Error thrown when an HTTP request is rate limited by the server.
|
|
23
|
-
* Contains information about the URL and optional retry-after duration.
|
|
24
|
-
*/
|
|
25
|
-
export declare class RateLimitError extends HttpClientError {
|
|
26
|
-
retryAfter?: number | undefined;
|
|
27
|
-
constructor(url: string, retryAfter?: number | undefined);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Log level for HTTP client logging.
|
|
31
|
-
* Defines the verbosity of log output from the client.
|
|
32
|
-
*/
|
|
33
|
-
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
34
|
-
/**
|
|
35
|
-
* Function type for logging HTTP client events.
|
|
36
|
-
* Used to customize how the client logs various events like requests, responses, and errors.
|
|
37
|
-
*
|
|
38
|
-
* @param level - The severity level of the log message
|
|
39
|
-
* @param message - The log message content
|
|
40
|
-
* @param meta - Optional additional context or metadata
|
|
41
|
-
*/
|
|
42
|
-
export type LoggerFunction = (level: LogLevel, message: string, meta?: any) => void;
|
|
43
|
-
/**
|
|
44
|
-
* Configuration options for HTTP request retry behavior.
|
|
45
|
-
* Defines how the client should handle failed requests and when to retry them.
|
|
46
|
-
*/
|
|
47
|
-
export interface RetryOptions {
|
|
48
|
-
/** Maximum number of retry attempts before giving up */
|
|
49
|
-
maxRetries: number;
|
|
50
|
-
/** Base delay in milliseconds between retry attempts (exponential backoff) */
|
|
51
|
-
baseDelay: number;
|
|
52
|
-
/** Maximum delay in milliseconds between retry attempts */
|
|
53
|
-
maxDelay: number;
|
|
54
|
-
/** HTTP status codes that should trigger a retry */
|
|
55
|
-
retryStatusCodes: number[];
|
|
56
|
-
/** Whether to add random jitter to retry delays to prevent thundering herd */
|
|
57
|
-
jitter: boolean;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Function type for intercepting and modifying HTTP requests before they are sent.
|
|
61
|
-
* Request interceptors can modify the URL, method, headers, or body of outgoing requests.
|
|
62
|
-
*
|
|
63
|
-
* @param config - The request configuration object
|
|
64
|
-
* @returns A promise that resolves to the modified request configuration
|
|
65
|
-
*/
|
|
66
|
-
export type RequestInterceptor = (config: {
|
|
67
|
-
url: string;
|
|
68
|
-
method: string;
|
|
69
|
-
headers: Record<string, string>;
|
|
70
|
-
body?: string | Buffer;
|
|
71
|
-
}) => Promise<{
|
|
72
|
-
url: string;
|
|
73
|
-
method: string;
|
|
74
|
-
headers: Record<string, string>;
|
|
75
|
-
body?: string | Buffer;
|
|
76
|
-
}>;
|
|
77
|
-
/**
|
|
78
|
-
* Function type for intercepting and modifying HTTP responses before they are processed.
|
|
79
|
-
* Response interceptors can modify the status, headers, body, or URL of incoming responses.
|
|
80
|
-
*
|
|
81
|
-
* @param response - The response object containing status, headers, body, and URL
|
|
82
|
-
* @returns A promise that resolves to the modified response object
|
|
83
|
-
*/
|
|
84
|
-
export type ResponseInterceptor = (response: {
|
|
85
|
-
status: number;
|
|
86
|
-
headers: Record<string, any>;
|
|
87
|
-
body: Buffer;
|
|
88
|
-
url: string;
|
|
89
|
-
}) => Promise<{
|
|
90
|
-
status: number;
|
|
91
|
-
headers: Record<string, any>;
|
|
92
|
-
body: Buffer;
|
|
93
|
-
url: string;
|
|
94
|
-
}>;
|
|
95
|
-
/**
|
|
96
|
-
* Configuration options for the HttpClientImproved instance.
|
|
97
|
-
* Defines all the behavior settings for HTTP requests including timeouts, retries, caching, and more.
|
|
98
|
-
*/
|
|
99
|
-
export interface HttpClientOptions {
|
|
100
|
-
/** Request timeout in milliseconds (default: 15000) */
|
|
101
|
-
timeout?: number;
|
|
102
|
-
/** Maximum number of concurrent requests (default: 50) */
|
|
103
|
-
maxConcurrent?: number;
|
|
104
|
-
/** Maximum number of retry attempts for failed requests (default: 3) */
|
|
105
|
-
maxRetries?: number;
|
|
106
|
-
/** Cache time-to-live in milliseconds (default: 300000) */
|
|
107
|
-
cacheTTL?: number;
|
|
108
|
-
/** Maximum number of cached entries (default: 500) */
|
|
109
|
-
cacheMaxSize?: number;
|
|
110
|
-
/** Rate limiting configuration to prevent overwhelming servers */
|
|
111
|
-
rateLimit?: RateLimiterConfig;
|
|
112
|
-
/** User-Agent string for HTTP requests (default: "Hyperttp/0.1.0 Node.js") */
|
|
113
|
-
userAgent?: string;
|
|
114
|
-
/** Custom logger function for HTTP client events */
|
|
115
|
-
logger?: LoggerFunction;
|
|
116
|
-
/** Retry behavior configuration */
|
|
117
|
-
retryOptions?: Partial<RetryOptions>;
|
|
118
|
-
/** Whether to automatically follow HTTP redirects (default: true) */
|
|
119
|
-
followRedirects?: boolean;
|
|
120
|
-
/** Maximum number of redirects to follow (default: 5) */
|
|
121
|
-
maxRedirects?: number;
|
|
122
|
-
/** Maximum response size in bytes (default: 1MB) */
|
|
123
|
-
maxResponseBytes?: number;
|
|
124
|
-
/** Function to validate HTTP status codes (default: 200-299) */
|
|
125
|
-
validateStatus?: (status: number) => boolean;
|
|
126
|
-
/** HTTP methods that should be cached (default: ["GET", "HEAD"]) */
|
|
127
|
-
cacheMethods?: string[];
|
|
128
|
-
/** Maximum number of request metrics to store (default: 10000) */
|
|
129
|
-
maxMetricsSize?: number;
|
|
130
|
-
/** Whether to enable verbose logging (default: false) */
|
|
131
|
-
verbose?: boolean;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Interface for defining HTTP request parameters.
|
|
135
|
-
* Used to encapsulate URL, headers, and body data for HTTP requests.
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* class ApiRequest implements RequestInterface {
|
|
140
|
-
* constructor(
|
|
141
|
-
* private url: string,
|
|
142
|
-
* private headers: Record<string, string> = {},
|
|
143
|
-
* private body?: any
|
|
144
|
-
* ) {}
|
|
145
|
-
*
|
|
146
|
-
* getURL(): string { return this.url; }
|
|
147
|
-
* getHeaders(): Record<string, string> { return this.headers; }
|
|
148
|
-
* getBodyData(): any { return this.body; }
|
|
149
|
-
* }
|
|
150
|
-
* ```
|
|
151
|
-
*/
|
|
152
|
-
export interface RequestInterface {
|
|
153
|
-
/** Returns the full URL for the HTTP request */
|
|
154
|
-
getURL(): string;
|
|
155
|
-
/** Returns the request body data (string, Buffer, or any serializable object) */
|
|
156
|
-
getBodyData(): any;
|
|
157
|
-
/** Returns the HTTP headers for the request */
|
|
158
|
-
getHeaders(): Record<string, string>;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Interface defining the contract for HTTP client implementations.
|
|
162
|
-
* Provides methods for making HTTP requests with various HTTP methods.
|
|
163
|
-
*/
|
|
164
|
-
export interface HttpClientInterface {
|
|
165
|
-
/**
|
|
166
|
-
* Makes an HTTP GET request
|
|
167
|
-
* @param req - Request configuration or URL string
|
|
168
|
-
* @param responseType - Expected response type (default: "json")
|
|
169
|
-
* @returns Promise resolving to the response data
|
|
170
|
-
*/
|
|
171
|
-
get<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
|
|
172
|
-
/**
|
|
173
|
-
* Makes an HTTP POST request
|
|
174
|
-
* @param req - Request configuration or URL string
|
|
175
|
-
* @param body - Request body data
|
|
176
|
-
* @param responseType - Expected response type (default: "json")
|
|
177
|
-
* @returns Promise resolving to the response data
|
|
178
|
-
*/
|
|
179
|
-
post<T = any>(req: RequestInterface, body?: any, responseType?: ResponseType): Promise<T>;
|
|
180
|
-
/**
|
|
181
|
-
* Makes an HTTP PUT request
|
|
182
|
-
* @param req - Request configuration or URL string
|
|
183
|
-
* @param body - Request body data
|
|
184
|
-
* @param responseType - Expected response type (default: "json")
|
|
185
|
-
* @returns Promise resolving to the response data
|
|
186
|
-
*/
|
|
187
|
-
put<T = any>(req: RequestInterface, body?: any, responseType?: ResponseType): Promise<T>;
|
|
188
|
-
/**
|
|
189
|
-
* Makes an HTTP DELETE request
|
|
190
|
-
* @param req - Request configuration or URL string
|
|
191
|
-
* @param responseType - Expected response type (default: "json")
|
|
192
|
-
* @returns Promise resolving to the response data
|
|
193
|
-
*/
|
|
194
|
-
delete<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
|
|
195
|
-
/**
|
|
196
|
-
* Makes an HTTP PATCH request
|
|
197
|
-
* @param req - Request configuration
|
|
198
|
-
* @param responseType - Expected response type (default: "json")
|
|
199
|
-
* @returns Promise resolving to the response data
|
|
200
|
-
*/
|
|
201
|
-
patch<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
|
|
202
|
-
/**
|
|
203
|
-
* Makes an HTTP HEAD request
|
|
204
|
-
* @param req - Request configuration or URL string
|
|
205
|
-
* @returns Promise resolving to status and headers
|
|
206
|
-
*/
|
|
207
|
-
head(req: RequestInterface): Promise<{
|
|
208
|
-
status: number;
|
|
209
|
-
headers: Record<string, any>;
|
|
210
|
-
}>;
|
|
211
|
-
/**
|
|
212
|
-
* Clears the internal cache of the HTTP client
|
|
213
|
-
*/
|
|
214
|
-
clearCache(): void;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Metrics collected for HTTP requests to monitor performance and behavior.
|
|
218
|
-
* Contains timing information, response details, and caching information.
|
|
219
|
-
*/
|
|
220
|
-
export interface RequestMetrics {
|
|
221
|
-
/** Timestamp when the request started */
|
|
222
|
-
startTime: number;
|
|
223
|
-
/** Timestamp when the request completed */
|
|
224
|
-
endTime: number;
|
|
225
|
-
/** Total duration of the request in milliseconds */
|
|
226
|
-
duration: number;
|
|
227
|
-
/** HTTP status code of the response (if available) */
|
|
228
|
-
statusCode?: number;
|
|
229
|
-
/** Number of bytes received in the response */
|
|
230
|
-
bytesReceived: number;
|
|
231
|
-
/** Number of bytes sent in the request body */
|
|
232
|
-
bytesSent: number;
|
|
233
|
-
/** Number of retry attempts made for this request */
|
|
234
|
-
retries: number;
|
|
235
|
-
/** Whether the response was served from cache */
|
|
236
|
-
cached: boolean;
|
|
237
|
-
/** URL of the request */
|
|
238
|
-
url: string;
|
|
239
|
-
/** HTTP method used (GET, POST, etc.) */
|
|
240
|
-
method: string;
|
|
241
|
-
/** Hash of the request body for cache key generation */
|
|
242
|
-
bodyHash?: string;
|
|
243
|
-
}
|
|
1
|
+
import { HttpClientInterface, HttpClientOptions, RequestInterface, RequestMetrics, ResponseType, StreamResponse } from "../../Types";
|
|
244
2
|
/**
|
|
245
3
|
* @ru
|
|
246
4
|
* Улучшенный HTTP-клиент с кэшированием, ограничением скорости, логикой повторных попыток и расширенными функциями.
|
|
@@ -298,12 +56,12 @@ export interface RequestMetrics {
|
|
|
298
56
|
export default class HttpClientImproved implements HttpClientInterface {
|
|
299
57
|
private cookieJar;
|
|
300
58
|
private agent;
|
|
301
|
-
private cache
|
|
302
|
-
private queue
|
|
303
|
-
private limiter
|
|
59
|
+
private cache?;
|
|
60
|
+
private queue?;
|
|
61
|
+
private limiter?;
|
|
304
62
|
private inflight;
|
|
305
63
|
private retryOptions;
|
|
306
|
-
private
|
|
64
|
+
private baseHeaders;
|
|
307
65
|
private options;
|
|
308
66
|
private requestInterceptors;
|
|
309
67
|
private responseInterceptors;
|
|
@@ -380,6 +138,7 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
380
138
|
* @param redirects - Number of redirects followed so far
|
|
381
139
|
* @returns Promise resolving to the response data
|
|
382
140
|
*/
|
|
141
|
+
private sendOnce;
|
|
383
142
|
private sendWithRetry;
|
|
384
143
|
/**
|
|
385
144
|
* Parses the Content-Type header to extract MIME type and character encoding.
|
|
@@ -413,6 +172,7 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
413
172
|
* @param responseType - Expected response type
|
|
414
173
|
* @returns Promise resolving to the response data
|
|
415
174
|
*/
|
|
175
|
+
private fastRequest;
|
|
416
176
|
private requestInternal;
|
|
417
177
|
/**
|
|
418
178
|
* Makes an HTTP GET request.
|
|
@@ -443,6 +203,11 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
443
203
|
* @returns Promise resolving to the response data
|
|
444
204
|
*/
|
|
445
205
|
put<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
206
|
+
/**
|
|
207
|
+
* @ru Получает потоковый ответ (для SSE, больших файлов).
|
|
208
|
+
* @en Gets streaming response (for SSE, large files).
|
|
209
|
+
*/
|
|
210
|
+
stream(req: RequestInterface | string): Promise<StreamResponse>;
|
|
446
211
|
/**
|
|
447
212
|
* Makes an HTTP DELETE request.
|
|
448
213
|
* Supports both RequestInterface objects and direct URL strings.
|
|
@@ -459,7 +224,7 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
459
224
|
* @param responseType - Expected response type (default: "json")
|
|
460
225
|
* @returns Promise resolving to the response data
|
|
461
226
|
*/
|
|
462
|
-
patch<T = any>(req: RequestInterface, responseType?: ResponseType): Promise<T>;
|
|
227
|
+
patch<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
463
228
|
/**
|
|
464
229
|
* Makes an HTTP HEAD request.
|
|
465
230
|
* Returns only the status code and headers without the response body.
|
|
@@ -475,7 +240,7 @@ export default class HttpClientImproved implements HttpClientInterface {
|
|
|
475
240
|
* Clears the internal cache of the HTTP client.
|
|
476
241
|
* Removes all cached responses and resets the cache state.
|
|
477
242
|
*/
|
|
478
|
-
clearCache(): void
|
|
243
|
+
clearCache(): Promise<void>;
|
|
479
244
|
/**
|
|
480
245
|
* Clears all collected request metrics.
|
|
481
246
|
* Removes performance and timing data from memory.
|
|
@@ -570,6 +335,11 @@ declare class RequestBuilder<T = any> {
|
|
|
570
335
|
* @returns The builder instance for chaining
|
|
571
336
|
*/
|
|
572
337
|
post(): this;
|
|
338
|
+
/**
|
|
339
|
+
* @ru Устанавливает потоковый режим ответа.
|
|
340
|
+
* @en Sets streaming response mode.
|
|
341
|
+
*/
|
|
342
|
+
stream(): this;
|
|
573
343
|
/**
|
|
574
344
|
* Sets the HTTP method to PUT.
|
|
575
345
|
* @returns The builder instance for chaining
|
|
@@ -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":"AAWA,OAAO,EAEL,mBAAmB,EACnB,iBAAiB,EAIjB,gBAAgB,EAChB,cAAc,EAEd,YAAY,EAEZ,cAAc,EAEf,MAAM,aAAa,CAAC;AAIrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,YAAW,mBAAmB;IACpE,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,KAAK,CAAC,CAAe;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,WAAW,CAGhB;IACH,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,oBAAoB,CAA6B;IACzD,OAAO,CAAC,cAAc,CAAqC;gBAE/C,OAAO,CAAC,EAAE,iBAAiB;IA2EvC,OAAO,CAAC,GAAG;IAiBX;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAMhB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAUjB;;;;OAIG;I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