@nxtedition/nxt-undici 7.4.1 → 7.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -55,17 +55,25 @@ export interface LoggerLike {
55
55
  info(obj: unknown, msg?: string): void
56
56
  }
57
57
 
58
+ export type BodyFactoryResult =
59
+ | Readable
60
+ | Uint8Array
61
+ | string
62
+ | Iterable<unknown>
63
+ | AsyncIterable<unknown>
64
+
65
+ /** Called with an options object (not a bare signal); the signal aborts when the
66
+ * request is destroyed before the factory resolves. May be async. */
67
+ export type BodyFactory = (opts: {
68
+ signal: AbortSignal
69
+ }) => BodyFactoryResult | Promise<BodyFactoryResult>
70
+
58
71
  export interface DispatchOptions {
59
72
  id?: string | null
60
73
  origin?: string | null
61
74
  path?: string | null
62
75
  method?: string | null
63
- body?:
64
- | Readable
65
- | Uint8Array
66
- | string
67
- | ((signal: AbortSignal) => Readable | Uint8Array | string | Iterable<unknown>)
68
- | null
76
+ body?: Readable | Uint8Array | string | BodyFactory | null
69
77
  query?: Record<string, unknown> | null
70
78
  headers?: Record<string, string | string[] | null | undefined> | null
71
79
  signal?: AbortSignal | null
@@ -80,8 +88,13 @@ export interface DispatchOptions {
80
88
  retry?: RetryOptions | number | boolean | RetryFn | null
81
89
  proxy?: ProxyOptions | boolean | null
82
90
  cache?: CacheOptions | boolean | null
83
- upgrade?: boolean | null
91
+ /** Protocol to upgrade to (e.g. 'websocket'). undici requires a string and the
92
+ * dispatch handler must implement onUpgrade — only meaningful with raw
93
+ * dispatch()/compose(); request() has no upgrade support (see RequestOptions). */
94
+ upgrade?: string | null
84
95
  follow?: number | FollowFn | boolean | null
96
+ /** Alias for `follow`; ignored when `follow` is also set. */
97
+ redirect?: number | FollowFn | boolean | null
85
98
  error?: boolean | null
86
99
  verify?: VerifyOptions | boolean | null
87
100
  logger?: LoggerLike | null
@@ -121,6 +134,15 @@ export interface ProxyOptions {
121
134
  export interface CacheOptions {
122
135
  store?: CacheStore
123
136
  maxEntrySize?: number
137
+ /** Upper bound on an entry's freshness lifetime AND retention, in seconds
138
+ * (default 30 days). */
139
+ maxEntryTTL?: number
140
+ /** Opt-in RFC 9111 §4.2.2 heuristic freshness (10% of time since
141
+ * Last-Modified) for 200 responses without explicit expiration. */
142
+ heuristic?: boolean
143
+ /** Opt-in fallback freshness lifetime in seconds for 200 responses without
144
+ * any expiration information. */
145
+ defaultTTL?: number
124
146
  }
125
147
 
126
148
  export interface VerifyOptions {
@@ -130,7 +152,16 @@ export interface VerifyOptions {
130
152
 
131
153
  export interface DnsOptions {
132
154
  ttl?: number
155
+ /** How long (ms) a failed lookup is negative-cached; requests inside this
156
+ * window fail fast without hitting the resolver again (default 1000). */
157
+ negativeTTL?: number
133
158
  balance?: 'hash'
159
+ /** Custom resolver, `dns.lookup`-compatible (called with `{ all: true }`). */
160
+ lookup?: (
161
+ hostname: string,
162
+ options: { all: boolean },
163
+ callback: (err: Error | null, addresses: { address: string; family: number }[]) => void,
164
+ ) => void
134
165
  }
135
166
 
136
167
  export interface LogInterceptorOptions {
@@ -221,6 +252,8 @@ export interface CacheValue {
221
252
  etag?: string
222
253
  vary?: Record<string, string | string[]>
223
254
  cachedAt: number
255
+ /** Optional on set(): omitting it defaults to deleteAt (staleAt === deleteAt). */
256
+ staleAt?: number
224
257
  deleteAt?: number
225
258
  }
226
259
 
@@ -233,6 +266,7 @@ export interface CacheGetResult {
233
266
  cacheControlDirectives?: Record<string, unknown>
234
267
  vary?: Record<string, string | string[]>
235
268
  cachedAt: number
269
+ staleAt: number
236
270
  deleteAt: number
237
271
  }
238
272
 
@@ -242,15 +276,22 @@ export interface CacheStore {
242
276
  key: CacheKey,
243
277
  value: CacheValue & { body: null | Buffer | Buffer[]; start: number; end: number },
244
278
  ): void
279
+ /** RFC 9111 §4.4 invalidation — optional; the cache interceptor
280
+ * feature-detects it and skips invalidation when absent. */
281
+ delete?(key: CacheKey): void
245
282
  gc(): void
246
283
  clear(): void
247
284
  close(): void
248
285
  }
249
286
 
250
- export interface RequestOptions extends DispatchOptions {
287
+ /** `upgrade` is omitted: request()'s internal handler has no onUpgrade, so any
288
+ * upgrade attempt rejects with InvalidArgumentError — use dispatch() instead. */
289
+ export interface RequestOptions extends Omit<DispatchOptions, 'upgrade'> {
251
290
  url?: URLLike | null
252
291
  dispatch?: DispatchFn | null
253
292
  dispatcher?: Dispatcher | null
293
+ /** highWaterMark for the response body readable (non-negative number). */
294
+ highWaterMark?: number | null
254
295
  }
255
296
 
256
297
  export interface ResponseData {
@@ -310,6 +351,8 @@ export class SqliteCacheStore implements CacheStore {
310
351
  key: CacheKey,
311
352
  value: CacheValue & { body: null | Buffer | Buffer[]; start: number; end: number },
312
353
  ): void
354
+ /** RFC 9111 §4.4: invalidates every stored response for the key's URI. */
355
+ delete(key: CacheKey): void
313
356
  gc(): void
314
357
  clear(): void
315
358
  close(): void
package/lib/index.js CHANGED
@@ -29,6 +29,7 @@ export const cache = {
29
29
  }
30
30
 
31
31
  export { parseHeaders } from './utils.js'
32
+ export { SqliteCacheStore } from './sqlite-cache-store.js'
32
33
  export { Client, Pool, Agent, getGlobalDispatcher, setGlobalDispatcher } from '@nxtedition/undici'
33
34
 
34
35
  function defaultLookup(origin, opts, callback) {