@cacheable/net 1.0.2 → 2.0.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 +156 -13
- package/dist/index.cjs +185 -41
- package/dist/index.d.cts +141 -30
- package/dist/index.d.ts +141 -30
- package/dist/index.js +185 -41
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Cacheable, CacheableOptions } from 'cacheable';
|
|
2
2
|
import { HookifiedOptions, Hookified } from 'hookified';
|
|
3
|
-
import { Response as Response$1
|
|
4
|
-
export { RequestInit as FetchRequestInit } from 'undici';
|
|
3
|
+
import { RequestInit, Response as Response$1 } from 'undici';
|
|
5
4
|
|
|
6
5
|
type FetchOptions = Omit<RequestInit, "cache"> & {
|
|
7
|
-
cache
|
|
6
|
+
cache?: Cacheable;
|
|
8
7
|
/**
|
|
9
8
|
* Enable HTTP cache semantics for intelligent response caching.
|
|
10
9
|
*
|
|
@@ -27,17 +26,19 @@ type FetchOptions = Omit<RequestInit, "cache"> & {
|
|
|
27
26
|
*
|
|
28
27
|
* @default true
|
|
29
28
|
*/
|
|
30
|
-
|
|
29
|
+
httpCachePolicy?: boolean;
|
|
31
30
|
};
|
|
32
31
|
/**
|
|
33
32
|
* Fetch data from a URL with optional request options.
|
|
34
33
|
*
|
|
35
|
-
* When `
|
|
34
|
+
* When `httpCachePolicy` is enabled (default), cache entries will have their TTL
|
|
36
35
|
* set based on HTTP cache headers (e.g., Cache-Control: max-age). When disabled,
|
|
37
36
|
* the default TTL from the Cacheable instance is used.
|
|
38
37
|
*
|
|
38
|
+
* If no cache is provided, the request will be made without any caching.
|
|
39
|
+
*
|
|
39
40
|
* @param {string} url The URL to fetch.
|
|
40
|
-
* @param {FetchOptions} options Optional request options.
|
|
41
|
+
* @param {FetchOptions} options Optional request options. If `cache` is not provided, no caching will be used.
|
|
41
42
|
* @returns {Promise<UndiciResponse>} The response from the fetch.
|
|
42
43
|
*/
|
|
43
44
|
declare function fetch(url: string, options: FetchOptions): Promise<Response$1>;
|
|
@@ -86,7 +87,39 @@ declare function del<T = unknown>(url: string, data?: unknown, options?: Omit<Fe
|
|
|
86
87
|
declare function head(url: string, options: Omit<FetchOptions, "method">): Promise<Response$1>;
|
|
87
88
|
type Response = Response$1;
|
|
88
89
|
|
|
90
|
+
type NetFetchOptions = {
|
|
91
|
+
/**
|
|
92
|
+
* Controls whether caching is enabled for this specific request.
|
|
93
|
+
* - `true`: Enable caching for this request
|
|
94
|
+
* - `false`: Disable caching for this request
|
|
95
|
+
* - `undefined`: Use default caching behavior based on the method (GET/HEAD are cached by default)
|
|
96
|
+
* @default undefined
|
|
97
|
+
*/
|
|
98
|
+
caching?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Custom function for converting JavaScript values to strings for this request.
|
|
101
|
+
* Overrides the instance-level stringify function if provided.
|
|
102
|
+
* @example
|
|
103
|
+
* // Use custom serialization for this request only
|
|
104
|
+
* stringify: (value) => superjson.stringify(value)
|
|
105
|
+
*/
|
|
106
|
+
stringify?: StringifyType;
|
|
107
|
+
/**
|
|
108
|
+
* Custom function for parsing strings back to JavaScript values for this request.
|
|
109
|
+
* Overrides the instance-level parse function if provided.
|
|
110
|
+
* @example
|
|
111
|
+
* // Use custom parsing for this request only
|
|
112
|
+
* parse: (text) => superjson.parse(text)
|
|
113
|
+
*/
|
|
114
|
+
parse?: ParseType;
|
|
115
|
+
} & Omit<FetchOptions, "method" | "cache">;
|
|
89
116
|
type CacheableNetOptions = {
|
|
117
|
+
/**
|
|
118
|
+
* The cache instance or configuration options for caching responses.
|
|
119
|
+
* Can be either an existing Cacheable instance or options to create a new one.
|
|
120
|
+
* If not provided, a default Cacheable instance will be created.
|
|
121
|
+
* @default new Cacheable()
|
|
122
|
+
*/
|
|
90
123
|
cache?: Cacheable | CacheableOptions;
|
|
91
124
|
/**
|
|
92
125
|
* Enable HTTP cache semantics for intelligent response caching.
|
|
@@ -110,75 +143,153 @@ type CacheableNetOptions = {
|
|
|
110
143
|
*
|
|
111
144
|
* @default true
|
|
112
145
|
*/
|
|
113
|
-
|
|
146
|
+
httpCachePolicy?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Custom function for converting JavaScript values to strings.
|
|
149
|
+
* This is used when serializing request bodies for POST, PUT, PATCH, and DELETE methods.
|
|
150
|
+
* Useful for handling complex data types that JSON.stringify doesn't support natively.
|
|
151
|
+
* @default JSON.stringify
|
|
152
|
+
* @example
|
|
153
|
+
* // Using superjson for enhanced serialization
|
|
154
|
+
* stringify: (value) => superjson.stringify(value)
|
|
155
|
+
*/
|
|
156
|
+
stringify?: StringifyType;
|
|
157
|
+
/**
|
|
158
|
+
* Custom function for parsing strings back to JavaScript values.
|
|
159
|
+
* This is used when deserializing response bodies.
|
|
160
|
+
* Should be compatible with the stringify function for proper round-trip serialization.
|
|
161
|
+
* @default JSON.parse
|
|
162
|
+
* @example
|
|
163
|
+
* // Using superjson for enhanced parsing
|
|
164
|
+
* parse: (text) => superjson.parse(text)
|
|
165
|
+
*/
|
|
166
|
+
parse?: ParseType;
|
|
114
167
|
} & HookifiedOptions;
|
|
168
|
+
/**
|
|
169
|
+
* Function type for converting JavaScript values to strings.
|
|
170
|
+
* Used for serializing request bodies and data.
|
|
171
|
+
* @param value - The JavaScript value to stringify
|
|
172
|
+
* @returns The string representation of the value
|
|
173
|
+
*/
|
|
174
|
+
type StringifyType = (value: unknown) => string;
|
|
175
|
+
/**
|
|
176
|
+
* Function type for parsing strings back to JavaScript values.
|
|
177
|
+
* Used for deserializing response bodies.
|
|
178
|
+
* @param value - The string to parse
|
|
179
|
+
* @returns The parsed JavaScript value
|
|
180
|
+
*/
|
|
181
|
+
type ParseType = (value: string) => unknown;
|
|
115
182
|
declare class CacheableNet extends Hookified {
|
|
116
183
|
private _cache;
|
|
117
|
-
private
|
|
184
|
+
private _httpCachePolicy;
|
|
185
|
+
private _stringify;
|
|
186
|
+
private _parse;
|
|
118
187
|
constructor(options?: CacheableNetOptions);
|
|
188
|
+
/**
|
|
189
|
+
* Get the stringify function used for converting objects to strings.
|
|
190
|
+
* @returns {StringifyType} The current stringify function
|
|
191
|
+
*/
|
|
192
|
+
get stringify(): StringifyType;
|
|
193
|
+
/**
|
|
194
|
+
* Set the stringify function for converting objects to strings.
|
|
195
|
+
* @param {StringifyType} value - The stringify function to use
|
|
196
|
+
*/
|
|
197
|
+
set stringify(value: StringifyType);
|
|
198
|
+
/**
|
|
199
|
+
* Get the parse function used for converting strings to objects.
|
|
200
|
+
* @returns {ParseType} The current parse function
|
|
201
|
+
*/
|
|
202
|
+
get parse(): ParseType;
|
|
203
|
+
/**
|
|
204
|
+
* Set the parse function for converting strings to objects.
|
|
205
|
+
* @param {ParseType} value - The parse function to use
|
|
206
|
+
*/
|
|
207
|
+
set parse(value: ParseType);
|
|
208
|
+
/**
|
|
209
|
+
* Get the Cacheable instance used for caching fetch operations.
|
|
210
|
+
* @returns {Cacheable} The current Cacheable instance
|
|
211
|
+
*/
|
|
119
212
|
get cache(): Cacheable;
|
|
213
|
+
/**
|
|
214
|
+
* Set the Cacheable instance for caching fetch operations.
|
|
215
|
+
* @param {Cacheable} value - The Cacheable instance to use for caching
|
|
216
|
+
*/
|
|
120
217
|
set cache(value: Cacheable);
|
|
121
218
|
/**
|
|
122
|
-
* Get the current HTTP cache setting.
|
|
219
|
+
* Get the current HTTP cache policy setting.
|
|
123
220
|
* @returns {boolean} Whether HTTP cache semantics are enabled
|
|
124
221
|
*/
|
|
125
|
-
get
|
|
222
|
+
get httpCachePolicy(): boolean;
|
|
126
223
|
/**
|
|
127
224
|
* Set whether to use HTTP cache semantics.
|
|
128
225
|
* @param {boolean} value - Enable or disable HTTP cache semantics
|
|
129
226
|
*/
|
|
130
|
-
set
|
|
227
|
+
set httpCachePolicy(value: boolean);
|
|
131
228
|
/**
|
|
132
229
|
* Fetch data from a URL with optional request options. Will use the cache that is already set in the instance.
|
|
133
230
|
*
|
|
134
|
-
* When `
|
|
231
|
+
* When `httpCachePolicy` is enabled (default), cache entries will have their TTL
|
|
135
232
|
* set based on HTTP cache headers (e.g., Cache-Control: max-age). When disabled,
|
|
136
233
|
* the default TTL from the Cacheable instance is used.
|
|
137
234
|
*
|
|
138
235
|
* @param {string} url The URL to fetch.
|
|
139
|
-
* @param {
|
|
236
|
+
* @param {Omit<FetchOptions, "cache">} options Optional request options.
|
|
140
237
|
* @returns {Promise<FetchResponse>} The response from the fetch.
|
|
141
238
|
*/
|
|
142
|
-
fetch(url: string, options?:
|
|
239
|
+
fetch(url: string, options?: Omit<FetchOptions, "cache">): Promise<Response>;
|
|
143
240
|
/**
|
|
144
|
-
* Perform a GET request to a URL with optional request options.
|
|
241
|
+
* Perform a GET request to a URL with optional request options. By default caching is enabled on all requests. To
|
|
242
|
+
* disable set `options.caching` to false.
|
|
145
243
|
* @param {string} url The URL to fetch.
|
|
146
|
-
* @param {
|
|
244
|
+
* @param {NetFetchOptions} options Optional request options (method will be set to GET).
|
|
147
245
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
148
246
|
*/
|
|
149
|
-
get<T = unknown>(url: string, options?:
|
|
247
|
+
get<T = unknown>(url: string, options?: NetFetchOptions): Promise<DataResponse<T>>;
|
|
150
248
|
/**
|
|
151
|
-
* Perform a POST request to a URL with data and optional request options.
|
|
249
|
+
* Perform a POST request to a URL with data and optional request options. By default caching is not enabled. To enable it
|
|
250
|
+
* set `options.caching` to true. Note, setting caching to tru means it will not post if the data is the same.
|
|
152
251
|
* @param {string} url The URL to fetch.
|
|
153
252
|
* @param {unknown} data The data to send in the request body.
|
|
154
|
-
* @param {Omit<
|
|
253
|
+
* @param {Omit<NetFetchOptions, "method" | "body" >} options Optional request options (method and body will be set).
|
|
155
254
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
156
255
|
*/
|
|
157
|
-
post<T = unknown>(url: string, data?: unknown, options?: Omit<
|
|
256
|
+
post<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
158
257
|
/**
|
|
159
|
-
* Perform a HEAD request to a URL with optional request options.
|
|
258
|
+
* Perform a HEAD request to a URL with optional request options. By default caching is enabled on all requests. To
|
|
259
|
+
* disable set `options.caching` to false.
|
|
160
260
|
* @param {string} url The URL to fetch.
|
|
161
|
-
* @param {
|
|
261
|
+
* @param {NetFetchOptions} options Optional request options (method will be set to HEAD).
|
|
162
262
|
* @returns {Promise<FetchResponse>} The response from the fetch (no body).
|
|
163
263
|
*/
|
|
164
|
-
head(url: string, options?:
|
|
264
|
+
head(url: string, options?: NetFetchOptions): Promise<Response>;
|
|
265
|
+
/**
|
|
266
|
+
* Perform a PUT request to a URL with data and optional request options. By default caching is not enabled. To enable it
|
|
267
|
+
* set `options.caching` to true. Note, setting caching to true means it will not put if the data is the same.
|
|
268
|
+
* @param {string} url The URL to fetch.
|
|
269
|
+
* @param {unknown} data The data to send in the request body.
|
|
270
|
+
* @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
|
|
271
|
+
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
272
|
+
*/
|
|
273
|
+
put<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
165
274
|
/**
|
|
166
|
-
* Perform a PATCH request to a URL with data and optional request options.
|
|
275
|
+
* Perform a PATCH request to a URL with data and optional request options. By default caching is not enabled. To enable it
|
|
276
|
+
* set `options.caching` to true. Note, setting caching to true means it will not patch if the data is the same.
|
|
167
277
|
* @param {string} url The URL to fetch.
|
|
168
278
|
* @param {unknown} data The data to send in the request body.
|
|
169
|
-
* @param {Omit<
|
|
279
|
+
* @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
|
|
170
280
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
171
281
|
*/
|
|
172
|
-
patch<T = unknown>(url: string, data?: unknown, options?: Omit<
|
|
282
|
+
patch<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
173
283
|
/**
|
|
174
|
-
* Perform a DELETE request to a URL with optional data and request options.
|
|
284
|
+
* Perform a DELETE request to a URL with optional data and request options. By default caching is not enabled. To enable it
|
|
285
|
+
* set `options.caching` to true. Note, setting caching to true means it will not delete if the data is the same.
|
|
175
286
|
* @param {string} url The URL to fetch.
|
|
176
287
|
* @param {unknown} data Optional data to send in the request body.
|
|
177
|
-
* @param {Omit<
|
|
288
|
+
* @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
|
|
178
289
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
179
290
|
*/
|
|
180
|
-
delete<T = unknown>(url: string, data?: unknown, options?: Omit<
|
|
291
|
+
delete<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
181
292
|
}
|
|
182
293
|
declare const Net: typeof CacheableNet;
|
|
183
294
|
|
|
184
|
-
export { CacheableNet, type CacheableNetOptions, type DataResponse, type FetchOptions, type Response as FetchResponse, type GetResponse, Net, del, fetch, get, head, patch, post };
|
|
295
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Cacheable, CacheableOptions } from 'cacheable';
|
|
2
2
|
import { HookifiedOptions, Hookified } from 'hookified';
|
|
3
|
-
import { Response as Response$1
|
|
4
|
-
export { RequestInit as FetchRequestInit } from 'undici';
|
|
3
|
+
import { RequestInit, Response as Response$1 } from 'undici';
|
|
5
4
|
|
|
6
5
|
type FetchOptions = Omit<RequestInit, "cache"> & {
|
|
7
|
-
cache
|
|
6
|
+
cache?: Cacheable;
|
|
8
7
|
/**
|
|
9
8
|
* Enable HTTP cache semantics for intelligent response caching.
|
|
10
9
|
*
|
|
@@ -27,17 +26,19 @@ type FetchOptions = Omit<RequestInit, "cache"> & {
|
|
|
27
26
|
*
|
|
28
27
|
* @default true
|
|
29
28
|
*/
|
|
30
|
-
|
|
29
|
+
httpCachePolicy?: boolean;
|
|
31
30
|
};
|
|
32
31
|
/**
|
|
33
32
|
* Fetch data from a URL with optional request options.
|
|
34
33
|
*
|
|
35
|
-
* When `
|
|
34
|
+
* When `httpCachePolicy` is enabled (default), cache entries will have their TTL
|
|
36
35
|
* set based on HTTP cache headers (e.g., Cache-Control: max-age). When disabled,
|
|
37
36
|
* the default TTL from the Cacheable instance is used.
|
|
38
37
|
*
|
|
38
|
+
* If no cache is provided, the request will be made without any caching.
|
|
39
|
+
*
|
|
39
40
|
* @param {string} url The URL to fetch.
|
|
40
|
-
* @param {FetchOptions} options Optional request options.
|
|
41
|
+
* @param {FetchOptions} options Optional request options. If `cache` is not provided, no caching will be used.
|
|
41
42
|
* @returns {Promise<UndiciResponse>} The response from the fetch.
|
|
42
43
|
*/
|
|
43
44
|
declare function fetch(url: string, options: FetchOptions): Promise<Response$1>;
|
|
@@ -86,7 +87,39 @@ declare function del<T = unknown>(url: string, data?: unknown, options?: Omit<Fe
|
|
|
86
87
|
declare function head(url: string, options: Omit<FetchOptions, "method">): Promise<Response$1>;
|
|
87
88
|
type Response = Response$1;
|
|
88
89
|
|
|
90
|
+
type NetFetchOptions = {
|
|
91
|
+
/**
|
|
92
|
+
* Controls whether caching is enabled for this specific request.
|
|
93
|
+
* - `true`: Enable caching for this request
|
|
94
|
+
* - `false`: Disable caching for this request
|
|
95
|
+
* - `undefined`: Use default caching behavior based on the method (GET/HEAD are cached by default)
|
|
96
|
+
* @default undefined
|
|
97
|
+
*/
|
|
98
|
+
caching?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Custom function for converting JavaScript values to strings for this request.
|
|
101
|
+
* Overrides the instance-level stringify function if provided.
|
|
102
|
+
* @example
|
|
103
|
+
* // Use custom serialization for this request only
|
|
104
|
+
* stringify: (value) => superjson.stringify(value)
|
|
105
|
+
*/
|
|
106
|
+
stringify?: StringifyType;
|
|
107
|
+
/**
|
|
108
|
+
* Custom function for parsing strings back to JavaScript values for this request.
|
|
109
|
+
* Overrides the instance-level parse function if provided.
|
|
110
|
+
* @example
|
|
111
|
+
* // Use custom parsing for this request only
|
|
112
|
+
* parse: (text) => superjson.parse(text)
|
|
113
|
+
*/
|
|
114
|
+
parse?: ParseType;
|
|
115
|
+
} & Omit<FetchOptions, "method" | "cache">;
|
|
89
116
|
type CacheableNetOptions = {
|
|
117
|
+
/**
|
|
118
|
+
* The cache instance or configuration options for caching responses.
|
|
119
|
+
* Can be either an existing Cacheable instance or options to create a new one.
|
|
120
|
+
* If not provided, a default Cacheable instance will be created.
|
|
121
|
+
* @default new Cacheable()
|
|
122
|
+
*/
|
|
90
123
|
cache?: Cacheable | CacheableOptions;
|
|
91
124
|
/**
|
|
92
125
|
* Enable HTTP cache semantics for intelligent response caching.
|
|
@@ -110,75 +143,153 @@ type CacheableNetOptions = {
|
|
|
110
143
|
*
|
|
111
144
|
* @default true
|
|
112
145
|
*/
|
|
113
|
-
|
|
146
|
+
httpCachePolicy?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Custom function for converting JavaScript values to strings.
|
|
149
|
+
* This is used when serializing request bodies for POST, PUT, PATCH, and DELETE methods.
|
|
150
|
+
* Useful for handling complex data types that JSON.stringify doesn't support natively.
|
|
151
|
+
* @default JSON.stringify
|
|
152
|
+
* @example
|
|
153
|
+
* // Using superjson for enhanced serialization
|
|
154
|
+
* stringify: (value) => superjson.stringify(value)
|
|
155
|
+
*/
|
|
156
|
+
stringify?: StringifyType;
|
|
157
|
+
/**
|
|
158
|
+
* Custom function for parsing strings back to JavaScript values.
|
|
159
|
+
* This is used when deserializing response bodies.
|
|
160
|
+
* Should be compatible with the stringify function for proper round-trip serialization.
|
|
161
|
+
* @default JSON.parse
|
|
162
|
+
* @example
|
|
163
|
+
* // Using superjson for enhanced parsing
|
|
164
|
+
* parse: (text) => superjson.parse(text)
|
|
165
|
+
*/
|
|
166
|
+
parse?: ParseType;
|
|
114
167
|
} & HookifiedOptions;
|
|
168
|
+
/**
|
|
169
|
+
* Function type for converting JavaScript values to strings.
|
|
170
|
+
* Used for serializing request bodies and data.
|
|
171
|
+
* @param value - The JavaScript value to stringify
|
|
172
|
+
* @returns The string representation of the value
|
|
173
|
+
*/
|
|
174
|
+
type StringifyType = (value: unknown) => string;
|
|
175
|
+
/**
|
|
176
|
+
* Function type for parsing strings back to JavaScript values.
|
|
177
|
+
* Used for deserializing response bodies.
|
|
178
|
+
* @param value - The string to parse
|
|
179
|
+
* @returns The parsed JavaScript value
|
|
180
|
+
*/
|
|
181
|
+
type ParseType = (value: string) => unknown;
|
|
115
182
|
declare class CacheableNet extends Hookified {
|
|
116
183
|
private _cache;
|
|
117
|
-
private
|
|
184
|
+
private _httpCachePolicy;
|
|
185
|
+
private _stringify;
|
|
186
|
+
private _parse;
|
|
118
187
|
constructor(options?: CacheableNetOptions);
|
|
188
|
+
/**
|
|
189
|
+
* Get the stringify function used for converting objects to strings.
|
|
190
|
+
* @returns {StringifyType} The current stringify function
|
|
191
|
+
*/
|
|
192
|
+
get stringify(): StringifyType;
|
|
193
|
+
/**
|
|
194
|
+
* Set the stringify function for converting objects to strings.
|
|
195
|
+
* @param {StringifyType} value - The stringify function to use
|
|
196
|
+
*/
|
|
197
|
+
set stringify(value: StringifyType);
|
|
198
|
+
/**
|
|
199
|
+
* Get the parse function used for converting strings to objects.
|
|
200
|
+
* @returns {ParseType} The current parse function
|
|
201
|
+
*/
|
|
202
|
+
get parse(): ParseType;
|
|
203
|
+
/**
|
|
204
|
+
* Set the parse function for converting strings to objects.
|
|
205
|
+
* @param {ParseType} value - The parse function to use
|
|
206
|
+
*/
|
|
207
|
+
set parse(value: ParseType);
|
|
208
|
+
/**
|
|
209
|
+
* Get the Cacheable instance used for caching fetch operations.
|
|
210
|
+
* @returns {Cacheable} The current Cacheable instance
|
|
211
|
+
*/
|
|
119
212
|
get cache(): Cacheable;
|
|
213
|
+
/**
|
|
214
|
+
* Set the Cacheable instance for caching fetch operations.
|
|
215
|
+
* @param {Cacheable} value - The Cacheable instance to use for caching
|
|
216
|
+
*/
|
|
120
217
|
set cache(value: Cacheable);
|
|
121
218
|
/**
|
|
122
|
-
* Get the current HTTP cache setting.
|
|
219
|
+
* Get the current HTTP cache policy setting.
|
|
123
220
|
* @returns {boolean} Whether HTTP cache semantics are enabled
|
|
124
221
|
*/
|
|
125
|
-
get
|
|
222
|
+
get httpCachePolicy(): boolean;
|
|
126
223
|
/**
|
|
127
224
|
* Set whether to use HTTP cache semantics.
|
|
128
225
|
* @param {boolean} value - Enable or disable HTTP cache semantics
|
|
129
226
|
*/
|
|
130
|
-
set
|
|
227
|
+
set httpCachePolicy(value: boolean);
|
|
131
228
|
/**
|
|
132
229
|
* Fetch data from a URL with optional request options. Will use the cache that is already set in the instance.
|
|
133
230
|
*
|
|
134
|
-
* When `
|
|
231
|
+
* When `httpCachePolicy` is enabled (default), cache entries will have their TTL
|
|
135
232
|
* set based on HTTP cache headers (e.g., Cache-Control: max-age). When disabled,
|
|
136
233
|
* the default TTL from the Cacheable instance is used.
|
|
137
234
|
*
|
|
138
235
|
* @param {string} url The URL to fetch.
|
|
139
|
-
* @param {
|
|
236
|
+
* @param {Omit<FetchOptions, "cache">} options Optional request options.
|
|
140
237
|
* @returns {Promise<FetchResponse>} The response from the fetch.
|
|
141
238
|
*/
|
|
142
|
-
fetch(url: string, options?:
|
|
239
|
+
fetch(url: string, options?: Omit<FetchOptions, "cache">): Promise<Response>;
|
|
143
240
|
/**
|
|
144
|
-
* Perform a GET request to a URL with optional request options.
|
|
241
|
+
* Perform a GET request to a URL with optional request options. By default caching is enabled on all requests. To
|
|
242
|
+
* disable set `options.caching` to false.
|
|
145
243
|
* @param {string} url The URL to fetch.
|
|
146
|
-
* @param {
|
|
244
|
+
* @param {NetFetchOptions} options Optional request options (method will be set to GET).
|
|
147
245
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
148
246
|
*/
|
|
149
|
-
get<T = unknown>(url: string, options?:
|
|
247
|
+
get<T = unknown>(url: string, options?: NetFetchOptions): Promise<DataResponse<T>>;
|
|
150
248
|
/**
|
|
151
|
-
* Perform a POST request to a URL with data and optional request options.
|
|
249
|
+
* Perform a POST request to a URL with data and optional request options. By default caching is not enabled. To enable it
|
|
250
|
+
* set `options.caching` to true. Note, setting caching to tru means it will not post if the data is the same.
|
|
152
251
|
* @param {string} url The URL to fetch.
|
|
153
252
|
* @param {unknown} data The data to send in the request body.
|
|
154
|
-
* @param {Omit<
|
|
253
|
+
* @param {Omit<NetFetchOptions, "method" | "body" >} options Optional request options (method and body will be set).
|
|
155
254
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
156
255
|
*/
|
|
157
|
-
post<T = unknown>(url: string, data?: unknown, options?: Omit<
|
|
256
|
+
post<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
158
257
|
/**
|
|
159
|
-
* Perform a HEAD request to a URL with optional request options.
|
|
258
|
+
* Perform a HEAD request to a URL with optional request options. By default caching is enabled on all requests. To
|
|
259
|
+
* disable set `options.caching` to false.
|
|
160
260
|
* @param {string} url The URL to fetch.
|
|
161
|
-
* @param {
|
|
261
|
+
* @param {NetFetchOptions} options Optional request options (method will be set to HEAD).
|
|
162
262
|
* @returns {Promise<FetchResponse>} The response from the fetch (no body).
|
|
163
263
|
*/
|
|
164
|
-
head(url: string, options?:
|
|
264
|
+
head(url: string, options?: NetFetchOptions): Promise<Response>;
|
|
265
|
+
/**
|
|
266
|
+
* Perform a PUT request to a URL with data and optional request options. By default caching is not enabled. To enable it
|
|
267
|
+
* set `options.caching` to true. Note, setting caching to true means it will not put if the data is the same.
|
|
268
|
+
* @param {string} url The URL to fetch.
|
|
269
|
+
* @param {unknown} data The data to send in the request body.
|
|
270
|
+
* @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
|
|
271
|
+
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
272
|
+
*/
|
|
273
|
+
put<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
165
274
|
/**
|
|
166
|
-
* Perform a PATCH request to a URL with data and optional request options.
|
|
275
|
+
* Perform a PATCH request to a URL with data and optional request options. By default caching is not enabled. To enable it
|
|
276
|
+
* set `options.caching` to true. Note, setting caching to true means it will not patch if the data is the same.
|
|
167
277
|
* @param {string} url The URL to fetch.
|
|
168
278
|
* @param {unknown} data The data to send in the request body.
|
|
169
|
-
* @param {Omit<
|
|
279
|
+
* @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
|
|
170
280
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
171
281
|
*/
|
|
172
|
-
patch<T = unknown>(url: string, data?: unknown, options?: Omit<
|
|
282
|
+
patch<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
173
283
|
/**
|
|
174
|
-
* Perform a DELETE request to a URL with optional data and request options.
|
|
284
|
+
* Perform a DELETE request to a URL with optional data and request options. By default caching is not enabled. To enable it
|
|
285
|
+
* set `options.caching` to true. Note, setting caching to true means it will not delete if the data is the same.
|
|
175
286
|
* @param {string} url The URL to fetch.
|
|
176
287
|
* @param {unknown} data Optional data to send in the request body.
|
|
177
|
-
* @param {Omit<
|
|
288
|
+
* @param {Omit<NetFetchOptions, 'method' | 'body'>} options Optional request options (method and body will be set).
|
|
178
289
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
179
290
|
*/
|
|
180
|
-
delete<T = unknown>(url: string, data?: unknown, options?: Omit<
|
|
291
|
+
delete<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
181
292
|
}
|
|
182
293
|
declare const Net: typeof CacheableNet;
|
|
183
294
|
|
|
184
|
-
export { CacheableNet, type CacheableNetOptions, type DataResponse, type FetchOptions, type Response as FetchResponse, type GetResponse, Net, del, fetch, get, head, patch, post };
|
|
295
|
+
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 };
|