@hyperttp/core 1.4.8 → 1.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/Core/HyperCore.d.ts +66 -124
- package/Core/HyperCore.d.ts.map +1 -1
- package/Core/HyperCore.js +2 -576
- package/Core/HyperCore.js.map +7 -1
- package/Core/RequestBuilder.d.ts +36 -0
- package/Core/RequestBuilder.d.ts.map +1 -0
- package/Core/RequestBuilder.js +2 -0
- package/Core/RequestBuilder.js.map +7 -0
- package/Core/index.js +2 -2
- package/Core/index.js.map +7 -1
- package/README.md +30 -0
- package/defaultConfig.d.ts +4 -0
- package/defaultConfig.d.ts.map +1 -1
- package/defaultConfig.js +2 -19
- package/defaultConfig.js.map +7 -1
- package/index.js +2 -3
- package/index.js.map +7 -1
- package/package.json +2 -2
- package/transports/browser.d.ts.map +1 -1
- package/transports/browser.js +2 -113
- package/transports/browser.js.map +7 -1
- package/transports/manager.d.ts +0 -33
- package/transports/manager.d.ts.map +1 -1
- package/transports/manager.js +7 -349
- package/transports/manager.js.map +7 -1
- package/transports/node.d.ts +1 -0
- package/transports/node.d.ts.map +1 -1
- package/transports/node.js +2 -380
- package/transports/node.js.map +7 -1
- package/utils/errors.d.ts +0 -11
- package/utils/errors.d.ts.map +1 -1
- package/utils/errors.js +2 -53
- package/utils/errors.js.map +7 -1
- package/utils/merge.js +2 -29
- package/utils/merge.js.map +7 -1
- package/utils/normalize.d.ts +22 -39
- package/utils/normalize.d.ts.map +1 -1
- package/utils/normalize.js +2 -285
- package/utils/normalize.js.map +7 -1
- package/utils/pipeline.js +2 -193
- package/utils/pipeline.js.map +7 -1
- package/utils/response.d.ts +49 -73
- package/utils/response.d.ts.map +1 -1
- package/utils/response.js +2 -389
- package/utils/response.js.map +7 -1
- package/utils/retryUtils.d.ts.map +1 -1
- package/utils/retryUtils.js +2 -55
- package/utils/retryUtils.js.map +7 -1
package/transports/manager.js
CHANGED
|
@@ -1,349 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (typeof Bun !== "undefined")
|
|
9
|
-
return "bun";
|
|
10
|
-
if (typeof Deno !== "undefined")
|
|
11
|
-
return "deno";
|
|
12
|
-
if (typeof process !== "undefined" && process.versions?.node)
|
|
13
|
-
return "node";
|
|
14
|
-
return "browser";
|
|
15
|
-
})();
|
|
16
|
-
/**
|
|
17
|
-
* @ru Внутренний реестр всех доступных транспортов с приоритетами.
|
|
18
|
-
* Заморожен для предотвращения модификаций в runtime.
|
|
19
|
-
* @en Internal registry of all available transports with priorities.
|
|
20
|
-
* Frozen to prevent runtime modifications.
|
|
21
|
-
*/
|
|
22
|
-
const INTERNAL_TRANSPORTS = [
|
|
23
|
-
{
|
|
24
|
-
name: "Bun",
|
|
25
|
-
runtime: ["bun"],
|
|
26
|
-
pkg: "@hyperttp/transport-bun",
|
|
27
|
-
export: "BunTransport",
|
|
28
|
-
priority: 100,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
name: "Deno",
|
|
32
|
-
runtime: ["deno"],
|
|
33
|
-
pkg: "@hyperttp/transport-deno",
|
|
34
|
-
export: "DenoTransport",
|
|
35
|
-
priority: 95,
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: "Undici",
|
|
39
|
-
runtime: ["node"],
|
|
40
|
-
pkg: "@hyperttp/transport-undici",
|
|
41
|
-
export: "UndiciTransport",
|
|
42
|
-
priority: 90,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: "Browser",
|
|
46
|
-
runtime: ["browser"],
|
|
47
|
-
pkg: "./browser.js",
|
|
48
|
-
export: "BrowserTransport",
|
|
49
|
-
priority: 80,
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: "Node",
|
|
53
|
-
runtime: ["node", "bun", "deno"],
|
|
54
|
-
pkg: "./node.js",
|
|
55
|
-
export: "NodeTransport",
|
|
56
|
-
priority: 10,
|
|
57
|
-
},
|
|
58
|
-
];
|
|
59
|
-
INTERNAL_TRANSPORTS.forEach(Object.freeze);
|
|
60
|
-
Object.freeze(INTERNAL_TRANSPORTS);
|
|
61
|
-
/**
|
|
62
|
-
* @ru Белый список разрешённых пакетов для защиты от несанкционированного импорта.
|
|
63
|
-
* @en Whitelist of allowed packages to protect against unauthorized imports.
|
|
64
|
-
*/
|
|
65
|
-
const ALLOWED_PACKAGES = new Set(INTERNAL_TRANSPORTS.map((t) => t.pkg));
|
|
66
|
-
/**
|
|
67
|
-
* @ru Возвращает список зарегистрированных транспортов (readonly для безопасности).
|
|
68
|
-
* @en Returns the list of registered transports (readonly for safety).
|
|
69
|
-
* @returns Readonly array of transport definitions.
|
|
70
|
-
*/
|
|
71
|
-
export const getRegisteredTransports = () => INTERNAL_TRANSPORTS;
|
|
72
|
-
/**
|
|
73
|
-
* @ru Отфильтрованный и отсортированный список транспортов для текущей среды.
|
|
74
|
-
* Вычисляется один раз при загрузке модуля.
|
|
75
|
-
* @en Filtered and sorted list of transports for the current runtime.
|
|
76
|
-
* Computed once at module load time.
|
|
77
|
-
*/
|
|
78
|
-
const CANDIDATES = INTERNAL_TRANSPORTS.filter((t) => t.runtime.includes(CURRENT_RUNTIME)).sort((a, b) => b.priority - a.priority);
|
|
79
|
-
/**
|
|
80
|
-
* @ru Кэш разрешённого конструктора транспорта для избежания повторного разрешения.
|
|
81
|
-
* @en Cached resolved transport constructor to avoid repeated resolution.
|
|
82
|
-
*/
|
|
83
|
-
let RESOLVED_RUNTIME_CTOR = null;
|
|
84
|
-
/**
|
|
85
|
-
* @ru Динамический импорт, изолированный от статического анализа сборщиков (Vite, Webpack).
|
|
86
|
-
* Используется как ядром, так и модулем декомпрессии для ленивой загрузки node:zlib/node:stream.
|
|
87
|
-
* @en Dynamic import isolated from bundlers' static analysis (Vite, Webpack).
|
|
88
|
-
* Used by both the core and decompression module for lazy loading of node:zlib/node:stream.
|
|
89
|
-
* @template T - Expected module type.
|
|
90
|
-
* @param specifier - Module specifier string.
|
|
91
|
-
* @returns Promise resolving to the imported module.
|
|
92
|
-
*/
|
|
93
|
-
export const runtimeImport = Function("s", "return import(s)");
|
|
94
|
-
/**
|
|
95
|
-
* @ru Проверяет, является ли ошибкой отсутствия модуля.
|
|
96
|
-
* Поддерживает коды ERR_MODULE_NOT_FOUND и MODULE_NOT_FOUND,
|
|
97
|
-
* а также сообщения об ошибках (для совместимости с Bun и Deno).
|
|
98
|
-
* @en Checks if the error is a module-not-found error.
|
|
99
|
-
* Supports ERR_MODULE_NOT_FOUND and MODULE_NOT_FOUND codes,
|
|
100
|
-
* as well as error messages (for Bun and Deno compatibility).
|
|
101
|
-
* @param err - The error to check.
|
|
102
|
-
* @returns True if the error indicates a missing module.
|
|
103
|
-
*/
|
|
104
|
-
function isModuleNotFoundError(err) {
|
|
105
|
-
if (!err || typeof err !== "object")
|
|
106
|
-
return false;
|
|
107
|
-
const e = err;
|
|
108
|
-
const code = e.code;
|
|
109
|
-
if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND")
|
|
110
|
-
return true;
|
|
111
|
-
const msg = err instanceof Error ? err.message : String(e.message ?? "");
|
|
112
|
-
return (msg.includes("Cannot find module") ||
|
|
113
|
-
msg.includes("Failed to resolve") ||
|
|
114
|
-
msg.includes("Failed to load"));
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @ru Логирует информацию о неудачной попытке загрузки транспорта.
|
|
118
|
-
* Активируется в режиме DEBUG=1 или при ошибке нативного транспорта в dev-окружении.
|
|
119
|
-
* @en Logs information about failed transport load attempts.
|
|
120
|
-
* Activated in DEBUG=1 mode or when native transport fails in dev environment.
|
|
121
|
-
* @param pkg - Package name that failed to load.
|
|
122
|
-
* @param err - The error that occurred.
|
|
123
|
-
* @param config - Optional client configuration for custom logger.
|
|
124
|
-
*/
|
|
125
|
-
function logDebugFallback(pkg, err, config) {
|
|
126
|
-
const isDev = typeof process !== "undefined" && process.env?.NODE_ENV === "development";
|
|
127
|
-
const isDebug = typeof process !== "undefined" && process.env?.DEBUG === "1";
|
|
128
|
-
const isNativeTransport = pkg.includes(CURRENT_RUNTIME);
|
|
129
|
-
if (isDebug || (isDev && isNativeTransport)) {
|
|
130
|
-
const primaryMessage = `Failed to load preferred transport "${pkg}"`;
|
|
131
|
-
const fallbackMessage = `Falling back to alternative transport...`;
|
|
132
|
-
if (config?.logger) {
|
|
133
|
-
config.logger("warn", `[Hyperttp Debug] ${primaryMessage}`, err);
|
|
134
|
-
config.logger("warn", `[Hyperttp Debug] ${fallbackMessage}`);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
console.warn(`\n⚠️ [Hyperttp Debug] ${primaryMessage}:`);
|
|
138
|
-
console.error(err);
|
|
139
|
-
console.warn(`${fallbackMessage}\n`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* @ru Загружает конструктор транспорта из пакета или относительного пути.
|
|
145
|
-
* Для браузерной среды использует статический импорт для совместимости с бандлерами.
|
|
146
|
-
* @en Loads a transport constructor from a package or relative path.
|
|
147
|
-
* For browser runtime, uses static import for bundler compatibility.
|
|
148
|
-
* @param pkg - Package name or relative path.
|
|
149
|
-
* @param exportName - Name of the exported transport class.
|
|
150
|
-
* @param config - Optional client configuration for debug logging.
|
|
151
|
-
* @returns Transport constructor or null if not found.
|
|
152
|
-
* @throws Error if the package is not in the whitelist.
|
|
153
|
-
*/
|
|
154
|
-
async function loadCtor(pkg, exportName, config) {
|
|
155
|
-
if (!ALLOWED_PACKAGES.has(pkg)) {
|
|
156
|
-
throw new Error(`[Hyperttp Security] Blocked untrusted transport import attempt: ${pkg}`);
|
|
157
|
-
}
|
|
158
|
-
if (CURRENT_RUNTIME === "browser") {
|
|
159
|
-
if (pkg !== "./browser.js")
|
|
160
|
-
return null;
|
|
161
|
-
const mod = (await import("./browser.js"));
|
|
162
|
-
const candidate = mod[exportName] ?? mod.default;
|
|
163
|
-
return typeof candidate === "function" ? candidate : null;
|
|
164
|
-
}
|
|
165
|
-
let specifier = pkg;
|
|
166
|
-
try {
|
|
167
|
-
if (typeof import.meta.resolve === "function") {
|
|
168
|
-
specifier = import.meta.resolve(pkg, import.meta.url);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch (err) {
|
|
172
|
-
if (isModuleNotFoundError(err)) {
|
|
173
|
-
logDebugFallback(pkg, err, config);
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
const mod = await runtimeImport(specifier);
|
|
179
|
-
const candidate = mod[exportName] ?? mod.default;
|
|
180
|
-
return typeof candidate === "function" ? candidate : null;
|
|
181
|
-
}
|
|
182
|
-
catch (err) {
|
|
183
|
-
if (isModuleNotFoundError(err)) {
|
|
184
|
-
logDebugFallback(pkg, err, config);
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
throw err;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* @ru Разрешает и создаёт оптимальный транспорт для текущей среды.
|
|
192
|
-
* Перебирает кандидатов по приоритету, кэширует первый успешный результат.
|
|
193
|
-
* @en Resolves and creates the optimal transport for the current runtime.
|
|
194
|
-
* Iterates candidates by priority, caches the first successful result.
|
|
195
|
-
* @param config - Client configuration options.
|
|
196
|
-
* @returns Promise resolving to the instantiated transport.
|
|
197
|
-
* @throws Error if no compatible transport is found.
|
|
198
|
-
*/
|
|
199
|
-
export async function resolveTransport(config) {
|
|
200
|
-
if (config.customTransport)
|
|
201
|
-
return config.customTransport;
|
|
202
|
-
if (RESOLVED_RUNTIME_CTOR)
|
|
203
|
-
return new RESOLVED_RUNTIME_CTOR(config);
|
|
204
|
-
const failures = [];
|
|
205
|
-
for (let i = 0; i < CANDIDATES.length; i++) {
|
|
206
|
-
const t = CANDIDATES[i];
|
|
207
|
-
try {
|
|
208
|
-
const ctor = await loadCtor(t.pkg, t.export, config);
|
|
209
|
-
if (!ctor) {
|
|
210
|
-
failures.push(`${t.pkg} (missing export or not installed)`);
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
RESOLVED_RUNTIME_CTOR = ctor;
|
|
214
|
-
return new ctor(config);
|
|
215
|
-
}
|
|
216
|
-
catch (err) {
|
|
217
|
-
if (isModuleNotFoundError(err)) {
|
|
218
|
-
failures.push(`${t.pkg} (not installed)`);
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
throw new Error(`[Hyperttp] transport crash in ${t.pkg}: ${err?.message}`, {
|
|
222
|
-
cause: err,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
throw new Error(`No compatible transport for runtime="${CURRENT_RUNTIME}".\nFailures:\n- ${failures.join("\n- ")}`);
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* @ru Менеджер транспорта с ленивой инициализацией и кэшированием.
|
|
230
|
-
* Поддерживает синхронный доступ, отложенную инициализацию и корректное завершение.
|
|
231
|
-
* @en Transport manager with lazy initialization and caching.
|
|
232
|
-
* Supports synchronous access, deferred initialization, and graceful shutdown.
|
|
233
|
-
*/
|
|
234
|
-
export class TransportManager {
|
|
235
|
-
/**
|
|
236
|
-
* @ru Текущий экземпляр транспорта (null до инициализации).
|
|
237
|
-
* @en Current transport instance (null before initialization).
|
|
238
|
-
*/
|
|
239
|
-
transport = null;
|
|
240
|
-
/**
|
|
241
|
-
* @ru Промис отложенной инициализации транспорта.
|
|
242
|
-
* @en Deferred transport initialization promise.
|
|
243
|
-
*/
|
|
244
|
-
promise = null;
|
|
245
|
-
/**
|
|
246
|
-
* @ru Конфигурация клиента для создания транспорта.
|
|
247
|
-
* @en Client configuration for transport creation.
|
|
248
|
-
*/
|
|
249
|
-
config;
|
|
250
|
-
/**
|
|
251
|
-
* @ru Создаёт менеджер транспорта с опциональным пользовательским транспортом.
|
|
252
|
-
* @en Creates a transport manager with an optional custom transport.
|
|
253
|
-
* @param config - Client configuration options.
|
|
254
|
-
* @param custom - Optional custom transport instance.
|
|
255
|
-
*/
|
|
256
|
-
constructor(config, custom) {
|
|
257
|
-
this.config = config;
|
|
258
|
-
if (custom) {
|
|
259
|
-
this.transport = custom;
|
|
260
|
-
}
|
|
261
|
-
else if (config.customTransport) {
|
|
262
|
-
this.transport = config.customTransport;
|
|
263
|
-
}
|
|
264
|
-
else if (RESOLVED_RUNTIME_CTOR) {
|
|
265
|
-
this.transport = new RESOLVED_RUNTIME_CTOR(config);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* @ru Синхронно возвращает текущий транспорт или null, если не инициализирован.
|
|
270
|
-
* @en Synchronously returns the current transport or null if not initialized.
|
|
271
|
-
* @returns The transport instance or null.
|
|
272
|
-
*/
|
|
273
|
-
getSync() {
|
|
274
|
-
return this.transport;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* @ru Гарантирует наличие транспорта, инициализируя его при необходимости.
|
|
278
|
-
* Повторные вызовы возвращают один и тот же промис.
|
|
279
|
-
* @en Ensures a transport exists, initializing it if necessary.
|
|
280
|
-
* Repeated calls return the same promise.
|
|
281
|
-
* @returns Promise resolving to the transport instance.
|
|
282
|
-
*/
|
|
283
|
-
ensure() {
|
|
284
|
-
if (this.transport !== null) {
|
|
285
|
-
return this.promise || (this.promise = Promise.resolve(this.transport));
|
|
286
|
-
}
|
|
287
|
-
if (this.promise !== null)
|
|
288
|
-
return this.promise;
|
|
289
|
-
return (this.promise = resolveTransport(this.config).then((t) => {
|
|
290
|
-
this.transport = t;
|
|
291
|
-
return t;
|
|
292
|
-
}));
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* @ru Возвращает транспорт синхронно или промис, если требуется инициализация.
|
|
296
|
-
* @en Returns the transport synchronously or a promise if initialization is needed.
|
|
297
|
-
* @returns The transport instance or a promise resolving to it.
|
|
298
|
-
*/
|
|
299
|
-
get() {
|
|
300
|
-
return this.transport ?? this.ensure();
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* @ru Обновляет конфигурацию транспорта, если он поддерживает setConfig.
|
|
304
|
-
* @en Updates the transport configuration if it supports setConfig.
|
|
305
|
-
* @param config - New client configuration options.
|
|
306
|
-
*/
|
|
307
|
-
setConfig(config) {
|
|
308
|
-
this.config = config;
|
|
309
|
-
if (this.transport && "setConfig" in this.transport) {
|
|
310
|
-
const dynamicTarget = this.transport;
|
|
311
|
-
if (typeof dynamicTarget.setConfig === "function") {
|
|
312
|
-
dynamicTarget.setConfig(config);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* @ru Завершает работу транспорта и освобождает ресурсы.
|
|
318
|
-
* В graceful-режиме вызывает close(), иначе — destroy().
|
|
319
|
-
* @en Shuts down the transport and releases resources.
|
|
320
|
-
* In graceful mode calls close(), otherwise calls destroy().
|
|
321
|
-
* @param graceful - If true, waits for active requests to complete.
|
|
322
|
-
* @returns Promise that resolves when shutdown is complete.
|
|
323
|
-
*/
|
|
324
|
-
async destroy(graceful = true) {
|
|
325
|
-
const t = this.transport;
|
|
326
|
-
if (!t)
|
|
327
|
-
return;
|
|
328
|
-
try {
|
|
329
|
-
if (graceful && "close" in t) {
|
|
330
|
-
const closable = t;
|
|
331
|
-
if (typeof closable.close === "function") {
|
|
332
|
-
await closable.close();
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
if ("destroy" in t) {
|
|
337
|
-
const destroyable = t;
|
|
338
|
-
if (typeof destroyable.destroy === "function") {
|
|
339
|
-
await destroyable.destroy();
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
finally {
|
|
344
|
-
this.transport = null;
|
|
345
|
-
this.promise = null;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
//# sourceMappingURL=manager.js.map
|
|
1
|
+
"use strict";export const CURRENT_RUNTIME=typeof Bun<"u"?"bun":typeof Deno<"u"?"deno":typeof process<"u"&&process.versions?.node?"node":"browser";const a=[{name:"Bun",runtime:["bun"],pkg:"@hyperttp/transport-bun",export:"BunTransport",priority:100},{name:"Deno",runtime:["deno"],pkg:"@hyperttp/transport-deno",export:"DenoTransport",priority:95},{name:"Undici",runtime:["node"],pkg:"@hyperttp/transport-undici",export:"UndiciTransport",priority:90},{name:"Browser",runtime:["browser"],pkg:"./browser.js",export:"BrowserTransport",priority:80},{name:"Node",runtime:["node","bun","deno"],pkg:"./node.js",export:"NodeTransport",priority:10}];a.forEach(Object.freeze),Object.freeze(a);const d=new Set(a.map(t=>t.pkg)),c=a.filter(t=>t.runtime.includes(CURRENT_RUNTIME)).sort((t,r)=>r.priority-t.priority);let i=null;function p(t){if(!t||typeof t!="object")return!1;const r=t,e=r.code;if(e==="ERR_MODULE_NOT_FOUND"||e==="MODULE_NOT_FOUND")return!0;const o=t instanceof Error?t.message:String(r.message??"");return o.includes("Cannot find module")||o.includes("Failed to resolve")||o.includes("Failed to load")}function f(t,r,e){const o=typeof process<"u"&&!1,n=typeof process<"u"&&process.env?.DEBUG==="1",s=t.includes(CURRENT_RUNTIME);if(n||o&&s){const u=`Failed to load preferred transport "${t}"`,l="Falling back to alternative transport...";e?.logger?(e.logger("warn",`[Hyperttp Debug] ${u}`,r),e.logger("warn",`[Hyperttp Debug] ${l}`)):(console.warn(`
|
|
2
|
+
\u26A0\uFE0F [Hyperttp Debug] ${u}:`),console.error(r),console.warn(`${l}
|
|
3
|
+
`))}}async function m(t,r,e){if(!d.has(t))throw new Error(`[Hyperttp Security] Blocked untrusted transport import attempt: ${t}`);if(CURRENT_RUNTIME==="browser"){if(t!=="./browser.js")return null;const n=await import("./browser.js"),s=n[r]??n.default;return typeof s=="function"?s:null}let o=t;try{typeof import.meta.resolve=="function"&&(o=import.meta.resolve(t,import.meta.url))}catch(n){if(p(n))return f(t,n,e),null}try{const n=await import(o),s=n[r]??n.default;return typeof s=="function"?s:null}catch(n){if(p(n))return f(t,n,e),null;throw n}}export async function resolveTransport(t){if(t.customTransport)return t.customTransport;if(i)return new i(t);const r=[];for(let e=0;e<c.length;e++){const o=c[e];try{const n=await m(o.pkg,o.export,t);if(!n){r.push(`${o.pkg} (missing export or not installed)`);continue}return i=n,new n(t)}catch(n){if(p(n)){r.push(`${o.pkg} (not installed)`);continue}throw new Error(`[Hyperttp] transport crash in ${o.pkg}: ${n?.message}`,{cause:n})}}throw new Error(`No compatible transport for runtime="${CURRENT_RUNTIME}".
|
|
4
|
+
Failures:
|
|
5
|
+
- ${r.join(`
|
|
6
|
+
- `)}`)}export class TransportManager{transport=null;promise=null;config;constructor(r,e){this.config=r,e?this.transport=e:r.customTransport?this.transport=r.customTransport:i&&(this.transport=new i(r))}getSync(){return this.transport}ensure(){return this.transport!==null?this.promise||(this.promise=Promise.resolve(this.transport)):this.promise!==null?this.promise:this.promise=resolveTransport(this.config).then(r=>(this.transport=r,r))}get(){return this.transport??this.ensure()}setConfig(r){if(this.config=r,this.transport&&"setConfig"in this.transport){const e=this.transport;typeof e.setConfig=="function"&&e.setConfig(r)}}async destroy(r=!0){const e=this.transport;if(e)try{if(r&&"close"in e){const o=e;if(typeof o.close=="function"){await o.close();return}}if("destroy"in e){const o=e;typeof o.destroy=="function"&&await o.destroy()}}finally{this.transport=null,this.promise=null}}}
|
|
7
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/transports/manager.ts"],
|
|
4
|
+
"sourcesContent": ["import type { HttpClientOptions, HyperTransport } from \"@hyperttp/types\";\n\n/**\n * @ru \u041F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0435 \u0441\u0440\u0435\u0434\u044B \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u044F \u0434\u043B\u044F \u0430\u0432\u0442\u043E\u043C\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u043E\u0433\u043E \u0432\u044B\u0431\u043E\u0440\u0430 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430.\n * @en Supported runtime environments for automatic transport selection.\n */\nexport type Runtime = \"bun\" | \"node\" | \"deno\" | \"browser\";\n\n/**\n * @ru \u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430, \u043F\u0440\u0438\u043D\u0438\u043C\u0430\u044E\u0449\u0438\u0439 \u043A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044E \u043A\u043B\u0438\u0435\u043D\u0442\u0430.\n * @en Transport constructor accepting client configuration.\n */\ntype TransportCtor = new (config: HttpClientOptions) => HyperTransport;\n\n/**\n * @ru \u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430: \u0438\u043C\u044F, \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0435 \u0441\u0440\u0435\u0434\u044B, \u043F\u0430\u043A\u0435\u0442, \u044D\u043A\u0441\u043F\u043E\u0440\u0442 \u0438 \u043F\u0440\u0438\u043E\u0440\u0438\u0442\u0435\u0442.\n * @en Transport descriptor: name, supported runtimes, package, export, and priority.\n */\ntype TransportDef = {\n /** @ru \u0418\u043C\u044F \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430 \u0434\u043B\u044F \u043B\u043E\u0433\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u044F. @en Transport name for logging. */\n readonly name: string;\n /** @ru \u0421\u043F\u0438\u0441\u043E\u043A \u0441\u0440\u0435\u0434, \u0432 \u043A\u043E\u0442\u043E\u0440\u044B\u0445 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442 \u043C\u043E\u0436\u0435\u0442 \u0440\u0430\u0431\u043E\u0442\u0430\u0442\u044C. @en List of runtimes where the transport can operate. */\n readonly runtime: readonly Runtime[];\n /** @ru \u0418\u043C\u044F \u043F\u0430\u043A\u0435\u0442\u0430 npm \u0438\u043B\u0438 \u043E\u0442\u043D\u043E\u0441\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u0439 \u043F\u0443\u0442\u044C \u0434\u043B\u044F \u0432\u0441\u0442\u0440\u043E\u0435\u043D\u043D\u044B\u0445 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u043E\u0432. @en npm package name or relative path for built-in transports. */\n readonly pkg: string;\n /** @ru \u0418\u043C\u044F \u044D\u043A\u0441\u043F\u043E\u0440\u0442\u0438\u0440\u0443\u0435\u043C\u043E\u0433\u043E \u043A\u043B\u0430\u0441\u0441\u0430 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430. @en Exported transport class name. */\n readonly export: string;\n /** @ru \u041F\u0440\u0438\u043E\u0440\u0438\u0442\u0435\u0442 \u0432\u044B\u0431\u043E\u0440\u0430 (\u0432\u044B\u0448\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 = \u0440\u0430\u043D\u044C\u0448\u0435 \u043F\u043E\u043F\u044B\u0442\u043A\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0438). @en Selection priority (higher value = earlier load attempt). */\n readonly priority: number;\n};\n\n/**\n * @ru \u041E\u043F\u0440\u0435\u0434\u0435\u043B\u044F\u0435\u0442 \u0442\u0435\u043A\u0443\u0449\u0443\u044E \u0441\u0440\u0435\u0434\u0443 \u0432\u044B\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u044F \u043F\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0435 \u043C\u043E\u0434\u0443\u043B\u044F.\n * \u041F\u043E\u0440\u044F\u0434\u043E\u043A \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438: Bun \u2192 Deno \u2192 Node.js \u2192 Browser.\n * @en Detects the current runtime at module load time.\n * Detection order: Bun \u2192 Deno \u2192 Node.js \u2192 Browser.\n */\nexport const CURRENT_RUNTIME: Runtime = (() => {\n if (typeof Bun !== \"undefined\") return \"bun\";\n if (typeof Deno !== \"undefined\") return \"deno\";\n if (typeof process !== \"undefined\" && process.versions?.node) return \"node\";\n return \"browser\";\n})();\n\n/**\n * @ru \u0412\u043D\u0443\u0442\u0440\u0435\u043D\u043D\u0438\u0439 \u0440\u0435\u0435\u0441\u0442\u0440 \u0432\u0441\u0435\u0445 \u0434\u043E\u0441\u0442\u0443\u043F\u043D\u044B\u0445 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u043E\u0432 \u0441 \u043F\u0440\u0438\u043E\u0440\u0438\u0442\u0435\u0442\u0430\u043C\u0438.\n * \u0417\u0430\u043C\u043E\u0440\u043E\u0436\u0435\u043D \u0434\u043B\u044F \u043F\u0440\u0435\u0434\u043E\u0442\u0432\u0440\u0430\u0449\u0435\u043D\u0438\u044F \u043C\u043E\u0434\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u0439 \u0432 runtime.\n * @en Internal registry of all available transports with priorities.\n * Frozen to prevent runtime modifications.\n */\nconst INTERNAL_TRANSPORTS: readonly TransportDef[] = [\n {\n name: \"Bun\",\n runtime: [\"bun\"],\n pkg: \"@hyperttp/transport-bun\",\n export: \"BunTransport\",\n priority: 100,\n },\n {\n name: \"Deno\",\n runtime: [\"deno\"],\n pkg: \"@hyperttp/transport-deno\",\n export: \"DenoTransport\",\n priority: 95,\n },\n {\n name: \"Undici\",\n runtime: [\"node\"],\n pkg: \"@hyperttp/transport-undici\",\n export: \"UndiciTransport\",\n priority: 90,\n },\n {\n name: \"Browser\",\n runtime: [\"browser\"],\n pkg: \"./browser.js\",\n export: \"BrowserTransport\",\n priority: 80,\n },\n {\n name: \"Node\",\n runtime: [\"node\", \"bun\", \"deno\"],\n pkg: \"./node.js\",\n export: \"NodeTransport\",\n priority: 10,\n },\n];\n\nINTERNAL_TRANSPORTS.forEach(Object.freeze);\nObject.freeze(INTERNAL_TRANSPORTS);\n\n/**\n * @ru \u0411\u0435\u043B\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043D\u043D\u044B\u0445 \u043F\u0430\u043A\u0435\u0442\u043E\u0432 \u0434\u043B\u044F \u0437\u0430\u0449\u0438\u0442\u044B \u043E\u0442 \u043D\u0435\u0441\u0430\u043D\u043A\u0446\u0438\u043E\u043D\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u043E\u0433\u043E \u0438\u043C\u043F\u043E\u0440\u0442\u0430.\n * @en Whitelist of allowed packages to protect against unauthorized imports.\n */\nconst ALLOWED_PACKAGES = new Set<string>(INTERNAL_TRANSPORTS.map((t) => t.pkg));\n\n/**\n * @ru \u041E\u0442\u0444\u0438\u043B\u044C\u0442\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0438 \u043E\u0442\u0441\u043E\u0440\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u043E\u0432 \u0434\u043B\u044F \u0442\u0435\u043A\u0443\u0449\u0435\u0439 \u0441\u0440\u0435\u0434\u044B.\n * \u0412\u044B\u0447\u0438\u0441\u043B\u044F\u0435\u0442\u0441\u044F \u043E\u0434\u0438\u043D \u0440\u0430\u0437 \u043F\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0435 \u043C\u043E\u0434\u0443\u043B\u044F.\n * @en Filtered and sorted list of transports for the current runtime.\n * Computed once at module load time.\n */\nconst CANDIDATES = INTERNAL_TRANSPORTS.filter((t) => t.runtime.includes(CURRENT_RUNTIME)).sort(\n (a, b) => b.priority - a.priority,\n);\n\n/**\n * @ru \u041A\u044D\u0448 \u0440\u0430\u0437\u0440\u0435\u0448\u0451\u043D\u043D\u043E\u0433\u043E \u043A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440\u0430 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430 \u0434\u043B\u044F \u0438\u0437\u0431\u0435\u0436\u0430\u043D\u0438\u044F \u043F\u043E\u0432\u0442\u043E\u0440\u043D\u043E\u0433\u043E \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043D\u0438\u044F.\n * @en Cached resolved transport constructor to avoid repeated resolution.\n */\nlet RESOLVED_RUNTIME_CTOR: TransportCtor | null = null;\n\n/**\n * @ru \u041F\u0440\u043E\u0432\u0435\u0440\u044F\u0435\u0442, \u044F\u0432\u043B\u044F\u0435\u0442\u0441\u044F \u043B\u0438 \u043E\u0448\u0438\u0431\u043A\u043E\u0439 \u043E\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044F \u043C\u043E\u0434\u0443\u043B\u044F.\n * \u041F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043A\u043E\u0434\u044B ERR_MODULE_NOT_FOUND \u0438 MODULE_NOT_FOUND,\n * \u0430 \u0442\u0430\u043A\u0436\u0435 \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u044F \u043E\u0431 \u043E\u0448\u0438\u0431\u043A\u0430\u0445 (\u0434\u043B\u044F \u0441\u043E\u0432\u043C\u0435\u0441\u0442\u0438\u043C\u043E\u0441\u0442\u0438 \u0441 Bun \u0438 Deno).\n * @en Checks if the error is a module-not-found error.\n * Supports ERR_MODULE_NOT_FOUND and MODULE_NOT_FOUND codes,\n * as well as error messages (for Bun and Deno compatibility).\n * @param err - The error to check.\n * @returns True if the error indicates a missing module.\n */\nfunction isModuleNotFoundError(err: unknown): boolean {\n if (!err || typeof err !== \"object\") return false;\n\n const e = err as Record<string, unknown>;\n const code = e.code as string | undefined;\n if (code === \"ERR_MODULE_NOT_FOUND\" || code === \"MODULE_NOT_FOUND\") return true;\n\n const msg = err instanceof Error ? err.message : String(e.message ?? \"\");\n return (\n msg.includes(\"Cannot find module\") ||\n msg.includes(\"Failed to resolve\") ||\n msg.includes(\"Failed to load\")\n );\n}\n\n/**\n * @ru \u041B\u043E\u0433\u0438\u0440\u0443\u0435\u0442 \u0438\u043D\u0444\u043E\u0440\u043C\u0430\u0446\u0438\u044E \u043E \u043D\u0435\u0443\u0434\u0430\u0447\u043D\u043E\u0439 \u043F\u043E\u043F\u044B\u0442\u043A\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043A\u0438 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430.\n * \u0410\u043A\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u0442\u0441\u044F \u0432 \u0440\u0435\u0436\u0438\u043C\u0435 DEBUG=1 \u0438\u043B\u0438 \u043F\u0440\u0438 \u043E\u0448\u0438\u0431\u043A\u0435 \u043D\u0430\u0442\u0438\u0432\u043D\u043E\u0433\u043E \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430 \u0432 dev-\u043E\u043A\u0440\u0443\u0436\u0435\u043D\u0438\u0438.\n * @en Logs information about failed transport load attempts.\n * Activated in DEBUG=1 mode or when native transport fails in dev environment.\n * @param pkg - Package name that failed to load.\n * @param err - The error that occurred.\n * @param config - Optional client configuration for custom logger.\n */\nfunction logDebugFallback(pkg: string, err: unknown, config?: HttpClientOptions): void {\n const isDev = typeof process !== \"undefined\" && process.env?.NODE_ENV === \"development\";\n const isDebug = typeof process !== \"undefined\" && process.env?.DEBUG === \"1\";\n const isNativeTransport = pkg.includes(CURRENT_RUNTIME);\n\n if (isDebug || (isDev && isNativeTransport)) {\n const primaryMessage = `Failed to load preferred transport \"${pkg}\"`;\n const fallbackMessage = `Falling back to alternative transport...`;\n\n if (config?.logger) {\n config.logger(\"warn\", `[Hyperttp Debug] ${primaryMessage}`, err);\n config.logger(\"warn\", `[Hyperttp Debug] ${fallbackMessage}`);\n } else {\n console.warn(`\\n\u26A0\uFE0F [Hyperttp Debug] ${primaryMessage}:`);\n console.error(err);\n console.warn(`${fallbackMessage}\\n`);\n }\n }\n}\n\n/**\n * @ru \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430 \u0438\u0437 \u043F\u0430\u043A\u0435\u0442\u0430 \u0438\u043B\u0438 \u043E\u0442\u043D\u043E\u0441\u0438\u0442\u0435\u043B\u044C\u043D\u043E\u0433\u043E \u043F\u0443\u0442\u0438.\n * \u0414\u043B\u044F \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043D\u043E\u0439 \u0441\u0440\u0435\u0434\u044B \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043A\u0438\u0439 \u0438\u043C\u043F\u043E\u0440\u0442 \u0434\u043B\u044F \u0441\u043E\u0432\u043C\u0435\u0441\u0442\u0438\u043C\u043E\u0441\u0442\u0438 \u0441 \u0431\u0430\u043D\u0434\u043B\u0435\u0440\u0430\u043C\u0438.\n * @en Loads a transport constructor from a package or relative path.\n * For browser runtime, uses static import for bundler compatibility.\n * @param pkg - Package name or relative path.\n * @param exportName - Name of the exported transport class.\n * @param config - Optional client configuration for debug logging.\n * @returns Transport constructor or null if not found.\n * @throws Error if the package is not in the whitelist.\n */\nasync function loadCtor(\n pkg: string,\n exportName: string,\n config?: HttpClientOptions,\n): Promise<TransportCtor | null> {\n if (!ALLOWED_PACKAGES.has(pkg)) {\n throw new Error(`[Hyperttp Security] Blocked untrusted transport import attempt: ${pkg}`);\n }\n\n if (CURRENT_RUNTIME === \"browser\") {\n if (pkg !== \"./browser.js\") return null;\n const mod = (await import(\"./browser.js\")) as Record<string, unknown>;\n const candidate = mod[exportName] ?? mod.default;\n return typeof candidate === \"function\" ? (candidate as TransportCtor) : null;\n }\n\n let specifier = pkg;\n try {\n if (typeof import.meta.resolve === \"function\") {\n specifier = import.meta.resolve(pkg, import.meta.url);\n }\n } catch (err) {\n if (isModuleNotFoundError(err)) {\n logDebugFallback(pkg, err, config);\n return null;\n }\n }\n\n try {\n const mod = (await import(specifier)) as Record<string, unknown>;\n const candidate = mod[exportName] ?? mod.default;\n return typeof candidate === \"function\" ? (candidate as TransportCtor) : null;\n } catch (err) {\n if (isModuleNotFoundError(err)) {\n logDebugFallback(pkg, err, config);\n return null;\n }\n throw err;\n }\n}\n\n/**\n * @ru \u0420\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 \u0438 \u0441\u043E\u0437\u0434\u0430\u0451\u0442 \u043E\u043F\u0442\u0438\u043C\u0430\u043B\u044C\u043D\u044B\u0439 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442 \u0434\u043B\u044F \u0442\u0435\u043A\u0443\u0449\u0435\u0439 \u0441\u0440\u0435\u0434\u044B.\n * \u041F\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u0442 \u043A\u0430\u043D\u0434\u0438\u0434\u0430\u0442\u043E\u0432 \u043F\u043E \u043F\u0440\u0438\u043E\u0440\u0438\u0442\u0435\u0442\u0443, \u043A\u044D\u0448\u0438\u0440\u0443\u0435\u0442 \u043F\u0435\u0440\u0432\u044B\u0439 \u0443\u0441\u043F\u0435\u0448\u043D\u044B\u0439 \u0440\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442.\n * @en Resolves and creates the optimal transport for the current runtime.\n * Iterates candidates by priority, caches the first successful result.\n * @param config - Client configuration options.\n * @returns Promise resolving to the instantiated transport.\n * @throws Error if no compatible transport is found.\n */\nexport async function resolveTransport(config: HttpClientOptions): Promise<HyperTransport> {\n if (config.customTransport) return config.customTransport;\n if (RESOLVED_RUNTIME_CTOR) return new RESOLVED_RUNTIME_CTOR(config);\n\n const failures: string[] = [];\n\n for (let i = 0; i < CANDIDATES.length; i++) {\n const t = CANDIDATES[i]!;\n try {\n const ctor = await loadCtor(t.pkg, t.export, config);\n if (!ctor) {\n failures.push(`${t.pkg} (missing export or not installed)`);\n continue;\n }\n\n RESOLVED_RUNTIME_CTOR = ctor;\n return new ctor(config);\n } catch (err) {\n if (isModuleNotFoundError(err)) {\n failures.push(`${t.pkg} (not installed)`);\n continue;\n }\n throw new Error(`[Hyperttp] transport crash in ${t.pkg}: ${(err as Error)?.message}`, {\n cause: err,\n });\n }\n }\n\n throw new Error(\n `No compatible transport for runtime=\"${CURRENT_RUNTIME}\".\\nFailures:\\n- ${failures.join(\"\\n- \")}`,\n );\n}\n\n/**\n * @ru \u041C\u0435\u043D\u0435\u0434\u0436\u0435\u0440 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430 \u0441 \u043B\u0435\u043D\u0438\u0432\u043E\u0439 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438 \u043A\u044D\u0448\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435\u043C.\n * \u041F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u043D\u0445\u0440\u043E\u043D\u043D\u044B\u0439 \u0434\u043E\u0441\u0442\u0443\u043F, \u043E\u0442\u043B\u043E\u0436\u0435\u043D\u043D\u0443\u044E \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044E \u0438 \u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u043E\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043D\u0438\u0435.\n * @en Transport manager with lazy initialization and caching.\n * Supports synchronous access, deferred initialization, and graceful shutdown.\n */\nexport class TransportManager {\n /**\n * @ru \u0422\u0435\u043A\u0443\u0449\u0438\u0439 \u044D\u043A\u0437\u0435\u043C\u043F\u043B\u044F\u0440 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430 (null \u0434\u043E \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0438).\n * @en Current transport instance (null before initialization).\n */\n public transport: HyperTransport | null = null;\n\n /**\n * @ru \u041F\u0440\u043E\u043C\u0438\u0441 \u043E\u0442\u043B\u043E\u0436\u0435\u043D\u043D\u043E\u0439 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430.\n * @en Deferred transport initialization promise.\n */\n private promise: Promise<HyperTransport> | null = null;\n\n /**\n * @ru \u041A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044F \u043A\u043B\u0438\u0435\u043D\u0442\u0430 \u0434\u043B\u044F \u0441\u043E\u0437\u0434\u0430\u043D\u0438\u044F \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430.\n * @en Client configuration for transport creation.\n */\n private config: HttpClientOptions;\n\n /**\n * @ru \u0421\u043E\u0437\u0434\u0430\u0451\u0442 \u043C\u0435\u043D\u0435\u0434\u0436\u0435\u0440 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430 \u0441 \u043E\u043F\u0446\u0438\u043E\u043D\u0430\u043B\u044C\u043D\u044B\u043C \u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u044C\u0441\u043A\u0438\u043C \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u043E\u043C.\n * @en Creates a transport manager with an optional custom transport.\n * @param config - Client configuration options.\n * @param custom - Optional custom transport instance.\n */\n constructor(config: HttpClientOptions, custom?: HyperTransport) {\n this.config = config;\n\n if (custom) {\n this.transport = custom;\n } else if (config.customTransport) {\n this.transport = config.customTransport;\n } else if (RESOLVED_RUNTIME_CTOR) {\n this.transport = new RESOLVED_RUNTIME_CTOR(config);\n }\n }\n\n /**\n * @ru \u0421\u0438\u043D\u0445\u0440\u043E\u043D\u043D\u043E \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0435\u043A\u0443\u0449\u0438\u0439 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442 \u0438\u043B\u0438 null, \u0435\u0441\u043B\u0438 \u043D\u0435 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0438\u0440\u043E\u0432\u0430\u043D.\n * @en Synchronously returns the current transport or null if not initialized.\n * @returns The transport instance or null.\n */\n public getSync(): HyperTransport | null {\n return this.transport;\n }\n\n /**\n * @ru \u0413\u0430\u0440\u0430\u043D\u0442\u0438\u0440\u0443\u0435\u0442 \u043D\u0430\u043B\u0438\u0447\u0438\u0435 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430, \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0438\u0440\u0443\u044F \u0435\u0433\u043E \u043F\u0440\u0438 \u043D\u0435\u043E\u0431\u0445\u043E\u0434\u0438\u043C\u043E\u0441\u0442\u0438.\n * \u041F\u043E\u0432\u0442\u043E\u0440\u043D\u044B\u0435 \u0432\u044B\u0437\u043E\u0432\u044B \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u044E\u0442 \u043E\u0434\u0438\u043D \u0438 \u0442\u043E\u0442 \u0436\u0435 \u043F\u0440\u043E\u043C\u0438\u0441.\n * @en Ensures a transport exists, initializing it if necessary.\n * Repeated calls return the same promise.\n * @returns Promise resolving to the transport instance.\n */\n public ensure(): Promise<HyperTransport> {\n if (this.transport !== null) {\n return this.promise || (this.promise = Promise.resolve(this.transport));\n }\n if (this.promise !== null) return this.promise;\n\n return (this.promise = resolveTransport(this.config).then((t) => {\n this.transport = t;\n return t;\n }));\n }\n\n /**\n * @ru \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442 \u0441\u0438\u043D\u0445\u0440\u043E\u043D\u043D\u043E \u0438\u043B\u0438 \u043F\u0440\u043E\u043C\u0438\u0441, \u0435\u0441\u043B\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044F \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0430\u0446\u0438\u044F.\n * @en Returns the transport synchronously or a promise if initialization is needed.\n * @returns The transport instance or a promise resolving to it.\n */\n public get(): HyperTransport | Promise<HyperTransport> {\n return this.transport ?? this.ensure();\n }\n\n /**\n * @ru \u041E\u0431\u043D\u043E\u0432\u043B\u044F\u0435\u0442 \u043A\u043E\u043D\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044E \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430, \u0435\u0441\u043B\u0438 \u043E\u043D \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 setConfig.\n * @en Updates the transport configuration if it supports setConfig.\n * @param config - New client configuration options.\n */\n public setConfig(config: HttpClientOptions): void {\n this.config = config;\n\n if (this.transport && \"setConfig\" in this.transport) {\n const dynamicTarget = this.transport as {\n setConfig: (config: HttpClientOptions) => void;\n };\n if (typeof dynamicTarget.setConfig === \"function\") {\n dynamicTarget.setConfig(config);\n }\n }\n }\n\n /**\n * @ru \u0417\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043E\u0442\u0443 \u0442\u0440\u0430\u043D\u0441\u043F\u043E\u0440\u0442\u0430 \u0438 \u043E\u0441\u0432\u043E\u0431\u043E\u0436\u0434\u0430\u0435\u0442 \u0440\u0435\u0441\u0443\u0440\u0441\u044B.\n * \u0412 graceful-\u0440\u0435\u0436\u0438\u043C\u0435 \u0432\u044B\u0437\u044B\u0432\u0430\u0435\u0442 close(), \u0438\u043D\u0430\u0447\u0435 \u2014 destroy().\n * @en Shuts down the transport and releases resources.\n * In graceful mode calls close(), otherwise calls destroy().\n * @param graceful - If true, waits for active requests to complete.\n * @returns Promise that resolves when shutdown is complete.\n */\n public async destroy(graceful = true): Promise<void> {\n const t = this.transport;\n if (!t) return;\n\n try {\n if (graceful && \"close\" in t) {\n const closable = t as { close: () => Promise<void> | void };\n if (typeof closable.close === \"function\") {\n await closable.close();\n return;\n }\n }\n if (\"destroy\" in t) {\n const destroyable = t as { destroy: () => Promise<void> | void };\n if (typeof destroyable.destroy === \"function\") {\n await destroyable.destroy();\n }\n }\n } finally {\n this.transport = null;\n this.promise = null;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["INTERNAL_TRANSPORTS", "ALLOWED_PACKAGES", "CANDIDATES", "a", "b", "RESOLVED_RUNTIME_CTOR", "isModuleNotFoundError", "err", "e", "code", "msg", "logDebugFallback", "pkg", "config", "isDev", "isDebug", "isNativeTransport", "primaryMessage", "fallbackMessage", "loadCtor", "exportName", "mod", "candidate", "specifier", "failures", "i", "t", "ctor", "custom", "dynamicTarget", "graceful", "closable", "destroyable"]
|
|
7
|
+
}
|
package/transports/node.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare class NodeTransport implements HyperTransport {
|
|
|
23
23
|
config: NodeTransportConfig;
|
|
24
24
|
private readonly isProduction;
|
|
25
25
|
private readonly cleanBaseUrl;
|
|
26
|
+
private readonly agentCache;
|
|
26
27
|
constructor(config: NodeTransportConfig);
|
|
27
28
|
execute(req: TransportRequest): Promise<TransportResponse>;
|
|
28
29
|
close(): Promise<void>;
|
package/transports/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/transports/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,iBAAiB,CAAC;AAQzB;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC5D;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/transports/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,iBAAiB,CAAC;AAQzB;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC5D;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAuWD;;;GAGG;AACH,qBAAa,aAAc,YAAW,cAAc;IAC3C,MAAM,EAAE,mBAAmB,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4C;IAEvE,YAAY,MAAM,EAAE,mBAAmB,EAMtC;IAEY,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA0HtE;IAEY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAKlC;IAEY,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAKpC;CACF"}
|