hyperttp 0.4.2 → 0.4.4
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 +143 -106
- package/Hyperttp/Client/HyperClient.d.ts.map +1 -1
- package/Hyperttp/Client/HyperClient.js +259 -198
- package/Hyperttp/Client/HyperClient.js.map +1 -1
- package/Hyperttp/Request.d.ts +3 -3
- package/Hyperttp/Request.d.ts.map +1 -1
- package/Hyperttp/Request.js +1 -3
- package/Hyperttp/Request.js.map +1 -1
- package/Hyperttp/UrlExtractor.d.ts.map +1 -1
- package/Hyperttp/UrlExtractor.js.map +1 -1
- package/Hyperttp/Utils/RequestBuilder.d.ts +27 -6
- package/Hyperttp/Utils/RequestBuilder.d.ts.map +1 -1
- package/Hyperttp/Utils/RequestBuilder.js +59 -19
- package/Hyperttp/Utils/RequestBuilder.js.map +1 -1
- package/README.md +216 -33
- package/package.json +20 -21
|
@@ -1,300 +1,361 @@
|
|
|
1
|
-
import { HyperCore } from "@hyperttp/core";
|
|
2
|
-
import { RequestBuilder } from "../Utils/RequestBuilder.js";
|
|
3
1
|
import { defaultConfig } from "../defaultConfig.js";
|
|
2
|
+
import { HyperCore } from "@hyperttp/core";
|
|
3
|
+
import { withParser } from "@hyperttp/parser";
|
|
4
4
|
import { withSerializer } from "@hyperttp/serializer";
|
|
5
5
|
import { withQueue } from "@hyperttp/queue";
|
|
6
|
+
import { withCache } from "@hyperttp/cache";
|
|
6
7
|
import { withRateLimit } from "@hyperttp/ratelimit";
|
|
7
8
|
import { withInflight } from "@hyperttp/inflight";
|
|
8
|
-
import { withCache } from "@hyperttp/cache";
|
|
9
9
|
import { withInterceptors } from "@hyperttp/interceptors";
|
|
10
10
|
import { withMetrics } from "@hyperttp/metrics";
|
|
11
|
-
import { withParser } from "@hyperttp/parser";
|
|
12
11
|
const EMPTY_HEADERS = Object.freeze({});
|
|
13
|
-
function streamCloneHandler() {
|
|
14
|
-
return {
|
|
15
|
-
status: this.status,
|
|
16
|
-
headers: this.headers,
|
|
17
|
-
body: this.body,
|
|
18
|
-
url: this.url,
|
|
19
|
-
clone: streamCloneHandler,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
12
|
/**
|
|
23
|
-
* @ru
|
|
24
|
-
*
|
|
13
|
+
* @ru Высокоуровневый HTTP-клиент с автоматической регистрацией плагинов
|
|
14
|
+
* (сериализация, парсинг, очередь, rate limit, inflight, кэш, перехватчики, метрики).
|
|
15
|
+
* Делегирует выполнение запросов ядру HyperCore и извлекает тело ответа.
|
|
16
|
+
* @en High-level HTTP client with automatic plugin registration
|
|
17
|
+
* (serialization, parsing, queue, rate limit, inflight, cache, interceptors, metrics).
|
|
18
|
+
* Delegates request execution to the HyperCore core and extracts the response body.
|
|
25
19
|
*/
|
|
26
20
|
export class HyperClient {
|
|
27
21
|
_engine;
|
|
28
22
|
_config;
|
|
29
23
|
/**
|
|
30
|
-
* @ru Создаёт экземпляр HyperClient
|
|
31
|
-
* @en Creates a HyperClient instance
|
|
32
|
-
* @param config - Client configuration
|
|
24
|
+
* @ru Создаёт экземпляр HyperClient и регистрирует все стандартные плагины.
|
|
25
|
+
* @en Creates a HyperClient instance and registers all standard plugins.
|
|
26
|
+
* @param config - Client configuration options.
|
|
33
27
|
*/
|
|
34
28
|
constructor(config = defaultConfig) {
|
|
35
29
|
this._config = {
|
|
36
30
|
...defaultConfig,
|
|
37
31
|
...config,
|
|
38
|
-
network: config.network
|
|
39
|
-
? { ...defaultConfig.network, ...config.network }
|
|
40
|
-
: defaultConfig.network,
|
|
41
|
-
logger: config.logger ?? (() => { }),
|
|
32
|
+
network: { ...defaultConfig.network, ...config.network },
|
|
42
33
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
34
|
+
this._engine = new HyperCore(this._config);
|
|
35
|
+
this._engine.use(withSerializer());
|
|
36
|
+
this._engine.use(withParser(this._config.responseConverter));
|
|
37
|
+
this._engine.use(withQueue());
|
|
38
|
+
this._engine.use(withRateLimit(this._config.rateLimit));
|
|
39
|
+
this._engine.use(withInflight(this._config.inflight));
|
|
40
|
+
this._engine.use(withCache(this._config.cache));
|
|
41
|
+
this._engine.use(withInterceptors());
|
|
42
|
+
this._engine.use(withMetrics(this._config.metrics));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @ru Регистрирует дополнительный плагин в клиенте.
|
|
46
|
+
* @en Registers an additional plugin in the client.
|
|
47
|
+
* @param plugin - Plugin instance to register.
|
|
48
|
+
* @returns The current instance for chaining.
|
|
49
|
+
*/
|
|
50
|
+
use(plugin) {
|
|
51
|
+
this._engine.use(plugin);
|
|
52
|
+
return this;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
* @ru Возвращает
|
|
56
|
-
* @en Returns the
|
|
55
|
+
* @ru Возвращает имя класса активного транспорта.
|
|
56
|
+
* @en Returns the class name of the active transport.
|
|
57
|
+
* @returns Promise resolving to the transport class name.
|
|
57
58
|
*/
|
|
58
59
|
async getTransportName() {
|
|
59
60
|
return this._engine.getTransportName();
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
/**
|
|
63
|
+
* @ru Строит RequestInterface, правильно извлекая данные из геттеров старого класса Request.
|
|
64
|
+
* @en Builds RequestInterface, correctly extracting data from getters of the old Request class.
|
|
65
|
+
* @param req - Request URL or configuration object.
|
|
66
|
+
* @param responseType - Response parsing strategy.
|
|
67
|
+
* @param body - Optional request body.
|
|
68
|
+
* @param signal - Optional abort signal.
|
|
69
|
+
* @returns Normalized RequestInterface ready for dispatching.
|
|
70
|
+
*/
|
|
71
|
+
_buildRequest(req, responseType, body, signal) {
|
|
72
|
+
if (typeof req === "string") {
|
|
73
|
+
return {
|
|
74
|
+
url: req,
|
|
75
|
+
headers: EMPTY_HEADERS,
|
|
76
|
+
body,
|
|
77
|
+
signal,
|
|
78
|
+
meta: { responseType },
|
|
79
|
+
};
|
|
80
|
+
}
|
|
78
81
|
const r = req;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
const url = req.url ?? r.getURL?.() ?? "";
|
|
83
|
+
const headers = req.headers ?? r.getHeaders?.() ?? EMPTY_HEADERS;
|
|
84
|
+
const extractedBody = body ?? r.body ?? r.bodyData ?? r._bodyData ?? r.getBodyData?.() ?? r.getBodyDataString?.();
|
|
85
|
+
const extractedSignal = signal ?? req.signal ?? r.getSignal?.();
|
|
86
|
+
let finalUrl = url;
|
|
87
|
+
const query = req.query ?? r.getQuery?.();
|
|
88
|
+
if (query && Object.keys(query).length > 0) {
|
|
89
|
+
try {
|
|
90
|
+
const urlObj = new URL(finalUrl);
|
|
91
|
+
for (const k in query) {
|
|
92
|
+
if (Object.prototype.hasOwnProperty.call(query, k)) {
|
|
93
|
+
const v = query[k];
|
|
94
|
+
if (v == null)
|
|
95
|
+
continue;
|
|
96
|
+
if (Array.isArray(v)) {
|
|
97
|
+
for (const item of v) {
|
|
98
|
+
if (item != null)
|
|
99
|
+
urlObj.searchParams.append(k, String(item));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
urlObj.searchParams.set(k, String(v));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
finalUrl = urlObj.toString();
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
const qs = r.getQueryAsString?.();
|
|
111
|
+
if (qs)
|
|
112
|
+
finalUrl += qs;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const qs = r.getQueryAsString?.();
|
|
117
|
+
if (qs)
|
|
118
|
+
finalUrl += qs;
|
|
119
|
+
}
|
|
91
120
|
return {
|
|
92
|
-
|
|
93
|
-
headers
|
|
94
|
-
body:
|
|
95
|
-
|
|
96
|
-
|
|
121
|
+
url: finalUrl,
|
|
122
|
+
headers,
|
|
123
|
+
body: extractedBody,
|
|
124
|
+
signal: extractedSignal,
|
|
125
|
+
meta: { ...req.meta, responseType },
|
|
97
126
|
};
|
|
98
127
|
}
|
|
99
128
|
/**
|
|
100
|
-
* @ru Выполняет
|
|
101
|
-
*
|
|
102
|
-
* @
|
|
103
|
-
*
|
|
129
|
+
* @ru Выполняет HTTP-запрос через ядро и возвращает распарсенное тело ответа.
|
|
130
|
+
* Плагин withParser автоматически парсит тело на основе meta.responseType.
|
|
131
|
+
* @en Executes an HTTP request through the core and returns the parsed response body.
|
|
132
|
+
* The withParser plugin automatically parses the body based on meta.responseType.
|
|
133
|
+
* @template T - Expected response body type.
|
|
134
|
+
* @param method - HTTP method (GET, POST, etc.).
|
|
135
|
+
* @param req - Request URL or configuration object.
|
|
136
|
+
* @param responseType - Response parsing strategy.
|
|
137
|
+
* @param body - Optional request body.
|
|
104
138
|
* @param signal - Optional abort signal.
|
|
105
|
-
* @returns Promise
|
|
139
|
+
* @returns Promise resolving to the parsed response body.
|
|
106
140
|
*/
|
|
107
|
-
async
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
:
|
|
112
|
-
|
|
141
|
+
async _execute(method, req, responseType = "auto", body, signal) {
|
|
142
|
+
const request = this._buildRequest(req, responseType, body, signal);
|
|
143
|
+
let response;
|
|
144
|
+
switch (method) {
|
|
145
|
+
case "GET":
|
|
146
|
+
response = await this._engine.get(request, signal);
|
|
147
|
+
break;
|
|
148
|
+
case "POST":
|
|
149
|
+
response = await this._engine.post(request, request.body, signal);
|
|
150
|
+
break;
|
|
151
|
+
case "PUT":
|
|
152
|
+
response = await this._engine.put(request, request.body, signal);
|
|
153
|
+
break;
|
|
154
|
+
case "PATCH":
|
|
155
|
+
response = await this._engine.patch(request, request.body, signal);
|
|
156
|
+
break;
|
|
157
|
+
case "DELETE":
|
|
158
|
+
response = await this._engine.delete(request, signal);
|
|
159
|
+
break;
|
|
160
|
+
case "OPTIONS":
|
|
161
|
+
response = await this._engine.options(request, request.body, signal);
|
|
162
|
+
break;
|
|
163
|
+
case "HEAD":
|
|
164
|
+
response = await this._engine.head(request, signal);
|
|
165
|
+
break;
|
|
166
|
+
default:
|
|
167
|
+
response = await this._engine.get(request, signal);
|
|
168
|
+
}
|
|
169
|
+
return response.body;
|
|
113
170
|
}
|
|
114
171
|
/**
|
|
115
|
-
* @ru Выполняет
|
|
116
|
-
* @en Performs a
|
|
117
|
-
* @
|
|
118
|
-
* @param
|
|
119
|
-
* @param
|
|
172
|
+
* @ru Выполняет GET-запрос и возвращает распарсенный ответ.
|
|
173
|
+
* @en Performs a GET request and returns the parsed response.
|
|
174
|
+
* @template T - Expected response body type.
|
|
175
|
+
* @param req - Request URL or configuration object.
|
|
176
|
+
* @param responseType - Response parsing strategy ('auto', 'json', 'text', 'stream', 'buffer', 'blob', 'xml', 'html').
|
|
120
177
|
* @param signal - Optional abort signal.
|
|
121
|
-
* @returns Promise
|
|
178
|
+
* @returns Promise resolving to the parsed response body.
|
|
122
179
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return this._engine
|
|
126
|
-
.post(typeof req === "string"
|
|
127
|
-
? { url: req, headers: EMPTY_HEADERS, signal, meta: { responseType } }
|
|
128
|
-
: this.wrapRequest(req, responseType, signal), finalBody, signal)
|
|
129
|
-
.then(HyperClient.extractBodyFromResponse);
|
|
180
|
+
get(req, responseType = "auto", signal) {
|
|
181
|
+
return this._execute("GET", req, responseType, undefined, signal);
|
|
130
182
|
}
|
|
131
183
|
/**
|
|
132
|
-
* @ru Выполняет
|
|
133
|
-
* @en Performs a
|
|
134
|
-
* @
|
|
135
|
-
* @param
|
|
136
|
-
* @param
|
|
184
|
+
* @ru Выполняет POST-запрос и возвращает распарсенный ответ.
|
|
185
|
+
* @en Performs a POST request and returns the parsed response.
|
|
186
|
+
* @template T - Expected response body type.
|
|
187
|
+
* @param req - Request URL or configuration object.
|
|
188
|
+
* @param responseType - Response parsing strategy.
|
|
189
|
+
* @param body - Request body data.
|
|
137
190
|
* @param signal - Optional abort signal.
|
|
138
|
-
* @returns Promise
|
|
191
|
+
* @returns Promise resolving to the parsed response body.
|
|
139
192
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return this._engine
|
|
143
|
-
.put(typeof req === "string"
|
|
144
|
-
? { url: req, headers: EMPTY_HEADERS, signal, meta: { responseType } }
|
|
145
|
-
: this.wrapRequest(req, responseType, signal), finalBody, signal)
|
|
146
|
-
.then(HyperClient.extractBodyFromResponse);
|
|
193
|
+
post(req, responseType = "auto", body, signal) {
|
|
194
|
+
return this._execute("POST", req, responseType, body, signal);
|
|
147
195
|
}
|
|
148
196
|
/**
|
|
149
|
-
* @ru Выполняет
|
|
150
|
-
* @en Performs a
|
|
151
|
-
* @
|
|
152
|
-
* @param
|
|
153
|
-
* @param
|
|
197
|
+
* @ru Выполняет PUT-запрос и возвращает распарсенный ответ.
|
|
198
|
+
* @en Performs a PUT request and returns the parsed response.
|
|
199
|
+
* @template T - Expected response body type.
|
|
200
|
+
* @param req - Request URL or configuration object.
|
|
201
|
+
* @param responseType - Response parsing strategy.
|
|
202
|
+
* @param body - Request body data.
|
|
154
203
|
* @param signal - Optional abort signal.
|
|
155
|
-
* @returns Promise
|
|
204
|
+
* @returns Promise resolving to the parsed response body.
|
|
156
205
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return this._engine
|
|
160
|
-
.patch(typeof req === "string"
|
|
161
|
-
? { url: req, headers: EMPTY_HEADERS, signal, meta: { responseType } }
|
|
162
|
-
: this.wrapRequest(req, responseType, signal), finalBody, signal)
|
|
163
|
-
.then(HyperClient.extractBodyFromResponse);
|
|
206
|
+
put(req, responseType = "auto", body, signal) {
|
|
207
|
+
return this._execute("PUT", req, responseType, body, signal);
|
|
164
208
|
}
|
|
165
209
|
/**
|
|
166
|
-
* @ru Выполняет
|
|
167
|
-
* @en Performs
|
|
168
|
-
* @
|
|
169
|
-
* @param
|
|
170
|
-
* @param
|
|
210
|
+
* @ru Выполняет PATCH-запрос и возвращает распарсенный ответ.
|
|
211
|
+
* @en Performs a PATCH request and returns the parsed response.
|
|
212
|
+
* @template T - Expected response body type.
|
|
213
|
+
* @param req - Request URL or configuration object.
|
|
214
|
+
* @param responseType - Response parsing strategy.
|
|
215
|
+
* @param body - Request body data.
|
|
171
216
|
* @param signal - Optional abort signal.
|
|
172
|
-
* @returns Promise
|
|
217
|
+
* @returns Promise resolving to the parsed response body.
|
|
173
218
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return this._engine
|
|
177
|
-
.options(typeof req === "string"
|
|
178
|
-
? { url: req, headers: EMPTY_HEADERS, signal, meta: { responseType } }
|
|
179
|
-
: this.wrapRequest(req, responseType, signal), finalBody, signal)
|
|
180
|
-
.then(HyperClient.extractBodyFromResponse);
|
|
219
|
+
patch(req, responseType = "auto", body, signal) {
|
|
220
|
+
return this._execute("PATCH", req, responseType, body, signal);
|
|
181
221
|
}
|
|
182
222
|
/**
|
|
183
|
-
* @ru Выполняет DELETE-запрос и возвращает распарсенный
|
|
184
|
-
* @en Performs a DELETE request and returns the parsed response
|
|
185
|
-
* @
|
|
186
|
-
* @param
|
|
223
|
+
* @ru Выполняет DELETE-запрос и возвращает распарсенный ответ.
|
|
224
|
+
* @en Performs a DELETE request and returns the parsed response.
|
|
225
|
+
* @template T - Expected response body type.
|
|
226
|
+
* @param req - Request URL or configuration object.
|
|
227
|
+
* @param responseType - Response parsing strategy.
|
|
187
228
|
* @param signal - Optional abort signal.
|
|
188
|
-
* @returns Promise
|
|
229
|
+
* @returns Promise resolving to the parsed response body.
|
|
189
230
|
*/
|
|
190
|
-
|
|
191
|
-
return this.
|
|
192
|
-
.delete(typeof req === "string"
|
|
193
|
-
? { url: req, headers: EMPTY_HEADERS, signal, meta: { responseType } }
|
|
194
|
-
: this.wrapRequest(req, responseType, signal), signal)
|
|
195
|
-
.then(HyperClient.extractBodyFromResponse);
|
|
231
|
+
delete(req, responseType = "auto", signal) {
|
|
232
|
+
return this._execute("DELETE", req, responseType, undefined, signal);
|
|
196
233
|
}
|
|
197
234
|
/**
|
|
198
|
-
* @ru Выполняет
|
|
199
|
-
* @en Performs
|
|
200
|
-
* @
|
|
201
|
-
* @param
|
|
235
|
+
* @ru Выполняет OPTIONS-запрос и возвращает распарсенный ответ.
|
|
236
|
+
* @en Performs an OPTIONS request and returns the parsed response.
|
|
237
|
+
* @template T - Expected response body type.
|
|
238
|
+
* @param req - Request URL or configuration object.
|
|
239
|
+
* @param responseType - Response parsing strategy.
|
|
240
|
+
* @param body - Optional request body data.
|
|
202
241
|
* @param signal - Optional abort signal.
|
|
203
|
-
* @returns Promise
|
|
242
|
+
* @returns Promise resolving to the parsed response body.
|
|
204
243
|
*/
|
|
205
|
-
|
|
206
|
-
return this.
|
|
207
|
-
.head(typeof req === "string"
|
|
208
|
-
? { url: req, headers: EMPTY_HEADERS, signal, meta: { responseType } }
|
|
209
|
-
: this.wrapRequest(req, responseType, signal), signal)
|
|
210
|
-
.then(HyperClient.formatHeadResponse);
|
|
244
|
+
options(req, responseType = "auto", body, signal) {
|
|
245
|
+
return this._execute("OPTIONS", req, responseType, body, signal);
|
|
211
246
|
}
|
|
212
247
|
/**
|
|
213
|
-
* @ru Выполняет
|
|
214
|
-
* @en Performs a
|
|
215
|
-
* @param req - Request URL or
|
|
248
|
+
* @ru Выполняет HEAD-запрос и возвращает статус и заголовки (без тела).
|
|
249
|
+
* @en Performs a HEAD request and returns status and headers (no body).
|
|
250
|
+
* @param req - Request URL or configuration object.
|
|
216
251
|
* @param signal - Optional abort signal.
|
|
217
|
-
* @returns Promise
|
|
252
|
+
* @returns Promise resolving to an object with status and headers.
|
|
218
253
|
*/
|
|
219
|
-
async
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
254
|
+
async head(req, signal) {
|
|
255
|
+
const request = this._buildRequest(req, "auto", undefined, signal);
|
|
256
|
+
const response = await this._engine.head(request, signal);
|
|
257
|
+
return {
|
|
258
|
+
status: response.status,
|
|
259
|
+
headers: response.headers,
|
|
260
|
+
};
|
|
223
261
|
}
|
|
224
262
|
/**
|
|
225
|
-
* @ru
|
|
226
|
-
* @en
|
|
227
|
-
* @param
|
|
228
|
-
* @
|
|
263
|
+
* @ru Выполняет потоковый GET-запрос. Тело ответа возвращается как ReadableStream.
|
|
264
|
+
* @en Performs a streaming GET request. Response body is returned as a ReadableStream.
|
|
265
|
+
* @param req - Request URL or configuration object.
|
|
266
|
+
* @param signal - Optional abort signal.
|
|
267
|
+
* @returns Promise resolving to the stream response.
|
|
229
268
|
*/
|
|
230
|
-
|
|
231
|
-
return
|
|
269
|
+
stream(req, signal) {
|
|
270
|
+
return this._engine.stream(req, signal);
|
|
232
271
|
}
|
|
233
272
|
/**
|
|
234
|
-
* @ru Создаёт новый экземпляр
|
|
235
|
-
* @en Creates a new
|
|
236
|
-
* @param options - Partial configuration to
|
|
237
|
-
* @returns
|
|
273
|
+
* @ru Создаёт новый экземпляр клиента, объединяя текущую конфигурацию с переданными опциями.
|
|
274
|
+
* @en Creates a new client instance by merging the current configuration with provided options.
|
|
275
|
+
* @param options - Partial configuration options to extend.
|
|
276
|
+
* @returns A new HyperClient instance.
|
|
238
277
|
*/
|
|
239
278
|
extend(options) {
|
|
240
279
|
return new HyperClient({
|
|
241
280
|
...this._config,
|
|
242
281
|
...options,
|
|
243
|
-
network: {
|
|
244
|
-
...this._config.network,
|
|
245
|
-
...options.network,
|
|
246
|
-
},
|
|
282
|
+
network: { ...this._config.network, ...options.network },
|
|
247
283
|
});
|
|
248
284
|
}
|
|
249
285
|
/**
|
|
250
|
-
* @ru Алиас для extend(). Создаёт новый экземпляр
|
|
251
|
-
* @en Alias for extend(). Creates a new
|
|
252
|
-
* @param options -
|
|
253
|
-
* @returns
|
|
286
|
+
* @ru Алиас для extend(). Создаёт новый экземпляр клиента.
|
|
287
|
+
* @en Alias for extend(). Creates a new client instance.
|
|
288
|
+
* @param options - Partial configuration options.
|
|
289
|
+
* @returns A new HyperClient instance.
|
|
254
290
|
*/
|
|
255
291
|
create(options) {
|
|
256
292
|
return this.extend(options);
|
|
257
293
|
}
|
|
258
294
|
/**
|
|
259
|
-
* @ru
|
|
260
|
-
* @en
|
|
261
|
-
* @returns Promise that resolves
|
|
295
|
+
* @ru Завершает работу клиента и освобождает ресурсы (соединения, пулы, плагины).
|
|
296
|
+
* @en Shuts down the client and releases resources (connections, pools, plugins).
|
|
297
|
+
* @returns Promise that resolves when shutdown is complete.
|
|
262
298
|
*/
|
|
263
299
|
async destroy() {
|
|
264
300
|
await this._engine.destroy();
|
|
265
301
|
}
|
|
266
302
|
/**
|
|
267
|
-
* @ru Возвращает статистику работы клиента (
|
|
268
|
-
*
|
|
269
|
-
* @
|
|
303
|
+
* @ru Возвращает статистику работы клиента (активные соединения, очередь, кэш).
|
|
304
|
+
* Требует наличия плагина метрик или очереди.
|
|
305
|
+
* @en Returns client statistics (active connections, queue, cache).
|
|
306
|
+
* Requires metrics or queue plugin to be registered.
|
|
307
|
+
* @returns Statistics object, or undefined if no plugin provides it.
|
|
270
308
|
*/
|
|
271
309
|
getStats() {
|
|
272
310
|
return this._engine.getStats?.();
|
|
273
311
|
}
|
|
274
312
|
/**
|
|
275
|
-
* @ru
|
|
276
|
-
*
|
|
277
|
-
* @
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return this._engine.clearCache?.();
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* @ru Возвращает все метрики (если включен плагин метрик).
|
|
284
|
-
* @en Returns all metrics (if the metrics plugin is enabled).
|
|
285
|
-
* @returns Metrics object or undefined.
|
|
313
|
+
* @ru Возвращает все агрегированные метрики (latency, RPS, cache hits и т.д.).
|
|
314
|
+
* Требует наличия плагина `withMetrics`.
|
|
315
|
+
* @en Returns all aggregated metrics (latency, RPS, cache hits, etc.).
|
|
316
|
+
* Requires the `withMetrics` plugin to be registered.
|
|
317
|
+
* @returns Array of metrics, or undefined if the plugin is not registered.
|
|
286
318
|
*/
|
|
287
319
|
getAllMetrics() {
|
|
288
320
|
return this._engine.getAllMetrics?.();
|
|
289
321
|
}
|
|
290
322
|
/**
|
|
291
323
|
* @ru Возвращает конкретную метрику по ключу.
|
|
324
|
+
* Требует наличия плагина `withMetrics`.
|
|
292
325
|
* @en Returns a specific metric by key.
|
|
293
|
-
*
|
|
294
|
-
* @
|
|
326
|
+
* Requires the `withMetrics` plugin to be registered.
|
|
327
|
+
* @param key - Metric key (e.g., 'rps', 'avgLatency', 'cacheHits').
|
|
328
|
+
* @returns Metric value, or undefined if not found.
|
|
295
329
|
*/
|
|
296
330
|
getMetrics(key) {
|
|
297
331
|
return this._engine.getMetrics?.(key);
|
|
298
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* @ru Очищает кэш ответов. Требует наличия плагина `withCache`.
|
|
335
|
+
* @en Clears the response cache. Requires the `withCache` plugin.
|
|
336
|
+
* @returns Void or Promise if async clearing is required.
|
|
337
|
+
*/
|
|
338
|
+
clearCache() {
|
|
339
|
+
return this._engine.clearCache?.();
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* @ru Возвращает агрегированную сводку метрик (success rate, avg duration, bottlenecks).
|
|
343
|
+
* Требует наличия плагина `withMetrics`.
|
|
344
|
+
* @en Returns aggregated metrics summary (success rate, avg duration, bottlenecks).
|
|
345
|
+
* Requires the `withMetrics` plugin to be registered.
|
|
346
|
+
* @returns Summary object, or null if no metrics collected.
|
|
347
|
+
*/
|
|
348
|
+
getMetricsSummary() {
|
|
349
|
+
return this._engine.getMetricsSummary?.();
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* @ru Сбрасывает все накопленные метрики.
|
|
353
|
+
* Требует наличия плагина `withMetrics`.
|
|
354
|
+
* @en Resets all accumulated metrics.
|
|
355
|
+
* Requires the `withMetrics` plugin to be registered.
|
|
356
|
+
*/
|
|
357
|
+
resetMetrics() {
|
|
358
|
+
this._engine.resetMetrics?.();
|
|
359
|
+
}
|
|
299
360
|
}
|
|
300
361
|
//# sourceMappingURL=HyperClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperClient.js","sourceRoot":"","sources":["../../../src/Hyperttp/Client/HyperClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HyperClient.js","sourceRoot":"","sources":["../../../src/Hyperttp/Client/HyperClient.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,aAAa,GAAoC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAezE;;;;;;;GAOG;AACH,MAAM,OAAO,WAAW;IACL,OAAO,CAAY;IACnB,OAAO,CAAoB;IAE5C;;;;OAIG;IACH,YAAY,SAA4B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