@indra211/exios 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/index.cjs +1463 -0
- package/dist/index.d.cts +31 -0
- package/dist/index.d.ts +233 -0
- package/dist/index.js +1442 -0
- package/package.json +51 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type * as Pkg from './index.js' with { 'resolution-mode': 'import' };
|
|
2
|
+
|
|
3
|
+
declare const exios: Pkg.ExiosDefault & { default: Pkg.ExiosDefault };
|
|
4
|
+
declare namespace exios {
|
|
5
|
+
type BreakerConfig = Pkg.BreakerConfig;
|
|
6
|
+
type BreakerState = Pkg.BreakerState;
|
|
7
|
+
type CanceledError<T = any, D = any> = Pkg.CanceledError<T, D>;
|
|
8
|
+
type CircuitOpenError = Pkg.CircuitOpenError;
|
|
9
|
+
type ExiosDefault = Pkg.ExiosDefault;
|
|
10
|
+
type ExiosDefaults<D = any> = Pkg.ExiosDefaults<D>;
|
|
11
|
+
type ExiosError<T = any, D = any> = Pkg.ExiosError<T, D>;
|
|
12
|
+
type ExiosInstance = Pkg.ExiosInstance;
|
|
13
|
+
type ExiosRequestConfig<D = any> = Pkg.ExiosRequestConfig<D>;
|
|
14
|
+
type ExiosResponse<T = any, D = any> = Pkg.ExiosResponse<T, D>;
|
|
15
|
+
type ExiosStatic = Pkg.ExiosStatic;
|
|
16
|
+
type HeaderValue = Pkg.HeaderValue;
|
|
17
|
+
type HeadersDefaults = Pkg.HeadersDefaults;
|
|
18
|
+
type InterceptorHandler<V> = Pkg.InterceptorHandler<V>;
|
|
19
|
+
type InterceptorManager<V> = Pkg.InterceptorManager<V>;
|
|
20
|
+
type InterceptorOptions = Pkg.InterceptorOptions;
|
|
21
|
+
type InternalConfig<D = any> = Pkg.InternalConfig<D>;
|
|
22
|
+
type Method = Pkg.Method;
|
|
23
|
+
type Outcome = Pkg.Outcome;
|
|
24
|
+
type ProgressEvent = Pkg.ProgressEvent;
|
|
25
|
+
type RawHeaders = Pkg.RawHeaders;
|
|
26
|
+
type RequestBreakerOverride = Pkg.RequestBreakerOverride;
|
|
27
|
+
type ResponseType = Pkg.ResponseType;
|
|
28
|
+
type RetryConfig = Pkg.RetryConfig;
|
|
29
|
+
type Transformer = Pkg.Transformer;
|
|
30
|
+
}
|
|
31
|
+
export = exios;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
declare class ExiosError<T = any, D = any> extends Error {
|
|
2
|
+
static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
|
|
3
|
+
static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
|
|
4
|
+
static readonly ERR_NETWORK = "ERR_NETWORK";
|
|
5
|
+
static readonly ECONNABORTED = "ECONNABORTED";
|
|
6
|
+
static readonly ETIMEDOUT = "ETIMEDOUT";
|
|
7
|
+
static readonly ERR_CANCELED = "ERR_CANCELED";
|
|
8
|
+
static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
|
9
|
+
static readonly ERR_CIRCUIT_OPEN = "ERR_CIRCUIT_OPEN";
|
|
10
|
+
code?: string;
|
|
11
|
+
config?: InternalConfig<D>;
|
|
12
|
+
request?: Request;
|
|
13
|
+
response?: ExiosResponse<T, D>;
|
|
14
|
+
status?: number;
|
|
15
|
+
readonly isExiosError: true;
|
|
16
|
+
meta: {
|
|
17
|
+
attempts: number;
|
|
18
|
+
};
|
|
19
|
+
constructor(message: string, code?: string, config?: InternalConfig<D>, request?: Request, response?: ExiosResponse<T, D>);
|
|
20
|
+
toJSON(): Record<string, unknown>;
|
|
21
|
+
static from<T = any, D = any>(err: unknown, code: string | undefined, config?: InternalConfig<D>, request?: Request, response?: ExiosResponse<T, D>): ExiosError<T, D>;
|
|
22
|
+
}
|
|
23
|
+
declare class CanceledError<T = any, D = any> extends ExiosError<T, D> {
|
|
24
|
+
constructor(message?: string, config?: InternalConfig<D>, request?: Request);
|
|
25
|
+
}
|
|
26
|
+
declare class CircuitOpenError extends ExiosError {
|
|
27
|
+
origin: string;
|
|
28
|
+
retryAt: number;
|
|
29
|
+
constructor(origin: string, retryAt: number, config?: InternalConfig);
|
|
30
|
+
}
|
|
31
|
+
declare function isExiosError(v: unknown): v is ExiosError;
|
|
32
|
+
/** Also true for a canceled error from another copy of the package (dual-package hazard). */
|
|
33
|
+
declare function isCancel(v: unknown): v is CanceledError;
|
|
34
|
+
|
|
35
|
+
type Method = "get" | "post" | "put" | "patch" | "delete" | "head" | "options" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
36
|
+
type ResponseType = "json" | "text" | "blob" | "arraybuffer" | "formData" | "stream";
|
|
37
|
+
type HeaderValue = string | number | boolean | null | undefined;
|
|
38
|
+
type RawHeaders = Record<string, HeaderValue> | Headers;
|
|
39
|
+
/** Per-method header buckets on `defaults.headers` (axios shape); every bucket always exists. */
|
|
40
|
+
type HeadersDefaults = {
|
|
41
|
+
common: Record<string, HeaderValue>;
|
|
42
|
+
} & Record<Lowercase<Method>, Record<string, HeaderValue>>;
|
|
43
|
+
interface Outcome {
|
|
44
|
+
error?: ExiosError;
|
|
45
|
+
response?: ExiosResponse;
|
|
46
|
+
}
|
|
47
|
+
interface RetryConfig {
|
|
48
|
+
retries: number;
|
|
49
|
+
methods: Lowercase<Method>[];
|
|
50
|
+
statusCodes: number[];
|
|
51
|
+
retryOnNetworkError: boolean;
|
|
52
|
+
baseDelayMs: number;
|
|
53
|
+
maxDelayMs: number;
|
|
54
|
+
factor: number;
|
|
55
|
+
jitter: "full" | "none";
|
|
56
|
+
respectRetryAfter: boolean;
|
|
57
|
+
maxElapsedMs?: number;
|
|
58
|
+
shouldRetry?: (ctx: Outcome & {
|
|
59
|
+
attempt: number;
|
|
60
|
+
config: InternalConfig;
|
|
61
|
+
}) => boolean | Promise<boolean>;
|
|
62
|
+
onRetry?: (ctx: Outcome & {
|
|
63
|
+
attempt: number;
|
|
64
|
+
delayMs: number;
|
|
65
|
+
}) => void;
|
|
66
|
+
}
|
|
67
|
+
interface BreakerConfig {
|
|
68
|
+
failureThreshold: number;
|
|
69
|
+
windowMs?: number;
|
|
70
|
+
minRequests: number;
|
|
71
|
+
failureRateThreshold: number;
|
|
72
|
+
resetTimeoutMs: number;
|
|
73
|
+
halfOpenMaxRequests: number;
|
|
74
|
+
successThreshold: number;
|
|
75
|
+
isFailure?: (o: Outcome) => boolean;
|
|
76
|
+
key?: (config: InternalConfig) => string;
|
|
77
|
+
onStateChange?: (key: string, from: BreakerState, to: BreakerState) => void;
|
|
78
|
+
}
|
|
79
|
+
type BreakerState = "closed" | "open" | "half-open";
|
|
80
|
+
type RequestBreakerOverride = false | Pick<Partial<BreakerConfig>, "key" | "isFailure">;
|
|
81
|
+
interface ProgressEvent {
|
|
82
|
+
loaded: number;
|
|
83
|
+
total?: number;
|
|
84
|
+
progress?: number;
|
|
85
|
+
bytes: number;
|
|
86
|
+
rate?: number;
|
|
87
|
+
estimated?: number;
|
|
88
|
+
download: true;
|
|
89
|
+
event?: undefined;
|
|
90
|
+
}
|
|
91
|
+
type Transformer = (this: InternalConfig, data: any, headers: Record<string, string>, status?: number) => any;
|
|
92
|
+
interface ExiosRequestConfig<D = any> {
|
|
93
|
+
url?: string;
|
|
94
|
+
method?: Method;
|
|
95
|
+
baseURL?: string;
|
|
96
|
+
allowAbsoluteUrls?: boolean;
|
|
97
|
+
headers?: RawHeaders | (Partial<HeadersDefaults> & Record<string, HeaderValue | Record<string, HeaderValue>>);
|
|
98
|
+
params?: any;
|
|
99
|
+
paramsSerializer?: ((params: any) => string) | {
|
|
100
|
+
serialize?: (p: any) => string;
|
|
101
|
+
indexes?: boolean | null;
|
|
102
|
+
encode?: (s: string) => string;
|
|
103
|
+
};
|
|
104
|
+
data?: D;
|
|
105
|
+
transformRequest?: Transformer | Transformer[];
|
|
106
|
+
transformResponse?: Transformer | Transformer[];
|
|
107
|
+
timeout?: number;
|
|
108
|
+
timeoutErrorMessage?: string;
|
|
109
|
+
withCredentials?: boolean;
|
|
110
|
+
auth?: {
|
|
111
|
+
username: string;
|
|
112
|
+
password: string;
|
|
113
|
+
};
|
|
114
|
+
responseType?: ResponseType;
|
|
115
|
+
responseEncoding?: string;
|
|
116
|
+
validateStatus?: ((status: number) => boolean) | null;
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
onDownloadProgress?: (e: ProgressEvent) => void;
|
|
119
|
+
maxContentLength?: number;
|
|
120
|
+
maxBodyLength?: number;
|
|
121
|
+
transitional?: {
|
|
122
|
+
silentJSONParsing?: boolean;
|
|
123
|
+
clarifyTimeoutError?: boolean;
|
|
124
|
+
};
|
|
125
|
+
fetch?: typeof fetch;
|
|
126
|
+
fetchOptions?: Omit<RequestInit, "body" | "headers" | "method" | "signal">;
|
|
127
|
+
redirect?: RequestRedirect;
|
|
128
|
+
retry?: false | Partial<RetryConfig>;
|
|
129
|
+
breaker?: false | Partial<BreakerConfig>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Type of `instance.defaults`: like a request config, but every header bucket, `retry` and `breaker`
|
|
133
|
+
* always exist. Partial retry/breaker objects are allowed; unset fields fall back to the library defaults.
|
|
134
|
+
*/
|
|
135
|
+
interface ExiosDefaults<D = any> extends Omit<ExiosRequestConfig<D>, "headers" | "retry" | "breaker"> {
|
|
136
|
+
headers: HeadersDefaults & Record<string, HeaderValue | Record<string, HeaderValue>>;
|
|
137
|
+
retry: false | Partial<RetryConfig>;
|
|
138
|
+
breaker: false | Partial<BreakerConfig>;
|
|
139
|
+
}
|
|
140
|
+
interface InternalConfig<D = any> extends Omit<ExiosRequestConfig<D>, "headers" | "retry" | "breaker"> {
|
|
141
|
+
method: Lowercase<Method>;
|
|
142
|
+
headers: Record<string, string>;
|
|
143
|
+
retry: false | RetryConfig;
|
|
144
|
+
breaker: false | BreakerConfig;
|
|
145
|
+
}
|
|
146
|
+
interface ExiosResponse<T = any, D = any> {
|
|
147
|
+
data: T;
|
|
148
|
+
status: number;
|
|
149
|
+
statusText: string;
|
|
150
|
+
headers: Record<string, string | string[]>;
|
|
151
|
+
config: InternalConfig<D>;
|
|
152
|
+
request: Request;
|
|
153
|
+
meta: {
|
|
154
|
+
attempts: number;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
interface InterceptorOptions {
|
|
159
|
+
synchronous?: boolean;
|
|
160
|
+
runWhen?: (config: InternalConfig) => boolean;
|
|
161
|
+
}
|
|
162
|
+
interface InterceptorHandler<V> {
|
|
163
|
+
fulfilled?: ((value: V) => V | Promise<V>) | null;
|
|
164
|
+
rejected?: ((error: any) => any) | null;
|
|
165
|
+
synchronous: boolean;
|
|
166
|
+
runWhen: ((config: InternalConfig) => boolean) | null;
|
|
167
|
+
}
|
|
168
|
+
/** axios-style interceptor registry: ids are array indexes, ejected slots become null. */
|
|
169
|
+
declare class InterceptorManager<V> {
|
|
170
|
+
private handlers;
|
|
171
|
+
use(onFulfilled?: ((value: V) => V | Promise<V>) | null, onRejected?: ((error: any) => any) | null, opts?: InterceptorOptions): number;
|
|
172
|
+
eject(id: number): void;
|
|
173
|
+
clear(): void;
|
|
174
|
+
forEach(fn: (handler: InterceptorHandler<V>) => void): void;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
type Cfg<D> = ExiosRequestConfig<D>;
|
|
178
|
+
declare class Exios {
|
|
179
|
+
defaults: ExiosDefaults;
|
|
180
|
+
interceptors: {
|
|
181
|
+
request: InterceptorManager<InternalConfig<any>>;
|
|
182
|
+
response: InterceptorManager<ExiosResponse<any, any>>;
|
|
183
|
+
};
|
|
184
|
+
breaker: {
|
|
185
|
+
state(key: string): BreakerState;
|
|
186
|
+
reset(key?: string): void;
|
|
187
|
+
};
|
|
188
|
+
private readonly registry;
|
|
189
|
+
constructor(defaults: ExiosDefaults);
|
|
190
|
+
request<T = any, R = ExiosResponse<T>, D = any>(configOrUrl: string | Cfg<D>, config?: Cfg<D>): Promise<R>;
|
|
191
|
+
/** Runs every request interceptor in this tick with promise-chain semantics, then dispatches. */
|
|
192
|
+
private runSync;
|
|
193
|
+
getUri(config?: ExiosRequestConfig): string;
|
|
194
|
+
private noData;
|
|
195
|
+
private withData;
|
|
196
|
+
get<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: Cfg<D>): Promise<R>;
|
|
197
|
+
delete<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: Cfg<D>): Promise<R>;
|
|
198
|
+
head<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: Cfg<D>): Promise<R>;
|
|
199
|
+
options<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: Cfg<D>): Promise<R>;
|
|
200
|
+
post<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
201
|
+
put<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
202
|
+
patch<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
203
|
+
postForm<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
204
|
+
putForm<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
205
|
+
patchForm<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
206
|
+
}
|
|
207
|
+
declare const METHODS: readonly ["request", "getUri", "get", "delete", "head", "options", "post", "put", "patch", "postForm", "putForm", "patchForm"];
|
|
208
|
+
interface ExiosStatic extends Pick<Exios, (typeof METHODS)[number] | "defaults" | "interceptors" | "breaker"> {
|
|
209
|
+
<T = any, R = ExiosResponse<T>, D = any>(config: ExiosRequestConfig<D>): Promise<R>;
|
|
210
|
+
<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: ExiosRequestConfig<D>): Promise<R>;
|
|
211
|
+
create(config?: ExiosRequestConfig): ExiosStatic;
|
|
212
|
+
}
|
|
213
|
+
type ExiosInstance = ExiosStatic;
|
|
214
|
+
|
|
215
|
+
declare function mergeConfig(a: ExiosRequestConfig, b?: ExiosRequestConfig): ExiosRequestConfig;
|
|
216
|
+
|
|
217
|
+
declare function toFormData(obj: object, fd?: FormData): FormData;
|
|
218
|
+
|
|
219
|
+
declare const statics: {
|
|
220
|
+
ExiosError: typeof ExiosError;
|
|
221
|
+
CanceledError: typeof CanceledError;
|
|
222
|
+
CircuitOpenError: typeof CircuitOpenError;
|
|
223
|
+
isExiosError: typeof isExiosError;
|
|
224
|
+
isCancel: typeof isCancel;
|
|
225
|
+
mergeConfig: typeof mergeConfig;
|
|
226
|
+
toFormData: typeof toFormData;
|
|
227
|
+
};
|
|
228
|
+
type ExiosDefault = ExiosStatic & typeof statics;
|
|
229
|
+
declare const exios: ExiosDefault;
|
|
230
|
+
declare const create: (config?: ExiosRequestConfig) => ExiosStatic;
|
|
231
|
+
|
|
232
|
+
export { CanceledError, CircuitOpenError, ExiosError, InterceptorManager, create, exios as default, isCancel, isExiosError, mergeConfig, toFormData };
|
|
233
|
+
export type { BreakerConfig, BreakerState, ExiosDefault, ExiosDefaults, ExiosInstance, ExiosRequestConfig, ExiosResponse, ExiosStatic, HeaderValue, HeadersDefaults, InterceptorHandler, InterceptorOptions, InternalConfig, Method, Outcome, ProgressEvent, RawHeaders, RequestBreakerOverride, ResponseType, RetryConfig, Transformer };
|