hyperttp 0.4.16 → 0.5.1
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/Hyperttp/Client/HyperClient.d.ts +73 -95
- package/Hyperttp/Client/HyperClient.d.ts.map +1 -1
- package/Hyperttp/Client/HyperClient.js +1 -1
- package/Hyperttp/Client/HyperClient.js.map +3 -3
- package/Hyperttp/Request.d.ts +19 -4
- package/Hyperttp/Request.d.ts.map +1 -1
- package/Hyperttp/Request.js +1 -1
- package/Hyperttp/Request.js.map +3 -3
- package/Hyperttp/UrlExtractor.d.ts +16 -5
- package/Hyperttp/UrlExtractor.d.ts.map +1 -1
- package/Hyperttp/UrlExtractor.js +1 -1
- package/Hyperttp/UrlExtractor.js.map +3 -3
- package/Hyperttp/Utils/RequestBuilder.d.ts +16 -43
- package/Hyperttp/Utils/RequestBuilder.d.ts.map +1 -1
- package/Hyperttp/Utils/RequestBuilder.js +1 -1
- package/Hyperttp/Utils/RequestBuilder.js.map +3 -3
- package/Hyperttp/Utils/index.d.ts +2 -0
- package/Hyperttp/Utils/index.d.ts.map +1 -1
- package/Hyperttp/Utils/index.js.map +2 -2
- package/Hyperttp/Utils/query.d.ts +3 -1
- package/Hyperttp/Utils/query.d.ts.map +1 -1
- package/Hyperttp/Utils/query.js.map +2 -2
- package/Hyperttp/defaultConfig.d.ts +2 -2
- package/Hyperttp/defaultConfig.d.ts.map +1 -1
- package/Hyperttp/defaultConfig.js +1 -1
- package/Hyperttp/defaultConfig.js.map +2 -2
- package/Hyperttp/index.d.ts +1 -0
- package/Hyperttp/index.d.ts.map +1 -1
- package/Hyperttp/index.js.map +2 -2
- package/README.md +406 -152
- package/Types/url-extractor.d.ts +5 -2
- package/Types/url-extractor.d.ts.map +1 -1
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -1
- package/index.js.map +2 -2
- package/package.json +14 -11
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { RequestBuilder } from "../Utils/RequestBuilder.js";
|
|
1
|
+
import type { HyperPlugin, HyperTransport, HyperClientOptions, HyperProtocols, UniversalResponse } from "@hyperttp/types";
|
|
2
|
+
import { RequestBuilder, type ResponseType } from "../Utils/RequestBuilder.js";
|
|
3
|
+
import type { HttpMethod, RestRequestOptions } from "@hyperttp/core/rest";
|
|
4
|
+
export type ShortcutRequestOptions = RestRequestOptions & {
|
|
5
|
+
responseType?: ResponseType;
|
|
6
|
+
};
|
|
7
|
+
declare module "@hyperttp/types" {
|
|
8
|
+
interface HyperClientOptions {
|
|
9
|
+
/** Base URL used to resolve relative URLs passed to high-level client methods. */
|
|
10
|
+
baseURL?: string;
|
|
11
|
+
/** Disable automatic registration of built-in HyperClient plugins. */
|
|
12
|
+
builtInPlugins?: boolean;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
16
|
* @ru Высокоуровневый HTTP-клиент с автоматической регистрацией плагинов
|
|
5
17
|
* (сериализация, парсинг, очередь, rate limit, inflight, кэш, перехватчики, метрики).
|
|
@@ -8,15 +20,33 @@ import { RequestBuilder } from "../Utils/RequestBuilder.js";
|
|
|
8
20
|
* (serialization, parsing, queue, rate limit, inflight, cache, interceptors, metrics).
|
|
9
21
|
* Delegates request execution to the HyperCore core and extracts the response body.
|
|
10
22
|
*/
|
|
23
|
+
export interface HyperClient extends HyperProtocols {
|
|
24
|
+
}
|
|
11
25
|
export declare class HyperClient {
|
|
12
26
|
private readonly _engine;
|
|
13
27
|
private readonly _config;
|
|
28
|
+
private readonly _transport?;
|
|
14
29
|
/**
|
|
15
|
-
* @ru Создаёт экземпляр HyperClient и регистрирует
|
|
16
|
-
*
|
|
30
|
+
* @ru Создаёт экземпляр HyperClient и регистрирует REST-протокол.
|
|
31
|
+
* Плагины передаются через config.plugins или регистрируются вручную через use().
|
|
32
|
+
* @en Creates a HyperClient instance and registers the REST protocol.
|
|
33
|
+
* Plugins are passed via config.plugins or registered manually via use().
|
|
17
34
|
* @param config - Client configuration options.
|
|
18
35
|
*/
|
|
19
|
-
constructor(config?:
|
|
36
|
+
constructor(config?: HyperClientOptions, transport?: HyperTransport);
|
|
37
|
+
/**
|
|
38
|
+
* @ru Подключает стандартный набор плагинов клиента.
|
|
39
|
+
* @en Registers the client's built-in plugin set.
|
|
40
|
+
*/
|
|
41
|
+
private useDefaultPlugins;
|
|
42
|
+
/**
|
|
43
|
+
* @ru Делегирует пространства имён протоколов ядра клиенту.
|
|
44
|
+
* Внешние пакеты расширяют HyperProtocols через module augmentation, поэтому
|
|
45
|
+
* после установки @hyperttp/protocol-grpc доступен client.grpc.call(...).
|
|
46
|
+
* @en Delegates core protocol namespaces to the client. External protocol
|
|
47
|
+
* packages augment HyperProtocols, making client.grpc.call(...) available.
|
|
48
|
+
*/
|
|
49
|
+
private exposeProtocolNamespaces;
|
|
20
50
|
/**
|
|
21
51
|
* @ru Регистрирует дополнительный плагин в клиенте.
|
|
22
52
|
* @en Registers an additional plugin in the client.
|
|
@@ -30,114 +60,107 @@ export declare class HyperClient {
|
|
|
30
60
|
* @returns Promise resolving to the transport class name.
|
|
31
61
|
*/
|
|
32
62
|
getTransportName(): Promise<string>;
|
|
33
|
-
|
|
34
|
-
* @ru Строит RequestInterface, правильно извлекая данные из геттеров старого класса Request.
|
|
35
|
-
* @en Builds RequestInterface, correctly extracting data from getters of the old Request class.
|
|
36
|
-
* @param req - Request URL or configuration object.
|
|
37
|
-
* @param responseType - Response parsing strategy.
|
|
38
|
-
* @param body - Optional request body.
|
|
39
|
-
* @param signal - Optional abort signal.
|
|
40
|
-
* @returns Normalized RequestInterface ready for dispatching.
|
|
41
|
-
*/
|
|
42
|
-
private _buildRequest;
|
|
63
|
+
private resolveUrl;
|
|
43
64
|
/**
|
|
44
65
|
* @ru Выполняет HTTP-запрос через ядро и возвращает распарсенное тело ответа.
|
|
45
|
-
* Плагин withParser автоматически парсит тело на основе meta.responseType.
|
|
46
66
|
* @en Executes an HTTP request through the core and returns the parsed response body.
|
|
47
|
-
* The withParser plugin automatically parses the body based on meta.responseType.
|
|
48
67
|
* @template T - Expected response body type.
|
|
49
|
-
* @param method - HTTP method
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
52
|
-
* @param body - Optional request body.
|
|
68
|
+
* @param method - HTTP method.
|
|
69
|
+
* @param url - Request URL.
|
|
70
|
+
* @param options - Optional request options (headers, query, body, timeout).
|
|
53
71
|
* @param signal - Optional abort signal.
|
|
54
72
|
* @returns Promise resolving to the parsed response body.
|
|
55
73
|
* @internal Used by RequestBuilder to bypass the public API double-pass
|
|
56
74
|
*/
|
|
57
|
-
_execute<T>(method:
|
|
75
|
+
_execute<T>(method: HttpMethod, url: string, options?: RestRequestOptions, signal?: AbortSignal, metadata?: Record<string, unknown>): Promise<T>;
|
|
76
|
+
private executeShortcut;
|
|
58
77
|
/**
|
|
59
78
|
* @ru Выполняет GET-запрос и возвращает распарсенный ответ.
|
|
60
79
|
* @en Performs a GET request and returns the parsed response.
|
|
61
80
|
* @template T - Expected response body type.
|
|
62
|
-
* @param
|
|
63
|
-
* @param responseType -
|
|
81
|
+
* @param url - Request URL.
|
|
82
|
+
* @param responseType - Optional response format override.
|
|
64
83
|
* @param signal - Optional abort signal.
|
|
65
84
|
* @returns Promise resolving to the parsed response body.
|
|
66
85
|
*/
|
|
67
|
-
get<T = unknown>(
|
|
86
|
+
get<T = unknown>(url: string, responseType: ResponseType, signal?: AbortSignal): Promise<T>;
|
|
87
|
+
get<T = unknown>(url: string, options?: ShortcutRequestOptions, signal?: AbortSignal): Promise<T>;
|
|
68
88
|
/**
|
|
69
89
|
* @ru Выполняет POST-запрос и возвращает распарсенный ответ.
|
|
70
90
|
* @en Performs a POST request and returns the parsed response.
|
|
71
91
|
* @template T - Expected response body type.
|
|
72
|
-
* @param
|
|
73
|
-
* @param responseType - Response parsing strategy.
|
|
92
|
+
* @param url - Request URL.
|
|
74
93
|
* @param body - Request body data.
|
|
94
|
+
* @param options - Optional request options.
|
|
75
95
|
* @param signal - Optional abort signal.
|
|
76
96
|
* @returns Promise resolving to the parsed response body.
|
|
77
97
|
*/
|
|
78
|
-
post<T = unknown>(
|
|
98
|
+
post<T = unknown>(url: string, body?: unknown, optionsOrResponseType?: ShortcutRequestOptions | ResponseType, signal?: AbortSignal): Promise<T>;
|
|
79
99
|
/**
|
|
80
100
|
* @ru Выполняет PUT-запрос и возвращает распарсенный ответ.
|
|
81
101
|
* @en Performs a PUT request and returns the parsed response.
|
|
82
102
|
* @template T - Expected response body type.
|
|
83
|
-
* @param
|
|
84
|
-
* @param responseType - Response parsing strategy.
|
|
103
|
+
* @param url - Request URL.
|
|
85
104
|
* @param body - Request body data.
|
|
105
|
+
* @param options - Optional request options.
|
|
86
106
|
* @param signal - Optional abort signal.
|
|
87
107
|
* @returns Promise resolving to the parsed response body.
|
|
88
108
|
*/
|
|
89
|
-
put<T = unknown>(
|
|
109
|
+
put<T = unknown>(url: string, body?: unknown, optionsOrResponseType?: ShortcutRequestOptions | ResponseType, signal?: AbortSignal): Promise<T>;
|
|
90
110
|
/**
|
|
91
111
|
* @ru Выполняет PATCH-запрос и возвращает распарсенный ответ.
|
|
92
112
|
* @en Performs a PATCH request and returns the parsed response.
|
|
93
113
|
* @template T - Expected response body type.
|
|
94
|
-
* @param
|
|
95
|
-
* @param responseType - Response parsing strategy.
|
|
114
|
+
* @param url - Request URL.
|
|
96
115
|
* @param body - Request body data.
|
|
116
|
+
* @param options - Optional request options.
|
|
97
117
|
* @param signal - Optional abort signal.
|
|
98
118
|
* @returns Promise resolving to the parsed response body.
|
|
99
119
|
*/
|
|
100
|
-
patch<T = unknown>(
|
|
120
|
+
patch<T = unknown>(url: string, body?: unknown, optionsOrResponseType?: ShortcutRequestOptions | ResponseType, signal?: AbortSignal): Promise<T>;
|
|
101
121
|
/**
|
|
102
122
|
* @ru Выполняет DELETE-запрос и возвращает распарсенный ответ.
|
|
103
123
|
* @en Performs a DELETE request and returns the parsed response.
|
|
104
124
|
* @template T - Expected response body type.
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
125
|
+
* @param url - Request URL.
|
|
126
|
+
* @param options - Optional request options.
|
|
107
127
|
* @param signal - Optional abort signal.
|
|
108
128
|
* @returns Promise resolving to the parsed response body.
|
|
109
129
|
*/
|
|
110
|
-
delete<T = unknown>(
|
|
130
|
+
delete<T = unknown>(url: string, optionsOrResponseType?: ShortcutRequestOptions | ResponseType, signal?: AbortSignal): Promise<T>;
|
|
111
131
|
/**
|
|
112
132
|
* @ru Выполняет OPTIONS-запрос и возвращает распарсенный ответ.
|
|
113
133
|
* @en Performs an OPTIONS request and returns the parsed response.
|
|
114
134
|
* @template T - Expected response body type.
|
|
115
|
-
* @param
|
|
116
|
-
* @param responseType - Response parsing strategy.
|
|
135
|
+
* @param url - Request URL.
|
|
117
136
|
* @param body - Optional request body data.
|
|
137
|
+
* @param options - Optional request options.
|
|
118
138
|
* @param signal - Optional abort signal.
|
|
119
139
|
* @returns Promise resolving to the parsed response body.
|
|
120
140
|
*/
|
|
121
|
-
options<T = unknown>(
|
|
141
|
+
options<T = unknown>(url: string, body?: unknown, optionsOrResponseType?: ShortcutRequestOptions | ResponseType, signal?: AbortSignal): Promise<T>;
|
|
122
142
|
/**
|
|
123
143
|
* @ru Выполняет HEAD-запрос и возвращает статус и заголовки (без тела).
|
|
124
144
|
* @en Performs a HEAD request and returns status and headers (no body).
|
|
125
|
-
* @param
|
|
145
|
+
* @param url - Request URL.
|
|
146
|
+
* @param options - Optional request options.
|
|
126
147
|
* @param signal - Optional abort signal.
|
|
127
148
|
* @returns Promise resolving to an object with status and headers.
|
|
128
149
|
*/
|
|
129
|
-
head(
|
|
150
|
+
head(url: string, options?: RestRequestOptions, signal?: AbortSignal): Promise<{
|
|
130
151
|
status: number;
|
|
131
152
|
headers: Record<string, string | string[]>;
|
|
132
153
|
}>;
|
|
133
154
|
/**
|
|
134
|
-
* @ru Выполняет потоковый GET-запрос. Тело ответа возвращается как
|
|
135
|
-
* @en Performs a streaming GET request. Response
|
|
136
|
-
* @param
|
|
155
|
+
* @ru Выполняет потоковый GET-запрос. Тело ответа возвращается как асинхронно итерируемый поток.
|
|
156
|
+
* @en Performs a streaming GET request. Response data is returned as an async-iterable stream.
|
|
157
|
+
* @param url - Request URL.
|
|
158
|
+
* @param options - Optional request options.
|
|
137
159
|
* @param signal - Optional abort signal.
|
|
138
160
|
* @returns Promise resolving to the stream response.
|
|
139
161
|
*/
|
|
140
|
-
stream(
|
|
162
|
+
stream(url: string, options?: RestRequestOptions, signal?: AbortSignal): Promise<UniversalResponse<AsyncIterable<Uint8Array>>>;
|
|
163
|
+
query<T = unknown>(url: string, body?: unknown, optionsOrResponseType?: ShortcutRequestOptions | ResponseType, signal?: AbortSignal): Promise<T>;
|
|
141
164
|
/**
|
|
142
165
|
* @ru Возвращает построитель запросов для цепочечного формирования HTTP-запроса.
|
|
143
166
|
* @en Returns a request builder for chainable HTTP request composition.
|
|
@@ -151,65 +174,20 @@ export declare class HyperClient {
|
|
|
151
174
|
* @param options - Partial configuration options to extend.
|
|
152
175
|
* @returns A new HyperClient instance.
|
|
153
176
|
*/
|
|
154
|
-
extend(options: Partial<
|
|
177
|
+
extend(options: Partial<HyperClientOptions>): HyperClient;
|
|
155
178
|
/**
|
|
156
179
|
* @ru Алиас для extend(). Создаёт новый экземпляр клиента.
|
|
157
180
|
* @en Alias for extend(). Creates a new client instance.
|
|
158
181
|
* @param options - Partial configuration options.
|
|
159
182
|
* @returns A new HyperClient instance.
|
|
160
183
|
*/
|
|
161
|
-
create(options: Partial<
|
|
184
|
+
create(options: Partial<HyperClientOptions>): HyperClient;
|
|
162
185
|
/**
|
|
163
186
|
* @ru Завершает работу клиента и освобождает ресурсы (соединения, пулы, плагины).
|
|
164
187
|
* @en Shuts down the client and releases resources (connections, pools, plugins).
|
|
188
|
+
* @param graceful - If true, waits for active requests to complete before closing.
|
|
165
189
|
* @returns Promise that resolves when shutdown is complete.
|
|
166
190
|
*/
|
|
167
|
-
destroy(): Promise<void>;
|
|
168
|
-
/**
|
|
169
|
-
* @ru Возвращает статистику работы клиента (активные соединения, очередь, кэш).
|
|
170
|
-
* Требует наличия плагина метрик или очереди.
|
|
171
|
-
* @en Returns client statistics (active connections, queue, cache).
|
|
172
|
-
* Requires metrics or queue plugin to be registered.
|
|
173
|
-
* @returns Statistics object, or undefined if no plugin provides it.
|
|
174
|
-
*/
|
|
175
|
-
getStats(): unknown;
|
|
176
|
-
/**
|
|
177
|
-
* @ru Возвращает все агрегированные метрики (latency, RPS, cache hits и т.д.).
|
|
178
|
-
* Требует наличия плагина `withMetrics`.
|
|
179
|
-
* @en Returns all aggregated metrics (latency, RPS, cache hits, etc.).
|
|
180
|
-
* Requires the `withMetrics` plugin to be registered.
|
|
181
|
-
* @returns Array of metrics, or undefined if the plugin is not registered.
|
|
182
|
-
*/
|
|
183
|
-
getAllMetrics(): RequestMetrics[] | undefined;
|
|
184
|
-
/**
|
|
185
|
-
* @ru Возвращает конкретную метрику по ключу.
|
|
186
|
-
* Требует наличия плагина `withMetrics`.
|
|
187
|
-
* @en Returns a specific metric by key.
|
|
188
|
-
* Requires the `withMetrics` plugin to be registered.
|
|
189
|
-
* @param key - Metric key (e.g., 'rps', 'avgLatency', 'cacheHits').
|
|
190
|
-
* @returns Metric value, or undefined if not found.
|
|
191
|
-
*/
|
|
192
|
-
getMetrics(key: string): RequestMetrics | RequestMetrics[] | undefined;
|
|
193
|
-
/**
|
|
194
|
-
* @ru Очищает кэш ответов. Требует наличия плагина `withCache`.
|
|
195
|
-
* @en Clears the response cache. Requires the `withCache` plugin.
|
|
196
|
-
* @returns Void or Promise if async clearing is required.
|
|
197
|
-
*/
|
|
198
|
-
clearCache(): void | Promise<void> | undefined;
|
|
199
|
-
/**
|
|
200
|
-
* @ru Возвращает агрегированную сводку метрик (success rate, avg duration, bottlenecks).
|
|
201
|
-
* Требует наличия плагина `withMetrics`.
|
|
202
|
-
* @en Returns aggregated metrics summary (success rate, avg duration, bottlenecks).
|
|
203
|
-
* Requires the `withMetrics` plugin to be registered.
|
|
204
|
-
* @returns Summary object, or null if no metrics collected.
|
|
205
|
-
*/
|
|
206
|
-
getMetricsSummary(): unknown;
|
|
207
|
-
/**
|
|
208
|
-
* @ru Сбрасывает все накопленные метрики.
|
|
209
|
-
* Требует наличия плагина `withMetrics`.
|
|
210
|
-
* @en Resets all accumulated metrics.
|
|
211
|
-
* Requires the `withMetrics` plugin to be registered.
|
|
212
|
-
*/
|
|
213
|
-
resetMetrics(): void;
|
|
191
|
+
destroy(graceful?: boolean): Promise<void>;
|
|
214
192
|
}
|
|
215
193
|
//# sourceMappingURL=HyperClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperClient.d.ts","sourceRoot":"","sources":["../../../src/Hyperttp/Client/HyperClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"HyperClient.d.ts","sourceRoot":"","sources":["../../../src/Hyperttp/Client/HyperClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAWzB,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAa,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAErF,MAAM,MAAM,sBAAsB,GAAG,kBAAkB,GAAG;IACxD,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,kBAAkB;QAC1B,kFAAkF;QAClF,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,sEAAsE;QACtE,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B;CACF;AAED;;;;;;;GAOG;AAEH,MAAM,WAAW,WAAY,SAAQ,cAAc;CAAG;AAEtD,qBAAa,WAAW;IACtB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M,EACX,OAAO,CAAC,EAAE,kBAAkB,EAC5B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAgBvD;IAEM,KAAK,CAAC,CAAC,GAAG,OAAO,EACtB,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,OAAO,EACd,qBAAqB,CAAC,EAAE,sBAAsB,GAAG,YAAY,EAC7D,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,CAAC,CAAC,CAMZ;IAED;;;;;OAKG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAE1C;IAED;;;;;OAKG;IACI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,WAAW,CAY/D;IAED;;;;;OAKG;IACI,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,WAAW,CAE/D;IAED;;;;;OAKG;IACU,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtD;CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";import{
|
|
1
|
+
"use strict";import{HyperCore as u,KNOWN_PROTOCOLS as h,RestProtocol as a}from"@hyperttp/core";import{withCache as g}from"@hyperttp/cache";import{withInflight as f}from"@hyperttp/inflight";import{withInterceptors as l}from"@hyperttp/interceptors";import{withMetrics as m}from"@hyperttp/metrics";import{withParser as _}from"@hyperttp/parser";import{withQueue as p}from"@hyperttp/queue";import{withRateLimit as S}from"@hyperttp/ratelimit";import{withSerializer as d}from"@hyperttp/serializer";import{defaultConfig as o}from"../defaultConfig.js";import{RequestBuilder as w}from"../Utils/RequestBuilder.js";export class HyperClient{_engine;_config;_transport;constructor(t=o,e){this._config={...o,...t,retry:{...o.retry,...t.retry}},this._transport=e,this._engine=new u(this._config,e),this._config.builtInPlugins!==!1&&this.useDefaultPlugins(),this._engine.registerProtocol(a),this.exposeProtocolNamespaces()}useDefaultPlugins(){this.use(l(this._config.interceptors)),this.use(d(this._config.serializer)),this.use(m(this._config.metrics)),this.use(f(this._config.inflight)),this.use(g(this._config.cache)),this.use(S(this._config.rateLimit)),this.use(p(this._config.queue)),this._config.responseConverter!==!1&&this.use(_(this._config.responseConverter))}exposeProtocolNamespaces(){for(const t of h)Object.defineProperty(this,t,{configurable:!1,enumerable:!0,get:()=>this._engine[t]})}use(t){return this._engine.use(t),this}async getTransportName(){return this._engine.getTransportName()}resolveUrl(t){return this._config.baseURL?new URL(t,this._config.baseURL).toString():t}async _execute(t,e,r,s,i){const n=s??r?.signal,c={protocol:"rest",input:{...r,method:t,url:this.resolveUrl(e),signal:n},signal:n,metadata:i};return(await this._engine.send(c)).data}executeShortcut(t,e,r,s){const{responseType:i,...n}=r??{};return this._execute(t,e,n,s,i?{responseType:i}:void 0)}get(t,e,r){const s=typeof e=="string"?{responseType:e}:e;return this.executeShortcut("GET",t,s,r)}post(t,e,r,s){const i=typeof r=="string"?{responseType:r,body:e}:{...r,body:e};return this.executeShortcut("POST",t,i,s)}put(t,e,r,s){const i=typeof r=="string"?{responseType:r,body:e}:{...r,body:e};return this.executeShortcut("PUT",t,i,s)}patch(t,e,r,s){const i=typeof r=="string"?{responseType:r,body:e}:{...r,body:e};return this.executeShortcut("PATCH",t,i,s)}delete(t,e,r){const s=typeof e=="string"?{responseType:e}:e;return this.executeShortcut("DELETE",t,s,r)}options(t,e,r,s){const i=typeof r=="string"?{responseType:r,body:e}:{...r,body:e};return this.executeShortcut("OPTIONS",t,i,s)}async head(t,e,r){const s=r??e?.signal,i=await this._engine.send({protocol:"rest",input:{...e,method:"HEAD",url:this.resolveUrl(t),signal:s},signal:s});return{status:i.status,headers:i.headers}}async stream(t,e,r){const s=r??e?.signal;return this._engine.send({protocol:"rest",input:{...e,method:"GET",url:this.resolveUrl(t),stream:!0,signal:s},metadata:{responseType:"stream"},signal:s})}query(t,e,r,s){const i=typeof r=="string"?{responseType:r,body:e}:{...r,body:e};return this.executeShortcut("QUERY",t,i,s)}request(t){return new w(t,this)}extend(t){const e={...this._config,...t,retry:{...this._config.retry,...t.retry}},r=t.customTransport??this._transport;return new HyperClient(e,r)}create(t){return this.extend(t)}async destroy(t){await this._engine.destroy(t)}}
|
|
2
2
|
//# sourceMappingURL=HyperClient.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Hyperttp/Client/HyperClient.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n HttpResponse,\n ResponseType,\n HttpClientOptions,\n RequestBodyData,\n RequestInterface,\n RequestHeaders,\n HyperPlugin,\n Method,\n RequestMetrics,\n HyperTransport,\n} from \"@hyperttp/types\";\nimport { defaultConfig } from \"../defaultConfig.js\";\nimport { HyperCore } from \"@hyperttp/core\";\nimport { withParser } from \"@hyperttp/parser\";\nimport { withQueue } from \"@hyperttp/queue\";\nimport { withCache } from \"@hyperttp/cache\";\nimport { withRateLimit } from \"@hyperttp/ratelimit\";\nimport { withInflight } from \"@hyperttp/inflight\";\nimport { withInterceptors } from \"@hyperttp/interceptors\";\nimport { withMetrics } from \"@hyperttp/metrics\";\nimport { appendQueryToUrl } from \"../Utils/query.js\";\nimport { RequestBuilder } from \"../Utils/RequestBuilder.js\";\n\nconst EMPTY_HEADERS: Readonly<Record<string, never>> = Object.freeze({});\n\ninterface HyperCoreEngine {\n getStats?(): unknown;\n getAllMetrics?(): RequestMetrics[];\n getMetrics?(key: string): RequestMetrics | RequestMetrics[] | undefined;\n clearCache?(key?: string): void | Promise<void>;\n getMetricsSummary?(): unknown;\n resetMetrics?(): void;\n}\n\ntype RequestLike = RequestInterface & {\n body?: RequestBodyData;\n bodyData?: RequestBodyData;\n _bodyData?: RequestBodyData;\n getURL?: () => string;\n getHeaders?: () => RequestHeaders;\n getBodyData?: () => RequestBodyData;\n getBodyDataString?: () => string;\n getSignal?: () => AbortSignal | undefined;\n getQuery?: () => Record<string, unknown>;\n getQueryAsString?: () => string;\n};\n\n/**\n * @ru \u0412\u044B\u0441\u043E\u043A\u043E\u0443\u0440\u043E\u0432\u043D\u0435\u0432\u044B\u0439 HTTP-\u043A\u043B\u0438\u0435\u043D\u0442 \u0441 \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u043E\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043F\u043B\u0430\u0433\u0438\u043D\u043E\u0432\n * (\u0441\u0435\u0440\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044F, \u043F\u0430\u0440\u0441\u0438\u043D\u0433, \u043E\u0447\u0435\u0440\u0435\u0434\u044C, rate limit, inflight, \u043A\u044D\u0448, \u043F\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043A\u0438, \u043C\u0435\u0442\u0440\u0438\u043A\u0438).\n * \u0414\u0435\u043B\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u0435 \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432 \u044F\u0434\u0440\u0443 HyperCore \u0438 \u0438\u0437\u0432\u043B\u0435\u043A\u0430\u0435\u0442 \u0442\u0435\u043B\u043E \u043E\u0442\u0432\u0435\u0442\u0430.\n * @en High-level HTTP client with automatic plugin registration\n * (serialization, parsing, queue, rate limit, inflight, cache, interceptors, metrics).\n * Delegates request execution to the HyperCore core and extracts the response body.\n */\nexport class HyperClient {\n private readonly _engine: HyperCore;\n private readonly _config: HttpClientOptions;\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 HyperClient \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u0441\u0435 \u0441\u0442\u0430\u043D\u0434\u0430\u0440\u0442\u043D\u044B\u0435 \u043F\u043B\u0430\u0433\u0438\u043D\u044B.\n * @en Creates a HyperClient instance and registers all standard plugins.\n * @param config - Client configuration options.\n */\n constructor(\n config: HttpClientOptions = defaultConfig,\n transport?: HyperTransport,\n ) {\n this._config = {\n ...defaultConfig,\n ...config,\n network: { ...defaultConfig.network, ...config.network },\n };\n this._engine = new HyperCore(this._config, transport);\n\n this._engine.use(withParser(this._config.responseConverter));\n this._engine.use(withQueue());\n this._engine.use(withRateLimit(this._config.rateLimit));\n this._engine.use(withInflight(this._config.inflight));\n this._engine.use(withCache(this._config.cache));\n this._engine.use(withInterceptors());\n this._engine.use(withMetrics(this._config.metrics));\n }\n\n /**\n * @ru \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u043E\u043F\u043E\u043B\u043D\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u0439 \u043F\u043B\u0430\u0433\u0438\u043D \u0432 \u043A\u043B\u0438\u0435\u043D\u0442\u0435.\n * @en Registers an additional plugin in the client.\n * @param plugin - Plugin instance to register.\n * @returns The current instance for chaining.\n */\n public use(plugin: HyperPlugin): this {\n this._engine.use(plugin);\n return this;\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043C\u044F \u043A\u043B\u0430\u0441\u0441\u0430 \u0430\u043A\u0442\u0438\u0432\u043D\u043E\u0433\u043E \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430.\n * @en Returns the class name of the active transport.\n * @returns Promise resolving to the transport class name.\n */\n public async getTransportName(): Promise<string> {\n return this._engine.getTransportName();\n }\n\n /**\n * @ru \u0421\u0442\u0440\u043E\u0438\u0442 RequestInterface, \u043F\u0440\u0430\u0432\u0438\u043B\u044C\u043D\u043E \u0438\u0437\u0432\u043B\u0435\u043A\u0430\u044F \u0434\u0430\u043D\u043D\u044B\u0435 \u0438\u0437 \u0433\u0435\u0442\u0442\u0435\u0440\u043E\u0432 \u0441\u0442\u0430\u0440\u043E\u0433\u043E \u043A\u043B\u0430\u0441\u0441\u0430 Request.\n * @en Builds RequestInterface, correctly extracting data from getters of the old Request class.\n * @param req - Request URL or configuration object.\n * @param responseType - Response parsing strategy.\n * @param body - Optional request body.\n * @param signal - Optional abort signal.\n * @returns Normalized RequestInterface ready for dispatching.\n */\n private _buildRequest(\n req: RequestInterface | string,\n responseType: ResponseType,\n body?: RequestBodyData,\n signal?: AbortSignal,\n ): RequestInterface {\n if (typeof req === \"string\") {\n return {\n url: req,\n headers: EMPTY_HEADERS,\n body,\n signal,\n meta: { responseType },\n };\n }\n const r = req as RequestLike;\n\n if (!r.getURL && !r.getHeaders && !r.getBodyData && !r.getQuery) {\n if (body) req.body = body;\n if (signal) req.signal = signal;\n if (req.meta?.responseType === responseType) return req;\n if (!req.meta) {\n req.meta = { responseType };\n } else if (req.meta.responseType !== responseType) {\n req.meta.responseType = responseType;\n }\n return req;\n }\n\n const url = req.url ?? r.getURL?.() ?? \"\";\n const headers = req.headers ?? r.getHeaders?.() ?? EMPTY_HEADERS;\n const extractedBody =\n body ??\n r.body ??\n r.bodyData ??\n r._bodyData ??\n r.getBodyData?.() ??\n r.getBodyDataString?.();\n\n const extractedSignal = signal ?? req.signal ?? r.getSignal?.();\n\n let finalUrl = url;\n\n if (!r.getURL) {\n const query = req.query ?? r.getQuery?.();\n if (query && Object.keys(query).length > 0) {\n const appended = appendQueryToUrl(\n finalUrl,\n query as Record<\n string,\n string | string[] | number | boolean | undefined | null\n >,\n );\n if (appended !== finalUrl) {\n finalUrl = appended;\n } else {\n const qs = r.getQueryAsString?.();\n if (qs) finalUrl += qs;\n }\n } else {\n const qs = r.getQueryAsString?.();\n if (qs) finalUrl += qs;\n }\n }\n\n return {\n url: finalUrl,\n headers,\n body: extractedBody,\n signal: extractedSignal,\n meta: { ...req.meta, responseType },\n };\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 HTTP-\u0437\u0430\u043F\u0440\u043E\u0441 \u0447\u0435\u0440\u0435\u0437 \u044F\u0434\u0440\u043E \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u043E\u0435 \u0442\u0435\u043B\u043E \u043E\u0442\u0432\u0435\u0442\u0430.\n * \u041F\u043B\u0430\u0433\u0438\u043D withParser \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438 \u043F\u0430\u0440\u0441\u0438\u0442 \u0442\u0435\u043B\u043E \u043D\u0430 \u043E\u0441\u043D\u043E\u0432\u0435 meta.responseType.\n * @en Executes an HTTP request through the core and returns the parsed response body.\n * The withParser plugin automatically parses the body based on meta.responseType.\n * @template T - Expected response body type.\n * @param method - HTTP method (GET, POST, etc.).\n * @param req - Request URL or configuration object.\n * @param responseType - Response parsing strategy.\n * @param body - Optional request body.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n * @internal Used by RequestBuilder to bypass the public API double-pass\n */\n public async _execute<T>(\n method: Method,\n req: RequestInterface | string,\n responseType: ResponseType = \"auto\",\n body?: RequestBodyData,\n signal?: AbortSignal,\n ): Promise<T> {\n const request = this._buildRequest(req, responseType, body, signal);\n\n let response: HttpResponse<unknown>;\n switch (method) {\n case \"GET\":\n response = await this._engine.get(request, signal);\n break;\n case \"POST\":\n response = await this._engine.post(request, request.body, signal);\n break;\n case \"PUT\":\n response = await this._engine.put(request, request.body, signal);\n break;\n case \"PATCH\":\n response = await this._engine.patch(request, request.body, signal);\n break;\n case \"DELETE\":\n response = await this._engine.delete(request, signal);\n break;\n case \"OPTIONS\":\n response = await this._engine.options(request, request.body, signal);\n break;\n case \"HEAD\":\n response = await this._engine.head(request, signal);\n break;\n default:\n response = await this._engine.get(request, signal);\n }\n\n return response.body as T;\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 GET-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a GET request and returns the parsed response.\n * @template T - Expected response body type.\n * @param req - Request URL or configuration object.\n * @param responseType - Response parsing strategy ('auto', 'json', 'text', 'stream', 'buffer', 'blob', 'xml', 'html').\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public get<T = unknown>(\n req: RequestInterface | string,\n responseType: ResponseType = \"auto\",\n signal?: AbortSignal,\n ): Promise<T> {\n return this._execute<T>(\"GET\", req, responseType, undefined, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 POST-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a POST request and returns the parsed response.\n * @template T - Expected response body type.\n * @param req - Request URL or configuration object.\n * @param responseType - Response parsing strategy.\n * @param body - Request body data.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public post<T = unknown>(\n req: RequestInterface | string,\n responseType: ResponseType = \"auto\",\n body?: RequestBodyData,\n signal?: AbortSignal,\n ): Promise<T> {\n return this._execute<T>(\"POST\", req, responseType, body, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 PUT-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a PUT request and returns the parsed response.\n * @template T - Expected response body type.\n * @param req - Request URL or configuration object.\n * @param responseType - Response parsing strategy.\n * @param body - Request body data.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public put<T = unknown>(\n req: RequestInterface | string,\n responseType: ResponseType = \"auto\",\n body?: RequestBodyData,\n signal?: AbortSignal,\n ): Promise<T> {\n return this._execute<T>(\"PUT\", req, responseType, body, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 PATCH-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a PATCH request and returns the parsed response.\n * @template T - Expected response body type.\n * @param req - Request URL or configuration object.\n * @param responseType - Response parsing strategy.\n * @param body - Request body data.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public patch<T = unknown>(\n req: RequestInterface | string,\n responseType: ResponseType = \"auto\",\n body?: RequestBodyData,\n signal?: AbortSignal,\n ): Promise<T> {\n return this._execute<T>(\"PATCH\", req, responseType, body, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 DELETE-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a DELETE request and returns the parsed response.\n * @template T - Expected response body type.\n * @param req - Request URL or configuration object.\n * @param responseType - Response parsing strategy.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public delete<T = unknown>(\n req: RequestInterface | string,\n responseType: ResponseType = \"auto\",\n signal?: AbortSignal,\n ): Promise<T> {\n return this._execute<T>(\"DELETE\", req, responseType, undefined, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 OPTIONS-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs an OPTIONS request and returns the parsed response.\n * @template T - Expected response body type.\n * @param req - Request URL or configuration object.\n * @param responseType - Response parsing strategy.\n * @param body - Optional request body data.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public options<T = unknown>(\n req: RequestInterface | string,\n responseType: ResponseType = \"auto\",\n body?: RequestBodyData,\n signal?: AbortSignal,\n ): Promise<T> {\n return this._execute<T>(\"OPTIONS\", req, responseType, body, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 HEAD-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438 \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u0438 (\u0431\u0435\u0437 \u0442\u0435\u043B\u0430).\n * @en Performs a HEAD request and returns status and headers (no body).\n * @param req - Request URL or configuration object.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to an object with status and headers.\n */\n public async head(\n req: RequestInterface | string,\n signal?: AbortSignal,\n ): Promise<{ status: number; headers: Record<string, string | string[]> }> {\n const request = this._buildRequest(req, \"auto\", undefined, signal);\n const response = await this._engine.head(request, signal);\n return {\n status: response.status,\n headers: response.headers as Record<string, string | string[]>,\n };\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 \u043F\u043E\u0442\u043E\u043A\u043E\u0432\u044B\u0439 GET-\u0437\u0430\u043F\u0440\u043E\u0441. \u0422\u0435\u043B\u043E \u043E\u0442\u0432\u0435\u0442\u0430 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044F \u043A\u0430\u043A ReadableStream.\n * @en Performs a streaming GET request. Response body is returned as a ReadableStream.\n * @param req - Request URL or configuration object.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the stream response.\n */\n public stream(req: RequestInterface | string, signal?: AbortSignal) {\n return this._engine.stream(req, signal);\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043F\u043E\u0441\u0442\u0440\u043E\u0438\u0442\u0435\u043B\u044C \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432 \u0434\u043B\u044F \u0446\u0435\u043F\u043E\u0447\u0435\u0447\u043D\u043E\u0433\u043E \u0444\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u044F HTTP-\u0437\u0430\u043F\u0440\u043E\u0441\u0430.\n * @en Returns a request builder for chainable HTTP request composition.\n * @param url - Target URL for the request.\n * @returns A RequestBuilder instance bound to this client.\n */\n public request(url: string): RequestBuilder {\n return new RequestBuilder(url, this);\n }\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u043D\u043E\u0432\u044B\u0439 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 \u043A\u043B\u0438\u0435\u043D\u0442\u0430, \u043E\u0431\u044A\u0435\u0434\u0438\u043D\u044F\u044F \u0442\u0435\u043A\u0443\u0449\u0443\u044E \u043A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044E \u0441 \u043F\u0435\u0440\u0435\u0434\u0430\u043D\u043D\u044B\u043C\u0438 \u043E\u043F\u0446\u0438\u044F\u043C\u0438.\n * @en Creates a new client instance by merging the current configuration with provided options.\n * @param options - Partial configuration options to extend.\n * @returns A new HyperClient instance.\n */\n public extend(options: Partial<HttpClientOptions>): HyperClient {\n return new HyperClient({\n ...this._config,\n ...options,\n network: { ...this._config.network, ...options.network },\n });\n }\n\n /**\n * @ru \u0410\u043B\u0438\u0430\u0441 \u0434\u043B\u044F extend(). \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u043D\u043E\u0432\u044B\u0439 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 \u043A\u043B\u0438\u0435\u043D\u0442\u0430.\n * @en Alias for extend(). Creates a new client instance.\n * @param options - Partial configuration options.\n * @returns A new HyperClient instance.\n */\n public create(options: Partial<HttpClientOptions>): HyperClient {\n return this.extend(options);\n }\n\n /**\n * @ru \u0417\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043E\u0442\u0443 \u043A\u043B\u0438\u0435\u043D\u0442\u0430 \u0438 \u043E\u0441\u0432\u043E\u0431\u043E\u0436\u0434\u0430\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044B (\u0441\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u044F, \u043F\u0443\u043B\u044B, \u043F\u043B\u0430\u0433\u0438\u043D\u044B).\n * @en Shuts down the client and releases resources (connections, pools, plugins).\n * @returns Promise that resolves when shutdown is complete.\n */\n public async destroy(): Promise<void> {\n await this._engine.destroy();\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043A\u0443 \u0440\u0430\u0431\u043E\u0442\u044B \u043A\u043B\u0438\u0435\u043D\u0442\u0430 (\u0430\u043A\u0442\u0438\u0432\u043D\u044B\u0435 \u0441\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u044F, \u043E\u0447\u0435\u0440\u0435\u0434\u044C, \u043A\u044D\u0448).\n * \u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u043F\u043B\u0430\u0433\u0438\u043D\u0430 \u043C\u0435\u0442\u0440\u0438\u043A \u0438\u043B\u0438 \u043E\u0447\u0435\u0440\u0435\u0434\u0438.\n * @en Returns client statistics (active connections, queue, cache).\n * Requires metrics or queue plugin to be registered.\n * @returns Statistics object, or undefined if no plugin provides it.\n */\n public getStats(): unknown {\n return (this._engine as unknown as HyperCoreEngine).getStats?.();\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u0441\u0435 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0435 \u043C\u0435\u0442\u0440\u0438\u043A\u0438 (latency, RPS, cache hits \u0438 \u0442.\u0434.).\n * \u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u043F\u043B\u0430\u0433\u0438\u043D\u0430 `withMetrics`.\n * @en Returns all aggregated metrics (latency, RPS, cache hits, etc.).\n * Requires the `withMetrics` plugin to be registered.\n * @returns Array of metrics, or undefined if the plugin is not registered.\n */\n public getAllMetrics(): RequestMetrics[] | undefined {\n return (this._engine as unknown as HyperCoreEngine).getAllMetrics?.();\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043A\u043E\u043D\u043A\u0440\u0435\u0442\u043D\u0443\u044E \u043C\u0435\u0442\u0440\u0438\u043A\u0443 \u043F\u043E \u043A\u043B\u044E\u0447\u0443.\n * \u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u043F\u043B\u0430\u0433\u0438\u043D\u0430 `withMetrics`.\n * @en Returns a specific metric by key.\n * Requires the `withMetrics` plugin to be registered.\n * @param key - Metric key (e.g., 'rps', 'avgLatency', 'cacheHits').\n * @returns Metric value, or undefined if not found.\n */\n public getMetrics(\n key: string,\n ): RequestMetrics | RequestMetrics[] | undefined {\n return (this._engine as unknown as HyperCoreEngine).getMetrics?.(key);\n }\n\n /**\n * @ru \u041E\u0447\u0438\u0449\u0430\u0435\u0442 \u043A\u044D\u0448 \u043E\u0442\u0432\u0435\u0442\u043E\u0432. \u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u043F\u043B\u0430\u0433\u0438\u043D\u0430 `withCache`.\n * @en Clears the response cache. Requires the `withCache` plugin.\n * @returns Void or Promise if async clearing is required.\n */\n public clearCache(): void | Promise<void> | undefined {\n return (this._engine as unknown as HyperCoreEngine).clearCache?.();\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u0443\u044E \u0441\u0432\u043E\u0434\u043A\u0443 \u043C\u0435\u0442\u0440\u0438\u043A (success rate, avg duration, bottlenecks).\n * \u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u043F\u043B\u0430\u0433\u0438\u043D\u0430 `withMetrics`.\n * @en Returns aggregated metrics summary (success rate, avg duration, bottlenecks).\n * Requires the `withMetrics` plugin to be registered.\n * @returns Summary object, or null if no metrics collected.\n */\n public getMetricsSummary(): unknown {\n return (this._engine as unknown as HyperCoreEngine).getMetricsSummary?.();\n }\n\n /**\n * @ru \u0421\u0431\u0440\u0430\u0441\u044B\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u043D\u0430\u043A\u043E\u043F\u043B\u0435\u043D\u043D\u044B\u0435 \u043C\u0435\u0442\u0440\u0438\u043A\u0438.\n * \u0422\u0440\u0435\u0431\u0443\u0435\u0442 \u043D\u0430\u043B\u0438\u0447\u0438\u044F \u043F\u043B\u0430\u0433\u0438\u043D\u0430 `withMetrics`.\n * @en Resets all accumulated metrics.\n * Requires the `withMetrics` plugin to be registered.\n */\n public resetMetrics(): void {\n (this._engine as unknown as HyperCoreEngine).resetMetrics?.();\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import type {\n HyperPlugin,\n HyperTransport,\n HyperClientOptions,\n HyperProtocols,\n UniversalResponse,\n} from \"@hyperttp/types\";\nimport { HyperCore, KNOWN_PROTOCOLS, RestProtocol } from \"@hyperttp/core\";\nimport { withCache } from \"@hyperttp/cache\";\nimport { withInflight } from \"@hyperttp/inflight\";\nimport { withInterceptors } from \"@hyperttp/interceptors\";\nimport { withMetrics } from \"@hyperttp/metrics\";\nimport { withParser } from \"@hyperttp/parser\";\nimport { withQueue } from \"@hyperttp/queue\";\nimport { withRateLimit } from \"@hyperttp/ratelimit\";\nimport { withSerializer } from \"@hyperttp/serializer\";\nimport { defaultConfig } from \"../defaultConfig.js\";\nimport { RequestBuilder, type ResponseType } from \"../Utils/RequestBuilder.js\";\nimport type { HttpMethod, RestInput, RestRequestOptions } from \"@hyperttp/core/rest\";\n\nexport type ShortcutRequestOptions = RestRequestOptions & {\n responseType?: ResponseType;\n};\n\ndeclare module \"@hyperttp/types\" {\n interface HyperClientOptions {\n /** Base URL used to resolve relative URLs passed to high-level client methods. */\n baseURL?: string;\n /** Disable automatic registration of built-in HyperClient plugins. */\n builtInPlugins?: boolean;\n }\n}\n\n/**\n * @ru \u0412\u044B\u0441\u043E\u043A\u043E\u0443\u0440\u043E\u0432\u043D\u0435\u0432\u044B\u0439 HTTP-\u043A\u043B\u0438\u0435\u043D\u0442 \u0441 \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u043E\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043F\u043B\u0430\u0433\u0438\u043D\u043E\u0432\n * (\u0441\u0435\u0440\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044F, \u043F\u0430\u0440\u0441\u0438\u043D\u0433, \u043E\u0447\u0435\u0440\u0435\u0434\u044C, rate limit, inflight, \u043A\u044D\u0448, \u043F\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043A\u0438, \u043C\u0435\u0442\u0440\u0438\u043A\u0438).\n * \u0414\u0435\u043B\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u0435 \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432 \u044F\u0434\u0440\u0443 HyperCore \u0438 \u0438\u0437\u0432\u043B\u0435\u043A\u0430\u0435\u0442 \u0442\u0435\u043B\u043E \u043E\u0442\u0432\u0435\u0442\u0430.\n * @en High-level HTTP client with automatic plugin registration\n * (serialization, parsing, queue, rate limit, inflight, cache, interceptors, metrics).\n * Delegates request execution to the HyperCore core and extracts the response body.\n */\n// oxlint-disable-next-line no-unsafe-declaration-merging\nexport interface HyperClient extends HyperProtocols {}\n\nexport class HyperClient {\n private readonly _engine: HyperCore;\n private readonly _config: HyperClientOptions;\n private readonly _transport?: HyperTransport;\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 HyperClient \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 REST-\u043F\u0440\u043E\u0442\u043E\u043A\u043E\u043B.\n * \u041F\u043B\u0430\u0433\u0438\u043D\u044B \u043F\u0435\u0440\u0435\u0434\u0430\u044E\u0442\u0441\u044F \u0447\u0435\u0440\u0435\u0437 config.plugins \u0438\u043B\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u044E\u0442\u0441\u044F \u0432\u0440\u0443\u0447\u043D\u0443\u044E \u0447\u0435\u0440\u0435\u0437 use().\n * @en Creates a HyperClient instance and registers the REST protocol.\n * Plugins are passed via config.plugins or registered manually via use().\n * @param config - Client configuration options.\n */\n constructor(config: HyperClientOptions = defaultConfig, transport?: HyperTransport) {\n this._config = {\n ...defaultConfig,\n ...config,\n retry: {\n ...defaultConfig.retry,\n ...config.retry,\n },\n };\n this._transport = transport;\n\n this._engine = new HyperCore(this._config, transport);\n\n if (this._config.builtInPlugins !== false) {\n this.useDefaultPlugins();\n }\n this._engine.registerProtocol(RestProtocol);\n this.exposeProtocolNamespaces();\n }\n\n /**\n * @ru \u041F\u043E\u0434\u043A\u043B\u044E\u0447\u0430\u0435\u0442 \u0441\u0442\u0430\u043D\u0434\u0430\u0440\u0442\u043D\u044B\u0439 \u043D\u0430\u0431\u043E\u0440 \u043F\u043B\u0430\u0433\u0438\u043D\u043E\u0432 \u043A\u043B\u0438\u0435\u043D\u0442\u0430.\n * @en Registers the client's built-in plugin set.\n */\n private useDefaultPlugins(): void {\n this.use(withInterceptors(this._config.interceptors));\n this.use(withSerializer(this._config.serializer));\n this.use(withMetrics(this._config.metrics));\n this.use(withInflight(this._config.inflight));\n this.use(withCache(this._config.cache));\n this.use(withRateLimit(this._config.rateLimit));\n this.use(withQueue(this._config.queue));\n if (this._config.responseConverter !== false) {\n this.use(withParser(this._config.responseConverter));\n }\n }\n\n /**\n * @ru \u0414\u0435\u043B\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u043F\u0440\u043E\u0441\u0442\u0440\u0430\u043D\u0441\u0442\u0432\u0430 \u0438\u043C\u0451\u043D \u043F\u0440\u043E\u0442\u043E\u043A\u043E\u043B\u043E\u0432 \u044F\u0434\u0440\u0430 \u043A\u043B\u0438\u0435\u043D\u0442\u0443.\n * \u0412\u043D\u0435\u0448\u043D\u0438\u0435 \u043F\u0430\u043A\u0435\u0442\u044B \u0440\u0430\u0441\u0448\u0438\u0440\u044F\u044E\u0442 HyperProtocols \u0447\u0435\u0440\u0435\u0437 module augmentation, \u043F\u043E\u044D\u0442\u043E\u043C\u0443\n * \u043F\u043E\u0441\u043B\u0435 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0438 @hyperttp/protocol-grpc \u0434\u043E\u0441\u0442\u0443\u043F\u0435\u043D client.grpc.call(...).\n * @en Delegates core protocol namespaces to the client. External protocol\n * packages augment HyperProtocols, making client.grpc.call(...) available.\n */\n private exposeProtocolNamespaces(): void {\n for (const protocol of KNOWN_PROTOCOLS) {\n Object.defineProperty(this, protocol, {\n configurable: false,\n enumerable: true,\n get: () => (this._engine as HyperCore & Record<string, unknown>)[protocol],\n });\n }\n }\n\n /**\n * @ru \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u043E\u043F\u043E\u043B\u043D\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u0439 \u043F\u043B\u0430\u0433\u0438\u043D \u0432 \u043A\u043B\u0438\u0435\u043D\u0442\u0435.\n * @en Registers an additional plugin in the client.\n * @param plugin - Plugin instance to register.\n * @returns The current instance for chaining.\n */\n public use(plugin: HyperPlugin): this {\n this._engine.use(plugin);\n return this;\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043C\u044F \u043A\u043B\u0430\u0441\u0441\u0430 \u0430\u043A\u0442\u0438\u0432\u043D\u043E\u0433\u043E \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430.\n * @en Returns the class name of the active transport.\n * @returns Promise resolving to the transport class name.\n */\n public async getTransportName(): Promise<string> {\n return this._engine.getTransportName();\n }\n\n private resolveUrl(url: string): string {\n return this._config.baseURL ? new URL(url, this._config.baseURL).toString() : url;\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 HTTP-\u0437\u0430\u043F\u0440\u043E\u0441 \u0447\u0435\u0440\u0435\u0437 \u044F\u0434\u0440\u043E \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u043E\u0435 \u0442\u0435\u043B\u043E \u043E\u0442\u0432\u0435\u0442\u0430.\n * @en Executes an HTTP request through the core and returns the parsed response body.\n * @template T - Expected response body type.\n * @param method - HTTP method.\n * @param url - Request URL.\n * @param options - Optional request options (headers, query, body, timeout).\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n * @internal Used by RequestBuilder to bypass the public API double-pass\n */\n public async _execute<T>(\n method: HttpMethod,\n url: string,\n options?: RestRequestOptions,\n signal?: AbortSignal,\n metadata?: Record<string, unknown>,\n ): Promise<T> {\n const requestSignal = signal ?? options?.signal;\n const request = {\n protocol: \"rest\" as const,\n input: {\n ...options,\n method,\n url: this.resolveUrl(url),\n signal: requestSignal,\n },\n signal: requestSignal,\n metadata,\n };\n const response = await this._engine.send<RestInput, T, \"rest\">(request);\n return response.data;\n }\n\n private executeShortcut<T>(\n method: HttpMethod,\n url: string,\n options?: ShortcutRequestOptions,\n signal?: AbortSignal,\n ): Promise<T> {\n const { responseType, ...requestOptions } = options ?? {};\n return this._execute<T>(\n method,\n url,\n requestOptions,\n signal,\n responseType ? { responseType } : undefined,\n );\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 GET-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a GET request and returns the parsed response.\n * @template T - Expected response body type.\n * @param url - Request URL.\n * @param responseType - Optional response format override.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public get<T = unknown>(\n url: string,\n responseType: ResponseType,\n signal?: AbortSignal,\n ): Promise<T>;\n public get<T = unknown>(\n url: string,\n options?: ShortcutRequestOptions,\n signal?: AbortSignal,\n ): Promise<T>;\n public get<T = unknown>(\n url: string,\n optionsOrResponseType?: ShortcutRequestOptions | ResponseType,\n signal?: AbortSignal,\n ): Promise<T> {\n const options =\n typeof optionsOrResponseType === \"string\"\n ? { responseType: optionsOrResponseType }\n : optionsOrResponseType;\n return this.executeShortcut<T>(\"GET\", url, options, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 POST-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a POST request and returns the parsed response.\n * @template T - Expected response body type.\n * @param url - Request URL.\n * @param body - Request body data.\n * @param options - Optional request options.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public post<T = unknown>(\n url: string,\n body?: unknown,\n optionsOrResponseType?: ShortcutRequestOptions | ResponseType,\n signal?: AbortSignal,\n ): Promise<T> {\n const options =\n typeof optionsOrResponseType === \"string\"\n ? { responseType: optionsOrResponseType, body }\n : { ...optionsOrResponseType, body };\n return this.executeShortcut<T>(\"POST\", url, options, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 PUT-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a PUT request and returns the parsed response.\n * @template T - Expected response body type.\n * @param url - Request URL.\n * @param body - Request body data.\n * @param options - Optional request options.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public put<T = unknown>(\n url: string,\n body?: unknown,\n optionsOrResponseType?: ShortcutRequestOptions | ResponseType,\n signal?: AbortSignal,\n ): Promise<T> {\n const options =\n typeof optionsOrResponseType === \"string\"\n ? { responseType: optionsOrResponseType, body }\n : { ...optionsOrResponseType, body };\n return this.executeShortcut<T>(\"PUT\", url, options, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 PATCH-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a PATCH request and returns the parsed response.\n * @template T - Expected response body type.\n * @param url - Request URL.\n * @param body - Request body data.\n * @param options - Optional request options.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public patch<T = unknown>(\n url: string,\n body?: unknown,\n optionsOrResponseType?: ShortcutRequestOptions | ResponseType,\n signal?: AbortSignal,\n ): Promise<T> {\n const options =\n typeof optionsOrResponseType === \"string\"\n ? { responseType: optionsOrResponseType, body }\n : { ...optionsOrResponseType, body };\n return this.executeShortcut<T>(\"PATCH\", url, options, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 DELETE-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs a DELETE request and returns the parsed response.\n * @template T - Expected response body type.\n * @param url - Request URL.\n * @param options - Optional request options.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public delete<T = unknown>(\n url: string,\n optionsOrResponseType?: ShortcutRequestOptions | ResponseType,\n signal?: AbortSignal,\n ): Promise<T> {\n const options =\n typeof optionsOrResponseType === \"string\"\n ? { responseType: optionsOrResponseType }\n : optionsOrResponseType;\n return this.executeShortcut<T>(\"DELETE\", url, options, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 OPTIONS-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0441\u043F\u0430\u0440\u0441\u0435\u043D\u043D\u044B\u0439 \u043E\u0442\u0432\u0435\u0442.\n * @en Performs an OPTIONS request and returns the parsed response.\n * @template T - Expected response body type.\n * @param url - Request URL.\n * @param body - Optional request body data.\n * @param options - Optional request options.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the parsed response body.\n */\n public options<T = unknown>(\n url: string,\n body?: unknown,\n optionsOrResponseType?: ShortcutRequestOptions | ResponseType,\n signal?: AbortSignal,\n ): Promise<T> {\n const options =\n typeof optionsOrResponseType === \"string\"\n ? { responseType: optionsOrResponseType, body }\n : { ...optionsOrResponseType, body };\n return this.executeShortcut<T>(\"OPTIONS\", url, options, signal);\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 HEAD-\u0437\u0430\u043F\u0440\u043E\u0441 \u0438 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438 \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u0438 (\u0431\u0435\u0437 \u0442\u0435\u043B\u0430).\n * @en Performs a HEAD request and returns status and headers (no body).\n * @param url - Request URL.\n * @param options - Optional request options.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to an object with status and headers.\n */\n public async head(\n url: string,\n options?: RestRequestOptions,\n signal?: AbortSignal,\n ): Promise<{ status: number; headers: Record<string, string | string[]> }> {\n const requestSignal = signal ?? options?.signal;\n const response = await this._engine.send<RestInput, unknown, \"rest\">({\n protocol: \"rest\",\n input: {\n ...options,\n method: \"HEAD\",\n url: this.resolveUrl(url),\n signal: requestSignal,\n },\n signal: requestSignal,\n });\n return {\n status: response.status,\n headers: response.headers as Record<string, string | string[]>,\n };\n }\n\n /**\n * @ru \u0412\u044B\u043F\u043E\u043B\u043D\u044F\u0435\u0442 \u043F\u043E\u0442\u043E\u043A\u043E\u0432\u044B\u0439 GET-\u0437\u0430\u043F\u0440\u043E\u0441. \u0422\u0435\u043B\u043E \u043E\u0442\u0432\u0435\u0442\u0430 \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044F \u043A\u0430\u043A \u0430\u0441\u0438\u043D\u0445\u0440\u043E\u043D\u043D\u043E \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043C\u044B\u0439 \u043F\u043E\u0442\u043E\u043A.\n * @en Performs a streaming GET request. Response data is returned as an async-iterable stream.\n * @param url - Request URL.\n * @param options - Optional request options.\n * @param signal - Optional abort signal.\n * @returns Promise resolving to the stream response.\n */\n public async stream(\n url: string,\n options?: RestRequestOptions,\n signal?: AbortSignal,\n ): Promise<UniversalResponse<AsyncIterable<Uint8Array>>> {\n const requestSignal = signal ?? options?.signal;\n return this._engine.send<RestInput, AsyncIterable<Uint8Array>, \"rest\">({\n protocol: \"rest\",\n input: {\n ...options,\n method: \"GET\",\n url: this.resolveUrl(url),\n stream: true,\n signal: requestSignal,\n },\n metadata: {\n responseType: \"stream\",\n },\n signal: requestSignal,\n });\n }\n\n public query<T = unknown>(\n url: string,\n body?: unknown,\n optionsOrResponseType?: ShortcutRequestOptions | ResponseType,\n signal?: AbortSignal,\n ): Promise<T> {\n const options =\n typeof optionsOrResponseType === \"string\"\n ? { responseType: optionsOrResponseType, body }\n : { ...optionsOrResponseType, body };\n return this.executeShortcut<T>(\"QUERY\", url, options, signal);\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043F\u043E\u0441\u0442\u0440\u043E\u0438\u0442\u0435\u043B\u044C \u0437\u0430\u043F\u0440\u043E\u0441\u043E\u0432 \u0434\u043B\u044F \u0446\u0435\u043F\u043E\u0447\u0435\u0447\u043D\u043E\u0433\u043E \u0444\u043E\u0440\u043C\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u044F HTTP-\u0437\u0430\u043F\u0440\u043E\u0441\u0430.\n * @en Returns a request builder for chainable HTTP request composition.\n * @param url - Target URL for the request.\n * @returns A RequestBuilder instance bound to this client.\n */\n public request(url: string): RequestBuilder {\n return new RequestBuilder(url, this);\n }\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u043D\u043E\u0432\u044B\u0439 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 \u043A\u043B\u0438\u0435\u043D\u0442\u0430, \u043E\u0431\u044A\u0435\u0434\u0438\u043D\u044F\u044F \u0442\u0435\u043A\u0443\u0449\u0443\u044E \u043A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044E \u0441 \u043F\u0435\u0440\u0435\u0434\u0430\u043D\u043D\u044B\u043C\u0438 \u043E\u043F\u0446\u0438\u044F\u043C\u0438.\n * @en Creates a new client instance by merging the current configuration with provided options.\n * @param options - Partial configuration options to extend.\n * @returns A new HyperClient instance.\n */\n public extend(options: Partial<HyperClientOptions>): HyperClient {\n const config: HyperClientOptions = {\n ...this._config,\n ...options,\n retry: {\n ...this._config.retry,\n ...options.retry,\n },\n };\n const transport = options.customTransport ?? this._transport;\n\n return new HyperClient(config, transport);\n }\n\n /**\n * @ru \u0410\u043B\u0438\u0430\u0441 \u0434\u043B\u044F extend(). \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u043D\u043E\u0432\u044B\u0439 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 \u043A\u043B\u0438\u0435\u043D\u0442\u0430.\n * @en Alias for extend(). Creates a new client instance.\n * @param options - Partial configuration options.\n * @returns A new HyperClient instance.\n */\n public create(options: Partial<HyperClientOptions>): HyperClient {\n return this.extend(options);\n }\n\n /**\n * @ru \u0417\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043E\u0442\u0443 \u043A\u043B\u0438\u0435\u043D\u0442\u0430 \u0438 \u043E\u0441\u0432\u043E\u0431\u043E\u0436\u0434\u0430\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044B (\u0441\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u044F, \u043F\u0443\u043B\u044B, \u043F\u043B\u0430\u0433\u0438\u043D\u044B).\n * @en Shuts down the client and releases resources (connections, pools, plugins).\n * @param graceful - If true, waits for active requests to complete before closing.\n * @returns Promise that resolves when shutdown is complete.\n */\n public async destroy(graceful?: boolean): Promise<void> {\n await this._engine.destroy(graceful);\n }\n}\n"],
|
|
5
|
+
"mappings": "aAOA,OAAS,aAAAA,EAAW,mBAAAC,EAAiB,gBAAAC,MAAoB,iBACzD,OAAS,aAAAC,MAAiB,kBAC1B,OAAS,gBAAAC,MAAoB,qBAC7B,OAAS,oBAAAC,MAAwB,yBACjC,OAAS,eAAAC,MAAmB,oBAC5B,OAAS,cAAAC,MAAkB,mBAC3B,OAAS,aAAAC,MAAiB,kBAC1B,OAAS,iBAAAC,MAAqB,sBAC9B,OAAS,kBAAAC,MAAsB,uBAC/B,OAAS,iBAAAC,MAAqB,sBAC9B,OAAS,kBAAAC,MAAyC,6BA2B5C,aAAO,WAAW,CACL,QACA,QACA,WASjB,YAAYC,EAA6BF,EAAeG,EAA0B,CAChF,KAAK,QAAU,CACb,GAAGH,EACH,GAAGE,EACH,MAAO,CACL,GAAGF,EAAc,MACjB,GAAGE,EAAO,QAGd,KAAK,WAAaC,EAElB,KAAK,QAAU,IAAId,EAAU,KAAK,QAASc,CAAS,EAEhD,KAAK,QAAQ,iBAAmB,IAClC,KAAK,kBAAiB,EAExB,KAAK,QAAQ,iBAAiBZ,CAAY,EAC1C,KAAK,yBAAwB,CAC/B,CAMQ,mBAAiB,CACvB,KAAK,IAAIG,EAAiB,KAAK,QAAQ,YAAY,CAAC,EACpD,KAAK,IAAIK,EAAe,KAAK,QAAQ,UAAU,CAAC,EAChD,KAAK,IAAIJ,EAAY,KAAK,QAAQ,OAAO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O,CACL,GAAGT,EACH,OAAQ,OACR,IAAK,KAAK,WAAWF,CAAG,EACxB,OAAQK,GAEV,OAAQA,EACT,EACD,MAAO,CACL,OAAQM,EAAS,OACjB,QAASA,EAAS,QAEtB,CAUO,MAAM,OACXX,EACAE,EACAC,EAAoB,CAEpB,MAAME,EAAgBF,GAAUD,GAAS,OACzC,OAAO,KAAK,QAAQ,KAAmD,CACrE,SAAU,OACV,MAAO,CACL,GAAGA,EACH,OAAQ,MACR,IAAK,KAAK,WAAWF,CAAG,EACxB,OAAQ,GACR,OAAQK,GAEV,SAAU,CACR,aAAc,UAEhB,OAAQA,EACT,CACH,CAEO,MACLL,EACAU,EACAD,EACAN,EAAoB,CAEpB,MAAMD,EACJ,OAAOO,GAA0B,SAC7B,CAAE,aAAcA,EAAuB,KAAAC,CAAI,EAC3C,CAAE,GAAGD,EAAuB,KAAAC,CAAI,EACtC,OAAO,KAAK,gBAAmB,QAASV,EAAKE,EAASC,CAAM,CAC9D,CAQO,QAAQH,EAAW,CACxB,OAAO,IAAIL,EAAeK,EAAK,IAAI,CACrC,CAQO,OAAOE,EAAoC,CAChD,MAAMN,EAA6B,CACjC,GAAG,KAAK,QACR,GAAGM,EACH,MAAO,CACL,GAAG,KAAK,QAAQ,MAChB,GAAGA,EAAQ,QAGTL,EAAYK,EAAQ,iBAAmB,KAAK,WAElD,OAAO,IAAI,YAAYN,EAAQC,CAAS,CAC1C,CAQO,OAAOK,EAAoC,CAChD,OAAO,KAAK,OAAOA,CAAO,CAC5B,CAQO,MAAM,QAAQU,EAAkB,CACrC,MAAM,KAAK,QAAQ,QAAQA,CAAQ,CACrC",
|
|
6
|
+
"names": ["HyperCore", "KNOWN_PROTOCOLS", "RestProtocol", "withCache", "withInflight", "withInterceptors", "withMetrics", "withParser", "withQueue", "withRateLimit", "withSerializer", "defaultConfig", "RequestBuilder", "config", "transport", "protocol", "plugin", "url", "method", "options", "signal", "metadata", "requestSignal", "request", "responseType", "requestOptions", "optionsOrResponseType", "body", "response", "graceful"]
|
|
7
7
|
}
|
package/Hyperttp/Request.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { HttpMethod } from "@hyperttp/core/rest";
|
|
2
|
+
import type { RequestQuery } from "./Utils/query.js";
|
|
3
|
+
export type RequestHeaders = Record<string, string>;
|
|
4
|
+
export type RequestBodyData = unknown;
|
|
5
|
+
export interface RequestConfig {
|
|
6
|
+
scheme: string;
|
|
7
|
+
host: string;
|
|
8
|
+
port?: number;
|
|
9
|
+
path?: string;
|
|
10
|
+
headers?: RequestHeaders;
|
|
11
|
+
query?: RequestQuery;
|
|
12
|
+
bodyData?: RequestBodyData;
|
|
13
|
+
}
|
|
2
14
|
/**
|
|
3
15
|
* @ru Представляет HTTP-запрос с настраиваемой схемой, хостом, портом, путём, заголовками, параметрами запроса и телом. Предоставляет методы для построения и манипуляции запросом.
|
|
4
16
|
* @en Represents an HTTP request with configurable scheme, host, port, path, headers, query, and body data. Provides methods to build and manipulate the request.
|
|
17
|
+
* @deprecated Use `HyperClient.request()` and `RequestBuilder` for new code.
|
|
5
18
|
*/
|
|
6
|
-
export default class Request
|
|
19
|
+
export default class Request {
|
|
7
20
|
private scheme;
|
|
8
21
|
private host;
|
|
9
22
|
private port;
|
|
@@ -11,7 +24,7 @@ export default class Request implements RequestInterface {
|
|
|
11
24
|
private _headers;
|
|
12
25
|
private _bodyData;
|
|
13
26
|
private _signal?;
|
|
14
|
-
method:
|
|
27
|
+
method: HttpMethod;
|
|
15
28
|
private bodyType;
|
|
16
29
|
private _meta;
|
|
17
30
|
query: RequestQuery;
|
|
@@ -161,7 +174,7 @@ export default class Request implements RequestInterface {
|
|
|
161
174
|
* @param method - HTTP method (e.g., 'GET', 'POST').
|
|
162
175
|
* @returns This request instance for chaining.
|
|
163
176
|
*/
|
|
164
|
-
setMethod(method:
|
|
177
|
+
setMethod(method: HttpMethod): this;
|
|
165
178
|
/**
|
|
166
179
|
* @ru Устанавливает сигнал отмены запроса.
|
|
167
180
|
* @en Sets the abort signal for the request.
|
|
@@ -198,6 +211,7 @@ export default class Request implements RequestInterface {
|
|
|
198
211
|
* @en Creates a deep copy of the current request.
|
|
199
212
|
* @returns Cloned request.
|
|
200
213
|
*/
|
|
214
|
+
private cloneValue;
|
|
201
215
|
clone(): Request;
|
|
202
216
|
/**
|
|
203
217
|
* @ru Создаёт новый запрос на основе текущего, добавляя указанные параметры запроса.
|
|
@@ -210,6 +224,7 @@ export default class Request implements RequestInterface {
|
|
|
210
224
|
/**
|
|
211
225
|
* @ru PreparedRequest исправно наследует измененное свойство. Создаёт запрос из базового URL.
|
|
212
226
|
* @en PreparedRequest correctly inherits changed properties. Creates a request from a base URL.
|
|
227
|
+
* @deprecated Use `HyperClient.request()` and `RequestBuilder` for new code.
|
|
213
228
|
*/
|
|
214
229
|
export declare class PreparedRequest extends Request {
|
|
215
230
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Request.d.ts","sourceRoot":"","sources":["../../src/Hyperttp/Request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Request.d.ts","sourceRoot":"","sources":["../../src/Hyperttp/Request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACpD,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC;AAEtC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,KAAK,CAAC,EAAE,YAAY,CAAC;IACr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1
|
+
"use strict";export default class n{scheme;host;port;path;_headers;_bodyData;_signal;method="GET";bodyType="json";_meta={};query;constructor(t){this.scheme=t.scheme,this.host=t.host,this.port=t.port??(t.scheme==="https"?443:80),this.path=t.path??"",this._headers=t.headers??{},this.query=t.query??{},this._bodyData=t.bodyData,this._signal=void 0,this._meta=t.meta??{}}get url(){return this.buildURL().toString()}get headers(){return this._headers}get body(){return this._bodyData}get signal(){return this._signal}get meta(){return this._meta}buildURL(){let t=this.host,e="";if(t.includes("://")&&(t=t.split("://")[1]),t.includes("/")){const i=t.split("/");t=i[0],e="/"+i.slice(1).join("/")}const s=new URL(`${this.scheme}://${t}`);s.port=this.port.toString();const r=e+(this.path.startsWith("/")?this.path:`/${this.path}`);s.pathname=r.replace(/\/+/g,"/");for(const[i,h]of Object.entries(this.query))h!=null&&(Array.isArray(h)?h.forEach(o=>s.searchParams.append(i,String(o))):s.searchParams.set(i,String(h)));return s}normalizePath(t){return!t||t==="/"?"":t.startsWith("/")?t:`/${t}`}isPlainObject(t){if(typeof t!="object"||t===null)return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||e===null}setPath(t){return this.path=this.normalizePath(t),this}setHost(t){return this.host=t,this}setHeaders(t){return this._headers={...t},this}addHeaders(t){return this._headers={...this._headers,...t},this}getQuery(){return this.query}setQuery(t){return this.query={...t},this}addQuery(t){return this.query={...this.query,...t},this}getQueryAsString(){const t=new URLSearchParams;for(const[s,r]of Object.entries(this.query))r!=null&&(Array.isArray(r)?r.forEach(i=>t.append(s,String(i))):t.set(s,String(r)));const e=t.toString();return e?`?${e}`:""}getBodyDataString(){return this._bodyData==null?"":typeof this._bodyData=="string"?this._bodyData:this.bodyType==="form"?new URLSearchParams(this._bodyData).toString():JSON.stringify(this._bodyData)}toFetchInit(){const e=this.method!=="GET"&&this.method!=="HEAD"?this.getBodyDataString():"";return{method:this.method,headers:this._headers,body:e||void 0,signal:this._signal}}setBodyData(t){return this._bodyData=this.isPlainObject(t)?{...t}:t,this}addBodyData(t){return this.isPlainObject(this._bodyData)&&this.isPlainObject(t)?this._bodyData={...this._bodyData,...t}:this._bodyData=t,this}setBodyType(t){return this.bodyType=t,this}setMethod(t){return this.method=t,this}setSignal(t){return this._signal=t,this}getURL(){return this.url}getHeaders(){return this.headers}getBodyData(){return this.body}getSignal(){return this.signal}cloneValue(t,e){try{return structuredClone(t)}catch{return e}}clone(){const t=new n({scheme:this.scheme,host:this.host,port:this.port,path:this.path||"",headers:this.cloneValue(this._headers,{...this._headers}),query:this.cloneValue(this.query,{...this.query}),bodyData:this.cloneValue(this._bodyData,this.isPlainObject(this._bodyData)?{...this._bodyData}:this._bodyData),meta:this.cloneValue(this._meta,{...this._meta})}).setMethod(this.method).setBodyType(this.bodyType);return this._signal&&t.setSignal(this._signal),t}withQuery(t){const e=this.clone();return e.setQuery({...e.query,...structuredClone(t)}),e}}export class PreparedRequest extends n{constructor(t){const e=new URL(t),s={};for(const[r,i]of e.searchParams){const h=s[r];h==null?s[r]=i:Array.isArray(h)?h.push(i):s[r]=[h,i]}super({scheme:e.protocol.replace(":",""),host:e.hostname,port:u(e),path:e.pathname==="/"?"":e.pathname,query:s})}}function u(a){if(a.port!==""){const t=Number(a.port);if(!Number.isNaN(t))return t}return a.protocol==="https:"?443:80}
|
|
2
2
|
//# sourceMappingURL=Request.js.map
|