hyperttp 0.2.4 → 0.2.6
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 +129 -16
- package/dist/Hyperttp/Core/CacheManager.d.ts +63 -40
- package/dist/Hyperttp/Core/CacheManager.d.ts.map +1 -1
- package/dist/Hyperttp/Core/CacheManager.js +64 -62
- package/dist/Hyperttp/Core/CacheManager.js.map +1 -1
- package/dist/Hyperttp/Core/HttpClientImproved.d.ts +55 -33
- package/dist/Hyperttp/Core/HttpClientImproved.d.ts.map +1 -1
- package/dist/Hyperttp/Core/HttpClientImproved.js +315 -211
- package/dist/Hyperttp/Core/HttpClientImproved.js.map +1 -1
- package/dist/Hyperttp/Core/InterceptorManager.d.ts +11 -11
- package/dist/Hyperttp/Core/InterceptorManager.d.ts.map +1 -1
- package/dist/Hyperttp/Core/InterceptorManager.js +10 -10
- package/dist/Hyperttp/Core/InterceptorManager.js.map +1 -1
- package/dist/Hyperttp/Core/MetricsManager.d.ts +33 -42
- package/dist/Hyperttp/Core/MetricsManager.d.ts.map +1 -1
- package/dist/Hyperttp/Core/MetricsManager.js +165 -59
- package/dist/Hyperttp/Core/MetricsManager.js.map +1 -1
- package/dist/Hyperttp/Core/QueueManager.d.ts +6 -4
- package/dist/Hyperttp/Core/QueueManager.d.ts.map +1 -1
- package/dist/Hyperttp/Core/QueueManager.js +42 -34
- package/dist/Hyperttp/Core/QueueManager.js.map +1 -1
- package/dist/Hyperttp/Core/RateLimiter.d.ts +29 -36
- package/dist/Hyperttp/Core/RateLimiter.d.ts.map +1 -1
- package/dist/Hyperttp/Core/RateLimiter.js +100 -36
- package/dist/Hyperttp/Core/RateLimiter.js.map +1 -1
- package/dist/Hyperttp/Core/RequestBuilder.d.ts +4 -2
- package/dist/Hyperttp/Core/RequestBuilder.d.ts.map +1 -1
- package/dist/Hyperttp/Core/RequestBuilder.js +10 -3
- package/dist/Hyperttp/Core/RequestBuilder.js.map +1 -1
- package/dist/Hyperttp/Core/RequestExecutor.d.ts +7 -34
- package/dist/Hyperttp/Core/RequestExecutor.d.ts.map +1 -1
- package/dist/Hyperttp/Core/RequestExecutor.js +121 -114
- package/dist/Hyperttp/Core/RequestExecutor.js.map +1 -1
- package/dist/Hyperttp/Core/RequestProfiler.d.ts +10 -0
- package/dist/Hyperttp/Core/RequestProfiler.d.ts.map +1 -0
- package/dist/Hyperttp/Core/RequestProfiler.js +55 -0
- package/dist/Hyperttp/Core/RequestProfiler.js.map +1 -0
- package/dist/Hyperttp/Core/ResponseConverter.d.ts +23 -0
- package/dist/Hyperttp/Core/ResponseConverter.d.ts.map +1 -0
- package/dist/Hyperttp/Core/ResponseConverter.js +369 -0
- package/dist/Hyperttp/Core/ResponseConverter.js.map +1 -0
- package/dist/Hyperttp/Core/index.d.ts +8 -10
- package/dist/Hyperttp/Core/index.d.ts.map +1 -1
- package/dist/Hyperttp/Core/index.js +28 -15
- package/dist/Hyperttp/Core/index.js.map +1 -1
- package/dist/Hyperttp/UrlExtractor.d.ts +1 -1
- package/dist/Hyperttp/UrlExtractor.d.ts.map +1 -1
- package/dist/Hyperttp/index.d.ts +1 -3
- package/dist/Hyperttp/index.d.ts.map +1 -1
- package/dist/Hyperttp/index.js +8 -8
- package/dist/Hyperttp/index.js.map +1 -1
- package/dist/Types/cache.d.ts +10 -0
- package/dist/Types/cache.d.ts.map +1 -0
- package/dist/Types/cache.js +3 -0
- package/dist/Types/cache.js.map +1 -0
- package/dist/Types/errors.d.ts +15 -0
- package/dist/Types/errors.d.ts.map +1 -0
- package/dist/Types/errors.js +34 -0
- package/dist/Types/errors.js.map +1 -0
- package/dist/Types/http-client.d.ts +39 -0
- package/dist/Types/http-client.d.ts.map +1 -0
- package/dist/Types/http-client.js +3 -0
- package/dist/Types/http-client.js.map +1 -0
- package/dist/Types/http.d.ts +5 -0
- package/dist/Types/http.d.ts.map +1 -0
- package/dist/Types/http.js +3 -0
- package/dist/Types/http.js.map +1 -0
- package/dist/Types/index.d.ts +12 -127
- package/dist/Types/index.d.ts.map +1 -1
- package/dist/Types/index.js +12 -39
- package/dist/Types/index.js.map +1 -1
- package/dist/Types/interceptors.d.ts +13 -0
- package/dist/Types/interceptors.d.ts.map +1 -0
- package/dist/Types/interceptors.js +3 -0
- package/dist/Types/interceptors.js.map +1 -0
- package/dist/Types/metrics.d.ts +90 -0
- package/dist/Types/metrics.d.ts.map +1 -0
- package/dist/Types/metrics.js +3 -0
- package/dist/Types/metrics.js.map +1 -0
- package/dist/Types/options.d.ts +233 -0
- package/dist/Types/options.d.ts.map +1 -0
- package/dist/Types/options.js +3 -0
- package/dist/Types/options.js.map +1 -0
- package/dist/Types/queue.d.ts +8 -0
- package/dist/Types/queue.d.ts.map +1 -0
- package/dist/Types/queue.js +3 -0
- package/dist/Types/queue.js.map +1 -0
- package/dist/Types/request.d.ts +148 -9
- package/dist/Types/request.d.ts.map +1 -1
- package/dist/Types/response.d.ts +28 -0
- package/dist/Types/response.d.ts.map +1 -0
- package/dist/Types/response.js +3 -0
- package/dist/Types/response.js.map +1 -0
- package/dist/Types/stream.d.ts +39 -0
- package/dist/Types/stream.d.ts.map +1 -0
- package/dist/Types/stream.js +3 -0
- package/dist/Types/stream.js.map +1 -0
- package/dist/Types/url-extractor.d.ts +10 -0
- package/dist/Types/url-extractor.d.ts.map +1 -0
- package/dist/Types/url-extractor.js +3 -0
- package/dist/Types/url-extractor.js.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
- package/dist/Hyperttp/Core/ResponseTransformer.d.ts +0 -35
- package/dist/Hyperttp/Core/ResponseTransformer.d.ts.map +0 -1
- package/dist/Hyperttp/Core/ResponseTransformer.js +0 -171
- package/dist/Hyperttp/Core/ResponseTransformer.js.map +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimitError = exports.TimeoutError = exports.HttpClientError = void 0;
|
|
4
|
+
class HttpClientError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
statusCode;
|
|
7
|
+
originalError;
|
|
8
|
+
url;
|
|
9
|
+
method;
|
|
10
|
+
constructor(message, code = "HTTP_ERROR", statusCode, originalError, url, method) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.originalError = originalError;
|
|
15
|
+
this.url = url;
|
|
16
|
+
this.method = method;
|
|
17
|
+
this.name = "HttpClientError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.HttpClientError = HttpClientError;
|
|
21
|
+
class TimeoutError extends HttpClientError {
|
|
22
|
+
constructor(url, timeout) {
|
|
23
|
+
super(`Timeout after ${timeout}ms`, "TIMEOUT", 408, undefined, url);
|
|
24
|
+
this.name = "TimeoutError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TimeoutError = TimeoutError;
|
|
28
|
+
class RateLimitError extends HttpClientError {
|
|
29
|
+
constructor(url, retryAfter) {
|
|
30
|
+
super(`Rate limited${retryAfter ? ` retry in ${retryAfter}ms` : ""}`, "RATE_LIMIT", 429, undefined, url);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.RateLimitError = RateLimitError;
|
|
34
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/Types/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAgB,SAAQ,KAAK;IAG/B;IACA;IACA;IACA;IACA;IANT,YACE,OAAe,EACR,OAAe,YAAY,EAC3B,UAAmB,EACnB,aAAqB,EACrB,GAAY,EACZ,MAAe;QAEtB,KAAK,CAAC,OAAO,CAAC,CAAC;QANR,SAAI,GAAJ,IAAI,CAAuB;QAC3B,eAAU,GAAV,UAAU,CAAS;QACnB,kBAAa,GAAb,aAAa,CAAQ;QACrB,QAAG,GAAH,GAAG,CAAS;QACZ,WAAM,GAAN,MAAM,CAAS;QAGtB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAZD,0CAYC;AAED,MAAa,YAAa,SAAQ,eAAe;IAC/C,YAAY,GAAW,EAAE,OAAe;QACtC,KAAK,CAAC,iBAAiB,OAAO,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAED,MAAa,cAAe,SAAQ,eAAe;IACjD,YAAY,GAAW,EAAE,UAAmB;QAC1C,KAAK,CACH,eAAe,UAAU,CAAC,CAAC,CAAC,aAAa,UAAU,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAC9D,YAAY,EACZ,GAAG,EACH,SAAS,EACT,GAAG,CACJ,CAAC;IACJ,CAAC;CACF;AAVD,wCAUC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RequestInterface } from "./request.js";
|
|
2
|
+
import type { ResponseType } from "./http.js";
|
|
3
|
+
import type { StreamResponse } from "./stream.js";
|
|
4
|
+
import type { RequestMetrics } from "./metrics.js";
|
|
5
|
+
import type { HttpClientOptions } from "./options.js";
|
|
6
|
+
import type { RequestBuilder } from "../Hyperttp/Core/RequestBuilder.js";
|
|
7
|
+
export interface HttpClientStats {
|
|
8
|
+
cacheSize: number;
|
|
9
|
+
inflightRequests: number;
|
|
10
|
+
queuedRequests: number;
|
|
11
|
+
activeRequests: number;
|
|
12
|
+
currentRateLimit: number;
|
|
13
|
+
}
|
|
14
|
+
export interface HeadResponse {
|
|
15
|
+
status: number;
|
|
16
|
+
headers: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
export interface HttpClientInterface {
|
|
19
|
+
readonly config?: HttpClientOptions;
|
|
20
|
+
get<T = unknown>(req: RequestInterface | string, responseType?: ResponseType): Promise<T>;
|
|
21
|
+
post<T = unknown>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
22
|
+
put<T = unknown>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
23
|
+
patch<T = unknown>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
24
|
+
delete<T = unknown>(req: RequestInterface | string, responseType?: ResponseType): Promise<T>;
|
|
25
|
+
options<T = unknown>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
26
|
+
head(req: RequestInterface | string): Promise<HeadResponse>;
|
|
27
|
+
stream(req: RequestInterface | string): Promise<StreamResponse>;
|
|
28
|
+
request(url: string): RequestBuilder;
|
|
29
|
+
create(options: Partial<HttpClientOptions>): HttpClientInterface;
|
|
30
|
+
extend(options: Partial<HttpClientOptions>): HttpClientInterface;
|
|
31
|
+
warmup(urls: string[], count?: number): Promise<void>;
|
|
32
|
+
getStats(): HttpClientStats;
|
|
33
|
+
getMetrics(key: string): RequestMetrics | undefined;
|
|
34
|
+
getAllMetrics(): RequestMetrics[];
|
|
35
|
+
clearMetrics(): void;
|
|
36
|
+
clearCache(): void;
|
|
37
|
+
destroy(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/Types/http-client.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/Types/http-client.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
2
|
+
export type Method = "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD";
|
|
3
|
+
export type ResponseType = "auto" | "json" | "text" | "xml" | "html" | "buffer" | "stream";
|
|
4
|
+
export type SourceType = "json" | "xml" | "html" | "text" | "buffer";
|
|
5
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/Types/http.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,MAAM,MAAM,GACd,KAAK,GACL,MAAM,GACN,KAAK,GACL,OAAO,GACP,SAAS,GACT,QAAQ,GACR,MAAM,CAAC;AAEX,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,MAAM,GACN,MAAM,GACN,KAAK,GACL,MAAM,GACN,QAAQ,GACR,QAAQ,CAAC;AAEb,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/Types/http.ts"],"names":[],"mappings":""}
|
package/dist/Types/index.d.ts
CHANGED
|
@@ -1,128 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "./
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
export declare class TimeoutError extends HttpClientError {
|
|
15
|
-
constructor(url: string, timeout: number);
|
|
16
|
-
}
|
|
17
|
-
export declare class RateLimitError extends HttpClientError {
|
|
18
|
-
retryAfter?: number | undefined;
|
|
19
|
-
constructor(url: string, retryAfter?: number | undefined);
|
|
20
|
-
}
|
|
21
|
-
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
22
|
-
export interface RetryOptions {
|
|
23
|
-
maxRetries: number;
|
|
24
|
-
baseDelay: number;
|
|
25
|
-
maxDelay: number;
|
|
26
|
-
retryStatusCodes: number[];
|
|
27
|
-
jitter: boolean;
|
|
28
|
-
}
|
|
29
|
-
export type RequestInterceptor = (config: {
|
|
30
|
-
url: string;
|
|
31
|
-
method: string;
|
|
32
|
-
headers: Record<string, string>;
|
|
33
|
-
body?: any;
|
|
34
|
-
}) => Promise<any> | any;
|
|
35
|
-
export type ResponseInterceptor = (response: {
|
|
36
|
-
status: number;
|
|
37
|
-
headers: Record<string, any>;
|
|
38
|
-
body: Buffer;
|
|
39
|
-
url: string;
|
|
40
|
-
}) => Promise<any> | any;
|
|
41
|
-
export interface HttpClientOptions {
|
|
42
|
-
timeout?: number;
|
|
43
|
-
maxConcurrent?: number;
|
|
44
|
-
maxRetries?: number;
|
|
45
|
-
cacheTTL?: number;
|
|
46
|
-
cacheMaxSize?: number;
|
|
47
|
-
rateLimit?: {
|
|
48
|
-
maxRequests: number;
|
|
49
|
-
windowMs: number;
|
|
50
|
-
};
|
|
51
|
-
userAgent?: string;
|
|
52
|
-
logger?: (level: LogLevel, message: string, meta?: any) => void;
|
|
53
|
-
retryOptions?: Partial<RetryOptions>;
|
|
54
|
-
followRedirects?: boolean;
|
|
55
|
-
maxRedirects?: number;
|
|
56
|
-
maxResponseBytes?: number;
|
|
57
|
-
validateStatus?: (status: number) => boolean;
|
|
58
|
-
cacheMethods?: string[];
|
|
59
|
-
maxMetricsSize?: number;
|
|
60
|
-
verbose?: boolean;
|
|
61
|
-
enableQueue?: boolean;
|
|
62
|
-
enableRateLimit?: boolean;
|
|
63
|
-
enableCache?: boolean;
|
|
64
|
-
allowHttp2?: boolean;
|
|
65
|
-
}
|
|
66
|
-
export interface HttpClientInterface {
|
|
67
|
-
get<T = any>(req: RequestInterface | string, responseType?: ResponseType): Promise<T>;
|
|
68
|
-
post<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
69
|
-
put<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
70
|
-
delete<T = any>(req: RequestInterface | string, responseType?: ResponseType): Promise<T>;
|
|
71
|
-
patch<T = any>(req: RequestInterface | string, body?: any, responseType?: ResponseType): Promise<T>;
|
|
72
|
-
head(req: RequestInterface | string): Promise<{
|
|
73
|
-
status: number;
|
|
74
|
-
headers: Record<string, any>;
|
|
75
|
-
}>;
|
|
76
|
-
stream(req: RequestInterface | string): Promise<StreamResponse>;
|
|
77
|
-
clearCache(): void;
|
|
78
|
-
}
|
|
79
|
-
export interface RequestMetrics {
|
|
80
|
-
startTime: number;
|
|
81
|
-
endTime: number;
|
|
82
|
-
duration: number;
|
|
83
|
-
statusCode?: number;
|
|
84
|
-
bytesReceived: number;
|
|
85
|
-
bytesSent: number;
|
|
86
|
-
retries: number;
|
|
87
|
-
cached: boolean;
|
|
88
|
-
url: string;
|
|
89
|
-
method: string;
|
|
90
|
-
bodyHash?: string;
|
|
91
|
-
}
|
|
92
|
-
export interface StreamResponse {
|
|
93
|
-
status: number;
|
|
94
|
-
headers: Record<string, any>;
|
|
95
|
-
body: AsyncIterable<Uint8Array>;
|
|
96
|
-
url: string;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Interface for a universal URL extractor
|
|
100
|
-
*/
|
|
101
|
-
export interface UrlExtractorInterface {
|
|
102
|
-
/**
|
|
103
|
-
* Register a platform with its URL patterns
|
|
104
|
-
* @param platform Platform name (e.g., "yandex", "spotify")
|
|
105
|
-
* @param patterns Array of URL patterns for the platform
|
|
106
|
-
*/
|
|
107
|
-
registerPlatform(platform: string, patterns: UrlPattern[]): void;
|
|
108
|
-
/**
|
|
109
|
-
* Extract an entity ID or related info from a URL
|
|
110
|
-
* @param url URL to extract from
|
|
111
|
-
* @param entity Entity type ("track", "album", "artist", "playlist", etc.)
|
|
112
|
-
* @param platform Platform name that has been registered
|
|
113
|
-
* @returns Record of extracted values (keys depend on the pattern)
|
|
114
|
-
*/
|
|
115
|
-
extractId<T extends string | number>(url: string, entity: string, platform: string): Record<string, T>;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Defines a URL extraction pattern for a platform
|
|
119
|
-
*/
|
|
120
|
-
export interface UrlPattern<T extends string = string> {
|
|
121
|
-
/** Entity type this pattern applies to (track, album, artist, playlist, etc.) */
|
|
122
|
-
entity: string;
|
|
123
|
-
/** Regex with named capturing groups to extract IDs or info */
|
|
124
|
-
regex: RegExp;
|
|
125
|
-
/** Names of the capturing groups to extract */
|
|
126
|
-
groupNames: T[];
|
|
127
|
-
}
|
|
1
|
+
export * from "./cache.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./http-client.js";
|
|
4
|
+
export * from "./http.js";
|
|
5
|
+
export * from "./interceptors.js";
|
|
6
|
+
export * from "./metrics.js";
|
|
7
|
+
export * from "./options.js";
|
|
8
|
+
export * from "./queue.js";
|
|
9
|
+
export * from "./request.js";
|
|
10
|
+
export * from "./response.js";
|
|
11
|
+
export * from "./stream.js";
|
|
12
|
+
export * from "./url-extractor.js";
|
|
128
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|
package/dist/Types/index.js
CHANGED
|
@@ -14,43 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
__exportStar(require("./
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
super(message);
|
|
30
|
-
this.code = code;
|
|
31
|
-
this.statusCode = statusCode;
|
|
32
|
-
this.originalError = originalError;
|
|
33
|
-
this.url = url;
|
|
34
|
-
this.method = method;
|
|
35
|
-
this.name = "HttpClientError";
|
|
36
|
-
Object.setPrototypeOf(this, HttpClientError.prototype);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.HttpClientError = HttpClientError;
|
|
40
|
-
class TimeoutError extends HttpClientError {
|
|
41
|
-
constructor(url, timeout) {
|
|
42
|
-
super(`Request timeout after ${timeout}ms for ${url}`, "TIMEOUT", 408, undefined, url);
|
|
43
|
-
this.name = "TimeoutError";
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.TimeoutError = TimeoutError;
|
|
47
|
-
class RateLimitError extends HttpClientError {
|
|
48
|
-
retryAfter;
|
|
49
|
-
constructor(url, retryAfter) {
|
|
50
|
-
super(`Rate limited for ${url}${retryAfter ? `, retry after ${retryAfter}ms` : ""}`, "RATE_LIMIT", 429, undefined, url);
|
|
51
|
-
this.retryAfter = retryAfter;
|
|
52
|
-
this.name = "RateLimitError";
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.RateLimitError = RateLimitError;
|
|
17
|
+
__exportStar(require("./cache.js"), exports);
|
|
18
|
+
__exportStar(require("./errors.js"), exports);
|
|
19
|
+
__exportStar(require("./http-client.js"), exports);
|
|
20
|
+
__exportStar(require("./http.js"), exports);
|
|
21
|
+
__exportStar(require("./interceptors.js"), exports);
|
|
22
|
+
__exportStar(require("./metrics.js"), exports);
|
|
23
|
+
__exportStar(require("./options.js"), exports);
|
|
24
|
+
__exportStar(require("./queue.js"), exports);
|
|
25
|
+
__exportStar(require("./request.js"), exports);
|
|
26
|
+
__exportStar(require("./response.js"), exports);
|
|
27
|
+
__exportStar(require("./stream.js"), exports);
|
|
28
|
+
__exportStar(require("./url-extractor.js"), exports);
|
|
56
29
|
//# sourceMappingURL=index.js.map
|
package/dist/Types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,mDAAiC;AACjC,4CAA0B;AAC1B,oDAAkC;AAClC,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,+CAA6B;AAC7B,gDAA8B;AAC9B,8CAA4B;AAC5B,qDAAmC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type RequestInterceptor = (config: {
|
|
2
|
+
url: string;
|
|
3
|
+
method: string;
|
|
4
|
+
headers: Record<string, string>;
|
|
5
|
+
body?: any;
|
|
6
|
+
}) => any | Promise<any>;
|
|
7
|
+
export type ResponseInterceptor = (response: {
|
|
8
|
+
status: number;
|
|
9
|
+
headers: Record<string, any>;
|
|
10
|
+
body: Buffer;
|
|
11
|
+
url: string;
|
|
12
|
+
}) => any | Promise<any>;
|
|
13
|
+
//# sourceMappingURL=interceptors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../src/Types/interceptors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAEzB,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../../src/Types/interceptors.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export interface RequestMetrics {
|
|
2
|
+
/**
|
|
3
|
+
* @ru Время начала запроса (timestamp)
|
|
4
|
+
* @en Request start time (timestamp)
|
|
5
|
+
*/
|
|
6
|
+
startTime: number;
|
|
7
|
+
/**
|
|
8
|
+
* @ru Время окончания запроса (timestamp)
|
|
9
|
+
* @en Request end time (timestamp)
|
|
10
|
+
*/
|
|
11
|
+
endTime: number;
|
|
12
|
+
/**
|
|
13
|
+
* @ru Длительность запроса (мс)
|
|
14
|
+
* @en Request duration (ms)
|
|
15
|
+
*/
|
|
16
|
+
duration: number;
|
|
17
|
+
/**
|
|
18
|
+
* @ru HTTP статус код ответа
|
|
19
|
+
* @en HTTP status code of response
|
|
20
|
+
*/
|
|
21
|
+
statusCode?: number;
|
|
22
|
+
/**
|
|
23
|
+
* @ru Количество полученных байт
|
|
24
|
+
* @en Bytes received
|
|
25
|
+
*/
|
|
26
|
+
bytesReceived: number;
|
|
27
|
+
/**
|
|
28
|
+
* @ru Количество отправленных байт
|
|
29
|
+
* @en Bytes sent
|
|
30
|
+
*/
|
|
31
|
+
bytesSent: number;
|
|
32
|
+
/**
|
|
33
|
+
* @ru Количество повторных попыток
|
|
34
|
+
* @en Number of retries performed
|
|
35
|
+
*/
|
|
36
|
+
retries: number;
|
|
37
|
+
/**
|
|
38
|
+
* @ru Ответ из кэша
|
|
39
|
+
* @en Response served from cache
|
|
40
|
+
*/
|
|
41
|
+
cached: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* @ru URL запроса
|
|
44
|
+
* @en Request URL
|
|
45
|
+
*/
|
|
46
|
+
url: string;
|
|
47
|
+
/**
|
|
48
|
+
* @ru HTTP метод запроса
|
|
49
|
+
* @en HTTP method
|
|
50
|
+
*/
|
|
51
|
+
method: string;
|
|
52
|
+
/**
|
|
53
|
+
* @ru Хэш тела запроса (для кэширования)
|
|
54
|
+
* @en Request body hash (for caching)
|
|
55
|
+
*/
|
|
56
|
+
bodyHash?: string;
|
|
57
|
+
}
|
|
58
|
+
export type CircuitStateName = "CLOSED" | "OPEN" | "HALF_OPEN";
|
|
59
|
+
export type CircuitState = {
|
|
60
|
+
state: CircuitStateName;
|
|
61
|
+
failureScore: number;
|
|
62
|
+
consecutiveFailures: number;
|
|
63
|
+
lastFailureTime: number;
|
|
64
|
+
lastTransitionTime: number;
|
|
65
|
+
probeInFlight: boolean;
|
|
66
|
+
};
|
|
67
|
+
export interface MemoryUsageSnapshot {
|
|
68
|
+
rss: number;
|
|
69
|
+
heapTotal: number;
|
|
70
|
+
heapUsed: number;
|
|
71
|
+
external: number;
|
|
72
|
+
arrayBuffers: number;
|
|
73
|
+
}
|
|
74
|
+
export interface RequestPerformanceProfile {
|
|
75
|
+
wallClockStart: number;
|
|
76
|
+
wallClockEnd: number;
|
|
77
|
+
durationMs: number;
|
|
78
|
+
cpu: {
|
|
79
|
+
userMs: number;
|
|
80
|
+
systemMs: number;
|
|
81
|
+
totalMs: number;
|
|
82
|
+
percent: number;
|
|
83
|
+
};
|
|
84
|
+
memory: {
|
|
85
|
+
before: MemoryUsageSnapshot;
|
|
86
|
+
after: MemoryUsageSnapshot;
|
|
87
|
+
delta: MemoryUsageSnapshot;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/Types/metrics.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE/D,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,gBAAgB,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,yBAAyB;IACxC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE;QACH,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,MAAM,EAAE;QACN,MAAM,EAAE,mBAAmB,CAAC;QAC5B,KAAK,EAAE,mBAAmB,CAAC;QAC3B,KAAK,EAAE,mBAAmB,CAAC;KAC5B,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/Types/metrics.ts"],"names":[],"mappings":""}
|