@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.
- package/_internal/consts.cjs +4 -0
- package/_internal/consts.js +4 -0
- package/_internal/error-adapters.cjs +146 -0
- package/_internal/error-adapters.js +142 -0
- package/_internal/guards.cjs +24 -0
- package/_internal/guards.js +17 -0
- package/_internal/net.cjs +95 -0
- package/_internal/net.js +92 -0
- package/_internal/promises.cjs +18 -0
- package/_internal/promises.js +18 -0
- package/_internal/streams.cjs +37 -0
- package/_internal/streams.js +36 -0
- package/_virtual/_rolldown/runtime.cjs +23 -0
- package/agent-pool.cjs +78 -0
- package/agent-pool.js +77 -0
- package/agent.cjs +257 -0
- package/agent.js +256 -0
- package/body.cjs +154 -0
- package/body.js +151 -0
- package/dialers/proxy.cjs +49 -0
- package/dialers/proxy.js +48 -0
- package/dialers/tcp.cjs +70 -0
- package/dialers/tcp.js +67 -0
- package/encoding.cjs +95 -0
- package/encoding.js +91 -0
- package/errors.cjs +275 -0
- package/errors.js +259 -0
- package/fetch.cjs +117 -0
- package/fetch.js +115 -0
- package/http-client.cjs +33 -0
- package/http-client.js +33 -0
- package/index.cjs +45 -0
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +9 -0
- package/io/_utils.cjs +56 -0
- package/io/_utils.js +51 -0
- package/io/buf-writer.cjs +149 -0
- package/io/buf-writer.js +148 -0
- package/io/io.cjs +135 -0
- package/io/io.js +134 -0
- package/io/readers.cjs +377 -0
- package/io/readers.js +373 -0
- package/io/writers.cjs +191 -0
- package/io/writers.js +190 -0
- package/package.json +7 -10
- package/src/_internal/consts.d.cts +3 -0
- package/src/_internal/consts.d.ts +3 -0
- package/src/_internal/error-adapters.d.cts +22 -0
- package/src/_internal/error-adapters.d.ts +22 -0
- package/src/_internal/guards.d.cts +13 -0
- package/src/_internal/guards.d.ts +13 -0
- package/src/_internal/net.d.cts +12 -0
- package/src/_internal/net.d.ts +12 -0
- package/src/_internal/promises.d.cts +1 -0
- package/src/_internal/promises.d.ts +1 -0
- package/src/_internal/streams.d.cts +21 -0
- package/src/_internal/streams.d.ts +21 -0
- package/src/agent-pool.d.cts +2 -0
- package/src/agent-pool.d.ts +2 -0
- package/src/agent.d.cts +3 -0
- package/src/agent.d.ts +3 -0
- package/src/body.d.cts +23 -0
- package/src/body.d.ts +23 -0
- package/src/dialers/index.d.cts +3 -0
- package/src/dialers/index.d.ts +3 -0
- package/src/dialers/proxy.d.cts +19 -0
- package/src/dialers/proxy.d.ts +19 -0
- package/src/dialers/tcp.d.cts +36 -0
- package/src/dialers/tcp.d.ts +36 -0
- package/src/encoding.d.cts +24 -0
- package/src/encoding.d.ts +24 -0
- package/src/errors.d.cts +110 -0
- package/src/errors.d.ts +110 -0
- package/src/fetch.d.cts +36 -0
- package/src/fetch.d.ts +36 -0
- package/src/http-client.d.cts +23 -0
- package/src/http-client.d.ts +23 -0
- package/src/index.d.cts +7 -0
- package/src/index.d.ts +7 -0
- package/src/io/_utils.d.cts +10 -0
- package/src/io/_utils.d.ts +10 -0
- package/src/io/buf-writer.d.cts +13 -0
- package/src/io/buf-writer.d.ts +13 -0
- package/src/io/io.d.cts +5 -0
- package/src/io/io.d.ts +5 -0
- package/src/io/readers.d.cts +199 -0
- package/src/io/readers.d.ts +199 -0
- package/src/io/writers.d.cts +22 -0
- package/src/io/writers.d.ts +22 -0
- package/src/types/agent.d.cts +128 -0
- package/src/types/agent.d.ts +128 -0
- package/src/types/dialer.d.cts +27 -0
- package/src/types/dialer.d.ts +27 -0
- package/src/types/index.d.cts +2 -0
- package/src/types/index.d.ts +2 -0
- package/tests/test-utils.d.cts +8 -0
- package/tests/test-utils.d.ts +8 -0
package/src/errors.d.cts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export declare const ErrorType: {
|
|
2
|
+
readonly ABORTED: "ABORTED";
|
|
3
|
+
readonly NETWORK: "NETWORK";
|
|
4
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
5
|
+
readonly HTTP_CLIENT_ERROR: "HTTP_CLIENT_ERROR";
|
|
6
|
+
readonly HTTP_SERVER_ERROR: "HTTP_SERVER_ERROR";
|
|
7
|
+
};
|
|
8
|
+
export type ErrorType = (typeof ErrorType)[keyof typeof ErrorType];
|
|
9
|
+
export declare const FetchErrorCode: {
|
|
10
|
+
readonly ABORTED: "ERR_FETCH_ABORTED";
|
|
11
|
+
readonly TIMEOUT: "ERR_FETCH_TIMEOUT";
|
|
12
|
+
readonly CONNECTION: "ERR_FETCH_CONNECTION";
|
|
13
|
+
readonly AGENT_CLOSED: "ERR_FETCH_AGENT_CLOSED";
|
|
14
|
+
readonly AGENT_BUSY: "ERR_FETCH_AGENT_BUSY";
|
|
15
|
+
readonly ORIGIN_MISMATCH: "ERR_FETCH_ORIGIN_MISMATCH";
|
|
16
|
+
readonly UNSUPPORTED_PROTOCOL: "ERR_FETCH_UNSUPPORTED_PROTOCOL";
|
|
17
|
+
readonly UNSUPPORTED_METHOD: "ERR_FETCH_UNSUPPORTED_METHOD";
|
|
18
|
+
readonly TLS_ALPN: "ERR_FETCH_TLS_ALPN";
|
|
19
|
+
readonly REQUEST_WRITE: "ERR_FETCH_REQUEST_WRITE";
|
|
20
|
+
readonly RESPONSE_HEADERS: "ERR_FETCH_RESPONSE_HEADERS";
|
|
21
|
+
readonly RESPONSE_BODY: "ERR_FETCH_RESPONSE_BODY";
|
|
22
|
+
readonly RESPONSE_DECODE: "ERR_FETCH_RESPONSE_DECODE";
|
|
23
|
+
readonly HTTP_STATUS: "ERR_FETCH_HTTP_STATUS";
|
|
24
|
+
};
|
|
25
|
+
export type FetchErrorCode = (typeof FetchErrorCode)[keyof typeof FetchErrorCode];
|
|
26
|
+
export type FetchErrorPhase = "agent" | "connect" | "request" | "response" | "body" | "decode" | "policy";
|
|
27
|
+
export interface FetchErrorContext {
|
|
28
|
+
url?: string;
|
|
29
|
+
method?: string;
|
|
30
|
+
origin?: string;
|
|
31
|
+
scheme?: string;
|
|
32
|
+
host?: string;
|
|
33
|
+
port?: number;
|
|
34
|
+
status?: number;
|
|
35
|
+
alpn?: string | null;
|
|
36
|
+
details?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export interface FetchErrorOptions {
|
|
39
|
+
message: string;
|
|
40
|
+
code: FetchErrorCode;
|
|
41
|
+
phase: FetchErrorPhase;
|
|
42
|
+
cause?: unknown;
|
|
43
|
+
context?: FetchErrorContext;
|
|
44
|
+
retryable?: boolean;
|
|
45
|
+
type?: ErrorType;
|
|
46
|
+
}
|
|
47
|
+
export declare class FetchError extends Error {
|
|
48
|
+
readonly code: FetchErrorCode;
|
|
49
|
+
readonly phase: FetchErrorPhase;
|
|
50
|
+
readonly context?: FetchErrorContext;
|
|
51
|
+
readonly retryable: boolean;
|
|
52
|
+
readonly type?: ErrorType;
|
|
53
|
+
readonly cause: unknown;
|
|
54
|
+
constructor(options: FetchErrorOptions);
|
|
55
|
+
get name(): string;
|
|
56
|
+
get [Symbol.toStringTag](): string;
|
|
57
|
+
toJSON(): {
|
|
58
|
+
name: string;
|
|
59
|
+
message: string;
|
|
60
|
+
code: FetchErrorCode;
|
|
61
|
+
phase: FetchErrorPhase;
|
|
62
|
+
retryable: boolean;
|
|
63
|
+
type: ErrorType | undefined;
|
|
64
|
+
context: FetchErrorContext | undefined;
|
|
65
|
+
cause: unknown;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export declare class RequestAbortedError extends FetchError {
|
|
69
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
70
|
+
}
|
|
71
|
+
export declare class ConnectTimeoutError extends FetchError {
|
|
72
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
73
|
+
}
|
|
74
|
+
export declare class ConnectionError extends FetchError {
|
|
75
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
76
|
+
}
|
|
77
|
+
export declare class AgentClosedError extends FetchError {
|
|
78
|
+
constructor(context?: FetchErrorContext, cause?: unknown);
|
|
79
|
+
}
|
|
80
|
+
export declare class AgentBusyError extends FetchError {
|
|
81
|
+
constructor(context?: FetchErrorContext, cause?: unknown);
|
|
82
|
+
}
|
|
83
|
+
export declare class OriginMismatchError extends FetchError {
|
|
84
|
+
constructor(expectedOrigin: string, actualOrigin: string, context?: FetchErrorContext);
|
|
85
|
+
}
|
|
86
|
+
export declare class UnsupportedProtocolError extends FetchError {
|
|
87
|
+
constructor(protocol: string, context?: FetchErrorContext);
|
|
88
|
+
}
|
|
89
|
+
export declare class UnsupportedMethodError extends FetchError {
|
|
90
|
+
constructor(method: string, context?: FetchErrorContext);
|
|
91
|
+
}
|
|
92
|
+
export declare class UnsupportedAlpnProtocolError extends FetchError {
|
|
93
|
+
constructor(alpn: string, context?: FetchErrorContext, cause?: unknown);
|
|
94
|
+
}
|
|
95
|
+
export declare class RequestWriteError extends FetchError {
|
|
96
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
97
|
+
}
|
|
98
|
+
export declare class ResponseHeaderError extends FetchError {
|
|
99
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
100
|
+
}
|
|
101
|
+
export declare class ResponseBodyError extends FetchError {
|
|
102
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
103
|
+
}
|
|
104
|
+
export declare class ResponseDecodeError extends FetchError {
|
|
105
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
106
|
+
}
|
|
107
|
+
export declare class HttpStatusError extends FetchError {
|
|
108
|
+
readonly statusCode: number;
|
|
109
|
+
constructor(statusCode: number, context?: FetchErrorContext, cause?: unknown, message?: string);
|
|
110
|
+
}
|
package/src/errors.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export declare const ErrorType: {
|
|
2
|
+
readonly ABORTED: "ABORTED";
|
|
3
|
+
readonly NETWORK: "NETWORK";
|
|
4
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
5
|
+
readonly HTTP_CLIENT_ERROR: "HTTP_CLIENT_ERROR";
|
|
6
|
+
readonly HTTP_SERVER_ERROR: "HTTP_SERVER_ERROR";
|
|
7
|
+
};
|
|
8
|
+
export type ErrorType = (typeof ErrorType)[keyof typeof ErrorType];
|
|
9
|
+
export declare const FetchErrorCode: {
|
|
10
|
+
readonly ABORTED: "ERR_FETCH_ABORTED";
|
|
11
|
+
readonly TIMEOUT: "ERR_FETCH_TIMEOUT";
|
|
12
|
+
readonly CONNECTION: "ERR_FETCH_CONNECTION";
|
|
13
|
+
readonly AGENT_CLOSED: "ERR_FETCH_AGENT_CLOSED";
|
|
14
|
+
readonly AGENT_BUSY: "ERR_FETCH_AGENT_BUSY";
|
|
15
|
+
readonly ORIGIN_MISMATCH: "ERR_FETCH_ORIGIN_MISMATCH";
|
|
16
|
+
readonly UNSUPPORTED_PROTOCOL: "ERR_FETCH_UNSUPPORTED_PROTOCOL";
|
|
17
|
+
readonly UNSUPPORTED_METHOD: "ERR_FETCH_UNSUPPORTED_METHOD";
|
|
18
|
+
readonly TLS_ALPN: "ERR_FETCH_TLS_ALPN";
|
|
19
|
+
readonly REQUEST_WRITE: "ERR_FETCH_REQUEST_WRITE";
|
|
20
|
+
readonly RESPONSE_HEADERS: "ERR_FETCH_RESPONSE_HEADERS";
|
|
21
|
+
readonly RESPONSE_BODY: "ERR_FETCH_RESPONSE_BODY";
|
|
22
|
+
readonly RESPONSE_DECODE: "ERR_FETCH_RESPONSE_DECODE";
|
|
23
|
+
readonly HTTP_STATUS: "ERR_FETCH_HTTP_STATUS";
|
|
24
|
+
};
|
|
25
|
+
export type FetchErrorCode = (typeof FetchErrorCode)[keyof typeof FetchErrorCode];
|
|
26
|
+
export type FetchErrorPhase = "agent" | "connect" | "request" | "response" | "body" | "decode" | "policy";
|
|
27
|
+
export interface FetchErrorContext {
|
|
28
|
+
url?: string;
|
|
29
|
+
method?: string;
|
|
30
|
+
origin?: string;
|
|
31
|
+
scheme?: string;
|
|
32
|
+
host?: string;
|
|
33
|
+
port?: number;
|
|
34
|
+
status?: number;
|
|
35
|
+
alpn?: string | null;
|
|
36
|
+
details?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export interface FetchErrorOptions {
|
|
39
|
+
message: string;
|
|
40
|
+
code: FetchErrorCode;
|
|
41
|
+
phase: FetchErrorPhase;
|
|
42
|
+
cause?: unknown;
|
|
43
|
+
context?: FetchErrorContext;
|
|
44
|
+
retryable?: boolean;
|
|
45
|
+
type?: ErrorType;
|
|
46
|
+
}
|
|
47
|
+
export declare class FetchError extends Error {
|
|
48
|
+
readonly code: FetchErrorCode;
|
|
49
|
+
readonly phase: FetchErrorPhase;
|
|
50
|
+
readonly context?: FetchErrorContext;
|
|
51
|
+
readonly retryable: boolean;
|
|
52
|
+
readonly type?: ErrorType;
|
|
53
|
+
readonly cause: unknown;
|
|
54
|
+
constructor(options: FetchErrorOptions);
|
|
55
|
+
get name(): string;
|
|
56
|
+
get [Symbol.toStringTag](): string;
|
|
57
|
+
toJSON(): {
|
|
58
|
+
name: string;
|
|
59
|
+
message: string;
|
|
60
|
+
code: FetchErrorCode;
|
|
61
|
+
phase: FetchErrorPhase;
|
|
62
|
+
retryable: boolean;
|
|
63
|
+
type: ErrorType | undefined;
|
|
64
|
+
context: FetchErrorContext | undefined;
|
|
65
|
+
cause: unknown;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export declare class RequestAbortedError extends FetchError {
|
|
69
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
70
|
+
}
|
|
71
|
+
export declare class ConnectTimeoutError extends FetchError {
|
|
72
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
73
|
+
}
|
|
74
|
+
export declare class ConnectionError extends FetchError {
|
|
75
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
76
|
+
}
|
|
77
|
+
export declare class AgentClosedError extends FetchError {
|
|
78
|
+
constructor(context?: FetchErrorContext, cause?: unknown);
|
|
79
|
+
}
|
|
80
|
+
export declare class AgentBusyError extends FetchError {
|
|
81
|
+
constructor(context?: FetchErrorContext, cause?: unknown);
|
|
82
|
+
}
|
|
83
|
+
export declare class OriginMismatchError extends FetchError {
|
|
84
|
+
constructor(expectedOrigin: string, actualOrigin: string, context?: FetchErrorContext);
|
|
85
|
+
}
|
|
86
|
+
export declare class UnsupportedProtocolError extends FetchError {
|
|
87
|
+
constructor(protocol: string, context?: FetchErrorContext);
|
|
88
|
+
}
|
|
89
|
+
export declare class UnsupportedMethodError extends FetchError {
|
|
90
|
+
constructor(method: string, context?: FetchErrorContext);
|
|
91
|
+
}
|
|
92
|
+
export declare class UnsupportedAlpnProtocolError extends FetchError {
|
|
93
|
+
constructor(alpn: string, context?: FetchErrorContext, cause?: unknown);
|
|
94
|
+
}
|
|
95
|
+
export declare class RequestWriteError extends FetchError {
|
|
96
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
97
|
+
}
|
|
98
|
+
export declare class ResponseHeaderError extends FetchError {
|
|
99
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
100
|
+
}
|
|
101
|
+
export declare class ResponseBodyError extends FetchError {
|
|
102
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
103
|
+
}
|
|
104
|
+
export declare class ResponseDecodeError extends FetchError {
|
|
105
|
+
constructor(cause?: unknown, context?: FetchErrorContext, message?: string);
|
|
106
|
+
}
|
|
107
|
+
export declare class HttpStatusError extends FetchError {
|
|
108
|
+
readonly statusCode: number;
|
|
109
|
+
constructor(statusCode: number, context?: FetchErrorContext, cause?: unknown, message?: string);
|
|
110
|
+
}
|
package/src/fetch.d.cts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BodyInit as FetchBodyInit } from './body';
|
|
2
|
+
import { HttpClientOptions, HttpClient } from './http-client';
|
|
3
|
+
export interface RequestInit extends Omit<globalThis.RequestInit, "body" | "headers"> {
|
|
4
|
+
body?: FetchBodyInit | null;
|
|
5
|
+
headers?: HeadersInit;
|
|
6
|
+
/**
|
|
7
|
+
* Optional client override for this call.
|
|
8
|
+
*
|
|
9
|
+
* Reader/Writer I/O options are configured at the client/pool level, not
|
|
10
|
+
* per request.
|
|
11
|
+
*/
|
|
12
|
+
client?: HttpClient;
|
|
13
|
+
}
|
|
14
|
+
/** Clearer export for consumers that want to avoid shadowing the global name. */
|
|
15
|
+
export interface FetchRequestInit extends RequestInit {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options used only for constructing the default internal `HttpClient`.
|
|
19
|
+
*
|
|
20
|
+
* These are high-level client/pool/socket/I-O options; low-level Readers/Writers
|
|
21
|
+
* are not configured per request through this fetch-like API.
|
|
22
|
+
*/
|
|
23
|
+
export interface FetchOptions extends HttpClientOptions {
|
|
24
|
+
}
|
|
25
|
+
export interface FetchLike {
|
|
26
|
+
(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
29
|
+
readonly client: HttpClient;
|
|
30
|
+
}
|
|
31
|
+
export declare function normalizeHeaders(headers?: HeadersInit): Headers;
|
|
32
|
+
export declare function createFetch(client?: HttpClient): FetchLike;
|
|
33
|
+
export type { HttpClientOptions };
|
|
34
|
+
export { HttpClient };
|
|
35
|
+
export declare const fetch: FetchLike;
|
|
36
|
+
export default fetch;
|
package/src/fetch.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BodyInit as FetchBodyInit } from './body';
|
|
2
|
+
import { HttpClientOptions, HttpClient } from './http-client';
|
|
3
|
+
export interface RequestInit extends Omit<globalThis.RequestInit, "body" | "headers"> {
|
|
4
|
+
body?: FetchBodyInit | null;
|
|
5
|
+
headers?: HeadersInit;
|
|
6
|
+
/**
|
|
7
|
+
* Optional client override for this call.
|
|
8
|
+
*
|
|
9
|
+
* Reader/Writer I/O options are configured at the client/pool level, not
|
|
10
|
+
* per request.
|
|
11
|
+
*/
|
|
12
|
+
client?: HttpClient;
|
|
13
|
+
}
|
|
14
|
+
/** Clearer export for consumers that want to avoid shadowing the global name. */
|
|
15
|
+
export interface FetchRequestInit extends RequestInit {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Options used only for constructing the default internal `HttpClient`.
|
|
19
|
+
*
|
|
20
|
+
* These are high-level client/pool/socket/I-O options; low-level Readers/Writers
|
|
21
|
+
* are not configured per request through this fetch-like API.
|
|
22
|
+
*/
|
|
23
|
+
export interface FetchOptions extends HttpClientOptions {
|
|
24
|
+
}
|
|
25
|
+
export interface FetchLike {
|
|
26
|
+
(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
29
|
+
readonly client: HttpClient;
|
|
30
|
+
}
|
|
31
|
+
export declare function normalizeHeaders(headers?: HeadersInit): Headers;
|
|
32
|
+
export declare function createFetch(client?: HttpClient): FetchLike;
|
|
33
|
+
export type { HttpClientOptions };
|
|
34
|
+
export { HttpClient };
|
|
35
|
+
export declare const fetch: FetchLike;
|
|
36
|
+
export default fetch;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AgentPoolOptions, SendOptions } from './types/agent';
|
|
2
|
+
export declare class HttpClient implements AsyncDisposable {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(options?: HttpClient.Options);
|
|
5
|
+
send(options: SendOptions): Promise<Response>;
|
|
6
|
+
close(): Promise<void>;
|
|
7
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare namespace HttpClient {
|
|
10
|
+
/**
|
|
11
|
+
* High-level client configuration.
|
|
12
|
+
*
|
|
13
|
+
* At this layer, the API exposes:
|
|
14
|
+
* - pool management options
|
|
15
|
+
* - socket connection options
|
|
16
|
+
* - HTTP reader/writer options forwarded to the agent I/O layer
|
|
17
|
+
*/
|
|
18
|
+
interface Options extends AgentPoolOptions {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Back-compat */
|
|
22
|
+
export interface HttpClientOptions extends HttpClient.Options {
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AgentPoolOptions, SendOptions } from './types/agent';
|
|
2
|
+
export declare class HttpClient implements AsyncDisposable {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(options?: HttpClient.Options);
|
|
5
|
+
send(options: SendOptions): Promise<Response>;
|
|
6
|
+
close(): Promise<void>;
|
|
7
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare namespace HttpClient {
|
|
10
|
+
/**
|
|
11
|
+
* High-level client configuration.
|
|
12
|
+
*
|
|
13
|
+
* At this layer, the API exposes:
|
|
14
|
+
* - pool management options
|
|
15
|
+
* - socket connection options
|
|
16
|
+
* - HTTP reader/writer options forwarded to the agent I/O layer
|
|
17
|
+
*/
|
|
18
|
+
interface Options extends AgentPoolOptions {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Back-compat */
|
|
22
|
+
export interface HttpClientOptions extends HttpClient.Options {
|
|
23
|
+
}
|
package/src/index.d.cts
ADDED
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type TransferEncodingInfo = {
|
|
2
|
+
has: boolean;
|
|
3
|
+
chunked: boolean;
|
|
4
|
+
codings: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function parseMaxBytes(value?: number | string): number | null;
|
|
7
|
+
export declare function splitTokens(v: string | null): string[];
|
|
8
|
+
export declare function parseTransferEncoding(headers: Headers): TransferEncodingInfo;
|
|
9
|
+
export declare function parseContentLength(headers: Headers): number | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type TransferEncodingInfo = {
|
|
2
|
+
has: boolean;
|
|
3
|
+
chunked: boolean;
|
|
4
|
+
codings: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function parseMaxBytes(value?: number | string): number | null;
|
|
7
|
+
export declare function splitTokens(v: string | null): string[];
|
|
8
|
+
export declare function parseTransferEncoding(headers: Headers): TransferEncodingInfo;
|
|
9
|
+
export declare function parseContentLength(headers: Headers): number | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ISyncWritable, IWritable } from '@fuman/io';
|
|
2
|
+
export declare class BufWriter implements IWritable, ISyncWritable {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(writable: IWritable, size?: number);
|
|
5
|
+
get bufferSize(): number;
|
|
6
|
+
get buffered(): number;
|
|
7
|
+
get available(): number;
|
|
8
|
+
reset(writable: IWritable): void;
|
|
9
|
+
writeSync(bytes: number): Uint8Array;
|
|
10
|
+
disposeWriteSync(written?: number): void;
|
|
11
|
+
flush(): Promise<void>;
|
|
12
|
+
write(bytes: Uint8Array): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ISyncWritable, IWritable } from '@fuman/io';
|
|
2
|
+
export declare class BufWriter implements IWritable, ISyncWritable {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(writable: IWritable, size?: number);
|
|
5
|
+
get bufferSize(): number;
|
|
6
|
+
get buffered(): number;
|
|
7
|
+
get available(): number;
|
|
8
|
+
reset(writable: IWritable): void;
|
|
9
|
+
writeSync(bytes: number): Uint8Array;
|
|
10
|
+
disposeWriteSync(written?: number): void;
|
|
11
|
+
flush(): Promise<void>;
|
|
12
|
+
write(bytes: Uint8Array): Promise<void>;
|
|
13
|
+
}
|
package/src/io/io.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IConnection } from '@fuman/net';
|
|
2
|
+
import { LineReader, Readers } from './readers';
|
|
3
|
+
import { Writers } from './writers';
|
|
4
|
+
export declare function readResponse(conn: IConnection<unknown>, options: (Readers.Options & LineReader.ReadHeadersOptions) | undefined, shouldIgnoreBody: (status: number) => boolean, onDone?: (reusable: boolean) => void): Promise<Response>;
|
|
5
|
+
export declare function writeRequest(conn: IConnection<unknown>, req: Writers.Request, options?: Writers.Options): Promise<void>;
|
package/src/io/io.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IConnection } from '@fuman/net';
|
|
2
|
+
import { LineReader, Readers } from './readers';
|
|
3
|
+
import { Writers } from './writers';
|
|
4
|
+
export declare function readResponse(conn: IConnection<unknown>, options: (Readers.Options & LineReader.ReadHeadersOptions) | undefined, shouldIgnoreBody: (status: number) => boolean, onDone?: (reusable: boolean) => void): Promise<Response>;
|
|
5
|
+
export declare function writeRequest(conn: IConnection<unknown>, req: Writers.Request, options?: Writers.Options): Promise<void>;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { IClosable, IReadable } from '@fuman/io';
|
|
2
|
+
type Source = IReadable & IClosable;
|
|
3
|
+
export declare function sanitizeHeaderValue(v: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Reader options shared across the HTTP/1 response pipeline.
|
|
6
|
+
*
|
|
7
|
+
* @namespace Readers
|
|
8
|
+
*/
|
|
9
|
+
export declare namespace Readers {
|
|
10
|
+
/**
|
|
11
|
+
* Buffering configuration.
|
|
12
|
+
*
|
|
13
|
+
* @property {number} [bufferSize] - Initial size (in bytes) for the internal buffer.
|
|
14
|
+
*
|
|
15
|
+
* @property {number} [highWaterMark] - Target read size (in bytes) for each pull from the underlying source.
|
|
16
|
+
* Defaults to 16 KiB.
|
|
17
|
+
*/
|
|
18
|
+
interface BufferingOptions {
|
|
19
|
+
bufferSize?: number;
|
|
20
|
+
highWaterMark?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Response size limits.
|
|
24
|
+
*
|
|
25
|
+
* @property {number|string} [maxBodySize] - Maximum allowed entity-body size (raw, before content decoding).
|
|
26
|
+
* Can be a number of bytes or a human-readable string like "10mb".
|
|
27
|
+
*
|
|
28
|
+
* @property {number|string} [maxDecodedBodySize] - Maximum allowed decoded body size (after content decoding).
|
|
29
|
+
* Can be a number of bytes or a human-readable string like "10mb".
|
|
30
|
+
*/
|
|
31
|
+
interface SizeLimitOptions {
|
|
32
|
+
maxBodySize?: number | string;
|
|
33
|
+
maxDecodedBodySize?: number | string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Decompression behavior.
|
|
37
|
+
*
|
|
38
|
+
* @property {boolean} [decompress] - If true, the response body may be transparently decompressed based on
|
|
39
|
+
* Content-Encoding. Defaults to true.
|
|
40
|
+
*/
|
|
41
|
+
interface DecompressionOptions {
|
|
42
|
+
decompress?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Delimiter scanning limits.
|
|
46
|
+
*
|
|
47
|
+
* @property {number} [maxLineSize] - Maximum allowed bytes for a single CRLF-delimited line (excluding CRLF).
|
|
48
|
+
* Defaults to 64 KiB.
|
|
49
|
+
*
|
|
50
|
+
* @property {number} [maxBufferedBytes] - Maximum allowed buffered bytes while searching for CRLF.
|
|
51
|
+
* Defaults to 256 KiB.
|
|
52
|
+
*/
|
|
53
|
+
interface DelimiterLimitsOptions {
|
|
54
|
+
maxLineSize?: number;
|
|
55
|
+
maxBufferedBytes?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Unified options shape suitable for fetch-like response parsing.
|
|
59
|
+
*/
|
|
60
|
+
type Options = LineReader.Options & BodyReader.Options & ChunkedBodyReader.Options;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* CRLF-delimited reader that preserves over-reads in an internal buffer.
|
|
64
|
+
*
|
|
65
|
+
* Key property: once you finish reading headers, any bytes already read beyond
|
|
66
|
+
* the header terminator stay buffered and will be returned by read().
|
|
67
|
+
*/
|
|
68
|
+
export declare class LineReader implements IReadable, IClosable {
|
|
69
|
+
#private;
|
|
70
|
+
close: () => Promise<void> | void;
|
|
71
|
+
/**
|
|
72
|
+
* LineReader configuration.
|
|
73
|
+
*
|
|
74
|
+
* @namespace LineReader
|
|
75
|
+
*/
|
|
76
|
+
static Options: never;
|
|
77
|
+
constructor(src: Source, opts?: LineReader.Options);
|
|
78
|
+
read(into: Uint8Array): Promise<number>;
|
|
79
|
+
readLine(): Promise<string | null>;
|
|
80
|
+
readHeaders(opts?: LineReader.ReadHeadersOptions): Promise<Headers>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* LineReader configuration.
|
|
84
|
+
*
|
|
85
|
+
* @namespace LineReader
|
|
86
|
+
*/
|
|
87
|
+
export declare namespace LineReader {
|
|
88
|
+
/**
|
|
89
|
+
* LineReader instance options.
|
|
90
|
+
*
|
|
91
|
+
* @property {number} [bufferSize] - Initial size (in bytes) for the internal buffer.
|
|
92
|
+
*
|
|
93
|
+
* @property {number} [highWaterMark] - Target read size (in bytes) for each pull from the underlying source.
|
|
94
|
+
* Defaults to 16 KiB.
|
|
95
|
+
*
|
|
96
|
+
* @property {number} [maxLineSize] - Maximum allowed bytes for a single CRLF-delimited line (excluding CRLF).
|
|
97
|
+
* Defaults to 64 KiB.
|
|
98
|
+
*
|
|
99
|
+
* @property {number} [maxBufferedBytes] - Maximum allowed buffered bytes while searching for CRLF.
|
|
100
|
+
* Defaults to 256 KiB.
|
|
101
|
+
*/
|
|
102
|
+
interface Options extends Readers.BufferingOptions, Readers.DelimiterLimitsOptions {
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Header parsing limits.
|
|
106
|
+
*
|
|
107
|
+
* @property {number} [maxHeaderSize] - Maximum allowed bytes for all header fields (including CRLFs).
|
|
108
|
+
* Defaults to 64 KiB.
|
|
109
|
+
*/
|
|
110
|
+
interface ReadHeadersOptions {
|
|
111
|
+
maxHeaderSize?: number;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Body reader that streams bytes with either a fixed Content-Length or until EOF.
|
|
116
|
+
*/
|
|
117
|
+
export declare class BodyReader implements IReadable, IClosable {
|
|
118
|
+
#private;
|
|
119
|
+
close: () => Promise<void> | void;
|
|
120
|
+
/**
|
|
121
|
+
* BodyReader configuration.
|
|
122
|
+
*
|
|
123
|
+
* @namespace BodyReader
|
|
124
|
+
*/
|
|
125
|
+
static Options: never;
|
|
126
|
+
constructor(src: Source, contentLength: number, opts?: BodyReader.Options);
|
|
127
|
+
read(into: Uint8Array): Promise<number>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* BodyReader configuration.
|
|
131
|
+
*
|
|
132
|
+
* @namespace BodyReader
|
|
133
|
+
*/
|
|
134
|
+
export declare namespace BodyReader {
|
|
135
|
+
/**
|
|
136
|
+
* BodyReader instance options.
|
|
137
|
+
*
|
|
138
|
+
* @property {number|string} [maxBodySize] - Maximum allowed entity-body size (raw, before content decoding).
|
|
139
|
+
* Can be a number of bytes or a human-readable string like "10mb".
|
|
140
|
+
*
|
|
141
|
+
* @property {number|string} [maxDecodedBodySize] - Maximum allowed decoded body size (after content decoding).
|
|
142
|
+
* Can be a number of bytes or a human-readable string like "10mb".
|
|
143
|
+
*
|
|
144
|
+
* @property {boolean} [decompress] - If true, the response body may be transparently decompressed based on
|
|
145
|
+
* Content-Encoding. Defaults to true.
|
|
146
|
+
*/
|
|
147
|
+
interface Options extends Readers.SizeLimitOptions, Readers.DecompressionOptions {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* RFC 7230 chunked transfer-coding decoder.
|
|
152
|
+
*/
|
|
153
|
+
export declare class ChunkedBodyReader implements IReadable, IClosable {
|
|
154
|
+
#private;
|
|
155
|
+
close: () => Promise<void> | void;
|
|
156
|
+
/**
|
|
157
|
+
* ChunkedBodyReader configuration.
|
|
158
|
+
*
|
|
159
|
+
* @namespace ChunkedBodyReader
|
|
160
|
+
*/
|
|
161
|
+
static Options: never;
|
|
162
|
+
constructor(src: Source, opts?: ChunkedBodyReader.Options);
|
|
163
|
+
read(into: Uint8Array): Promise<number>;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* ChunkedBodyReader configuration.
|
|
167
|
+
*
|
|
168
|
+
* @namespace ChunkedBodyReader
|
|
169
|
+
*/
|
|
170
|
+
export declare namespace ChunkedBodyReader {
|
|
171
|
+
/**
|
|
172
|
+
* ChunkedBodyReader instance options.
|
|
173
|
+
*
|
|
174
|
+
* @property {number|string} [maxBodySize] - Maximum allowed entity-body size (raw, before content decoding).
|
|
175
|
+
* Can be a number of bytes or a human-readable string like "10mb".
|
|
176
|
+
*
|
|
177
|
+
* @property {number|string} [maxDecodedBodySize] - Maximum allowed decoded body size (after content decoding).
|
|
178
|
+
* Can be a number of bytes or a human-readable string like "10mb".
|
|
179
|
+
*
|
|
180
|
+
* @property {boolean} [decompress] - If true, the response body may be transparently decompressed based on
|
|
181
|
+
* Content-Encoding. Defaults to true.
|
|
182
|
+
*
|
|
183
|
+
* @property {number} [bufferSize] - Initial size (in bytes) for the internal buffer.
|
|
184
|
+
*
|
|
185
|
+
* @property {number} [highWaterMark] - Target read size (in bytes) for each pull from the underlying source.
|
|
186
|
+
* Defaults to 16 KiB.
|
|
187
|
+
*
|
|
188
|
+
* @property {number} [maxLineSize] - Maximum allowed bytes for CRLF-delimited chunk control lines.
|
|
189
|
+
* Defaults to 64 KiB.
|
|
190
|
+
*
|
|
191
|
+
* @property {number} [maxChunkSize] - Maximum allowed bytes for any single chunk.
|
|
192
|
+
* Defaults to 16 MiB.
|
|
193
|
+
*/
|
|
194
|
+
interface Options extends BodyReader.Options, Readers.BufferingOptions {
|
|
195
|
+
maxLineSize?: number;
|
|
196
|
+
maxChunkSize?: number;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
export {};
|