@npy/fetch 0.1.0 → 0.1.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.
Files changed (98) hide show
  1. package/_internal/consts.cjs +4 -0
  2. package/_internal/consts.js +4 -0
  3. package/_internal/error-adapters.cjs +146 -0
  4. package/_internal/error-adapters.js +142 -0
  5. package/_internal/guards.cjs +24 -0
  6. package/_internal/guards.js +17 -0
  7. package/_internal/net.cjs +95 -0
  8. package/_internal/net.js +92 -0
  9. package/_internal/promises.cjs +18 -0
  10. package/_internal/promises.js +18 -0
  11. package/_internal/streams.cjs +37 -0
  12. package/_internal/streams.js +36 -0
  13. package/_virtual/_rolldown/runtime.cjs +23 -0
  14. package/agent-pool.cjs +78 -0
  15. package/agent-pool.js +77 -0
  16. package/agent.cjs +257 -0
  17. package/agent.js +256 -0
  18. package/body.cjs +154 -0
  19. package/body.js +151 -0
  20. package/dialers/proxy.cjs +49 -0
  21. package/dialers/proxy.js +48 -0
  22. package/dialers/tcp.cjs +70 -0
  23. package/dialers/tcp.js +67 -0
  24. package/encoding.cjs +95 -0
  25. package/encoding.js +91 -0
  26. package/errors.cjs +275 -0
  27. package/errors.js +259 -0
  28. package/fetch.cjs +117 -0
  29. package/fetch.js +115 -0
  30. package/http-client.cjs +33 -0
  31. package/http-client.js +33 -0
  32. package/index.cjs +45 -0
  33. package/index.d.cts +1 -0
  34. package/index.d.ts +1 -0
  35. package/index.js +9 -0
  36. package/io/_utils.cjs +56 -0
  37. package/io/_utils.js +51 -0
  38. package/io/buf-writer.cjs +149 -0
  39. package/io/buf-writer.js +148 -0
  40. package/io/io.cjs +135 -0
  41. package/io/io.js +134 -0
  42. package/io/readers.cjs +377 -0
  43. package/io/readers.js +373 -0
  44. package/io/writers.cjs +191 -0
  45. package/io/writers.js +190 -0
  46. package/package.json +7 -10
  47. package/src/_internal/consts.d.cts +3 -0
  48. package/src/_internal/consts.d.ts +3 -0
  49. package/src/_internal/error-adapters.d.cts +22 -0
  50. package/src/_internal/error-adapters.d.ts +22 -0
  51. package/src/_internal/guards.d.cts +13 -0
  52. package/src/_internal/guards.d.ts +13 -0
  53. package/src/_internal/net.d.cts +12 -0
  54. package/src/_internal/net.d.ts +12 -0
  55. package/src/_internal/promises.d.cts +1 -0
  56. package/src/_internal/promises.d.ts +1 -0
  57. package/src/_internal/streams.d.cts +21 -0
  58. package/src/_internal/streams.d.ts +21 -0
  59. package/src/agent-pool.d.cts +2 -0
  60. package/src/agent-pool.d.ts +2 -0
  61. package/src/agent.d.cts +3 -0
  62. package/src/agent.d.ts +3 -0
  63. package/src/body.d.cts +23 -0
  64. package/src/body.d.ts +23 -0
  65. package/src/dialers/index.d.cts +3 -0
  66. package/src/dialers/index.d.ts +3 -0
  67. package/src/dialers/proxy.d.cts +19 -0
  68. package/src/dialers/proxy.d.ts +19 -0
  69. package/src/dialers/tcp.d.cts +36 -0
  70. package/src/dialers/tcp.d.ts +36 -0
  71. package/src/encoding.d.cts +24 -0
  72. package/src/encoding.d.ts +24 -0
  73. package/src/errors.d.cts +110 -0
  74. package/src/errors.d.ts +110 -0
  75. package/src/fetch.d.cts +36 -0
  76. package/src/fetch.d.ts +36 -0
  77. package/src/http-client.d.cts +23 -0
  78. package/src/http-client.d.ts +23 -0
  79. package/src/index.d.cts +7 -0
  80. package/src/index.d.ts +7 -0
  81. package/src/io/_utils.d.cts +10 -0
  82. package/src/io/_utils.d.ts +10 -0
  83. package/src/io/buf-writer.d.cts +13 -0
  84. package/src/io/buf-writer.d.ts +13 -0
  85. package/src/io/io.d.cts +5 -0
  86. package/src/io/io.d.ts +5 -0
  87. package/src/io/readers.d.cts +199 -0
  88. package/src/io/readers.d.ts +199 -0
  89. package/src/io/writers.d.cts +22 -0
  90. package/src/io/writers.d.ts +22 -0
  91. package/src/types/agent.d.cts +128 -0
  92. package/src/types/agent.d.ts +128 -0
  93. package/src/types/dialer.d.cts +27 -0
  94. package/src/types/dialer.d.ts +27 -0
  95. package/src/types/index.d.cts +2 -0
  96. package/src/types/index.d.ts +2 -0
  97. package/tests/test-utils.d.cts +8 -0
  98. package/tests/test-utils.d.ts +8 -0
package/io/writers.js ADDED
@@ -0,0 +1,190 @@
1
+ import { isReadableStream } from "../_internal/guards.js";
2
+ import { extractBody } from "../body.js";
3
+ import { createEncoders, encodeStream } from "../encoding.js";
4
+ import { bytesToStream } from "../_internal/streams.js";
5
+ import { parseContentLength, parseTransferEncoding } from "./_utils.js";
6
+ import { sanitizeHeaderValue } from "./readers.js";
7
+ import { BufWriter } from "./buf-writer.js";
8
+ import { nodeReadableToWeb } from "@fuman/node";
9
+ import { Bytes, write } from "@fuman/io";
10
+ //#region src/io/writers.ts
11
+ function toRequestTarget(url) {
12
+ return (url.pathname?.startsWith("/") ? url.pathname : "/") + (url.search || "");
13
+ }
14
+ function encodeHead(into, head) {
15
+ write.rawString(into, `${head.method.toUpperCase()} ${head.target} HTTP/1.1\r
16
+ `);
17
+ for (const [k, v] of head.headers) write.rawString(into, `${k}: ${sanitizeHeaderValue(v)}\r
18
+ `);
19
+ write.rawString(into, "\r\n");
20
+ }
21
+ function prepareBody(headers, init) {
22
+ const state = extractBody(init);
23
+ if (state.body != null && !headers.has("content-type")) headers.set("content-type", state.contentType ?? "application/octet-stream");
24
+ const body = state.body;
25
+ if (body == null) return { kind: "none" };
26
+ if (body instanceof Uint8Array) return {
27
+ kind: "bytes",
28
+ bytes: body,
29
+ length: body.byteLength
30
+ };
31
+ if (isReadableStream(body)) return {
32
+ kind: "stream",
33
+ stream: body,
34
+ length: state.contentLength
35
+ };
36
+ return {
37
+ kind: "stream",
38
+ stream: nodeReadableToWeb(body),
39
+ length: state.contentLength
40
+ };
41
+ }
42
+ function finalizeDelimitation(headers, body) {
43
+ if (body.kind === "none") return { chunked: false };
44
+ const te = parseTransferEncoding(headers);
45
+ if (te.has) {
46
+ headers.delete("content-length");
47
+ if (!te.chunked) {
48
+ const tokens = [...te.codings, "chunked"].filter(Boolean);
49
+ headers.set("transfer-encoding", tokens.join(", "));
50
+ }
51
+ return { chunked: true };
52
+ }
53
+ const knownLength = body.kind === "bytes" ? body.length : body.length ?? null;
54
+ if (knownLength != null) {
55
+ const existing = parseContentLength(headers);
56
+ if (existing != null && existing !== knownLength) throw new Error(`Conflicting content-length: header=${existing} body=${knownLength}`);
57
+ if (existing == null) headers.set("content-length", String(knownLength));
58
+ return { chunked: false };
59
+ }
60
+ if (parseContentLength(headers) != null) return { chunked: false };
61
+ headers.set("transfer-encoding", "chunked");
62
+ headers.delete("content-length");
63
+ return { chunked: true };
64
+ }
65
+ function createBufferedConnWriter(dst, opts) {
66
+ const bufferSize = opts.highWaterMark ?? 16 * 1024;
67
+ const directWriteThreshold = opts.directWriteThreshold ?? 64 * 1024;
68
+ const bufWriter = new BufWriter(dst, bufferSize);
69
+ const flush = async () => {
70
+ await bufWriter.flush();
71
+ };
72
+ const writeBytes = async (bytes) => {
73
+ if (bytes.length === 0) return;
74
+ if (bytes.length >= directWriteThreshold) {
75
+ await bufWriter.flush();
76
+ await dst.write(bytes);
77
+ return;
78
+ }
79
+ await bufWriter.write(bytes);
80
+ };
81
+ const writeRawString = async (str) => {
82
+ if (str.length === 0) return;
83
+ write.rawString(bufWriter, str);
84
+ };
85
+ return {
86
+ flush,
87
+ writeBytes,
88
+ writeRawString,
89
+ directWriteThreshold
90
+ };
91
+ }
92
+ async function writeBody(dst, body, chunked, opts, signal) {
93
+ const bw = createBufferedConnWriter(dst, opts);
94
+ const writeChunk = async (chunk) => {
95
+ if (signal?.aborted) throw signal.reason ?? /* @__PURE__ */ new Error("Request aborted");
96
+ if (!chunked) {
97
+ await bw.writeBytes(chunk);
98
+ return;
99
+ }
100
+ if (chunk.length === 0) return;
101
+ await bw.writeRawString(chunk.length.toString(16));
102
+ await bw.writeRawString("\r\n");
103
+ await bw.writeBytes(chunk);
104
+ await bw.writeRawString("\r\n");
105
+ };
106
+ if (body.kind === "bytes") await writeChunk(body.bytes);
107
+ else for await (const chunk of body.stream) await writeChunk(chunk);
108
+ if (chunked) await bw.writeRawString(`0\r
109
+ \r
110
+ `);
111
+ await bw.flush();
112
+ }
113
+ async function writeCoalesced(dst, scratch, head, bodyBytes, chunked) {
114
+ scratch.reset();
115
+ encodeHead(scratch, head);
116
+ if (!chunked) {
117
+ write.bytes(scratch, bodyBytes);
118
+ await dst.write(scratch.result());
119
+ scratch.reset();
120
+ return;
121
+ }
122
+ write.rawString(scratch, bodyBytes.length.toString(16));
123
+ write.rawString(scratch, "\r\n");
124
+ write.bytes(scratch, bodyBytes);
125
+ write.rawString(scratch, `\r
126
+ 0\r
127
+ \r
128
+ `);
129
+ await dst.write(scratch.result());
130
+ scratch.reset();
131
+ }
132
+ function createRequestWriter(dst, opts = {}) {
133
+ const scratch = Bytes.alloc(opts.highWaterMark ?? 16 * 1024);
134
+ const write = async (req) => {
135
+ if (req.signal?.aborted) throw req.signal.reason ?? /* @__PURE__ */ new Error("Request aborted");
136
+ const method = req.method.toUpperCase();
137
+ const headers = req.headers ? new Headers(req.headers) : new Headers();
138
+ const url = req.url;
139
+ if (!headers.has("host")) headers.set("host", url.host);
140
+ if (!headers.has("date")) headers.set("date", (/* @__PURE__ */ new Date()).toUTCString());
141
+ const target = toRequestTarget(url);
142
+ let body = prepareBody(headers, req.body ?? null);
143
+ const ceRaw = headers.get("content-encoding") ?? void 0;
144
+ const ceEncoders = createEncoders(ceRaw);
145
+ if (body.kind !== "none" && ceEncoders.length > 0) {
146
+ body = {
147
+ kind: "stream",
148
+ stream: encodeStream(body.kind === "stream" ? body.stream : bytesToStream(body.bytes), ceRaw),
149
+ length: null
150
+ };
151
+ headers.delete("content-length");
152
+ }
153
+ const teInfo = parseTransferEncoding(headers);
154
+ if (body.kind !== "none" && teInfo.has && teInfo.codings.length > 0) {
155
+ body = {
156
+ kind: "stream",
157
+ stream: encodeStream(body.kind === "stream" ? body.stream : bytesToStream(body.bytes), teInfo.codings),
158
+ length: null
159
+ };
160
+ headers.delete("content-length");
161
+ }
162
+ const { chunked } = finalizeDelimitation(headers, body);
163
+ const head = {
164
+ method,
165
+ target,
166
+ headers
167
+ };
168
+ if (body.kind === "bytes") {
169
+ const max = opts.coalesceBodyMaxBytes ?? 64 * 1024;
170
+ if (body.bytes.length <= max) {
171
+ await writeCoalesced(dst, scratch, head, body.bytes, chunked);
172
+ return;
173
+ }
174
+ }
175
+ scratch.reset();
176
+ encodeHead(scratch, head);
177
+ await dst.write(scratch.result());
178
+ scratch.reset();
179
+ if (body.kind === "none") return;
180
+ if (body.kind === "bytes" && !chunked) {
181
+ if (req.signal?.aborted) throw req.signal.reason ?? /* @__PURE__ */ new Error("Request aborted");
182
+ await dst.write(body.bytes);
183
+ return;
184
+ }
185
+ await writeBody(dst, body, chunked, opts, req.signal);
186
+ };
187
+ return { write };
188
+ }
189
+ //#endregion
190
+ export { createRequestWriter };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@npy/fetch",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "license": "MIT",
6
6
  "scripts": {},
7
7
  "dependencies": {
@@ -9,10 +9,9 @@
9
9
  "@fuman/net": "^0.0.19",
10
10
  "@fuman/node": "^0.0.19",
11
11
  "@fuman/utils": "^0.0.19",
12
- "@npy/proxy-kit": "0.1.0",
12
+ "@npy/proxy-kit": "0.1.1",
13
13
  "bytes": "^3.1.2",
14
- "generic-pool": "^3.9.0",
15
- "mitata": "^1.0.34"
14
+ "generic-pool": "^3.9.0"
16
15
  },
17
16
  "exports": {
18
17
  ".": {
@@ -27,13 +26,11 @@
27
26
  }
28
27
  },
29
28
  "sideEffects": false,
30
- "files": [
31
- "dist",
32
- "LICENSE",
33
- "README.md"
34
- ],
35
29
  "repository": {
36
30
  "type": "git",
37
31
  "url": "git+https://github.com/neeopy/npy.git"
38
- }
32
+ },
33
+ "files": [
34
+ "**/*"
35
+ ]
39
36
  }
@@ -0,0 +1,3 @@
1
+ export declare const CRLF_BYTES: Uint8Array<ArrayBuffer>;
2
+ export declare const CRLF_STR = "\r\n";
3
+ export declare const CRLF_LENGTH = 2;
@@ -0,0 +1,3 @@
1
+ export declare const CRLF_BYTES: Uint8Array<ArrayBuffer>;
2
+ export declare const CRLF_STR = "\r\n";
3
+ export declare const CRLF_LENGTH = 2;
@@ -0,0 +1,22 @@
1
+ import { FetchError, FetchErrorContext } from '../errors';
2
+ export interface ErrorMappingContext extends FetchErrorContext {
3
+ }
4
+ export declare function unknownToError(error: unknown): Error;
5
+ export declare function isAbortLike(error: unknown): boolean;
6
+ export declare function defaultAbortDomException(): DOMException;
7
+ export declare function getRawAbortReason(signal?: AbortSignal): unknown;
8
+ export declare function toAbortCause(signal?: AbortSignal, fallback?: unknown): Error;
9
+ export declare function isTimeoutReason(reason: unknown): boolean;
10
+ export declare function mapAdvancedConnectError(error: unknown, { signal, context, timedOut, }: {
11
+ signal?: AbortSignal;
12
+ context?: ErrorMappingContext;
13
+ timedOut?: boolean;
14
+ }): FetchError;
15
+ export declare function mapAdvancedSendError(error: unknown, { signal, context, phase, }: {
16
+ signal?: AbortSignal;
17
+ context?: ErrorMappingContext;
18
+ phase: "request" | "response" | "body";
19
+ }): FetchError;
20
+ export declare function wrapResponseBodyErrors(response: Response, mapError: (error: unknown) => unknown): Response;
21
+ export declare function toWebFetchError(error: unknown, signal?: AbortSignal): unknown;
22
+ export declare function toWebBodyReadError(error: unknown, signal?: AbortSignal): unknown;
@@ -0,0 +1,22 @@
1
+ import { FetchError, FetchErrorContext } from '../errors';
2
+ export interface ErrorMappingContext extends FetchErrorContext {
3
+ }
4
+ export declare function unknownToError(error: unknown): Error;
5
+ export declare function isAbortLike(error: unknown): boolean;
6
+ export declare function defaultAbortDomException(): DOMException;
7
+ export declare function getRawAbortReason(signal?: AbortSignal): unknown;
8
+ export declare function toAbortCause(signal?: AbortSignal, fallback?: unknown): Error;
9
+ export declare function isTimeoutReason(reason: unknown): boolean;
10
+ export declare function mapAdvancedConnectError(error: unknown, { signal, context, timedOut, }: {
11
+ signal?: AbortSignal;
12
+ context?: ErrorMappingContext;
13
+ timedOut?: boolean;
14
+ }): FetchError;
15
+ export declare function mapAdvancedSendError(error: unknown, { signal, context, phase, }: {
16
+ signal?: AbortSignal;
17
+ context?: ErrorMappingContext;
18
+ phase: "request" | "response" | "body";
19
+ }): FetchError;
20
+ export declare function wrapResponseBodyErrors(response: Response, mapError: (error: unknown) => unknown): Response;
21
+ export declare function toWebFetchError(error: unknown, signal?: AbortSignal): unknown;
22
+ export declare function toWebBodyReadError(error: unknown, signal?: AbortSignal): unknown;
@@ -0,0 +1,13 @@
1
+ import { Readable } from 'node:stream';
2
+ export interface FormDataPolyfill extends Readable {
3
+ getBoundary(): string;
4
+ getLengthSync(): number;
5
+ hasKnownLength(): boolean;
6
+ }
7
+ export declare const isReadable: (object: any) => object is Readable;
8
+ export declare const isIterable: (object: any) => object is AsyncIterable<any> | Iterable<any>;
9
+ export declare const isMultipartFormDataStream: (object: any) => object is FormDataPolyfill;
10
+ export declare const isFormData: (object: any) => object is FormData;
11
+ export declare const isURLSearchParameters: (object: any) => object is URLSearchParams;
12
+ export declare const isReadableStream: (object: any) => object is ReadableStream;
13
+ export declare const isBlob: (object: any) => object is Blob;
@@ -0,0 +1,13 @@
1
+ import { Readable } from 'node:stream';
2
+ export interface FormDataPolyfill extends Readable {
3
+ getBoundary(): string;
4
+ getLengthSync(): number;
5
+ hasKnownLength(): boolean;
6
+ }
7
+ export declare const isReadable: (object: any) => object is Readable;
8
+ export declare const isIterable: (object: any) => object is AsyncIterable<any> | Iterable<any>;
9
+ export declare const isMultipartFormDataStream: (object: any) => object is FormDataPolyfill;
10
+ export declare const isFormData: (object: any) => object is FormData;
11
+ export declare const isURLSearchParameters: (object: any) => object is URLSearchParams;
12
+ export declare const isReadableStream: (object: any) => object is ReadableStream;
13
+ export declare const isBlob: (object: any) => object is Blob;
@@ -0,0 +1,12 @@
1
+ import { ConnectFunction, TcpEndpoint, TlsUpgradeFunction } from '@fuman/net';
2
+ import { NodeTlsConnectOptions, NodeTlsUpgradeOptions, TcpConnection, TlsConnection } from '@fuman/node';
3
+ type WithSignal<T = {}> = T & {
4
+ signal?: AbortSignal;
5
+ };
6
+ export interface AbortError extends Error {
7
+ name: "AbortError";
8
+ }
9
+ export declare const connectTcp: ConnectFunction<WithSignal<TcpEndpoint>, TcpConnection>;
10
+ export declare const connectTls: ConnectFunction<WithSignal<NodeTlsConnectOptions>, TlsConnection>;
11
+ export declare const upgradeTls: TlsUpgradeFunction<WithSignal<NodeTlsUpgradeOptions>, TcpConnection, TlsConnection>;
12
+ export {};
@@ -0,0 +1,12 @@
1
+ import { ConnectFunction, TcpEndpoint, TlsUpgradeFunction } from '@fuman/net';
2
+ import { NodeTlsConnectOptions, NodeTlsUpgradeOptions, TcpConnection, TlsConnection } from '@fuman/node';
3
+ type WithSignal<T = {}> = T & {
4
+ signal?: AbortSignal;
5
+ };
6
+ export interface AbortError extends Error {
7
+ name: "AbortError";
8
+ }
9
+ export declare const connectTcp: ConnectFunction<WithSignal<TcpEndpoint>, TcpConnection>;
10
+ export declare const connectTls: ConnectFunction<WithSignal<NodeTlsConnectOptions>, TlsConnection>;
11
+ export declare const upgradeTls: TlsUpgradeFunction<WithSignal<NodeTlsUpgradeOptions>, TcpConnection, TlsConnection>;
12
+ export {};
@@ -0,0 +1 @@
1
+ export declare function raceSignal<T>(promise: PromiseLike<T>, signal: AbortSignal): Promise<T>;
@@ -0,0 +1 @@
1
+ export declare function raceSignal<T>(promise: PromiseLike<T>, signal: AbortSignal): Promise<T>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Create a ReadableStream from a Uint8Array.
3
+ *
4
+ * The stream will emit the entire byte array as a single chunk,
5
+ * then close immediately.
6
+ *
7
+ * @param bytes - The byte array to wrap.
8
+ * @returns A ReadableStream that emits the bytes.
9
+ */
10
+ export declare function bytesToStream(bytes: Uint8Array): ReadableStream<Uint8Array<ArrayBufferLike>>;
11
+ /**
12
+ * A TransformStream that limits the total number of bytes passed through.
13
+ *
14
+ * It accumulates the byte count from incoming chunks and enqueues them
15
+ * if the total remains within the limit; otherwise, it errors.
16
+ *
17
+ * @param maxBytes - The maximum allowed bytes before erroring.
18
+ */
19
+ export declare class MaxBytesTransformStream extends TransformStream<Uint8Array, Uint8Array> {
20
+ constructor(maxBytes: number);
21
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Create a ReadableStream from a Uint8Array.
3
+ *
4
+ * The stream will emit the entire byte array as a single chunk,
5
+ * then close immediately.
6
+ *
7
+ * @param bytes - The byte array to wrap.
8
+ * @returns A ReadableStream that emits the bytes.
9
+ */
10
+ export declare function bytesToStream(bytes: Uint8Array): ReadableStream<Uint8Array<ArrayBufferLike>>;
11
+ /**
12
+ * A TransformStream that limits the total number of bytes passed through.
13
+ *
14
+ * It accumulates the byte count from incoming chunks and enqueues them
15
+ * if the total remains within the limit; otherwise, it errors.
16
+ *
17
+ * @param maxBytes - The maximum allowed bytes before erroring.
18
+ */
19
+ export declare class MaxBytesTransformStream extends TransformStream<Uint8Array, Uint8Array> {
20
+ constructor(maxBytes: number);
21
+ }
@@ -0,0 +1,2 @@
1
+ import { AgentPool, AgentPoolOptions } from './types/agent';
2
+ export declare function createAgentPool(baseUrl: string, options?: AgentPoolOptions): AgentPool;
@@ -0,0 +1,2 @@
1
+ import { AgentPool, AgentPoolOptions } from './types/agent';
2
+ export declare function createAgentPool(baseUrl: string, options?: AgentPoolOptions): AgentPool;
@@ -0,0 +1,3 @@
1
+ import { Agent } from './types/agent';
2
+ import { Dialer } from './types/dialer';
3
+ export declare function createAgent(dialer: Dialer, baseUrl: string, options?: Agent.Options): Agent;
package/src/agent.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Agent } from './types/agent';
2
+ import { Dialer } from './types/dialer';
3
+ export declare function createAgent(dialer: Dialer, baseUrl: string, options?: Agent.Options): Agent;
package/src/body.d.cts ADDED
@@ -0,0 +1,23 @@
1
+ import { Readable } from 'node:stream';
2
+ import { FormDataPolyfill } from './_internal/guards';
3
+ export type BodyInit = Exclude<RequestInit["body"], undefined | null> | FormDataPolyfill | Readable;
4
+ export interface BodyState {
5
+ contentLength: number | null;
6
+ contentType: string | null;
7
+ body: Readable | ReadableStream | Uint8Array | null;
8
+ }
9
+ export declare const getFormDataLength: (form: FormData, boundary: string) => number;
10
+ export declare const extractBody: (object: BodyInit | null) => BodyState;
11
+ declare const kBodyInternals: unique symbol;
12
+ export declare class Body {
13
+ private [kBodyInternals];
14
+ constructor(init: BodyInit | null);
15
+ get body(): Uint8Array<ArrayBufferLike> | Readable | ReadableStream<any> | null;
16
+ get bodyUsed(): boolean;
17
+ arrayBuffer(): Promise<ArrayBuffer>;
18
+ formData(): Promise<FormData>;
19
+ blob(): Promise<Blob>;
20
+ json(): Promise<any>;
21
+ text(): Promise<string>;
22
+ }
23
+ export {};
package/src/body.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { Readable } from 'node:stream';
2
+ import { FormDataPolyfill } from './_internal/guards';
3
+ export type BodyInit = Exclude<RequestInit["body"], undefined | null> | FormDataPolyfill | Readable;
4
+ export interface BodyState {
5
+ contentLength: number | null;
6
+ contentType: string | null;
7
+ body: Readable | ReadableStream | Uint8Array | null;
8
+ }
9
+ export declare const getFormDataLength: (form: FormData, boundary: string) => number;
10
+ export declare const extractBody: (object: BodyInit | null) => BodyState;
11
+ declare const kBodyInternals: unique symbol;
12
+ export declare class Body {
13
+ private [kBodyInternals];
14
+ constructor(init: BodyInit | null);
15
+ get body(): Uint8Array<ArrayBufferLike> | Readable | ReadableStream<any> | null;
16
+ get bodyUsed(): boolean;
17
+ arrayBuffer(): Promise<ArrayBuffer>;
18
+ formData(): Promise<FormData>;
19
+ blob(): Promise<Blob>;
20
+ json(): Promise<any>;
21
+ text(): Promise<string>;
22
+ }
23
+ export {};
@@ -0,0 +1,3 @@
1
+ export type { ConnectionLike, Dialer, DialTarget } from '../types/dialer';
2
+ export * from './proxy';
3
+ export * from './tcp';
@@ -0,0 +1,3 @@
1
+ export type { ConnectionLike, Dialer, DialTarget } from '../types/dialer';
2
+ export * from './proxy';
3
+ export * from './tcp';
@@ -0,0 +1,19 @@
1
+ import { NodeTlsUpgradeOptions } from '@fuman/node';
2
+ import { createProxyConnection, ProxyInfo } from '@npy/proxy-kit';
3
+ import { Dialer } from '../types/dialer';
4
+ export declare class ProxyDialer implements Dialer {
5
+ #private;
6
+ readonly proxy: ProxyDialer.Proxy;
7
+ constructor(proxy: ProxyDialer.Input, options?: ProxyDialer.Options);
8
+ dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
9
+ }
10
+ export declare namespace ProxyDialer {
11
+ type Proxy = Parameters<typeof createProxyConnection>[0]["proxy"];
12
+ type Input = string | Proxy | ProxyInfo;
13
+ interface Options {
14
+ caCerts?: string[];
15
+ sni?: string;
16
+ alpnProtocols?: string[];
17
+ extraOptions?: NodeTlsUpgradeOptions["extraOptions"];
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import { NodeTlsUpgradeOptions } from '@fuman/node';
2
+ import { createProxyConnection, ProxyInfo } from '@npy/proxy-kit';
3
+ import { Dialer } from '../types/dialer';
4
+ export declare class ProxyDialer implements Dialer {
5
+ #private;
6
+ readonly proxy: ProxyDialer.Proxy;
7
+ constructor(proxy: ProxyDialer.Input, options?: ProxyDialer.Options);
8
+ dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
9
+ }
10
+ export declare namespace ProxyDialer {
11
+ type Proxy = Parameters<typeof createProxyConnection>[0]["proxy"];
12
+ type Input = string | Proxy | ProxyInfo;
13
+ interface Options {
14
+ caCerts?: string[];
15
+ sni?: string;
16
+ alpnProtocols?: string[];
17
+ extraOptions?: NodeTlsUpgradeOptions["extraOptions"];
18
+ }
19
+ }
@@ -0,0 +1,36 @@
1
+ import { NodeTlsConnectOptions } from '@fuman/node';
2
+ import { Dialer } from '../types/dialer';
3
+ type HostPort = {
4
+ address: string;
5
+ port: number;
6
+ };
7
+ export declare function resolveHostPort(target: URL | Dialer.Target, defaultPort: number): HostPort;
8
+ export declare class TcpDialer implements Dialer {
9
+ dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
10
+ }
11
+ export declare class TlsDialer implements Dialer {
12
+ #private;
13
+ constructor(options?: TlsDialer.Options);
14
+ dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
15
+ }
16
+ export declare namespace TlsDialer {
17
+ interface Options {
18
+ caCerts?: string[];
19
+ sni?: string;
20
+ alpnProtocols?: string[];
21
+ extraOptions?: NodeTlsConnectOptions["extraOptions"];
22
+ }
23
+ }
24
+ export declare class AutoDialer implements Dialer {
25
+ readonly tcpDialer: TcpDialer;
26
+ readonly tlsDialer: TlsDialer;
27
+ constructor(options?: AutoDialer.Options);
28
+ dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
29
+ }
30
+ export declare namespace AutoDialer {
31
+ interface Options {
32
+ tcp?: TcpDialer;
33
+ tls?: TlsDialer;
34
+ }
35
+ }
36
+ export {};
@@ -0,0 +1,36 @@
1
+ import { NodeTlsConnectOptions } from '@fuman/node';
2
+ import { Dialer } from '../types/dialer';
3
+ type HostPort = {
4
+ address: string;
5
+ port: number;
6
+ };
7
+ export declare function resolveHostPort(target: URL | Dialer.Target, defaultPort: number): HostPort;
8
+ export declare class TcpDialer implements Dialer {
9
+ dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
10
+ }
11
+ export declare class TlsDialer implements Dialer {
12
+ #private;
13
+ constructor(options?: TlsDialer.Options);
14
+ dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
15
+ }
16
+ export declare namespace TlsDialer {
17
+ interface Options {
18
+ caCerts?: string[];
19
+ sni?: string;
20
+ alpnProtocols?: string[];
21
+ extraOptions?: NodeTlsConnectOptions["extraOptions"];
22
+ }
23
+ }
24
+ export declare class AutoDialer implements Dialer {
25
+ readonly tcpDialer: TcpDialer;
26
+ readonly tlsDialer: TlsDialer;
27
+ constructor(options?: AutoDialer.Options);
28
+ dial(target: Dialer.Target, options?: Dialer.Options): Promise<Dialer.ConnectionLike>;
29
+ }
30
+ export declare namespace AutoDialer {
31
+ interface Options {
32
+ tcp?: TcpDialer;
33
+ tls?: TlsDialer;
34
+ }
35
+ }
36
+ export {};
@@ -0,0 +1,24 @@
1
+ type ByteStream = ReadableStream<Uint8Array>;
2
+ type ByteTransform = TransformStream<Uint8Array, Uint8Array>;
3
+ export declare function decodeStream(stream: ByteStream, contentEncoding?: string | string[]): ByteStream;
4
+ export declare function decodeStream(stream: AsyncIterable<Uint8Array>, contentEncoding?: string | string[]): AsyncIterable<Uint8Array> | ByteStream;
5
+ export declare function encodeStream(stream: ByteStream, contentEncoding?: string | string[]): ByteStream;
6
+ export declare function encodeStream(stream: AsyncIterable<Uint8Array>, contentEncoding?: string | string[]): AsyncIterable<Uint8Array> | ByteStream;
7
+ /**
8
+ * Create a series of decoding streams based on the content-encoding header. The
9
+ * resulting streams should be piped together to decode the content.
10
+ *
11
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}
12
+ */
13
+ export declare function createDecoders(contentEncoding?: string | string[]): ByteTransform[];
14
+ /**
15
+ * Create a series of encoding streams based on the content-encoding header (or
16
+ * transfer-coding list).
17
+ *
18
+ * The resulting streams should be piped together to apply the encoding in the
19
+ * declared order.
20
+ *
21
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}
22
+ */
23
+ export declare function createEncoders(contentEncoding?: string | string[]): ByteTransform[];
24
+ export {};
@@ -0,0 +1,24 @@
1
+ type ByteStream = ReadableStream<Uint8Array>;
2
+ type ByteTransform = TransformStream<Uint8Array, Uint8Array>;
3
+ export declare function decodeStream(stream: ByteStream, contentEncoding?: string | string[]): ByteStream;
4
+ export declare function decodeStream(stream: AsyncIterable<Uint8Array>, contentEncoding?: string | string[]): AsyncIterable<Uint8Array> | ByteStream;
5
+ export declare function encodeStream(stream: ByteStream, contentEncoding?: string | string[]): ByteStream;
6
+ export declare function encodeStream(stream: AsyncIterable<Uint8Array>, contentEncoding?: string | string[]): AsyncIterable<Uint8Array> | ByteStream;
7
+ /**
8
+ * Create a series of decoding streams based on the content-encoding header. The
9
+ * resulting streams should be piped together to decode the content.
10
+ *
11
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}
12
+ */
13
+ export declare function createDecoders(contentEncoding?: string | string[]): ByteTransform[];
14
+ /**
15
+ * Create a series of encoding streams based on the content-encoding header (or
16
+ * transfer-coding list).
17
+ *
18
+ * The resulting streams should be piped together to apply the encoding in the
19
+ * declared order.
20
+ *
21
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc9110#section-8.4.1}
22
+ */
23
+ export declare function createEncoders(contentEncoding?: string | string[]): ByteTransform[];
24
+ export {};