@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/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@cacheable/net",
3
- "version": "2.0.8",
4
- "description": "High Performance Network Caching for Node.js with fetch, request, http 1.1, and http 2 support",
3
+ "version": "2.1.0",
4
+ "description": "High Performance Network Caching for Node.js with fetch, http 1.1, http 2, and cached WHOIS and RDAP lookups",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.mts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/index.js"
12
+ "types": "./dist/index.d.mts",
13
+ "default": "./dist/index.mjs"
14
14
  },
15
15
  "require": {
16
16
  "types": "./dist/index.d.cts",
@@ -21,21 +21,22 @@
21
21
  "repository": {
22
22
  "type": "git",
23
23
  "url": "git+https://github.com/jaredwray/cacheable.git",
24
- "directory": "packages/cacheable"
24
+ "directory": "packages/net"
25
25
  },
26
26
  "author": "Jared Wray <me@jaredwray.com>",
27
27
  "license": "MIT",
28
28
  "private": false,
29
29
  "devDependencies": {
30
30
  "@types/http-cache-semantics": "^4.2.0",
31
- "tsup": "^8.5.1",
31
+ "tsdown": "^0.22.0",
32
32
  "typescript": "^5.9.3"
33
33
  },
34
34
  "dependencies": {
35
35
  "hookified": "^1.15.1",
36
36
  "http-cache-semantics": "^4.2.0",
37
37
  "undici": "^7.24.5",
38
- "cacheable": "^2.3.5"
38
+ "@cacheable/utils": "^2.5.0",
39
+ "cacheable": "^2.5.0"
39
40
  },
40
41
  "keywords": [
41
42
  "cacheable",
@@ -46,6 +47,11 @@
46
47
  "http 2 caching",
47
48
  "dns caching",
48
49
  "whois caching",
50
+ "whois",
51
+ "rdap",
52
+ "whois lookup",
53
+ "rdap lookup",
54
+ "domain lookup",
49
55
  "high performance",
50
56
  "layer 1 caching",
51
57
  "layer 2 caching",
@@ -69,7 +75,7 @@
69
75
  "LICENSE"
70
76
  ],
71
77
  "scripts": {
72
- "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
78
+ "build": "rimraf ./dist && tsdown src/index.ts --format cjs,esm --dts --clean",
73
79
  "lint": "biome check --write --error-on-warnings",
74
80
  "test": "pnpm lint && TEST_URL=http://localhost:3737 vitest run --coverage",
75
81
  "test:ci": "biome check --error-on-warnings && TEST_URL=http://localhost:3737 vitest run --coverage",
package/dist/index.d.ts DELETED
@@ -1,304 +0,0 @@
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';
5
-
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
-
91
- 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;
116
- } & Omit<FetchOptions, "method" | "cache">;
117
- 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;
168
- } & HookifiedOptions;
169
- /**
170
- * Function type for converting JavaScript values to strings.
171
- * Used for serializing request bodies and data.
172
- * @param value - The JavaScript value to stringify
173
- * @returns The string representation of the value
174
- */
175
- type StringifyType = (value: unknown) => string;
176
- /**
177
- * Function type for parsing strings back to JavaScript values.
178
- * Used for deserializing response bodies.
179
- * @param value - The string to parse
180
- * @returns The parsed JavaScript value
181
- */
182
- type ParseType = (value: string) => unknown;
183
- 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;
301
- }
302
- 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 };