@nxtedition/nxt-undici 7.3.0 → 7.3.2

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