@cacheable/net 2.0.7 → 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/README.md +578 -72
- package/dist/index.cjs +1309 -699
- package/dist/index.d.cts +420 -225
- package/dist/index.d.mts +499 -0
- package/dist/index.mjs +1291 -0
- package/package.json +17 -11
- package/dist/index.d.ts +0 -304
- package/dist/index.js +0 -679
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import { Cacheable, CacheableOptions } from "cacheable";
|
|
2
|
+
import { Hookified, HookifiedOptions } from "hookified";
|
|
3
|
+
import { RequestInit, RequestInit as FetchRequestInit, Response as Response$1 } from "undici";
|
|
4
|
+
|
|
5
|
+
//#region src/fetch.d.ts
|
|
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;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Fetch data from a URL with optional request options.
|
|
34
|
+
*
|
|
35
|
+
* When `httpCachePolicy` is enabled (default), cache entries will have their TTL
|
|
36
|
+
* set based on HTTP cache headers (e.g., Cache-Control: max-age). When disabled,
|
|
37
|
+
* the default TTL from the Cacheable instance is used.
|
|
38
|
+
*
|
|
39
|
+
* If no cache is provided, the request will be made without any caching.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} url The URL to fetch.
|
|
42
|
+
* @param {FetchOptions} options Optional request options. If `cache` is not provided, no caching will be used.
|
|
43
|
+
* @returns {Promise<UndiciResponse>} The response from the fetch.
|
|
44
|
+
*/
|
|
45
|
+
declare function fetch(url: string, options?: FetchOptions): Promise<Response$1>;
|
|
46
|
+
type DataResponse<T = unknown> = {
|
|
47
|
+
data: T;
|
|
48
|
+
response: Response$1;
|
|
49
|
+
};
|
|
50
|
+
type GetResponse<T = unknown> = DataResponse<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Perform a GET request to a URL with optional request options.
|
|
53
|
+
* @param {string} url The URL to fetch.
|
|
54
|
+
* @param {Omit<FetchOptions, 'method'>} options Optional request options. The `cache` property is required.
|
|
55
|
+
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
56
|
+
*/
|
|
57
|
+
declare function get<T = unknown>(url: string, options: Omit<FetchOptions, "method">): Promise<DataResponse<T>>;
|
|
58
|
+
/**
|
|
59
|
+
* Perform a POST request to a URL with data and optional request options.
|
|
60
|
+
* @param {string} url The URL to fetch.
|
|
61
|
+
* @param {unknown} data The data to send in the request body.
|
|
62
|
+
* @param {Omit<FetchOptions, 'method' | 'body'>} options Optional request options. The `cache` property is required.
|
|
63
|
+
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
64
|
+
*/
|
|
65
|
+
declare function post<T = unknown>(url: string, data: unknown, options: Omit<FetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
66
|
+
/**
|
|
67
|
+
* Perform a PATCH request to a URL with data and optional request options.
|
|
68
|
+
* @param {string} url The URL to fetch.
|
|
69
|
+
* @param {unknown} data The data to send in the request body.
|
|
70
|
+
* @param {Omit<FetchOptions, 'method' | 'body'>} options Optional request options. The `cache` property is required.
|
|
71
|
+
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
72
|
+
*/
|
|
73
|
+
declare function patch<T = unknown>(url: string, data: unknown, options: Omit<FetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
74
|
+
/**
|
|
75
|
+
* Perform a DELETE request to a URL with optional data and request options.
|
|
76
|
+
* @param {string} url The URL to fetch.
|
|
77
|
+
* @param {unknown} data Optional data to send in the request body.
|
|
78
|
+
* @param {Omit<FetchOptions, 'method' | 'body'>} options Optional request options. The `cache` property is required.
|
|
79
|
+
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
80
|
+
*/
|
|
81
|
+
declare function del<T = unknown>(url: string, data?: unknown, options?: Omit<FetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
82
|
+
/**
|
|
83
|
+
* Perform a HEAD request to a URL with optional request options.
|
|
84
|
+
* @param {string} url The URL to fetch.
|
|
85
|
+
* @param {Omit<FetchOptions, 'method'>} options Optional request options. The `cache` property is required.
|
|
86
|
+
* @returns {Promise<UndiciResponse>} The response from the fetch (no body).
|
|
87
|
+
*/
|
|
88
|
+
declare function head(url: string, options: Omit<FetchOptions, "method">): Promise<Response$1>;
|
|
89
|
+
type Response = Response$1;
|
|
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
|
|
265
|
+
type NetFetchOptions = {
|
|
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;
|
|
290
|
+
} & Omit<FetchOptions, "method" | "cache">;
|
|
291
|
+
type CacheableNetOptions = {
|
|
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;
|
|
342
|
+
} & HookifiedOptions;
|
|
343
|
+
/**
|
|
344
|
+
* Function type for converting JavaScript values to strings.
|
|
345
|
+
* Used for serializing request bodies and data.
|
|
346
|
+
* @param value - The JavaScript value to stringify
|
|
347
|
+
* @returns The string representation of the value
|
|
348
|
+
*/
|
|
349
|
+
type StringifyType = (value: unknown) => string;
|
|
350
|
+
/**
|
|
351
|
+
* Function type for parsing strings back to JavaScript values.
|
|
352
|
+
* Used for deserializing response bodies.
|
|
353
|
+
* @param value - The string to parse
|
|
354
|
+
* @returns The parsed JavaScript value
|
|
355
|
+
*/
|
|
356
|
+
type ParseType = (value: string) => unknown;
|
|
357
|
+
declare class CacheableNet extends Hookified {
|
|
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;
|
|
496
|
+
}
|
|
497
|
+
declare const Net: typeof CacheableNet;
|
|
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 };
|