@nxtedition/nxt-undici 7.3.0 → 7.3.1

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.
Files changed (2) hide show
  1. package/lib/index.d.ts +247 -13
  2. package/package.json +1 -1
package/lib/index.d.ts CHANGED
@@ -1,18 +1,252 @@
1
- import type { Dispatcher } from 'undici-types'
2
- import type { Logger } from 'pino'
1
+ import type { Readable } from 'node:stream'
3
2
 
4
- export type Headers =
5
- | Record<string, string | string[] | null | undefined>
6
- | (Buffer | string | (Buffer | string)[])[]
3
+ export interface URLObject {
4
+ origin?: string | null
5
+ path?: string | null
6
+ host?: string | null
7
+ hostname?: string | null
8
+ port?: string | number | null
9
+ protocol?: string | null
10
+ pathname?: string | null
11
+ search?: string | null
12
+ }
13
+
14
+ export type URLLike = string | URL | URLObject
15
+
16
+ export interface Dispatcher {
17
+ dispatch(opts: object, handler: DispatchHandler): void
18
+ }
19
+
20
+ export interface DispatchHandler {
21
+ onConnect?(abort: (reason?: Error) => void): void
22
+ onHeaders?(
23
+ statusCode: number,
24
+ headers: Record<string, string | string[]>,
25
+ resume: () => void,
26
+ ): boolean | void
27
+ onData?(chunk: Buffer): boolean | void
28
+ onComplete?(trailers?: Record<string, string | string[]>): void
29
+ onError?(err: Error): void
30
+ onUpgrade?(
31
+ statusCode: number,
32
+ headers: Record<string, string | string[]>,
33
+ socket: import('node:net').Socket,
34
+ ): void
35
+ }
36
+
37
+ export type DispatchFn = (opts: DispatchOptions, handler: DispatchHandler) => void | Promise<void>
38
+
39
+ export type Interceptor = (dispatch: DispatchFn) => DispatchFn
40
+
41
+ export interface LoggerLike {
42
+ child(bindings: Record<string, unknown>): LoggerLike
43
+ debug(obj: unknown, msg?: string): void
44
+ error(obj: unknown, msg?: string): void
45
+ warn(obj: unknown, msg?: string): void
46
+ info(obj: unknown, msg?: string): void
47
+ }
48
+
49
+ export interface DispatchOptions {
50
+ id?: string | null
51
+ origin?: string | null
52
+ path?: string | null
53
+ method?: string | null
54
+ body?:
55
+ | Readable
56
+ | Uint8Array
57
+ | string
58
+ | ((signal: AbortSignal) => Readable | Uint8Array | string | Iterable<unknown>)
59
+ | null
60
+ query?: Record<string, unknown> | null
61
+ headers?: Record<string, string | string[] | null | undefined> | null
62
+ signal?: AbortSignal | null
63
+ reset?: boolean | null
64
+ blocking?: boolean | null
65
+ timeout?: number | { headers?: number | null; body?: number | null } | null
66
+ headersTimeout?: number | null
67
+ bodyTimeout?: number | null
68
+ idempotent?: boolean | null
69
+ typeOfService?: number | null
70
+ retry?: RetryOptions | number | boolean | RetryFn | null
71
+ proxy?: ProxyOptions | boolean | null
72
+ cache?: CacheOptions | boolean | null
73
+ upgrade?: boolean | null
74
+ follow?: number | FollowFn | boolean | null
75
+ error?: boolean | null
76
+ verify?: VerifyOptions | boolean | null
77
+ logger?: LoggerLike | null
78
+ dns?: DnsOptions | boolean | null
79
+ connect?: Record<string, unknown> | null
80
+ priority?:
81
+ | 0
82
+ | 1
83
+ | 2
84
+ | 'low'
85
+ | 'normal'
86
+ | 'high'
87
+ | 'lower'
88
+ | 'lowest'
89
+ | 'higher'
90
+ | 'highest'
91
+ | null
92
+ lookup?: LookupFn | null
93
+ }
7
94
 
8
- export interface NxtUndiciRequestInit extends RequestInit {
9
- headers?: Headers
10
- throwOnError?: boolean
11
- logger?: Logger
95
+ export interface RetryOptions {
96
+ count?: number
97
+ retry?: RetryFn
98
+ }
99
+
100
+ export type RetryFn = (
101
+ err: Error,
102
+ retryCount: number,
103
+ opts: DispatchOptions,
104
+ defaultRetryFn: () => Promise<boolean>,
105
+ ) => boolean | Promise<boolean>
106
+
107
+ export type FollowFn = (location: string, count: number, opts: DispatchOptions) => boolean
108
+
109
+ export type LookupFn = (
110
+ origin: string | URLLike | Array<string | URLLike>,
111
+ opts: { signal?: AbortSignal },
112
+ callback: (err: Error | null, address: string | null) => void,
113
+ ) => void | Promise<string>
114
+
115
+ export interface ProxyOptions {
116
+ httpVersion?: string
117
+ socket?: import('node:net').Socket
118
+ name?: string
119
+ req?: import('node:http').IncomingMessage
120
+ }
121
+
122
+ export interface CacheOptions {
123
+ store?: CacheStore
124
+ maxEntrySize?: number
125
+ }
126
+
127
+ export interface VerifyOptions {
128
+ hash?: boolean
129
+ size?: boolean
130
+ }
131
+
132
+ export interface DnsOptions {
133
+ ttl?: number
134
+ balance?: 'hash'
135
+ }
136
+
137
+ export interface LogInterceptorOptions {
138
+ bindings?: Record<string, unknown>
139
+ }
140
+
141
+ export interface CacheKey {
142
+ origin: string
143
+ method: string
144
+ path: string
145
+ headers?: Record<string, string | string[] | null | undefined>
146
+ }
147
+
148
+ export interface CacheValue {
149
+ statusCode: number
150
+ statusMessage: string
151
+ headers?: Record<string, string | string[]>
152
+ body: Uint8Array | null
153
+ start: number
154
+ end: number
155
+ cacheControlDirectives?: Record<string, unknown>
156
+ etag?: string
157
+ vary?: Record<string, string | string[]>
158
+ cachedAt: number
159
+ staleAt: number
160
+ deleteAt?: number
161
+ }
162
+
163
+ export interface CacheGetResult {
164
+ statusCode: number
165
+ statusMessage: string
166
+ headers?: Record<string, string | string[]>
167
+ body?: Buffer
168
+ etag?: string
169
+ cacheControlDirectives?: Record<string, unknown>
170
+ vary?: Record<string, string | string[]>
171
+ cachedAt: number
172
+ staleAt: number
173
+ deleteAt: number
174
+ }
175
+
176
+ export interface CacheStore {
177
+ get(key: CacheKey): CacheGetResult | undefined
178
+ set(
179
+ key: CacheKey,
180
+ value: CacheValue & { body: null | Buffer | Buffer[]; start: number; end: number },
181
+ ): void
182
+ purgeStale(): void
183
+ close(): void
184
+ }
185
+
186
+ export interface RequestOptions extends DispatchOptions {
187
+ url?: URLLike | null
188
+ dispatch?: DispatchFn | null
189
+ dispatcher?: Dispatcher | null
190
+ }
191
+
192
+ export interface ResponseData {
193
+ statusCode: number
194
+ headers: Record<string, string | string[] | undefined>
195
+ body: Readable
12
196
  }
13
197
 
14
- export function request(options: NxtUndiciRequestInit): Promise<Dispatcher.ResponseData>
15
198
  export function request(
16
- url: string | URL,
17
- options?: NxtUndiciRequestInit,
18
- ): Promise<Dispatcher.ResponseData>
199
+ urlOrOpts: URLLike | RequestOptions,
200
+ opts?: RequestOptions | null,
201
+ ): Promise<ResponseData>
202
+
203
+ export function dispatch(
204
+ dispatcher: Dispatcher,
205
+ opts: DispatchOptions,
206
+ handler: DispatchHandler,
207
+ ): void | Promise<void>
208
+
209
+ export function compose(
210
+ dispatcherOrInterceptor: Dispatcher | DispatchFn | Interceptor,
211
+ ...interceptors: (Interceptor | null | undefined)[]
212
+ ): DispatchFn
213
+
214
+ export function parseHeaders(
215
+ headers:
216
+ | Record<string, string | string[] | null | undefined>
217
+ | (Buffer | string | (Buffer | string)[])[],
218
+ obj?: Record<string, string | string[]>,
219
+ ): Record<string, string | string[]>
220
+
221
+ export const interceptors: {
222
+ query: () => Interceptor
223
+ requestBodyFactory: () => Interceptor
224
+ responseError: () => Interceptor
225
+ responseRetry: () => Interceptor
226
+ responseVerify: () => Interceptor
227
+ log: (opts?: LogInterceptorOptions) => Interceptor
228
+ redirect: () => Interceptor
229
+ proxy: () => Interceptor
230
+ cache: () => Interceptor
231
+ requestId: () => Interceptor
232
+ dns: () => Interceptor
233
+ lookup: () => Interceptor
234
+ priority: () => Interceptor
235
+ }
236
+
237
+ export const cache: {
238
+ SqliteCacheStore: typeof SqliteCacheStore
239
+ }
240
+
241
+ export class SqliteCacheStore implements CacheStore {
242
+ constructor(opts?: { location?: string; db?: Record<string, unknown>; maxSize?: number })
243
+ get(key: CacheKey): CacheGetResult | undefined
244
+ set(
245
+ key: CacheKey,
246
+ value: CacheValue & { body: null | Buffer | Buffer[]; start: number; end: number },
247
+ ): void
248
+ purgeStale(): void
249
+ close(): void
250
+ }
251
+
252
+ export { Client, Pool, Agent, getGlobalDispatcher, setGlobalDispatcher } from '@nxtedition/undici'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "7.3.0",
3
+ "version": "7.3.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",