@hyperttp/core 1.3.3 → 1.4.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 +142 -152
- package/Core/HyperCore.d.ts.map +1 -1
- package/Core/HyperCore.js +289 -286
- package/Core/HyperCore.js.map +1 -1
- package/README.md +279 -134
- 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 +35 -44
- package/utils/response.d.ts.map +1 -1
- package/utils/response.js +228 -69
- 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
package/transports/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/transports/node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/transports/node.ts"],"names":[],"mappings":"AAYA,MAAM,OAAO,GAA4B,UAAU,CAAC,KAAK,CAAC;AAE1D,SAAS,yBAAyB;IAChC,IAAI,OAAO,cAAc,KAAK,WAAW;QAAE,OAAO;IAElD,MAAM,KAAK,GAAG,cAAc,CAAC,SAE5B,CAAC;IAEF,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO;IAE7C,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE;QACnC,KAAK,EAAE,KAAK;YACV,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;YAC7B,CAAC;YAAC,MAAM,CAAC;gBACP,EAAE;YACJ,CAAC;QACH,CAAC;QACD,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC;AAED,yBAAyB,EAAE,CAAC;AAE5B,SAAS,iBAAiB,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,UAAU,CAAC,OAAe,EAAE,GAAW;IAC9C,IAAI,iBAAiB,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IACvC,OAAO,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC;AACxE,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,SAAS,KAAK,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAEnC,MAAM,S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2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/D,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACjC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC1B,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,OAAO,EAAE,UAAU;YACnB,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,IAAI,EAAE,MAAM;SACb,CAAC;IACJ,CAAC;CACF"}
|
package/utils/decompress.d.ts
CHANGED
|
@@ -2,26 +2,24 @@ import type { TransportStreamExtensions } from "@hyperttp/types";
|
|
|
2
2
|
type StreamPayload = ReadableStream<Uint8Array> & TransportStreamExtensions;
|
|
3
3
|
type BufferPayload = Uint8Array & TransportStreamExtensions;
|
|
4
4
|
/**
|
|
5
|
-
* @ru
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
5
|
+
* @ru Декомпрессирует буфер с поддержкой множественных кодировок.
|
|
6
|
+
* Сначала пытается Web API, затем fallback на node:zlib для серверных сред.
|
|
7
|
+
* @en Decompresses a buffer with support for multiple encodings.
|
|
8
|
+
* Tries Web API first, then falls back to node:zlib for server environments.
|
|
9
|
+
* @param body - The compressed Uint8Array.
|
|
10
|
+
* @param encoding - The Content-Encoding header value (e.g., 'gzip, br').
|
|
11
|
+
* @returns The decompressed buffer with dump() method attached.
|
|
10
12
|
*/
|
|
11
|
-
export declare function decompressBuffer(body: Uint8Array, encoding: string): BufferPayload
|
|
13
|
+
export declare function decompressBuffer(body: Uint8Array, encoding: string): Promise<BufferPayload>;
|
|
12
14
|
/**
|
|
13
|
-
* @ru Создаёт
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param body - Original compressed ReadableStream.
|
|
22
|
-
* @param encoding - Raw Content-Encoding header (may be a chain).
|
|
23
|
-
* @returns Decompressed ReadableStream with a dump method that cancels the stream.
|
|
15
|
+
* @ru Создаёт декомпрессированный стрим с поддержкой множественных кодировок.
|
|
16
|
+
* Использует DecompressionStream для Web и node:zlib для Node.js.
|
|
17
|
+
* @en Creates a decompressed stream with support for multiple encodings.
|
|
18
|
+
* Uses DecompressionStream for Web and node:zlib for Node.js.
|
|
19
|
+
* @param body - The compressed ReadableStream.
|
|
20
|
+
* @param encoding - The Content-Encoding header value (e.g., 'gzip, br').
|
|
21
|
+
* @returns The decompressed stream with dump() method attached.
|
|
24
22
|
*/
|
|
25
|
-
export declare function createDecompressStream(body: ReadableStream<Uint8Array>, encoding: string): StreamPayload
|
|
23
|
+
export declare function createDecompressStream(body: ReadableStream<Uint8Array>, encoding: string): Promise<StreamPayload>;
|
|
26
24
|
export {};
|
|
27
25
|
//# sourceMappingURL=decompress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../../src/utils/decompress.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../../src/utils/decompress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAGjE,KAAK,aAAa,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,yBAAyB,CAAC;AAC5E,KAAK,aAAa,GAAG,UAAU,GAAG,yBAAyB,CAAC;AAiJ5D;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAsBjG;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,aAAa,CAAC,CAoCxB"}
|
package/utils/decompress.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Readable } from "node:stream";
|
|
1
|
+
import { runtimeImport } from "../transports/manager.js";
|
|
3
2
|
/**
|
|
4
|
-
* @ru
|
|
5
|
-
* @en
|
|
6
|
-
|
|
3
|
+
* @ru Флаг серверного окружения (Node.js/Bun/Deno).
|
|
4
|
+
* @en Server environment flag (Node.js/Bun/Deno).
|
|
5
|
+
*/
|
|
6
|
+
const IS_SERVER = typeof window === "undefined" && typeof self === "undefined";
|
|
7
|
+
/**
|
|
8
|
+
* @ru No-op функция для dump() буферов. Буферы не требуют освобождения ресурсов.
|
|
9
|
+
* @en No-op function for buffer dump(). Buffers don't require resource cleanup.
|
|
10
|
+
*/
|
|
11
|
+
const NOOP_DUMP = async () => { };
|
|
12
|
+
/**
|
|
13
|
+
* @ru Парсит строку Content-Encoding в массив кодировок.
|
|
14
|
+
* Игнорирует 'identity' (без сжатия) и пустые значения.
|
|
15
|
+
* @en Parses Content-Encoding string into an array of encodings.
|
|
16
|
+
* Ignores 'identity' (no compression) and empty values.
|
|
17
|
+
* @param encoding - The Content-Encoding header value.
|
|
7
18
|
* @returns Array of normalized encoding names.
|
|
8
19
|
*/
|
|
9
20
|
function parseEncodings(encoding) {
|
|
@@ -13,21 +24,21 @@ function parseEncodings(encoding) {
|
|
|
13
24
|
.filter((part) => part.length > 0 && part !== "identity");
|
|
14
25
|
}
|
|
15
26
|
/**
|
|
16
|
-
* @ru Добавляет
|
|
17
|
-
* @en Attaches a
|
|
18
|
-
* @param buffer - The Uint8Array
|
|
19
|
-
* @returns
|
|
27
|
+
* @ru Добавляет no-op метод dump() к буферу.
|
|
28
|
+
* @en Attaches a no-op dump() method to the buffer.
|
|
29
|
+
* @param buffer - The Uint8Array to extend.
|
|
30
|
+
* @returns The buffer with dump() method attached.
|
|
20
31
|
*/
|
|
21
32
|
function attachNoopDump(buffer) {
|
|
22
33
|
const payload = buffer;
|
|
23
|
-
payload.dump =
|
|
34
|
+
payload.dump = NOOP_DUMP;
|
|
24
35
|
return payload;
|
|
25
36
|
}
|
|
26
37
|
/**
|
|
27
|
-
* @ru Добавляет метод dump к
|
|
28
|
-
* @en Attaches a dump method to
|
|
29
|
-
* @param stream - ReadableStream to
|
|
30
|
-
* @returns
|
|
38
|
+
* @ru Добавляет метод dump() к стриму для отмены и освобождения сокета.
|
|
39
|
+
* @en Attaches a dump() method to the stream for cancellation and socket release.
|
|
40
|
+
* @param stream - The ReadableStream to extend.
|
|
41
|
+
* @returns The stream with dump() method attached.
|
|
31
42
|
*/
|
|
32
43
|
function attachStreamDump(stream) {
|
|
33
44
|
const payload = stream;
|
|
@@ -42,87 +53,156 @@ function attachStreamDump(stream) {
|
|
|
42
53
|
return payload;
|
|
43
54
|
}
|
|
44
55
|
/**
|
|
45
|
-
* @ru
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
56
|
+
* @ru Декомпрессирует буфер с использованием Web API (DecompressionStream).
|
|
57
|
+
* Поддерживает gzip и deflate. Возвращает исходный буфер, если декомпрессия невозможна.
|
|
58
|
+
* @en Decompresses a buffer using Web API (DecompressionStream).
|
|
59
|
+
* Supports gzip and deflate. Returns the original buffer if decompression is not possible.
|
|
60
|
+
* @param input - The compressed Uint8Array.
|
|
61
|
+
* @param encoding - The compression encoding ('gzip', 'deflate').
|
|
62
|
+
* @returns The decompressed Uint8Array, or the original input if not applicable.
|
|
63
|
+
*/
|
|
64
|
+
async function decompressOnceWeb(input, encoding) {
|
|
65
|
+
const enc = encoding.trim().toLowerCase();
|
|
66
|
+
if (typeof globalThis.DecompressionStream === "undefined")
|
|
67
|
+
return input;
|
|
68
|
+
const isGzip = enc === "gzip" || enc === "x-gzip";
|
|
69
|
+
const isDeflate = enc === "deflate";
|
|
70
|
+
if (!isGzip && !isDeflate)
|
|
71
|
+
return input;
|
|
72
|
+
const format = isGzip ? "gzip" : "deflate";
|
|
73
|
+
const inputStream = new ReadableStream({
|
|
74
|
+
start(controller) {
|
|
75
|
+
controller.enqueue(input);
|
|
76
|
+
controller.close();
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const decompressedStream = inputStream.pipeThrough(new globalThis.DecompressionStream(format));
|
|
80
|
+
const reader = decompressedStream.getReader();
|
|
81
|
+
const chunks = [];
|
|
82
|
+
let totalLength = 0;
|
|
83
|
+
try {
|
|
84
|
+
while (true) {
|
|
85
|
+
const { done, value } = await reader.read();
|
|
86
|
+
if (done)
|
|
87
|
+
break;
|
|
88
|
+
if (value) {
|
|
89
|
+
chunks.push(value);
|
|
90
|
+
totalLength += value.byteLength;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
reader.releaseLock();
|
|
96
|
+
}
|
|
97
|
+
if (chunks.length === 0)
|
|
98
|
+
return new Uint8Array(0);
|
|
99
|
+
if (chunks.length === 1)
|
|
100
|
+
return chunks[0];
|
|
101
|
+
const result = new Uint8Array(totalLength);
|
|
102
|
+
let offset = 0;
|
|
103
|
+
for (const chunk of chunks) {
|
|
104
|
+
result.set(chunk, offset);
|
|
105
|
+
offset += chunk.byteLength;
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @ru Декомпрессирует буфер с использованием node:zlib.
|
|
111
|
+
* Поддерживает gzip, deflate и brotli.
|
|
112
|
+
* @en Decompresses a buffer using node:zlib.
|
|
113
|
+
* Supports gzip, deflate, and brotli.
|
|
114
|
+
* @param input - The compressed Uint8Array.
|
|
115
|
+
* @param encoding - The compression encoding.
|
|
116
|
+
* @returns The decompressed Uint8Array.
|
|
51
117
|
*/
|
|
52
|
-
function
|
|
118
|
+
async function decompressOnceNode(input, encoding) {
|
|
119
|
+
const enc = encoding.trim().toLowerCase();
|
|
120
|
+
const zlib = await runtimeImport("node:zlib");
|
|
53
121
|
const buffer = Buffer.from(input.buffer, input.byteOffset, input.byteLength);
|
|
54
|
-
switch (
|
|
122
|
+
switch (enc) {
|
|
55
123
|
case "gzip":
|
|
56
124
|
case "x-gzip":
|
|
57
|
-
return gunzipSync(buffer);
|
|
125
|
+
return new Uint8Array(zlib.gunzipSync(buffer));
|
|
58
126
|
case "deflate":
|
|
59
|
-
return inflateSync(buffer);
|
|
127
|
+
return new Uint8Array(zlib.inflateSync(buffer));
|
|
60
128
|
case "br":
|
|
61
|
-
return brotliDecompressSync(buffer);
|
|
129
|
+
return new Uint8Array(zlib.brotliDecompressSync(buffer));
|
|
62
130
|
default:
|
|
63
131
|
return input;
|
|
64
132
|
}
|
|
65
133
|
}
|
|
66
134
|
/**
|
|
67
|
-
* @ru
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
70
|
-
*
|
|
71
|
-
* @
|
|
135
|
+
* @ru Декомпрессирует буфер с поддержкой множественных кодировок.
|
|
136
|
+
* Сначала пытается Web API, затем fallback на node:zlib для серверных сред.
|
|
137
|
+
* @en Decompresses a buffer with support for multiple encodings.
|
|
138
|
+
* Tries Web API first, then falls back to node:zlib for server environments.
|
|
139
|
+
* @param body - The compressed Uint8Array.
|
|
140
|
+
* @param encoding - The Content-Encoding header value (e.g., 'gzip, br').
|
|
141
|
+
* @returns The decompressed buffer with dump() method attached.
|
|
72
142
|
*/
|
|
73
|
-
export function decompressBuffer(body, encoding) {
|
|
143
|
+
export async function decompressBuffer(body, encoding) {
|
|
74
144
|
let current = body;
|
|
75
145
|
const encodings = parseEncodings(encoding);
|
|
76
146
|
for (let i = 0; i < encodings.length; i++) {
|
|
77
|
-
|
|
147
|
+
const enc = encodings[i];
|
|
148
|
+
const webResult = await decompressOnceWeb(current, enc);
|
|
149
|
+
if (webResult !== current) {
|
|
150
|
+
current = webResult;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (IS_SERVER && (enc === "br" || enc === "gzip" || enc === "deflate" || enc === "x-gzip")) {
|
|
154
|
+
try {
|
|
155
|
+
current = await decompressOnceNode(current, enc);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
78
161
|
}
|
|
79
162
|
return attachNoopDump(current);
|
|
80
163
|
}
|
|
81
164
|
/**
|
|
82
|
-
* @ru Создаёт
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @param body - Original compressed ReadableStream.
|
|
91
|
-
* @param encoding - Raw Content-Encoding header (may be a chain).
|
|
92
|
-
* @returns Decompressed ReadableStream with a dump method that cancels the stream.
|
|
165
|
+
* @ru Создаёт декомпрессированный стрим с поддержкой множественных кодировок.
|
|
166
|
+
* Использует DecompressionStream для Web и node:zlib для Node.js.
|
|
167
|
+
* @en Creates a decompressed stream with support for multiple encodings.
|
|
168
|
+
* Uses DecompressionStream for Web and node:zlib for Node.js.
|
|
169
|
+
* @param body - The compressed ReadableStream.
|
|
170
|
+
* @param encoding - The Content-Encoding header value (e.g., 'gzip, br').
|
|
171
|
+
* @returns The decompressed stream with dump() method attached.
|
|
93
172
|
*/
|
|
94
|
-
export function createDecompressStream(body, encoding) {
|
|
173
|
+
export async function createDecompressStream(body, encoding) {
|
|
95
174
|
const encodings = parseEncodings(encoding);
|
|
96
175
|
if (encodings.length === 0)
|
|
97
176
|
return attachStreamDump(body);
|
|
98
177
|
let current = body;
|
|
99
|
-
let nodeReadableStream = null;
|
|
100
178
|
for (let i = 0; i < encodings.length; i++) {
|
|
101
179
|
const enc = encodings[i];
|
|
102
180
|
const isGzip = enc === "gzip" || enc === "x-gzip";
|
|
103
181
|
const isDeflate = enc === "deflate";
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
current = current.pipeThrough(new DecompressionStream(isGzip ? "gzip" : "deflate"));
|
|
182
|
+
const isBrotli = enc === "br";
|
|
183
|
+
if ((isGzip || isDeflate) && typeof globalThis.DecompressionStream !== "undefined") {
|
|
184
|
+
const format = isGzip ? "gzip" : "deflate";
|
|
185
|
+
current = current.pipeThrough(new globalThis.DecompressionStream(format));
|
|
110
186
|
}
|
|
111
|
-
else {
|
|
112
|
-
|
|
113
|
-
|
|
187
|
+
else if (IS_SERVER) {
|
|
188
|
+
try {
|
|
189
|
+
const { Readable } = await runtimeImport("node:stream");
|
|
190
|
+
const zlib = await runtimeImport("node:zlib");
|
|
191
|
+
const nodeReadableStream = Readable.fromWeb(current);
|
|
192
|
+
let transformer = nodeReadableStream;
|
|
193
|
+
if (isGzip)
|
|
194
|
+
transformer = nodeReadableStream.pipe(zlib.createGunzip());
|
|
195
|
+
else if (isDeflate)
|
|
196
|
+
transformer = nodeReadableStream.pipe(zlib.createInflate());
|
|
197
|
+
else if (isBrotli)
|
|
198
|
+
transformer = nodeReadableStream.pipe(zlib.createBrotliDecompress());
|
|
199
|
+
current = Readable.toWeb(transformer);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
continue;
|
|
114
203
|
}
|
|
115
|
-
if (isGzip)
|
|
116
|
-
nodeReadableStream = nodeReadableStream.pipe(createGunzip());
|
|
117
|
-
else if (isDeflate)
|
|
118
|
-
nodeReadableStream = nodeReadableStream.pipe(createInflate());
|
|
119
|
-
else if (enc === "br")
|
|
120
|
-
nodeReadableStream = nodeReadableStream.pipe(createBrotliDecompress());
|
|
121
204
|
}
|
|
122
205
|
}
|
|
123
|
-
if (nodeReadableStream) {
|
|
124
|
-
current = Readable.toWeb(nodeReadableStream);
|
|
125
|
-
}
|
|
126
206
|
return attachStreamDump(current);
|
|
127
207
|
}
|
|
128
208
|
//# sourceMappingURL=decompress.js.map
|
package/utils/decompress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decompress.js","sourceRoot":"","sources":["../../src/utils/decompress.ts"],"names":[],"mappings":"
|
|
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|
@@ -11,12 +11,6 @@ export declare class HttpClientError extends Error {
|
|
|
11
11
|
/**
|
|
12
12
|
* @ru Создает новый экземпляр HttpClientError.
|
|
13
13
|
* @en Creates a new HttpClientError instance.
|
|
14
|
-
* @param message - Human-readable error message text.
|
|
15
|
-
* @param code - Internal stringified error state identifier code.
|
|
16
|
-
* @param statusCode - Numerical HTTP response status code received from the server.
|
|
17
|
-
* @param originalError - Raw captured exception instance causing this failure.
|
|
18
|
-
* @param url - Targeted request URL destination string.
|
|
19
|
-
* @param method - HTTP method verb utilized for the request.
|
|
20
14
|
*/
|
|
21
15
|
constructor(message: string, code?: string, statusCode?: number | undefined, originalError?: Error | undefined, url?: string | undefined, method?: string | undefined);
|
|
22
16
|
}
|
|
@@ -28,8 +22,6 @@ export declare class TimeoutError extends HttpClientError {
|
|
|
28
22
|
/**
|
|
29
23
|
* @ru Создает новый экземпляр TimeoutError.
|
|
30
24
|
* @en Creates a new TimeoutError instance.
|
|
31
|
-
* @param url - Targeted request URL destination string.
|
|
32
|
-
* @param timeout - Threshold duration statement in milliseconds.
|
|
33
25
|
*/
|
|
34
26
|
constructor(url: string, timeout: number);
|
|
35
27
|
}
|
|
@@ -41,8 +33,6 @@ export declare class RateLimitError extends HttpClientError {
|
|
|
41
33
|
/**
|
|
42
34
|
* @ru Создает новый экземпляр RateLimitError.
|
|
43
35
|
* @en Creates a new RateLimitError instance.
|
|
44
|
-
* @param url - Targeted request URL destination string.
|
|
45
|
-
* @param retryAfter - Optional cool-down period duration in milliseconds before the next retry attempt.
|
|
46
36
|
*/
|
|
47
37
|
constructor(url: string, retryAfter?: number);
|
|
48
38
|
}
|
package/utils/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IAO/B,IAAI,EAAE,MAAM;IACZ,UAAU,CAAC,EAAE,MAAM;IACnB,aAAa,CAAC,EAAE,KAAK;IACrB,GAAG,CAAC,EAAE,MAAM;IACZ,MAAM,CAAC,EAAE,MAAM;IAVxB;;;OAGG;gBAED,OAAO,EAAE,MAAM,EACR,IAAI,GAAE,MAAqB,EAC3B,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,aAAa,CAAC,EAAE,KAAK,YAAA,EACrB,GAAG,CAAC,EAAE,MAAM,YAAA,EACZ,MAAM,CAAC,EAAE,MAAM,YAAA;CAKzB;AAED;;;GAGG;AACH,qBAAa,YAAa,SAAQ,eAAe;IAC/C;;;OAGG;gBACS,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAIzC;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,eAAe;IACjD;;;OAGG;gBACS,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAU7C"}
|
package/utils/errors.js
CHANGED
|
@@ -11,15 +11,9 @@ export class HttpClientError extends Error {
|
|
|
11
11
|
/**
|
|
12
12
|
* @ru Создает новый экземпляр HttpClientError.
|
|
13
13
|
* @en Creates a new HttpClientError instance.
|
|
14
|
-
* @param message - Human-readable error message text.
|
|
15
|
-
* @param code - Internal stringified error state identifier code.
|
|
16
|
-
* @param statusCode - Numerical HTTP response status code received from the server.
|
|
17
|
-
* @param originalError - Raw captured exception instance causing this failure.
|
|
18
|
-
* @param url - Targeted request URL destination string.
|
|
19
|
-
* @param method - HTTP method verb utilized for the request.
|
|
20
14
|
*/
|
|
21
15
|
constructor(message, code = "HTTP_ERROR", statusCode, originalError, url, method) {
|
|
22
|
-
super(message);
|
|
16
|
+
super(message, originalError ? { cause: originalError } : undefined);
|
|
23
17
|
this.code = code;
|
|
24
18
|
this.statusCode = statusCode;
|
|
25
19
|
this.originalError = originalError;
|
|
@@ -36,8 +30,6 @@ export class TimeoutError extends HttpClientError {
|
|
|
36
30
|
/**
|
|
37
31
|
* @ru Создает новый экземпляр TimeoutError.
|
|
38
32
|
* @en Creates a new TimeoutError instance.
|
|
39
|
-
* @param url - Targeted request URL destination string.
|
|
40
|
-
* @param timeout - Threshold duration statement in milliseconds.
|
|
41
33
|
*/
|
|
42
34
|
constructor(url, timeout) {
|
|
43
35
|
super(`Timeout after ${timeout}ms`, "TIMEOUT", 408, undefined, url);
|
|
@@ -52,8 +44,6 @@ export class RateLimitError extends HttpClientError {
|
|
|
52
44
|
/**
|
|
53
45
|
* @ru Создает новый экземпляр RateLimitError.
|
|
54
46
|
* @en Creates a new RateLimitError instance.
|
|
55
|
-
* @param url - Targeted request URL destination string.
|
|
56
|
-
* @param retryAfter - Optional cool-down period duration in milliseconds before the next retry attempt.
|
|
57
47
|
*/
|
|
58
48
|
constructor(url, retryAfter) {
|
|
59
49
|
super(`Rate limited${retryAfter ? ` retry in ${retryAfter}ms` : ""}`, "RATE_LIMIT", 429, undefined, url);
|
package/utils/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAO/B;IACA;IACA;IACA;IACA;IAVT;;;OAGG;IACH,YACE,OAAe,EACR,OAAe,YAAY,EAC3B,UAAmB,EACnB,aAAqB,EACrB,GAAY,EACZ,MAAe;QAEtB,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAN9D,SAAI,GAAJ,IAAI,CAAuB;QAC3B,eAAU,GAAV,UAAU,CAAS;QACnB,kBAAa,GAAb,aAAa,CAAQ;QACrB,QAAG,GAAH,GAAG,CAAS;QACZ,WAAM,GAAN,MAAM,CAAS;QAGtB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,eAAe;IAC/C;;;OAGG;IACH,YAAY,GAAW,EAAE,OAAe;QACtC,KAAK,CAAC,iBAAiB,OAAO,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QACpE,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IACjD;;;OAGG;IACH,YAAY,GAAW,EAAE,UAAmB;QAC1C,KAAK,CACH,eAAe,UAAU,CAAC,CAAC,CAAC,aAAa,UAAU,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,EAC9D,YAAY,EACZ,GAAG,EACH,SAAS,EACT,GAAG,CACJ,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
|
package/utils/merge.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @ru Рекурсивно объединяет два объекта. Избегает лишних аллокаций памяти и защищает от разделения ссылок nested-структур.
|
|
3
3
|
* @en Recursively merges two objects. Avoids redundant memory allocations and prevents shared reference leakage for nested structures.
|
|
4
|
-
* @param target - Foundational target base object layout.
|
|
5
|
-
* @param source - High-priority source object containing overrides.
|
|
6
|
-
* @returns New deeply merged intersection object.
|
|
7
4
|
*/
|
|
8
5
|
export declare function deepMerge<T extends Record<string, unknown>, S extends Record<string, unknown>>(target: T, source: S): T & S;
|
|
9
6
|
//# sourceMappingURL=merge.d.ts.map
|
package/utils/merge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/utils/merge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/utils/merge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5F,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,GACR,CAAC,GAAG,CAAC,CAoBP"}
|
package/utils/merge.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @ru Рекурсивно объединяет два объекта. Избегает лишних аллокаций памяти и защищает от разделения ссылок nested-структур.
|
|
3
3
|
* @en Recursively merges two objects. Avoids redundant memory allocations and prevents shared reference leakage for nested structures.
|
|
4
|
-
* @param target - Foundational target base object layout.
|
|
5
|
-
* @param source - High-priority source object containing overrides.
|
|
6
|
-
* @returns New deeply merged intersection object.
|
|
7
4
|
*/
|
|
8
5
|
export function deepMerge(target, source) {
|
|
9
6
|
const output = { ...target };
|
|
@@ -25,7 +22,6 @@ export function deepMerge(target, source) {
|
|
|
25
22
|
/**
|
|
26
23
|
* @ru Быстрая проверка, является ли переданный элемент чистым объектом (исключая массивы и null).
|
|
27
24
|
* @en Fast check verifying if the provided item is a plain object layout (excluding arrays and null).
|
|
28
|
-
* @param item - Evaluated runtime variable value context.
|
|
29
25
|
*/
|
|
30
26
|
function isObject(item) {
|
|
31
27
|
return Object.prototype.toString.call(item) === "[object Object]";
|
package/utils/merge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/utils/merge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/utils/merge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,MAAS,EACT,MAAS;IAET,MAAM,MAAM,GAA4B,EAAE,GAAG,MAAM,EAAE,CAAC;IACtD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YACnD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CACrB,WAAsC,EACtC,WAAsC,CACvC,CAAC;YACF,SAAS;QACX,CAAC;QAED,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC;gBACjC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,WAAsC,CAAC;gBACvD,CAAC,CAAC,WAAW,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,MAAe,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,SAAS,QAAQ,CAAC,IAAa;IAC7B,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,iBAAiB,CAAC;AACpE,CAAC"}
|
package/utils/normalize.d.ts
CHANGED
|
@@ -1,32 +1,52 @@
|
|
|
1
1
|
import type { Method, RequestBodyData } from "@hyperttp/types";
|
|
2
|
+
type NormalizedHeaders = Record<string, string | string[]>;
|
|
2
3
|
/**
|
|
3
|
-
* @ru Нормализует
|
|
4
|
-
* @en Normalizes
|
|
5
|
-
* @param method -
|
|
6
|
-
* @returns
|
|
4
|
+
* @ru Нормализует HTTP-метод в верхний регистр с кэшированием.
|
|
5
|
+
* @en Normalizes HTTP method to uppercase with caching.
|
|
6
|
+
* @param method - The HTTP method string (e.g., 'get', 'POST').
|
|
7
|
+
* @returns The normalized HTTP method in uppercase.
|
|
7
8
|
*/
|
|
8
9
|
export declare function normalizeMethod(method: string): Method;
|
|
9
10
|
/**
|
|
10
|
-
* @ru Извлекает
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
11
|
+
* @ru Извлекает URL из объекта запроса или строки.
|
|
12
|
+
* Поддерживает различные форматы: строка, объект с полем `url`, `_url`, или `scheme/host/path`.
|
|
13
|
+
* @en Extracts URL from a request object or string.
|
|
14
|
+
* Supports various formats: string, object with `url`, `_url`, or `scheme/host/path` fields.
|
|
15
|
+
* @param req - The request object or URL string.
|
|
16
|
+
* @returns The extracted URL string.
|
|
17
|
+
* @throws Error if URL is missing in the request.
|
|
15
18
|
*/
|
|
16
|
-
export declare function normalizeUrl(req:
|
|
19
|
+
export declare function normalizeUrl(req: unknown): string;
|
|
17
20
|
/**
|
|
18
|
-
* @ru Нормализует
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
21
|
+
* @ru Нормализует заголовки запроса в единый формат с ключами в нижнем регистре.
|
|
22
|
+
* Поддерживает различные входные форматы: объект, массив пар, плоский массив.
|
|
23
|
+
*
|
|
24
|
+
* Специальные правила:
|
|
25
|
+
* - `set-cookie` всегда хранится как массив
|
|
26
|
+
* - `cookie`/`cookie2` объединяются через `; `
|
|
27
|
+
* - Остальные множественные заголовки объединяются через `, `
|
|
28
|
+
* - Заголовки из SINGLE_VALUE_HEADERS перезаписываются (не объединяются)
|
|
29
|
+
*
|
|
30
|
+
* @en Normalizes request headers into a unified format with lowercase keys.
|
|
31
|
+
* Supports various input formats: object, array of pairs, flat array.
|
|
32
|
+
*
|
|
33
|
+
* Special rules:
|
|
34
|
+
* - `set-cookie` is always stored as an array
|
|
35
|
+
* - `cookie`/`cookie2` are joined with `; `
|
|
36
|
+
* - Other multiple headers are joined with `, `
|
|
37
|
+
* - Headers from SINGLE_VALUE_HEADERS are overwritten (not merged)
|
|
38
|
+
*
|
|
39
|
+
* @param headers - The headers to normalize (object, array of pairs, or flat array).
|
|
40
|
+
* @returns Normalized headers object with lowercase keys.
|
|
22
41
|
*/
|
|
23
|
-
export declare function normalizeHeaders(headers: unknown):
|
|
42
|
+
export declare function normalizeHeaders(headers: unknown): NormalizedHeaders;
|
|
24
43
|
/**
|
|
25
|
-
* @ru
|
|
26
|
-
* @en
|
|
27
|
-
* @param method - HTTP method.
|
|
28
|
-
* @param body -
|
|
29
|
-
* @returns The body for
|
|
44
|
+
* @ru Нормализует тело запроса, удаляя его для методов GET и HEAD.
|
|
45
|
+
* @en Normalizes request body by removing it for GET and HEAD methods.
|
|
46
|
+
* @param method - The HTTP method.
|
|
47
|
+
* @param body - The request body data.
|
|
48
|
+
* @returns The body for methods that support it, or undefined for GET/HEAD.
|
|
30
49
|
*/
|
|
31
50
|
export declare function normalizeBody(method: Method, body: RequestBodyData | undefined): RequestBodyData | undefined;
|
|
51
|
+
export {};
|
|
32
52
|
//# sourceMappingURL=normalize.d.ts.map
|
package/utils/normalize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/utils/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE/D,KAAK,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAqH3D;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAwBjD;AAmED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAqDpE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,eAAe,GAAG,SAAS,GAChC,eAAe,GAAG,SAAS,CAE7B"}
|