feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -19,8 +19,8 @@ declare class Dispatcher extends EventEmitter {
connect(options: Dispatcher.ConnectOptions): Promise<Dispatcher.ConnectData>;
connect(options: Dispatcher.ConnectOptions, callback: (err: Error | null, data: Dispatcher.ConnectData) => void): void;
/** Compose a chain of dispatchers */
compose(dispatchers: Dispatcher.DispatcherInterceptor[]): Dispatcher.ComposedDispatcher;
compose(...dispatchers: Dispatcher.DispatcherInterceptor[]): Dispatcher.ComposedDispatcher;
compose(dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher;
compose(...dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher;
/** Performs an HTTP request. */
request(options: Dispatcher.RequestOptions): Promise<Dispatcher.ResponseData>;
request(options: Dispatcher.RequestOptions, callback: (err: Error | null, data: Dispatcher.ResponseData) => void): void;
@@ -97,7 +97,7 @@ declare class Dispatcher extends EventEmitter {
declare namespace Dispatcher {
export interface ComposedDispatcher extends Dispatcher {}
export type DispatcherInterceptor = (dispatch: Dispatcher['dispatch']) => Dispatcher['dispatch'];
export type DispatcherComposeInterceptor = (dispatch: Dispatcher['dispatch']) => Dispatcher['dispatch'];
export interface DispatchOptions {
origin?: string | URL;
path: string;
@@ -217,7 +217,7 @@ declare namespace Dispatcher {
export type StreamFactory = (data: StreamFactoryData) => Writable;
export interface DispatchHandlers {
/** Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. */
onConnect?(abort: () => void): void;
onConnect?(abort: (err?: Error) => void): void;
/** Invoked when an error has occurred. */
onError?(err: Error): void;
/** Invoked when request is upgraded either due to a `Upgrade` header or `CONNECT` method. */

View File

@@ -125,4 +125,25 @@ declare namespace Errors {
name: 'ResponseExceededMaxSizeError';
code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE';
}
export class RequestRetryError extends UndiciError {
constructor (
message: string,
statusCode: number,
headers?: IncomingHttpHeaders | string[] | null,
body?: null | Record<string, any> | string
);
name: 'RequestRetryError';
code: 'UND_ERR_REQ_RETRY';
statusCode: number;
data: {
count: number;
};
headers: Record<string, string | string[]>;
}
export class SecureProxyConnectionError extends UndiciError {
name: 'SecureProxyConnectionError';
code: 'UND_ERR_PRX_TLS';
}
}

View File

@@ -1,4 +1,5 @@
import { MessageEvent, ErrorEvent } from './websocket'
import Dispatcher from './dispatcher'
import {
EventTarget,
@@ -50,12 +51,13 @@ interface EventSource extends EventTarget {
export declare const EventSource: {
prototype: EventSource
new (url: string | URL, init: EventSourceInit): EventSource
new (url: string | URL, init?: EventSourceInit): EventSource
readonly CLOSED: 2
readonly CONNECTING: 0
readonly OPEN: 1
}
interface EventSourceInit {
withCredentials?: boolean
withCredentials?: boolean,
dispatcher?: Dispatcher
}

View File

@@ -85,7 +85,7 @@ export declare class Headers implements SpecIterable<[string, string]> {
readonly keys: () => SpecIterableIterator<string>
readonly values: () => SpecIterableIterator<string>
readonly entries: () => SpecIterableIterator<[string, string]>
readonly [Symbol.iterator]: () => SpecIterator<[string, string]>
readonly [Symbol.iterator]: () => SpecIterableIterator<[string, string]>
}
export type RequestCache =
@@ -163,6 +163,7 @@ export declare class Request extends BodyMixin {
readonly method: string
readonly mode: RequestMode
readonly redirect: RequestRedirect
readonly referrer: string
readonly referrerPolicy: ReferrerPolicy
readonly url: string

View File

@@ -2,7 +2,7 @@
/// <reference types="node" />
import { File } from './file'
import { SpecIterator, SpecIterableIterator } from './fetch'
import { SpecIterableIterator } from './fetch'
/**
* A `string` or `File` that represents a single value from a set of `FormData` key-value pairs.

View File

@@ -14,9 +14,11 @@ import MockPool from'./mock-pool'
import MockAgent from'./mock-agent'
import mockErrors from'./mock-errors'
import ProxyAgent from'./proxy-agent'
import EnvHttpProxyAgent from './env-http-proxy-agent'
import RetryHandler from'./retry-handler'
import RetryAgent from'./retry-agent'
import { request, pipeline, stream, connect, upgrade } from './api'
import interceptors from './interceptors'
export * from './util'
export * from './cookies'
@@ -31,7 +33,7 @@ export * from './content-type'
export * from './cache'
export { Interceptable } from './mock-interceptor'
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, RedirectHandler, DecoratorHandler, RetryHandler, RetryAgent }
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, interceptors, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, EnvHttpProxyAgent, RedirectHandler, DecoratorHandler, RetryHandler, RetryAgent }
export default Undici
declare namespace Undici {
@@ -40,7 +42,7 @@ declare namespace Undici {
var RedirectHandler: typeof import ('./handlers').RedirectHandler
var DecoratorHandler: typeof import ('./handlers').DecoratorHandler
var RetryHandler: typeof import ('./retry-handler').default
var createRedirectInterceptor: typeof import ('./interceptors').createRedirectInterceptor
var createRedirectInterceptor: typeof import ('./interceptors').default.createRedirectInterceptor
var BalancedPool: typeof import('./balanced-pool').default;
var Client: typeof import('./client').default;
var buildConnector: typeof import('./connector').default;
@@ -65,4 +67,5 @@ declare namespace Undici {
var File: typeof import('./file').File;
var FileReader: typeof import('./filereader').FileReader;
var caches: typeof import('./cache').caches;
var interceptors: typeof import('./interceptors').default;
}

View File

@@ -1,5 +1,15 @@
import Dispatcher from "./dispatcher";
import RetryHandler from "./retry-handler";
type RedirectInterceptorOpts = { maxRedirections?: number }
export default Interceptors;
export declare function createRedirectInterceptor (opts: RedirectInterceptorOpts): Dispatcher.DispatchInterceptor
declare namespace Interceptors {
export type DumpInterceptorOpts = { maxSize?: number }
export type RetryInterceptorOpts = RetryHandler.RetryOptions
export type RedirectInterceptorOpts = { maxRedirections?: number }
export function createRedirectInterceptor(opts: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
export function dump(opts?: DumpInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
export function retry(opts?: RetryInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
export function redirect(opts?: RedirectInterceptorOpts): Dispatcher.DispatcherComposeInterceptor
}

View File

@@ -71,11 +71,11 @@ declare namespace MockInterceptor {
export interface MockResponseCallbackOptions {
path: string;
origin: string;
method: string;
body?: BodyInit | Dispatcher.DispatchOptions['body'];
headers: Headers | Record<string, string>;
maxRedirections: number;
headers?: Headers | Record<string, string>;
origin?: string;
body?: BodyInit | Dispatcher.DispatchOptions['body'] | null;
maxRedirections?: number;
}
export type MockResponseDataHandler<TData extends object = object> = (

View File

@@ -1,6 +1,6 @@
{
"name": "undici-types",
"version": "6.13.0",
"version": "6.19.8",
"description": "A stand-alone types package for Undici",
"homepage": "https://undici.nodejs.org",
"bugs": {

View File

@@ -1,7 +1,4 @@
import Agent from './agent'
import buildConnector from './connector';
import Dispatcher from './dispatcher'
import { IncomingHttpHeaders } from './header'
import RetryHandler from './retry-handler'
export default RetryAgent

21
node_modules/undici-types/util.d.ts generated vendored
View File

@@ -8,24 +8,11 @@ export namespace util {
/**
* Receives a header object and returns the parsed value.
* @param headers Header object
* @param obj Object to specify a proxy object. Used to assign parsed values.
* @returns If `obj` is specified, it is equivalent to `obj`.
*/
export function parseHeaders(
headers:
| Record<string, string | string[]>
| (Buffer | string | (Buffer | string)[])[]
): Record<string, string | string[]>;
/**
* Receives a header object and returns the parsed value.
* @param headers Header object
* @param obj Object to specify a proxy object. Used to assign parsed values. But, if `headers` is an object, it is not used.
* @returns If `headers` is an object, it is `headers`. Otherwise, if `obj` is specified, it is equivalent to `obj`.
*/
export function parseHeaders<
H extends
| Record<string, string | string[]>
| (Buffer | string | (Buffer | string)[])[]
>(
headers: H,
obj?: H extends any[] ? Record<string, string | string[]> : never
headers: (Buffer | string | (Buffer | string)[])[],
obj?: Record<string, string | string[]>
): Record<string, string | string[]>;
}

View File

@@ -73,14 +73,14 @@ interface WebidlConverters {
/**
* @see https://webidl.spec.whatwg.org/#es-DOMString
*/
DOMString (V: unknown, opts?: {
DOMString (V: unknown, prefix: string, argument: string, opts?: {
legacyNullToEmptyString: boolean
}): string
/**
* @see https://webidl.spec.whatwg.org/#es-ByteString
*/
ByteString (V: unknown): string
ByteString (V: unknown, prefix: string, argument: string): string
/**
* @see https://webidl.spec.whatwg.org/#es-USVString
@@ -204,7 +204,7 @@ export interface Webidl {
*/
dictionaryConverter (converters: {
key: string,
defaultValue?: unknown,
defaultValue?: () => unknown,
required?: boolean,
converter: (...args: unknown[]) => unknown,
allowedValues?: unknown[]
@@ -218,8 +218,5 @@ export interface Webidl {
converter: Converter<T>
): (V: unknown) => ReturnType<typeof converter> | null
argumentLengthCheck (args: { length: number }, min: number, context: {
header: string
message?: string
}): void
argumentLengthCheck (args: { length: number }, min: number, context: string): void
}