@cacheable/net 2.0.8 → 2.1.0

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/dist/index.d.cts CHANGED
@@ -1,33 +1,33 @@
1
- import { Cacheable, CacheableOptions } from 'cacheable';
2
- import { Hookified, HookifiedOptions } from 'hookified';
3
- import { RequestInit, Response as Response$1 } from 'undici';
4
- export { RequestInit as FetchRequestInit } from 'undici';
1
+ import { Cacheable, CacheableOptions } from "cacheable";
2
+ import { Hookified, HookifiedOptions } from "hookified";
3
+ import { RequestInit, RequestInit as FetchRequestInit, Response as Response$1 } from "undici";
5
4
 
5
+ //#region src/fetch.d.ts
6
6
  type FetchOptions = Omit<RequestInit, "cache"> & {
7
- cache?: Cacheable;
8
- /**
9
- * Enable HTTP cache semantics for intelligent response caching.
10
- *
11
- * When enabled (default), the fetch function will:
12
- * - Respect standard HTTP cache headers (Cache-Control, ETag, Last-Modified, Expires)
13
- * - Store and validate cache policies according to RFC 7234
14
- * - Handle conditional requests with If-None-Match and If-Modified-Since headers
15
- * - Process 304 Not Modified responses to update cached entries
16
- * - Only cache responses that are considered "storable" per HTTP specifications
17
- * - Automatically revalidate stale cache entries when needed
18
- * - **Set cache TTL based on HTTP headers (e.g., max-age directive)**
19
- * - Refresh TTL when receiving 304 Not Modified responses
20
- *
21
- * When disabled, the fetch function will:
22
- * - Use simple key-based caching without considering HTTP headers
23
- * - Cache all successful GET responses regardless of cache directives
24
- * - Never revalidate cached entries
25
- * - Ignore cache-control directives from the server
26
- * - **Use the default TTL from the Cacheable instance**
27
- *
28
- * @default true
29
- */
30
- httpCachePolicy?: boolean;
7
+ cache?: Cacheable;
8
+ /**
9
+ * Enable HTTP cache semantics for intelligent response caching.
10
+ *
11
+ * When enabled (default), the fetch function will:
12
+ * - Respect standard HTTP cache headers (Cache-Control, ETag, Last-Modified, Expires)
13
+ * - Store and validate cache policies according to RFC 7234
14
+ * - Handle conditional requests with If-None-Match and If-Modified-Since headers
15
+ * - Process 304 Not Modified responses to update cached entries
16
+ * - Only cache responses that are considered "storable" per HTTP specifications
17
+ * - Automatically revalidate stale cache entries when needed
18
+ * - **Set cache TTL based on HTTP headers (e.g., max-age directive)**
19
+ * - Refresh TTL when receiving 304 Not Modified responses
20
+ *
21
+ * When disabled, the fetch function will:
22
+ * - Use simple key-based caching without considering HTTP headers
23
+ * - Cache all successful GET responses regardless of cache directives
24
+ * - Never revalidate cached entries
25
+ * - Ignore cache-control directives from the server
26
+ * - **Use the default TTL from the Cacheable instance**
27
+ *
28
+ * @default true
29
+ */
30
+ httpCachePolicy?: boolean;
31
31
  };
32
32
  /**
33
33
  * Fetch data from a URL with optional request options.
@@ -42,10 +42,10 @@ type FetchOptions = Omit<RequestInit, "cache"> & {
42
42
  * @param {FetchOptions} options Optional request options. If `cache` is not provided, no caching will be used.
43
43
  * @returns {Promise<UndiciResponse>} The response from the fetch.
44
44
  */
45
- declare function fetch(url: string, options: FetchOptions): Promise<Response$1>;
45
+ declare function fetch(url: string, options?: FetchOptions): Promise<Response$1>;
46
46
  type DataResponse<T = unknown> = {
47
- data: T;
48
- response: Response$1;
47
+ data: T;
48
+ response: Response$1;
49
49
  };
50
50
  type GetResponse<T = unknown> = DataResponse<T>;
51
51
  /**
@@ -87,84 +87,258 @@ declare function del<T = unknown>(url: string, data?: unknown, options?: Omit<Fe
87
87
  */
88
88
  declare function head(url: string, options: Omit<FetchOptions, "method">): Promise<Response$1>;
89
89
  type Response = Response$1;
90
-
90
+ //#endregion
91
+ //#region src/whois.d.ts
92
+ /**
93
+ * The detected category of a WHOIS query.
94
+ */
95
+ type WhoisQueryType = "domain" | "ipv4" | "ipv6" | "asn";
96
+ /**
97
+ * Parsed WHOIS fields. Repeated keys (e.g. multiple `Name Server` lines) are
98
+ * grouped into an array; single occurrences remain a string.
99
+ */
100
+ type WhoisFields = Record<string, string | string[]>;
101
+ /**
102
+ * A single server response collected while resolving a WHOIS query. When
103
+ * referrals are followed there will be one hop per server queried.
104
+ */
105
+ type WhoisHop = {
106
+ /** The server queried for this hop. */server: string; /** The TCP port used for this hop. */
107
+ port: number; /** The raw text returned by this server. */
108
+ raw: string; /** The parsed key/value fields for this hop. */
109
+ fields: WhoisFields;
110
+ };
111
+ /**
112
+ * The result of a WHOIS lookup, exposing both the raw text and parsed JSON.
113
+ */
114
+ type WhoisResult = {
115
+ /** The normalized query that was looked up. */query: string; /** The detected type of the query. */
116
+ type: WhoisQueryType; /** The final authoritative server that produced the primary data. */
117
+ server: string; /** The raw text across all hops, separated by a blank line. */
118
+ raw: string; /** The merged parsed fields across all hops (repeats become arrays). */
119
+ fields: WhoisFields; /** Every server response, in the order they were queried. */
120
+ hops: WhoisHop[];
121
+ };
122
+ /**
123
+ * Options for {@link queryWhoisServer}.
124
+ */
125
+ type QueryWhoisServerOptions = {
126
+ /** The server hostname or IP to connect to. */host: string; /** The TCP port to connect to. @default 43 */
127
+ port?: number; /** The query string written to the socket. */
128
+ query: string; /** An optional prefix written before the query (e.g. `"domain "`). @default "" */
129
+ queryPrefix?: string; /** Milliseconds before the socket is destroyed and the call rejects. @default 10000 */
130
+ timeout?: number; /** The encoding used to decode the response. @default "utf8" */
131
+ encoding?: BufferEncoding;
132
+ };
133
+ /**
134
+ * Options for {@link whois} and {@link whoisRaw}.
135
+ */
136
+ type WhoisOptions = {
137
+ /**
138
+ * Override the WHOIS server to query first. When set, the IANA bootstrap
139
+ * step is skipped and this server is queried directly.
140
+ */
141
+ server?: string; /** The TCP port to use for the initial server. @default 43 */
142
+ port?: number; /** The socket timeout in milliseconds. @default 10000 */
143
+ timeout?: number;
144
+ /**
145
+ * Whether to follow registry → registrar referrals.
146
+ * - `false` / `0`: do not follow (authoritative server only)
147
+ * - `true`: follow up to the default depth (2)
148
+ * - `number`: follow up to N referral hops
149
+ * @default true
150
+ */
151
+ follow?: boolean | number; /** An optional prefix written before the query (e.g. `"domain "`). @default "" */
152
+ queryPrefix?: string; /** The encoding used to decode responses. @default "utf8" */
153
+ encoding?: BufferEncoding; /** The bootstrap WHOIS server used when no `server` is provided. @default "whois.iana.org" */
154
+ bootstrapServer?: string; /** The TCP port of the bootstrap WHOIS server. @default 43 */
155
+ bootstrapPort?: number;
156
+ /**
157
+ * Enable or disable caching for this lookup. When `false`, no caching is
158
+ * performed even if a cache is available. @default true (when a cache is available)
159
+ */
160
+ caching?: boolean; /** The cache instance. The standalone {@link whois} caches only when this is provided. */
161
+ cache?: Cacheable; /** An optional TTL override for cached results (milliseconds or shorthand). */
162
+ ttl?: number | string;
163
+ };
164
+ /**
165
+ * Open a raw WHOIS connection to a single server on TCP port 43, write the
166
+ * query, and resolve with the full text response. This is the low-level
167
+ * primitive used by {@link whois}; host and port are explicit so it can be
168
+ * pointed at any server (including a local test server).
169
+ *
170
+ * @param {QueryWhoisServerOptions} options The connection and query options.
171
+ * @returns {Promise<string>} The raw text returned by the server.
172
+ */
173
+ declare function queryWhoisServer(options: QueryWhoisServerOptions): Promise<string>;
174
+ /**
175
+ * Normalize a WHOIS query by stripping URL scheme, `www.`, path/query/hash, and
176
+ * trailing dots, lowercasing, and converting internationalized domains to
177
+ * punycode.
178
+ *
179
+ * @param {string} input The raw query (domain, URL, IP, or ASN).
180
+ * @returns {string} The normalized query.
181
+ */
182
+ declare function normalizeWhoisQuery(input: string): string;
183
+ /**
184
+ * Detect whether a normalized query is a domain, IPv4 address, IPv6 address, or
185
+ * autonomous system number.
186
+ *
187
+ * @param {string} value The normalized query.
188
+ * @returns {WhoisQueryType} The detected query type.
189
+ */
190
+ declare function detectQueryType(value: string): WhoisQueryType;
191
+ /**
192
+ * Parse raw WHOIS text into a key/value object. Comment and disclaimer lines are
193
+ * ignored, and repeated keys are grouped into arrays.
194
+ *
195
+ * @param {string} raw The raw WHOIS text.
196
+ * @returns {WhoisFields} The parsed fields.
197
+ */
198
+ declare function parseWhois(raw: string): WhoisFields;
199
+ /**
200
+ * Perform a WHOIS lookup for a domain, IP address, or ASN and return both the
201
+ * raw text and parsed JSON fields. The authoritative server is discovered
202
+ * dynamically through IANA (and cached), and registry → registrar referrals are
203
+ * followed by default. When a cache is provided, results are cached and
204
+ * concurrent identical lookups are coalesced.
205
+ *
206
+ * @param {string} query The domain, URL, IP address, or ASN to look up.
207
+ * @param {WhoisOptions} options Optional lookup options.
208
+ * @returns {Promise<WhoisResult>} The raw text and parsed fields.
209
+ */
210
+ declare function whois(query: string, options?: WhoisOptions): Promise<WhoisResult>;
211
+ /**
212
+ * Perform a WHOIS lookup and return only the raw text response.
213
+ *
214
+ * @param {string} query The domain, URL, IP address, or ASN to look up.
215
+ * @param {WhoisOptions} options Optional lookup options.
216
+ * @returns {Promise<string>} The raw WHOIS text.
217
+ */
218
+ declare function whoisRaw(query: string, options?: WhoisOptions): Promise<string>;
219
+ //#endregion
220
+ //#region src/rdap.d.ts
221
+ /**
222
+ * The result of an RDAP lookup, exposing both the raw JSON text and the parsed
223
+ * object.
224
+ */
225
+ type RdapResult = {
226
+ /** The normalized query that was looked up. */query: string; /** The detected type of the query. */
227
+ type: WhoisQueryType; /** The RDAP base URL that produced the data. */
228
+ server: string; /** The raw JSON text returned by the server. */
229
+ raw: string; /** The parsed RDAP object. */
230
+ data: Record<string, unknown>;
231
+ };
232
+ /**
233
+ * Options for {@link rdap}.
234
+ */
235
+ type RdapOptions = {
236
+ /**
237
+ * Override the RDAP base URL to query. When set, the IANA bootstrap step is
238
+ * skipped and this server is queried directly.
239
+ */
240
+ server?: string; /** Override the IANA bootstrap base URL. @default "https://data.iana.org/rdap" */
241
+ bootstrapUrl?: string; /** Additional request headers to send with the RDAP request. */
242
+ headers?: Record<string, string>;
243
+ /**
244
+ * Enable or disable caching for this lookup. When `false`, no caching is
245
+ * performed even if a cache is available. @default true (when a cache is available)
246
+ */
247
+ caching?: boolean; /** The cache instance. The standalone {@link rdap} caches only when this is provided. */
248
+ cache?: Cacheable; /** An optional TTL override for cached results (milliseconds or shorthand). */
249
+ ttl?: number | string;
250
+ };
251
+ /**
252
+ * Perform an RDAP lookup for a domain, IP address, or ASN and return both the raw
253
+ * JSON text and the parsed object. The RDAP server is discovered dynamically
254
+ * through the IANA bootstrap registries (fetched through the package's cached
255
+ * fetch). When a cache is provided, results are cached and concurrent identical
256
+ * lookups are coalesced.
257
+ *
258
+ * @param {string} query The domain, URL, IP address, or ASN to look up.
259
+ * @param {RdapOptions} options Optional lookup options.
260
+ * @returns {Promise<RdapResult>} The raw JSON text and parsed data.
261
+ */
262
+ declare function rdap(query: string, options?: RdapOptions): Promise<RdapResult>;
263
+ //#endregion
264
+ //#region src/index.d.ts
91
265
  type NetFetchOptions = {
92
- /**
93
- * Controls whether caching is enabled for this specific request.
94
- * - `true`: Enable caching for this request
95
- * - `false`: Disable caching for this request
96
- * - `undefined`: Use default caching behavior based on the method (GET/HEAD are cached by default)
97
- * @default undefined
98
- */
99
- caching?: boolean;
100
- /**
101
- * Custom function for converting JavaScript values to strings for this request.
102
- * Overrides the instance-level stringify function if provided.
103
- * @example
104
- * // Use custom serialization for this request only
105
- * stringify: (value) => superjson.stringify(value)
106
- */
107
- stringify?: StringifyType;
108
- /**
109
- * Custom function for parsing strings back to JavaScript values for this request.
110
- * Overrides the instance-level parse function if provided.
111
- * @example
112
- * // Use custom parsing for this request only
113
- * parse: (text) => superjson.parse(text)
114
- */
115
- parse?: ParseType;
266
+ /**
267
+ * Controls whether caching is enabled for this specific request.
268
+ * - `true`: Enable caching for this request
269
+ * - `false`: Disable caching for this request
270
+ * - `undefined`: Use default caching behavior based on the method (GET/HEAD are cached by default)
271
+ * @default undefined
272
+ */
273
+ caching?: boolean;
274
+ /**
275
+ * Custom function for converting JavaScript values to strings for this request.
276
+ * Overrides the instance-level stringify function if provided.
277
+ * @example
278
+ * // Use custom serialization for this request only
279
+ * stringify: (value) => superjson.stringify(value)
280
+ */
281
+ stringify?: StringifyType;
282
+ /**
283
+ * Custom function for parsing strings back to JavaScript values for this request.
284
+ * Overrides the instance-level parse function if provided.
285
+ * @example
286
+ * // Use custom parsing for this request only
287
+ * parse: (text) => superjson.parse(text)
288
+ */
289
+ parse?: ParseType;
116
290
  } & Omit<FetchOptions, "method" | "cache">;
117
291
  type CacheableNetOptions = {
118
- /**
119
- * The cache instance or configuration options for caching responses.
120
- * Can be either an existing Cacheable instance or options to create a new one.
121
- * If not provided, a default Cacheable instance will be created.
122
- * @default new Cacheable()
123
- */
124
- cache?: Cacheable | CacheableOptions;
125
- /**
126
- * Enable HTTP cache semantics for intelligent response caching.
127
- *
128
- * When enabled (default), fetch operations will:
129
- * - Respect standard HTTP cache headers (Cache-Control, ETag, Last-Modified, Expires)
130
- * - Store and validate cache policies according to RFC 7234
131
- * - Handle conditional requests with If-None-Match and If-Modified-Since headers
132
- * - Process 304 Not Modified responses to update cached entries
133
- * - Only cache responses that are considered "storable" per HTTP specifications
134
- * - Automatically revalidate stale cache entries when needed
135
- * - **Set cache TTL based on HTTP headers (e.g., max-age directive)**
136
- * - Refresh TTL when receiving 304 Not Modified responses
137
- *
138
- * When disabled, fetch operations will:
139
- * - Use simple key-based caching without considering HTTP headers
140
- * - Cache all successful GET responses regardless of cache directives
141
- * - Never revalidate cached entries
142
- * - Ignore cache-control directives from the server
143
- * - **Use the default TTL from the Cacheable instance**
144
- *
145
- * @default true
146
- */
147
- httpCachePolicy?: boolean;
148
- /**
149
- * Custom function for converting JavaScript values to strings.
150
- * This is used when serializing request bodies for POST, PUT, PATCH, and DELETE methods.
151
- * Useful for handling complex data types that JSON.stringify doesn't support natively.
152
- * @default JSON.stringify
153
- * @example
154
- * // Using superjson for enhanced serialization
155
- * stringify: (value) => superjson.stringify(value)
156
- */
157
- stringify?: StringifyType;
158
- /**
159
- * Custom function for parsing strings back to JavaScript values.
160
- * This is used when deserializing response bodies.
161
- * Should be compatible with the stringify function for proper round-trip serialization.
162
- * @default JSON.parse
163
- * @example
164
- * // Using superjson for enhanced parsing
165
- * parse: (text) => superjson.parse(text)
166
- */
167
- parse?: ParseType;
292
+ /**
293
+ * The cache instance or configuration options for caching responses.
294
+ * Can be either an existing Cacheable instance or options to create a new one.
295
+ * If not provided, a default Cacheable instance will be created.
296
+ * @default new Cacheable()
297
+ */
298
+ cache?: Cacheable | CacheableOptions;
299
+ /**
300
+ * Enable HTTP cache semantics for intelligent response caching.
301
+ *
302
+ * When enabled (default), fetch operations will:
303
+ * - Respect standard HTTP cache headers (Cache-Control, ETag, Last-Modified, Expires)
304
+ * - Store and validate cache policies according to RFC 7234
305
+ * - Handle conditional requests with If-None-Match and If-Modified-Since headers
306
+ * - Process 304 Not Modified responses to update cached entries
307
+ * - Only cache responses that are considered "storable" per HTTP specifications
308
+ * - Automatically revalidate stale cache entries when needed
309
+ * - **Set cache TTL based on HTTP headers (e.g., max-age directive)**
310
+ * - Refresh TTL when receiving 304 Not Modified responses
311
+ *
312
+ * When disabled, fetch operations will:
313
+ * - Use simple key-based caching without considering HTTP headers
314
+ * - Cache all successful GET responses regardless of cache directives
315
+ * - Never revalidate cached entries
316
+ * - Ignore cache-control directives from the server
317
+ * - **Use the default TTL from the Cacheable instance**
318
+ *
319
+ * @default true
320
+ */
321
+ httpCachePolicy?: boolean;
322
+ /**
323
+ * Custom function for converting JavaScript values to strings.
324
+ * This is used when serializing request bodies for POST, PUT, PATCH, and DELETE methods.
325
+ * Useful for handling complex data types that JSON.stringify doesn't support natively.
326
+ * @default JSON.stringify
327
+ * @example
328
+ * // Using superjson for enhanced serialization
329
+ * stringify: (value) => superjson.stringify(value)
330
+ */
331
+ stringify?: StringifyType;
332
+ /**
333
+ * Custom function for parsing strings back to JavaScript values.
334
+ * This is used when deserializing response bodies.
335
+ * Should be compatible with the stringify function for proper round-trip serialization.
336
+ * @default JSON.parse
337
+ * @example
338
+ * // Using superjson for enhanced parsing
339
+ * parse: (text) => superjson.parse(text)
340
+ */
341
+ parse?: ParseType;
168
342
  } & HookifiedOptions;
169
343
  /**
170
344
  * Function type for converting JavaScript values to strings.
@@ -181,124 +355,145 @@ type StringifyType = (value: unknown) => string;
181
355
  */
182
356
  type ParseType = (value: string) => unknown;
183
357
  declare class CacheableNet extends Hookified {
184
- private _cache;
185
- private _httpCachePolicy;
186
- private _stringify;
187
- private _parse;
188
- constructor(options?: CacheableNetOptions);
189
- /**
190
- * Get the stringify function used for converting objects to strings.
191
- * @returns {StringifyType} The current stringify function
192
- */
193
- get stringify(): StringifyType;
194
- /**
195
- * Set the stringify function for converting objects to strings.
196
- * @param {StringifyType} value - The stringify function to use
197
- */
198
- set stringify(value: StringifyType);
199
- /**
200
- * Get the parse function used for converting strings to objects.
201
- * @returns {ParseType} The current parse function
202
- */
203
- get parse(): ParseType;
204
- /**
205
- * Set the parse function for converting strings to objects.
206
- * @param {ParseType} value - The parse function to use
207
- */
208
- set parse(value: ParseType);
209
- /**
210
- * Get the Cacheable instance used for caching fetch operations.
211
- * @returns {Cacheable} The current Cacheable instance
212
- */
213
- get cache(): Cacheable;
214
- /**
215
- * Set the Cacheable instance for caching fetch operations.
216
- * @param {Cacheable} value - The Cacheable instance to use for caching
217
- */
218
- set cache(value: Cacheable);
219
- /**
220
- * Get the current HTTP cache policy setting.
221
- * @returns {boolean} Whether HTTP cache semantics are enabled
222
- */
223
- get httpCachePolicy(): boolean;
224
- /**
225
- * Set whether to use HTTP cache semantics.
226
- * @param {boolean} value - Enable or disable HTTP cache semantics
227
- */
228
- set httpCachePolicy(value: boolean);
229
- /**
230
- * Fetch data from a URL with optional request options. Will use the cache that is already set in the instance.
231
- *
232
- * When `httpCachePolicy` is enabled (default), cache entries will have their TTL
233
- * set based on HTTP cache headers (e.g., Cache-Control: max-age). When disabled,
234
- * the default TTL from the Cacheable instance is used.
235
- *
236
- * @param {string} url The URL to fetch.
237
- * @param {Omit<FetchOptions, "cache">} options Optional request options.
238
- * @returns {Promise<FetchResponse>} The response from the fetch.
239
- */
240
- fetch(url: string, options?: Omit<FetchOptions, "cache">): Promise<Response>;
241
- /**
242
- * Perform a GET request to a URL with optional request options. By default caching is enabled on all requests. To
243
- * disable set `options.caching` to false.
244
- * @param {string} url The URL to fetch.
245
- * @param {NetFetchOptions} options Optional request options (method will be set to GET).
246
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
247
- */
248
- get<T = unknown>(url: string, options?: NetFetchOptions): Promise<DataResponse<T>>;
249
- /**
250
- * Perform a POST request to a URL with data and optional request options. By default caching is not enabled. To enable it
251
- * set `options.caching` to true. Note, setting caching to tru means it will not post if the data is the same.
252
- * @param {string} url The URL to fetch.
253
- * @param {unknown} data The data to send in the request body.
254
- * @param {Omit<NetFetchOptions, "method" | "body" >} options Optional request options (method and body will be set).
255
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
256
- */
257
- post<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
258
- /**
259
- * Perform a HEAD request to a URL with optional request options. By default caching is enabled on all requests. To
260
- * disable set `options.caching` to false.
261
- * @param {string} url The URL to fetch.
262
- * @param {NetFetchOptions} options Optional request options (method will be set to HEAD).
263
- * @returns {Promise<FetchResponse>} The response from the fetch (no body).
264
- */
265
- head(url: string, options?: NetFetchOptions): Promise<Response>;
266
- /**
267
- * Perform a PUT request to a URL with data and optional request options. By default caching is not enabled. To enable it
268
- * set `options.caching` to true. Note, setting caching to true means it will not put if the data is the same.
269
- * @param {string} url The URL to fetch.
270
- * @param {unknown} data The data to send in the request body.
271
- * @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
272
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
273
- */
274
- put<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
275
- /**
276
- * Perform a PATCH request to a URL with data and optional request options. By default caching is not enabled. To enable it
277
- * set `options.caching` to true. Note, setting caching to true means it will not patch if the data is the same.
278
- * @param {string} url The URL to fetch.
279
- * @param {unknown} data The data to send in the request body.
280
- * @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
281
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
282
- */
283
- patch<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
284
- /**
285
- * Perform a DELETE request to a URL with optional data and request options. By default caching is not enabled. To enable it
286
- * set `options.caching` to true. Note, setting caching to true means it will not delete if the data is the same.
287
- * @param {string} url The URL to fetch.
288
- * @param {unknown} data Optional data to send in the request body.
289
- * @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
290
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
291
- */
292
- delete<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
293
- /**
294
- * Sets the Content-Type header if not already set.
295
- * Checks both "Content-Type" and "content-type" to handle case variations.
296
- * @param headers - The headers object to modify
297
- * @param contentType - The content type to set (defaults to "application/json")
298
- * @private
299
- */
300
- private setContentType;
358
+ private _cache;
359
+ private _httpCachePolicy;
360
+ private _stringify;
361
+ private _parse;
362
+ constructor(options?: CacheableNetOptions);
363
+ /**
364
+ * Get the stringify function used for converting objects to strings.
365
+ * @returns {StringifyType} The current stringify function
366
+ */
367
+ get stringify(): StringifyType;
368
+ /**
369
+ * Set the stringify function for converting objects to strings.
370
+ * @param {StringifyType} value - The stringify function to use
371
+ */
372
+ set stringify(value: StringifyType);
373
+ /**
374
+ * Get the parse function used for converting strings to objects.
375
+ * @returns {ParseType} The current parse function
376
+ */
377
+ get parse(): ParseType;
378
+ /**
379
+ * Set the parse function for converting strings to objects.
380
+ * @param {ParseType} value - The parse function to use
381
+ */
382
+ set parse(value: ParseType);
383
+ /**
384
+ * Get the Cacheable instance used for caching fetch operations.
385
+ * @returns {Cacheable} The current Cacheable instance
386
+ */
387
+ get cache(): Cacheable;
388
+ /**
389
+ * Set the Cacheable instance for caching fetch operations.
390
+ * @param {Cacheable} value - The Cacheable instance to use for caching
391
+ */
392
+ set cache(value: Cacheable);
393
+ /**
394
+ * Get the current HTTP cache policy setting.
395
+ * @returns {boolean} Whether HTTP cache semantics are enabled
396
+ */
397
+ get httpCachePolicy(): boolean;
398
+ /**
399
+ * Set whether to use HTTP cache semantics.
400
+ * @param {boolean} value - Enable or disable HTTP cache semantics
401
+ */
402
+ set httpCachePolicy(value: boolean);
403
+ /**
404
+ * Fetch data from a URL with optional request options. Will use the cache that is already set in the instance.
405
+ *
406
+ * When `httpCachePolicy` is enabled (default), cache entries will have their TTL
407
+ * set based on HTTP cache headers (e.g., Cache-Control: max-age). When disabled,
408
+ * the default TTL from the Cacheable instance is used.
409
+ *
410
+ * @param {string} url The URL to fetch.
411
+ * @param {Omit<FetchOptions, "cache">} options Optional request options.
412
+ * @returns {Promise<FetchResponse>} The response from the fetch.
413
+ */
414
+ fetch(url: string, options?: Omit<FetchOptions, "cache">): Promise<Response>;
415
+ /**
416
+ * Perform a GET request to a URL with optional request options. By default caching is enabled on all requests. To
417
+ * disable set `options.caching` to false.
418
+ * @param {string} url The URL to fetch.
419
+ * @param {NetFetchOptions} options Optional request options (method will be set to GET).
420
+ * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
421
+ */
422
+ get<T = unknown>(url: string, options?: NetFetchOptions): Promise<DataResponse<T>>;
423
+ /**
424
+ * Perform a POST request to a URL with data and optional request options. By default caching is not enabled. To enable it
425
+ * set `options.caching` to true. Note, setting caching to tru means it will not post if the data is the same.
426
+ * @param {string} url The URL to fetch.
427
+ * @param {unknown} data The data to send in the request body.
428
+ * @param {Omit<NetFetchOptions, "method" | "body" >} options Optional request options (method and body will be set).
429
+ * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
430
+ */
431
+ post<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
432
+ /**
433
+ * Perform a HEAD request to a URL with optional request options. By default caching is enabled on all requests. To
434
+ * disable set `options.caching` to false.
435
+ * @param {string} url The URL to fetch.
436
+ * @param {NetFetchOptions} options Optional request options (method will be set to HEAD).
437
+ * @returns {Promise<FetchResponse>} The response from the fetch (no body).
438
+ */
439
+ head(url: string, options?: NetFetchOptions): Promise<Response>;
440
+ /**
441
+ * Perform a PUT request to a URL with data and optional request options. By default caching is not enabled. To enable it
442
+ * set `options.caching` to true. Note, setting caching to true means it will not put if the data is the same.
443
+ * @param {string} url The URL to fetch.
444
+ * @param {unknown} data The data to send in the request body.
445
+ * @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
446
+ * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
447
+ */
448
+ put<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
449
+ /**
450
+ * Perform a PATCH request to a URL with data and optional request options. By default caching is not enabled. To enable it
451
+ * set `options.caching` to true. Note, setting caching to true means it will not patch if the data is the same.
452
+ * @param {string} url The URL to fetch.
453
+ * @param {unknown} data The data to send in the request body.
454
+ * @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
455
+ * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
456
+ */
457
+ patch<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
458
+ /**
459
+ * Perform a DELETE request to a URL with optional data and request options. By default caching is not enabled. To enable it
460
+ * set `options.caching` to true. Note, setting caching to true means it will not delete if the data is the same.
461
+ * @param {string} url The URL to fetch.
462
+ * @param {unknown} data Optional data to send in the request body.
463
+ * @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
464
+ * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
465
+ */
466
+ delete<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
467
+ /**
468
+ * Perform a WHOIS lookup for a domain, IP address, or ASN, returning both the
469
+ * raw text and parsed JSON fields. Uses the instance cache so repeated lookups
470
+ * are served from cache and concurrent identical lookups are coalesced. To
471
+ * disable caching for a single lookup, set `options.caching` to false.
472
+ * @param {string} query The domain, URL, IP address, or ASN to look up.
473
+ * @param {WhoisOptions} options Optional lookup options.
474
+ * @returns {Promise<WhoisResult>} The raw text and parsed fields.
475
+ */
476
+ whois(query: string, options?: WhoisOptions): Promise<WhoisResult>;
477
+ /**
478
+ * Perform an RDAP lookup for a domain, IP address, or ASN, returning both the
479
+ * raw JSON text and the parsed object. Uses the instance cache so repeated
480
+ * lookups are served from cache and concurrent identical lookups are
481
+ * coalesced. To disable caching for a single lookup, set `options.caching` to
482
+ * false.
483
+ * @param {string} query The domain, URL, IP address, or ASN to look up.
484
+ * @param {RdapOptions} options Optional lookup options.
485
+ * @returns {Promise<RdapResult>} The raw JSON text and parsed data.
486
+ */
487
+ rdap(query: string, options?: RdapOptions): Promise<RdapResult>;
488
+ /**
489
+ * Sets the Content-Type header if not already set.
490
+ * Checks both "Content-Type" and "content-type" to handle case variations.
491
+ * @param headers - The headers object to modify
492
+ * @param contentType - The content type to set (defaults to "application/json")
493
+ * @private
494
+ */
495
+ private setContentType;
301
496
  }
302
497
  declare const Net: typeof CacheableNet;
303
-
304
- export { CacheableNet, type CacheableNetOptions, type DataResponse, type FetchOptions, type Response as FetchResponse, type GetResponse, Net, type NetFetchOptions, type ParseType, type StringifyType, del, fetch, get, head, patch, post };
498
+ //#endregion
499
+ export { CacheableNet, CacheableNetOptions, type DataResponse, type FetchOptions, type FetchRequestInit, type Response as FetchResponse, type GetResponse, Net, NetFetchOptions, ParseType, type QueryWhoisServerOptions, type RdapOptions, type RdapResult, StringifyType, type WhoisFields, type WhoisHop, type WhoisOptions, type WhoisQueryType, type WhoisResult, del, detectQueryType, fetch, get, head, normalizeWhoisQuery, parseWhois, patch, post, queryWhoisServer, rdap, whois, whoisRaw };