@npy/fetch 0.1.1 → 0.1.3

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 (140) hide show
  1. package/README.md +143 -50
  2. package/bun.lock +68 -0
  3. package/examples/custom-proxy-client.ts +32 -0
  4. package/examples/http-client.ts +47 -0
  5. package/examples/proxy.ts +16 -0
  6. package/examples/simple.ts +15 -0
  7. package/package.json +36 -25
  8. package/src/_internal/consts.ts +3 -0
  9. package/src/_internal/decode-stream-error.ts +16 -0
  10. package/src/_internal/error-mapping.ts +160 -0
  11. package/src/_internal/guards.ts +78 -0
  12. package/src/_internal/net.ts +173 -0
  13. package/src/_internal/promises.ts +22 -0
  14. package/src/_internal/streams.ts +52 -0
  15. package/src/_internal/symbols.ts +1 -0
  16. package/src/agent-pool.ts +157 -0
  17. package/src/agent.ts +408 -0
  18. package/src/body.ts +179 -0
  19. package/src/dialers/index.ts +3 -0
  20. package/src/dialers/proxy.ts +102 -0
  21. package/src/dialers/tcp.ts +162 -0
  22. package/src/encoding.ts +222 -0
  23. package/src/errors.ts +357 -0
  24. package/src/fetch.ts +626 -0
  25. package/src/http-client.ts +111 -0
  26. package/src/index.ts +14 -0
  27. package/src/io/_utils.ts +82 -0
  28. package/src/io/buf-writer.ts +183 -0
  29. package/src/io/io.ts +322 -0
  30. package/src/io/readers.ts +576 -0
  31. package/src/io/writers.ts +331 -0
  32. package/src/types/agent.ts +98 -0
  33. package/src/types/{dialer.d.cts → dialer.ts} +22 -9
  34. package/src/types/index.ts +2 -0
  35. package/tests/agent-pool.test.ts +111 -0
  36. package/tests/agent.test.ts +134 -0
  37. package/tests/body.test.ts +228 -0
  38. package/tests/errors.test.ts +152 -0
  39. package/tests/fetch.test.ts +421 -0
  40. package/tests/io-options.test.ts +127 -0
  41. package/tests/multipart.test.ts +348 -0
  42. package/tests/test-utils.ts +335 -0
  43. package/tsconfig.json +15 -0
  44. package/LICENSE +0 -21
  45. package/_internal/consts.cjs +0 -4
  46. package/_internal/consts.js +0 -4
  47. package/_internal/error-adapters.cjs +0 -146
  48. package/_internal/error-adapters.js +0 -142
  49. package/_internal/guards.cjs +0 -24
  50. package/_internal/guards.js +0 -17
  51. package/_internal/net.cjs +0 -95
  52. package/_internal/net.js +0 -92
  53. package/_internal/promises.cjs +0 -18
  54. package/_internal/promises.js +0 -18
  55. package/_internal/streams.cjs +0 -37
  56. package/_internal/streams.js +0 -36
  57. package/_virtual/_rolldown/runtime.cjs +0 -23
  58. package/agent-pool.cjs +0 -78
  59. package/agent-pool.js +0 -77
  60. package/agent.cjs +0 -257
  61. package/agent.js +0 -256
  62. package/body.cjs +0 -154
  63. package/body.js +0 -151
  64. package/dialers/proxy.cjs +0 -49
  65. package/dialers/proxy.js +0 -48
  66. package/dialers/tcp.cjs +0 -70
  67. package/dialers/tcp.js +0 -67
  68. package/encoding.cjs +0 -95
  69. package/encoding.js +0 -91
  70. package/errors.cjs +0 -275
  71. package/errors.js +0 -259
  72. package/fetch.cjs +0 -117
  73. package/fetch.js +0 -115
  74. package/http-client.cjs +0 -33
  75. package/http-client.js +0 -33
  76. package/index.cjs +0 -45
  77. package/index.d.cts +0 -1
  78. package/index.d.ts +0 -1
  79. package/index.js +0 -9
  80. package/io/_utils.cjs +0 -56
  81. package/io/_utils.js +0 -51
  82. package/io/buf-writer.cjs +0 -149
  83. package/io/buf-writer.js +0 -148
  84. package/io/io.cjs +0 -135
  85. package/io/io.js +0 -134
  86. package/io/readers.cjs +0 -377
  87. package/io/readers.js +0 -373
  88. package/io/writers.cjs +0 -191
  89. package/io/writers.js +0 -190
  90. package/src/_internal/consts.d.cts +0 -3
  91. package/src/_internal/consts.d.ts +0 -3
  92. package/src/_internal/error-adapters.d.cts +0 -22
  93. package/src/_internal/error-adapters.d.ts +0 -22
  94. package/src/_internal/guards.d.cts +0 -13
  95. package/src/_internal/guards.d.ts +0 -13
  96. package/src/_internal/net.d.cts +0 -12
  97. package/src/_internal/net.d.ts +0 -12
  98. package/src/_internal/promises.d.cts +0 -1
  99. package/src/_internal/promises.d.ts +0 -1
  100. package/src/_internal/streams.d.cts +0 -21
  101. package/src/_internal/streams.d.ts +0 -21
  102. package/src/agent-pool.d.cts +0 -2
  103. package/src/agent-pool.d.ts +0 -2
  104. package/src/agent.d.cts +0 -3
  105. package/src/agent.d.ts +0 -3
  106. package/src/body.d.cts +0 -23
  107. package/src/body.d.ts +0 -23
  108. package/src/dialers/index.d.cts +0 -3
  109. package/src/dialers/index.d.ts +0 -3
  110. package/src/dialers/proxy.d.cts +0 -19
  111. package/src/dialers/proxy.d.ts +0 -19
  112. package/src/dialers/tcp.d.cts +0 -36
  113. package/src/dialers/tcp.d.ts +0 -36
  114. package/src/encoding.d.cts +0 -24
  115. package/src/encoding.d.ts +0 -24
  116. package/src/errors.d.cts +0 -110
  117. package/src/errors.d.ts +0 -110
  118. package/src/fetch.d.cts +0 -36
  119. package/src/fetch.d.ts +0 -36
  120. package/src/http-client.d.cts +0 -23
  121. package/src/http-client.d.ts +0 -23
  122. package/src/index.d.cts +0 -7
  123. package/src/index.d.ts +0 -7
  124. package/src/io/_utils.d.cts +0 -10
  125. package/src/io/_utils.d.ts +0 -10
  126. package/src/io/buf-writer.d.cts +0 -13
  127. package/src/io/buf-writer.d.ts +0 -13
  128. package/src/io/io.d.cts +0 -5
  129. package/src/io/io.d.ts +0 -5
  130. package/src/io/readers.d.cts +0 -199
  131. package/src/io/readers.d.ts +0 -199
  132. package/src/io/writers.d.cts +0 -22
  133. package/src/io/writers.d.ts +0 -22
  134. package/src/types/agent.d.cts +0 -128
  135. package/src/types/agent.d.ts +0 -128
  136. package/src/types/dialer.d.ts +0 -27
  137. package/src/types/index.d.cts +0 -2
  138. package/src/types/index.d.ts +0 -2
  139. package/tests/test-utils.d.cts +0 -8
  140. package/tests/test-utils.d.ts +0 -8
package/src/errors.d.cts DELETED
@@ -1,110 +0,0 @@
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 DELETED
@@ -1,110 +0,0 @@
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 DELETED
@@ -1,36 +0,0 @@
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 DELETED
@@ -1,36 +0,0 @@
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;
@@ -1,23 +0,0 @@
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
- }
@@ -1,23 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
1
- export { connectTcp, connectTls, upgradeTls } from './_internal/net';
2
- export * from './body';
3
- export * from './dialers';
4
- export * from './encoding';
5
- export * from './errors';
6
- export * from './fetch';
7
- export * from './types';
package/src/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export { connectTcp, connectTls, upgradeTls } from './_internal/net';
2
- export * from './body';
3
- export * from './dialers';
4
- export * from './encoding';
5
- export * from './errors';
6
- export * from './fetch';
7
- export * from './types';
@@ -1,10 +0,0 @@
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 {};
@@ -1,10 +0,0 @@
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 {};
@@ -1,13 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
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>;
@@ -1,199 +0,0 @@
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 {};