@hyperttp/core 1.3.3 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Core/HyperCore.d.ts +142 -152
- package/Core/HyperCore.d.ts.map +1 -1
- package/Core/HyperCore.js +285 -286
- package/Core/HyperCore.js.map +1 -1
- package/package.json +14 -8
- package/transports/browser.d.ts +228 -0
- package/transports/browser.d.ts.map +1 -0
- package/transports/browser.js +451 -0
- package/transports/browser.js.map +1 -0
- package/transports/manager.d.ts +7 -67
- package/transports/manager.d.ts.map +1 -1
- package/transports/manager.js +138 -145
- package/transports/manager.js.map +1 -1
- package/transports/node.d.ts +0 -20
- package/transports/node.d.ts.map +1 -1
- package/transports/node.js +104 -48
- package/transports/node.js.map +1 -1
- package/utils/decompress.d.ts +16 -18
- package/utils/decompress.d.ts.map +1 -1
- package/utils/decompress.js +143 -63
- package/utils/decompress.js.map +1 -1
- package/utils/errors.d.ts +0 -10
- package/utils/errors.d.ts.map +1 -1
- package/utils/errors.js +1 -11
- package/utils/errors.js.map +1 -1
- package/utils/merge.d.ts +0 -3
- package/utils/merge.d.ts.map +1 -1
- package/utils/merge.js +0 -4
- package/utils/merge.js.map +1 -1
- package/utils/normalize.d.ts +40 -20
- package/utils/normalize.d.ts.map +1 -1
- package/utils/normalize.js +197 -63
- package/utils/normalize.js.map +1 -1
- package/utils/pipeline.d.ts +10 -30
- package/utils/pipeline.d.ts.map +1 -1
- package/utils/pipeline.js +44 -44
- package/utils/pipeline.js.map +1 -1
- package/utils/response.d.ts +95 -31
- package/utils/response.d.ts.map +1 -1
- package/utils/response.js +288 -58
- package/utils/response.js.map +1 -1
- package/utils/retryUtils.d.ts +2 -10
- package/utils/retryUtils.d.ts.map +1 -1
- package/utils/retryUtils.js +17 -21
- package/utils/retryUtils.js.map +1 -1
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { defaultConfig } from "../defaultConfig.js";
|
|
2
|
+
import { mapResponseFast, mapStreamFast, mergeHeadersFast } from "../utils/response.js";
|
|
3
|
+
import { TransportManager } from "../transports/manager.js";
|
|
4
|
+
import { createPipelines, executeErrorPipeline, executeRequestPipeline, executeResponsePipeline, executeResponseDataPipeline, insertHookSorted, } from "../utils/pipeline.js";
|
|
5
|
+
import { normalizeBody, normalizeHeaders, normalizeUrl } from "../utils/normalize.js";
|
|
6
|
+
const urlCache = Object.create(null);
|
|
7
|
+
let urlCacheCount = 0;
|
|
8
|
+
const MAX_CACHE_SIZE = 512;
|
|
9
|
+
const requestPool = [];
|
|
10
|
+
const MAX_POOL_SIZE = 64;
|
|
11
|
+
/**
|
|
12
|
+
* @ru Основной класс HTTP-клиента Hyperttp. Обеспечивает диспетчеризацию запросов,
|
|
13
|
+
* управление плагинами, пулинг объектов запросов и кэширование URL.
|
|
14
|
+
* @en Core HTTP client class for Hyperttp. Provides request dispatching,
|
|
15
|
+
* plugin management, request object pooling, and URL caching.
|
|
16
|
+
*/
|
|
17
|
+
export class HyperCore {
|
|
18
|
+
config;
|
|
19
|
+
transportManager;
|
|
20
|
+
transportReady;
|
|
21
|
+
defaultHeaders;
|
|
22
|
+
pluginCtx;
|
|
23
|
+
pipelines = createPipelines();
|
|
24
|
+
hasRequestPlugins = false;
|
|
25
|
+
hasResponseDataPlugins = false;
|
|
26
|
+
hasResponsePlugins = false;
|
|
27
|
+
hasErrorPlugins = false;
|
|
28
|
+
/**
|
|
29
|
+
* @ru Создаёт новый экземпляр HTTP-клиента.
|
|
30
|
+
* @en Creates a new HTTP client instance.
|
|
31
|
+
* @param config - Client configuration options.
|
|
32
|
+
* @param transport - Optional custom transport implementation.
|
|
33
|
+
*/
|
|
34
|
+
constructor(config = defaultConfig, transport) {
|
|
35
|
+
this.config = {
|
|
36
|
+
...defaultConfig,
|
|
37
|
+
...config,
|
|
38
|
+
network: { ...defaultConfig.network, ...config.network },
|
|
39
|
+
};
|
|
40
|
+
this.transportManager = new TransportManager(this.config, transport);
|
|
41
|
+
this.transportReady = this.transportManager.getSync()
|
|
42
|
+
? Promise.resolve(this.transportManager.getSync())
|
|
43
|
+
: this.transportManager.ensure();
|
|
44
|
+
this.defaultHeaders = normalizeHeaders({
|
|
45
|
+
Accept: "application/json, text/plain, */*",
|
|
46
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
47
|
+
"User-Agent": this.config.network?.userAgent ?? "Hyperttp/2.0",
|
|
48
|
+
...this.config.network?.headers,
|
|
49
|
+
});
|
|
50
|
+
this.pluginCtx = { config: this.config, core: this };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @ru Возвращает имя класса текущего активного транспорта.
|
|
54
|
+
* @en Returns the class name of the currently active transport.
|
|
55
|
+
* @returns Promise resolving to the transport class name.
|
|
56
|
+
*/
|
|
57
|
+
async getTransportName() {
|
|
58
|
+
const t = this.transportManager.transport ?? (await this.transportManager.get());
|
|
59
|
+
return t.constructor.name;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @ru Отправляет внутренний запрос через полный конвейер обработки:
|
|
63
|
+
* плагины запроса → транспорт → плагины данных ответа → маппинг → плагины ответа.
|
|
64
|
+
* @en Dispatches an internal request through the full processing pipeline:
|
|
65
|
+
* request plugins → transport → response data plugins → mapping → response plugins.
|
|
66
|
+
* @template T - Expected response body type.
|
|
67
|
+
* @param req - The normalized internal request object.
|
|
68
|
+
* @returns Promise resolving to the HTTP response.
|
|
69
|
+
*/
|
|
70
|
+
async dispatch(req) {
|
|
71
|
+
try {
|
|
72
|
+
if (this.hasRequestPlugins) {
|
|
73
|
+
const shortCircuit = await Promise.resolve(executeRequestPipeline(this.pipelines.request, req, this.pluginCtx));
|
|
74
|
+
if (shortCircuit != null) {
|
|
75
|
+
this.recycleRequest(req);
|
|
76
|
+
return shortCircuit;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const transport = this.transportManager.getSync() ?? (await this.transportReady);
|
|
80
|
+
let rawResponse = await transport.execute(req);
|
|
81
|
+
if (this.hasResponseDataPlugins) {
|
|
82
|
+
rawResponse = await Promise.resolve(executeResponseDataPipeline(this.pipelines.responseData, rawResponse, this.pluginCtx));
|
|
83
|
+
}
|
|
84
|
+
const response = req.meta?.responseType === "stream"
|
|
85
|
+
? mapStreamFast(rawResponse)
|
|
86
|
+
: mapResponseFast(rawResponse);
|
|
87
|
+
if (this.hasResponsePlugins) {
|
|
88
|
+
await Promise.resolve(executeResponsePipeline(this.pipelines.responseMutators, this.pipelines.responseSideEffects, response, req, this.pluginCtx, this.config.logger));
|
|
89
|
+
}
|
|
90
|
+
this.recycleRequest(req);
|
|
91
|
+
return response;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
this.recycleRequest(req);
|
|
95
|
+
return this.handleDispatchError(error, req);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @ru Регистрирует плагин в экземпляре клиента. Плагины выполняются в порядке приоритета.
|
|
100
|
+
* @en Registers a plugin into the client instance. Plugins are executed in priority order.
|
|
101
|
+
* @param plugin - The plugin instance to register.
|
|
102
|
+
* @returns The current instance for chaining.
|
|
103
|
+
*/
|
|
104
|
+
use(plugin) {
|
|
105
|
+
const isEnabled = plugin.enabled ? plugin.enabled(this.config) : true;
|
|
106
|
+
if (!isEnabled)
|
|
107
|
+
return this;
|
|
108
|
+
plugin.setup?.(this.pluginCtx);
|
|
109
|
+
const priority = plugin.priority ?? 0;
|
|
110
|
+
const hook = { name: plugin.name, priority };
|
|
111
|
+
if (plugin.onRequest) {
|
|
112
|
+
insertHookSorted(this.pipelines.request, {
|
|
113
|
+
...hook,
|
|
114
|
+
run: plugin.onRequest,
|
|
115
|
+
});
|
|
116
|
+
this.hasRequestPlugins = true;
|
|
117
|
+
}
|
|
118
|
+
if (plugin.onResponse) {
|
|
119
|
+
const target = plugin.mode === "background"
|
|
120
|
+
? this.pipelines.responseSideEffects
|
|
121
|
+
: this.pipelines.responseMutators;
|
|
122
|
+
insertHookSorted(target, { ...hook, run: plugin.onResponse });
|
|
123
|
+
this.hasResponsePlugins = true;
|
|
124
|
+
}
|
|
125
|
+
if (plugin.onResponseData) {
|
|
126
|
+
insertHookSorted(this.pipelines.responseData, {
|
|
127
|
+
...hook,
|
|
128
|
+
run: plugin.onResponseData,
|
|
129
|
+
});
|
|
130
|
+
this.hasResponseDataPlugins = true;
|
|
131
|
+
}
|
|
132
|
+
if (plugin.onError) {
|
|
133
|
+
insertHookSorted(this.pipelines.error, { ...hook, run: plugin.onError });
|
|
134
|
+
this.hasErrorPlugins = true;
|
|
135
|
+
}
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @ru Выполняет GET-запрос.
|
|
140
|
+
* @en Performs a GET request.
|
|
141
|
+
* @template T - Expected response body type.
|
|
142
|
+
* @param req - Request URL or RequestInterface object.
|
|
143
|
+
* @param signal - Optional abort signal.
|
|
144
|
+
* @returns Promise resolving to the HTTP response.
|
|
145
|
+
*/
|
|
146
|
+
get(req, signal) {
|
|
147
|
+
return this.dispatch(this.acquireReq("GET", req, undefined, signal));
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* @ru Выполняет POST-запрос с телом.
|
|
151
|
+
* @en Performs a POST request with a body.
|
|
152
|
+
* @template T - Expected response body type.
|
|
153
|
+
* @param req - Request URL or RequestInterface object.
|
|
154
|
+
* @param body - Request body data.
|
|
155
|
+
* @param signal - Optional abort signal.
|
|
156
|
+
* @returns Promise resolving to the HTTP response.
|
|
157
|
+
*/
|
|
158
|
+
post(req, body, signal) {
|
|
159
|
+
return this.dispatch(this.acquireReq("POST", req, body, signal));
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @ru Выполняет PUT-запрос с телом.
|
|
163
|
+
* @en Performs a PUT request with a body.
|
|
164
|
+
* @template T - Expected response body type.
|
|
165
|
+
* @param req - Request URL or RequestInterface object.
|
|
166
|
+
* @param body - Request body data.
|
|
167
|
+
* @param signal - Optional abort signal.
|
|
168
|
+
* @returns Promise resolving to the HTTP response.
|
|
169
|
+
*/
|
|
170
|
+
put(req, body, signal) {
|
|
171
|
+
return this.dispatch(this.acquireReq("PUT", req, body, signal));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* @ru Выполняет PATCH-запрос с телом.
|
|
175
|
+
* @en Performs a PATCH request with a body.
|
|
176
|
+
* @template T - Expected response body type.
|
|
177
|
+
* @param req - Request URL or RequestInterface object.
|
|
178
|
+
* @param body - Request body data.
|
|
179
|
+
* @param signal - Optional abort signal.
|
|
180
|
+
* @returns Promise resolving to the HTTP response.
|
|
181
|
+
*/
|
|
182
|
+
patch(req, body, signal) {
|
|
183
|
+
return this.dispatch(this.acquireReq("PATCH", req, body, signal));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @ru Выполняет DELETE-запрос.
|
|
187
|
+
* @en Performs a DELETE request.
|
|
188
|
+
* @template T - Expected response body type.
|
|
189
|
+
* @param req - Request URL or RequestInterface object.
|
|
190
|
+
* @param signal - Optional abort signal.
|
|
191
|
+
* @returns Promise resolving to the HTTP response.
|
|
192
|
+
*/
|
|
193
|
+
delete(req, signal) {
|
|
194
|
+
return this.dispatch(this.acquireReq("DELETE", req, undefined, signal));
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* @ru Выполняет OPTIONS-запрос.
|
|
198
|
+
* @en Performs an OPTIONS request.
|
|
199
|
+
* @template T - Expected response body type.
|
|
200
|
+
* @param req - Request URL or RequestInterface object.
|
|
201
|
+
* @param body - Optional request body data.
|
|
202
|
+
* @param signal - Optional abort signal.
|
|
203
|
+
* @returns Promise resolving to the HTTP response.
|
|
204
|
+
*/
|
|
205
|
+
options(req, body, signal) {
|
|
206
|
+
return this.dispatch(this.acquireReq("OPTIONS", req, body, signal));
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* @ru Выполняет HEAD-запрос (без тела ответа).
|
|
210
|
+
* @en Performs a HEAD request (no response body).
|
|
211
|
+
* @param req - Request URL or RequestInterface object.
|
|
212
|
+
* @param signal - Optional abort signal.
|
|
213
|
+
* @returns Promise resolving to the HTTP response with null body.
|
|
214
|
+
*/
|
|
215
|
+
head(req, signal) {
|
|
216
|
+
return this.dispatch(this.acquireReq("HEAD", req, undefined, signal));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @ru Инициирует потоковый GET-запрос. Тело ответа возвращается как ReadableStream.
|
|
220
|
+
* @en Initiates a streaming GET request. Response body is returned as a ReadableStream.
|
|
221
|
+
* @param req - Request URL or RequestInterface object.
|
|
222
|
+
* @param signal - Optional abort signal.
|
|
223
|
+
* @returns Promise resolving to the stream response.
|
|
224
|
+
*/
|
|
225
|
+
stream(req, signal) {
|
|
226
|
+
return this.dispatch(this.acquireReq("GET", req, undefined, signal, "stream"));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* @ru Инициирует потоковый POST-запрос с телом. Тело ответа возвращается как ReadableStream.
|
|
230
|
+
* @en Initiates a streaming POST request with a body. Response body is returned as a ReadableStream.
|
|
231
|
+
* @template T - Expected response body type.
|
|
232
|
+
* @param req - Request URL or RequestInterface object.
|
|
233
|
+
* @param body - Request body data.
|
|
234
|
+
* @param signal - Optional abort signal.
|
|
235
|
+
* @returns Promise resolving to the stream response.
|
|
236
|
+
*/
|
|
237
|
+
postStream(req, body, signal) {
|
|
238
|
+
return this.dispatch(this.acquireReq("POST", req, body, signal, "stream"));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* @ru Создаёт новый экземпляр клиента, объединяя текущую конфигурацию с переданными опциями.
|
|
242
|
+
* @en Creates a new client instance by merging the current configuration with provided options.
|
|
243
|
+
* @param options - Partial configuration options to extend.
|
|
244
|
+
* @returns A new HyperCore instance.
|
|
245
|
+
*/
|
|
246
|
+
extend(options) {
|
|
247
|
+
return new HyperCore({
|
|
248
|
+
...this.config,
|
|
249
|
+
...options,
|
|
250
|
+
network: { ...this.config.network, ...options.network },
|
|
251
|
+
}, this.transportManager.transport ?? undefined);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* @ru Создаёт полностью новый экземпляр клиента на основе переданных опций.
|
|
255
|
+
* @en Creates a completely new client instance based on provided options.
|
|
256
|
+
* @param options - Partial configuration options for the new instance.
|
|
257
|
+
* @returns A new HyperCore instance.
|
|
258
|
+
*/
|
|
259
|
+
create(options) {
|
|
260
|
+
return this.extend(options);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* @ru Завершает работу клиента и освобождает ресурсы (соединения, пулы).
|
|
264
|
+
* @en Shuts down the client and releases resources (connections, pools).
|
|
265
|
+
* @param graceful - If true, waits for active requests to complete before closing.
|
|
266
|
+
* @returns Promise that resolves when shutdown is complete.
|
|
267
|
+
*/
|
|
268
|
+
destroy(graceful = true) {
|
|
269
|
+
return this.transportManager.destroy(graceful);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* @ru Выполняет GET-запрос и возвращает распарсенное JSON-тело ответа.
|
|
273
|
+
* @en Performs a GET request and returns the parsed JSON response body.
|
|
274
|
+
* @template T - Expected type of the parsed JSON.
|
|
275
|
+
* @param req - Request URL or RequestInterface object.
|
|
276
|
+
* @param signal - Optional abort signal.
|
|
277
|
+
* @returns Promise resolving to the parsed JSON data.
|
|
278
|
+
*/
|
|
279
|
+
async json(req, signal) {
|
|
280
|
+
return ((await this.shortcut(req, signal)).json?.() ??
|
|
281
|
+
Promise.reject(new Error("json() not supported")));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* @ru Выполняет GET-запрос и возвращает тело ответа как текст.
|
|
285
|
+
* @en Performs a GET request and returns the response body as text.
|
|
286
|
+
* @param req - Request URL or RequestInterface object.
|
|
287
|
+
* @param signal - Optional abort signal.
|
|
288
|
+
* @returns Promise resolving to the response text.
|
|
289
|
+
*/
|
|
290
|
+
async text(req, signal) {
|
|
291
|
+
return ((await this.shortcut(req, signal)).text?.() ??
|
|
292
|
+
Promise.reject(new Error("text() not supported")));
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* @ru Выполняет GET-запрос и немедленно отбрасывает тело ответа для освобождения ресурсов.
|
|
296
|
+
* @en Performs a GET request and immediately discards the response body to free resources.
|
|
297
|
+
* @param req - Request URL or RequestInterface object.
|
|
298
|
+
* @param signal - Optional abort signal.
|
|
299
|
+
* @returns Promise that resolves when the stream is drained.
|
|
300
|
+
*/
|
|
301
|
+
async dump(req, signal) {
|
|
302
|
+
await (await this.shortcut(req, signal)).dump?.();
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* @ru Обрабатывает ошибку диспетчеризации через конвейер плагинов обработки ошибок.
|
|
306
|
+
* @en Handles dispatch errors through the error handling plugin pipeline.
|
|
307
|
+
* @template T - Expected response body type.
|
|
308
|
+
* @param error - The error that occurred.
|
|
309
|
+
* @param req - The original internal request.
|
|
310
|
+
* @returns Promise resolving to a recovered HTTP response, or throws if unrecoverable.
|
|
311
|
+
*/
|
|
312
|
+
async handleDispatchError(error, req) {
|
|
313
|
+
if (this.hasErrorPlugins) {
|
|
314
|
+
const recovered = await executeErrorPipeline(this.pipelines.error, error, req, this.pluginCtx);
|
|
315
|
+
if (recovered != null) {
|
|
316
|
+
if (this.hasResponsePlugins) {
|
|
317
|
+
await Promise.resolve(executeResponsePipeline(this.pipelines.responseMutators, this.pipelines.responseSideEffects, recovered, req, this.pluginCtx, this.config.logger));
|
|
318
|
+
}
|
|
319
|
+
return recovered;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @ru Создаёт или переиспользует объект InternalRequest из пула, заполняя его поля.
|
|
326
|
+
* @en Creates or reuses an InternalRequest object from the pool, populating its fields.
|
|
327
|
+
* @param method - HTTP method (GET, POST, etc.).
|
|
328
|
+
* @param req - Request URL or RequestInterface object.
|
|
329
|
+
* @param body - Optional request body data.
|
|
330
|
+
* @param signal - Optional abort signal.
|
|
331
|
+
* @param responseType - Optional response type hint ('stream').
|
|
332
|
+
* @returns The populated internal request object.
|
|
333
|
+
*/
|
|
334
|
+
acquireReq(method, req, body, signal, responseType) {
|
|
335
|
+
const pooled = requestPool.pop();
|
|
336
|
+
const internalReq = pooled ?? {
|
|
337
|
+
method: "GET",
|
|
338
|
+
url: "",
|
|
339
|
+
headers: this.defaultHeaders,
|
|
340
|
+
body: undefined,
|
|
341
|
+
signal: undefined,
|
|
342
|
+
meta: undefined,
|
|
343
|
+
};
|
|
344
|
+
if (typeof req === "string") {
|
|
345
|
+
internalReq.method = method;
|
|
346
|
+
internalReq.url = this.resolveUrl(req);
|
|
347
|
+
internalReq.headers = this.defaultHeaders;
|
|
348
|
+
internalReq.body = body !== undefined ? normalizeBody(method, body) : undefined;
|
|
349
|
+
internalReq.signal = signal;
|
|
350
|
+
internalReq.meta = responseType ? { responseType } : undefined;
|
|
351
|
+
return internalReq;
|
|
352
|
+
}
|
|
353
|
+
const rawUrl = normalizeUrl(req);
|
|
354
|
+
if (!rawUrl)
|
|
355
|
+
throw new Error(`[HyperCore] URL is undefined for ${method}`);
|
|
356
|
+
let finalUrl = urlCache[rawUrl];
|
|
357
|
+
if (!finalUrl) {
|
|
358
|
+
const urlObj = new URL(rawUrl);
|
|
359
|
+
if (req.query)
|
|
360
|
+
this.appendQueryParams(urlObj, req.query);
|
|
361
|
+
finalUrl = urlObj.href;
|
|
362
|
+
if (urlCacheCount < MAX_CACHE_SIZE) {
|
|
363
|
+
urlCache[rawUrl] = finalUrl;
|
|
364
|
+
urlCacheCount++;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
internalReq.method = method;
|
|
368
|
+
internalReq.url = finalUrl;
|
|
369
|
+
internalReq.headers = req.headers
|
|
370
|
+
? mergeHeadersFast(this.defaultHeaders, req.headers)
|
|
371
|
+
: this.defaultHeaders;
|
|
372
|
+
internalReq.body = normalizeBody(method, req.body ?? body);
|
|
373
|
+
internalReq.signal = req.signal ?? signal;
|
|
374
|
+
internalReq.meta = responseType
|
|
375
|
+
? { responseType }
|
|
376
|
+
: req.meta
|
|
377
|
+
? {
|
|
378
|
+
responseType: req.meta.responseType,
|
|
379
|
+
}
|
|
380
|
+
: undefined;
|
|
381
|
+
return internalReq;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* @ru Возвращает объект запроса в пул для переиспользования, очищая ссылки для GC.
|
|
385
|
+
* @en Returns the request object to the pool for reuse, clearing references for GC.
|
|
386
|
+
* @param req - The internal request object to recycle.
|
|
387
|
+
*/
|
|
388
|
+
recycleRequest(req) {
|
|
389
|
+
if (requestPool.length < MAX_POOL_SIZE) {
|
|
390
|
+
req.body = undefined;
|
|
391
|
+
req.signal = undefined;
|
|
392
|
+
req.meta = undefined;
|
|
393
|
+
requestPool.push(req);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* @ru Разрешает и кэширует URL, нормализуя его через URL API при необходимости.
|
|
398
|
+
* @en Resolves and caches the URL, normalizing it via the URL API when necessary.
|
|
399
|
+
* @param url - The raw URL string.
|
|
400
|
+
* @returns The resolved and cached URL string.
|
|
401
|
+
*/
|
|
402
|
+
resolveUrl(url) {
|
|
403
|
+
if (!url)
|
|
404
|
+
throw new Error("[HyperCore] URL is undefined");
|
|
405
|
+
let finalUrl = urlCache[url];
|
|
406
|
+
if (finalUrl)
|
|
407
|
+
return finalUrl;
|
|
408
|
+
const hasQuery = url.includes("?") || url.endsWith("?");
|
|
409
|
+
const isAbsolute = url.startsWith("http://") || url.startsWith("https://");
|
|
410
|
+
finalUrl = !hasQuery || !isAbsolute ? new URL(url).href : url;
|
|
411
|
+
if (urlCacheCount < MAX_CACHE_SIZE) {
|
|
412
|
+
urlCache[url] = finalUrl;
|
|
413
|
+
urlCacheCount++;
|
|
414
|
+
}
|
|
415
|
+
return finalUrl;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* @ru Добавляет query-параметры к объекту URL, поддерживая массивы значений.
|
|
419
|
+
* @en Appends query parameters to the URL object, supporting arrays of values.
|
|
420
|
+
* @param url - The URL object to modify.
|
|
421
|
+
* @param query - Record of query parameter key-value pairs.
|
|
422
|
+
*/
|
|
423
|
+
appendQueryParams(url, query) {
|
|
424
|
+
for (const k in query) {
|
|
425
|
+
if (Object.prototype.hasOwnProperty.call(query, k)) {
|
|
426
|
+
const v = query[k];
|
|
427
|
+
if (v == null)
|
|
428
|
+
continue;
|
|
429
|
+
if (Array.isArray(v)) {
|
|
430
|
+
for (let j = 0; j < v.length; j++)
|
|
431
|
+
url.searchParams.append(k, String(v[j]));
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
url.searchParams.set(k, String(v));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* @ru Выполняет быстрый запрос с автоматическим определением HTTP-метода.
|
|
441
|
+
* @en Performs a shortcut request with automatic HTTP method detection.
|
|
442
|
+
* @param req - Request URL or RequestInterface object.
|
|
443
|
+
* @param signal - Optional abort signal.
|
|
444
|
+
* @returns Promise resolving to the HTTP response.
|
|
445
|
+
*/
|
|
446
|
+
shortcut(req, signal) {
|
|
447
|
+
const method = typeof req === "string" ? "GET" : (req.method ?? "GET");
|
|
448
|
+
return this.dispatch(this.acquireReq(method, req, undefined, signal));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/transports/browser.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,sBA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AAC;qBAAM,CAAC;oBACN,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACK,QAAQ,CACd,GAA8B,EAC9B,MAAoB;QAEpB,MAAM,MAAM,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAG,GAAW,CAAC,MAAiB,IAAI,KAAK,CAAC,CAAC;QAC5F,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;CACF"}
|
package/transports/manager.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { HttpClientOptions, HyperTransport
|
|
2
|
-
export type Runtime = "bun" | "node";
|
|
1
|
+
import type { HttpClientOptions, HyperTransport } from "@hyperttp/types";
|
|
2
|
+
export type Runtime = "bun" | "node" | "deno" | "browser";
|
|
3
3
|
type TransportDef = {
|
|
4
4
|
name: string;
|
|
5
5
|
runtime: Runtime[];
|
|
@@ -8,78 +8,18 @@ type TransportDef = {
|
|
|
8
8
|
priority: number;
|
|
9
9
|
};
|
|
10
10
|
export declare const CURRENT_RUNTIME: Runtime;
|
|
11
|
-
export declare function getRuntime(): Runtime;
|
|
12
11
|
export declare const TRANSPORTS: TransportDef[];
|
|
13
|
-
|
|
14
|
-
* @ru Главный резолвер транспорта (диагностический и детерминированный).
|
|
15
|
-
* @en Main transport resolver (diagnostic and deterministic).
|
|
16
|
-
* @param config - Client configuration (may contain customTransport).
|
|
17
|
-
* @returns Promise resolving to a HyperTransport instance.
|
|
18
|
-
* @throws If no compatible transport can be loaded.
|
|
19
|
-
*/
|
|
12
|
+
export declare const runtimeImport: <T = any>(specifier: string) => Promise<T>;
|
|
20
13
|
export declare function resolveTransport(config: HttpClientOptions): Promise<HyperTransport>;
|
|
21
|
-
export interface TransportDebugInfo {
|
|
22
|
-
name: string;
|
|
23
|
-
pkg: string;
|
|
24
|
-
runtime: Runtime;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @ru Управляет жизненным циклом транспортного слоя: ленивая инициализация, кеширование, синхронизация конфигурации.
|
|
28
|
-
* @en Manages the transport layer lifecycle: lazy initialization, caching, configuration synchronization.
|
|
29
|
-
*/
|
|
30
14
|
export declare class TransportManager {
|
|
31
|
-
|
|
15
|
+
transport: HyperTransport | null;
|
|
32
16
|
private promise;
|
|
33
17
|
private config;
|
|
34
|
-
/**
|
|
35
|
-
* @ru Создаёт менеджер транспорта.
|
|
36
|
-
* @en Creates a transport manager.
|
|
37
|
-
* @param config - Client configuration.
|
|
38
|
-
* @param custom - Optional externally provided transport instance.
|
|
39
|
-
*/
|
|
40
18
|
constructor(config: HttpClientOptions, custom?: HyperTransport);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* @param config - New configuration.
|
|
45
|
-
*/
|
|
19
|
+
getSync(): HyperTransport | null;
|
|
20
|
+
ensure(): Promise<HyperTransport>;
|
|
21
|
+
get(): HyperTransport | Promise<HyperTransport>;
|
|
46
22
|
setConfig(config: HttpClientOptions): void;
|
|
47
|
-
/**
|
|
48
|
-
* @ru Возвращает текущий экземпляр транспорта (если уже инициализирован).
|
|
49
|
-
* @en Returns the current transport instance (if already initialised).
|
|
50
|
-
*/
|
|
51
|
-
get instance(): HyperTransport | null;
|
|
52
|
-
/**
|
|
53
|
-
* @ru Асинхронно получает экземпляр транспорта (инициализирует при необходимости).
|
|
54
|
-
* @en Asynchronously obtains a transport instance (initialises if needed).
|
|
55
|
-
* @returns Promise resolving to a HyperTransport.
|
|
56
|
-
*/
|
|
57
|
-
get(): Promise<HyperTransport>;
|
|
58
|
-
/**
|
|
59
|
-
* @ru Выполняет запрос через транспорт и возвращает обычный (не стриминговый) ответ.
|
|
60
|
-
* @en Executes a request through the transport and returns a regular (non‑streaming) response.
|
|
61
|
-
* @param req - Request parameters.
|
|
62
|
-
* @returns Promise resolving to HttpResponse.
|
|
63
|
-
*/
|
|
64
|
-
execute<T = unknown>(req: Parameters<HyperTransport["execute"]>[0]): Promise<HttpResponse<T>>;
|
|
65
|
-
/**
|
|
66
|
-
* @ru Выполняет запрос через транспорт и возвращает стриминговый ответ.
|
|
67
|
-
* @en Executes a request through the transport and returns a streaming response.
|
|
68
|
-
* @param req - Request parameters.
|
|
69
|
-
* @returns Promise resolving to StreamResponse.
|
|
70
|
-
*/
|
|
71
|
-
executeStream<T = unknown>(req: Parameters<HyperTransport["execute"]>[0]): Promise<StreamResponse<T>>;
|
|
72
|
-
/**
|
|
73
|
-
* @ru Возвращает отладочную информацию о текущем транспорте.
|
|
74
|
-
* @en Returns debug information about the current transport.
|
|
75
|
-
*/
|
|
76
|
-
get debug(): TransportDebugInfo | null;
|
|
77
|
-
/**
|
|
78
|
-
* @ru Завершает работу транспорта (закрывает соединения при graceful shutdown, иначе принудительно уничтожает).
|
|
79
|
-
* @en Shuts down the transport (gracefully closes connections or forcefully destroys).
|
|
80
|
-
* @param graceful - If true, attempt graceful close; otherwise call destroy.
|
|
81
|
-
* @returns Promise that resolves when shutdown is complete.
|
|
82
|
-
*/
|
|
83
23
|
destroy(graceful?: boolean): Promise<void>;
|
|
84
24
|
}
|
|
85
25
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/transports/manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/transports/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEzE,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAG1D,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,OAK1B,CAAC;AAEL,eAAO,MAAM,UAAU,EAAE,YAAY,EAoCpC,CAAC;AAUF,eAAO,MAAM,aAAa,EAAwC,CAAC,CAAC,GAAG,GAAG,EACxE,SAAS,EAAE,MAAM,KACd,OAAO,CAAC,CAAC,CAAC,CAAC;AAsFhB,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CA+BzF;AAED,qBAAa,gBAAgB;IACpB,SAAS,EAAE,cAAc,GAAG,IAAI,CAAQ;IAC/C,OAAO,CAAC,OAAO,CAAwC;IACvD,OAAO,CAAC,MAAM,CAAoB;gBAEtB,MAAM,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,cAAc;IAYvD,OAAO,IAAI,cAAc,GAAG,IAAI;IAIhC,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC;IAYjC,GAAG,IAAI,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAI/C,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAOpC,OAAO,CAAC,QAAQ,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBrD"}
|