@zayne-labs/callapi 0.0.6 → 0.1.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/README.md +536 -0
- package/dist/createFetchClient.cjs +3 -2
- package/dist/createFetchClient.cjs.map +1 -1
- package/dist/createFetchClient.d.cts +5 -17
- package/dist/createFetchClient.d.ts +5 -17
- package/dist/createFetchClient.js +4 -3
- package/dist/createFetchClient.js.map +1 -1
- package/dist/index.cjs +8 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/types-CGXvcfe9.d.cts +241 -0
- package/dist/types-CGXvcfe9.d.ts +241 -0
- package/dist/utils.cjs +14 -14
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +4 -2
- package/dist/utils.js.map +1 -1
- package/package.json +2 -3
- package/dist/types-B8arQl4O.d.cts +0 -147
- package/dist/types-B8arQl4O.d.ts +0 -147
package/dist/types-B8arQl4O.d.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
type AnyString = string & {
|
|
2
|
-
placeholder?: never;
|
|
3
|
-
};
|
|
4
|
-
type AnyNumber = number & {
|
|
5
|
-
placeholder?: never;
|
|
6
|
-
};
|
|
7
|
-
type AnyFunction = (...args: any[]) => any;
|
|
8
|
-
|
|
9
|
-
declare const mergeUrlWithParams: (url: string, params: ExtraOptions["query"]) => string;
|
|
10
|
-
declare const objectifyHeaders: (headers: RequestInit["headers"]) => Record<string, string> | undefined;
|
|
11
|
-
declare const defaultRetryCodes: Required<BaseConfig>["retryCodes"];
|
|
12
|
-
declare const defaultRetryMethods: Required<BaseConfig>["retryMethods"];
|
|
13
|
-
declare const fetchSpecificKeys: ("headers" | "body" | "method" | "cache" | "credentials" | "integrity" | "keepalive" | "mode" | "priority" | "redirect" | "referrer" | "referrerPolicy" | "signal" | "window")[];
|
|
14
|
-
declare const splitConfig: <TObject extends object>(config: TObject) => ["body" extends keyof TObject ? $RequestConfig : $BaseRequestConfig, ExtraOptions];
|
|
15
|
-
declare const handleResponseType: <TResponse>(response: Response, parser?: Required<ExtraOptions>["responseParser"]) => {
|
|
16
|
-
json: () => Promise<TResponse>;
|
|
17
|
-
arrayBuffer: () => Promise<TResponse>;
|
|
18
|
-
blob: () => Promise<TResponse>;
|
|
19
|
-
formData: () => Promise<TResponse>;
|
|
20
|
-
text: () => Promise<TResponse>;
|
|
21
|
-
};
|
|
22
|
-
declare const getResponseData: <TResponse>(response: Response, responseType: keyof ReturnType<typeof handleResponseType>, parser: ExtraOptions["responseParser"]) => Promise<TResponse>;
|
|
23
|
-
type DataInfo = {
|
|
24
|
-
successData: unknown;
|
|
25
|
-
options: ExtraOptions;
|
|
26
|
-
response: Response;
|
|
27
|
-
};
|
|
28
|
-
declare const resolveSuccessResult: <CallApiResult>(info: DataInfo) => CallApiResult;
|
|
29
|
-
declare const $resolveErrorResult: <CallApiResult>($info: {
|
|
30
|
-
error?: unknown;
|
|
31
|
-
options: ExtraOptions;
|
|
32
|
-
}) => (info?: {
|
|
33
|
-
response?: Response;
|
|
34
|
-
errorData?: unknown;
|
|
35
|
-
message?: string;
|
|
36
|
-
}) => CallApiResult;
|
|
37
|
-
declare const isHTTPErrorInfo: (errorInfo: Record<string, unknown> | null) => errorInfo is {
|
|
38
|
-
errorName: "HTTPError";
|
|
39
|
-
};
|
|
40
|
-
type ErrorDetails<TErrorResponse> = {
|
|
41
|
-
response: Response & {
|
|
42
|
-
errorData: TErrorResponse;
|
|
43
|
-
};
|
|
44
|
-
defaultErrorMessage: string;
|
|
45
|
-
};
|
|
46
|
-
type ErrorOptions = {
|
|
47
|
-
cause?: unknown;
|
|
48
|
-
};
|
|
49
|
-
declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {
|
|
50
|
-
response: ErrorDetails<TErrorResponse>["response"];
|
|
51
|
-
name: "HTTPError";
|
|
52
|
-
isHTTPError: boolean;
|
|
53
|
-
constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
|
|
54
|
-
}
|
|
55
|
-
declare const isHTTPErrorInstance: <TErrorResponse>(error: unknown) => error is HTTPError<TErrorResponse>;
|
|
56
|
-
declare const wait: (delay: number) => Promise<unknown> | undefined;
|
|
57
|
-
declare const isFormData: (value: unknown) => value is FormData;
|
|
58
|
-
declare const isObject: <TObject extends Record<string, unknown>>(value: unknown) => value is TObject;
|
|
59
|
-
declare const isFunction: <TFunction extends AnyFunction>(value: unknown) => value is TFunction;
|
|
60
|
-
|
|
61
|
-
type $RequestConfig = Pick<FetchConfig, (typeof fetchSpecificKeys)[number]>;
|
|
62
|
-
type $BaseRequestConfig = Omit<$RequestConfig, "body">;
|
|
63
|
-
type ExtraOptions<TBaseData = unknown, TBaseErrorData = unknown, TBaseResultMode extends ResultStyleUnion = ResultStyleUnion> = {
|
|
64
|
-
body?: Record<string, unknown> | RequestInit["body"];
|
|
65
|
-
method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE" | AnyString;
|
|
66
|
-
query?: Record<string, string | number | boolean>;
|
|
67
|
-
bodySerializer?: (bodyData: Record<string, unknown>) => string;
|
|
68
|
-
responseParser?: {
|
|
69
|
-
(data: string): unknown;
|
|
70
|
-
<TData>(data: string): TData;
|
|
71
|
-
};
|
|
72
|
-
resultMode?: TBaseResultMode;
|
|
73
|
-
cancelRedundantRequests?: boolean;
|
|
74
|
-
baseURL?: string;
|
|
75
|
-
timeout?: number;
|
|
76
|
-
defaultErrorMessage?: string;
|
|
77
|
-
throwOnError?: boolean | ((error?: Error | HTTPError<TBaseErrorData>) => boolean);
|
|
78
|
-
responseType?: keyof ReturnType<typeof handleResponseType>;
|
|
79
|
-
retries?: number;
|
|
80
|
-
retryDelay?: number;
|
|
81
|
-
retryCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;
|
|
82
|
-
retryMethods?: Array<"GET" | "POST" | "PATCH" | "DELETE" | AnyString>;
|
|
83
|
-
meta?: Record<string, unknown>;
|
|
84
|
-
onRequest?: (requestContext: {
|
|
85
|
-
request: $RequestConfig;
|
|
86
|
-
options: ExtraOptions;
|
|
87
|
-
}) => void | Promise<void>;
|
|
88
|
-
onRequestError?: (requestContext: {
|
|
89
|
-
request: $RequestConfig;
|
|
90
|
-
error: Error;
|
|
91
|
-
options: ExtraOptions;
|
|
92
|
-
}) => void | Promise<void>;
|
|
93
|
-
onResponse?: (successContext: {
|
|
94
|
-
request: $RequestConfig;
|
|
95
|
-
response: Response & {
|
|
96
|
-
data: TBaseData;
|
|
97
|
-
};
|
|
98
|
-
options: ExtraOptions;
|
|
99
|
-
}) => void | Promise<void>;
|
|
100
|
-
onResponseError?: (errorContext: {
|
|
101
|
-
request: $RequestConfig;
|
|
102
|
-
response: Response & {
|
|
103
|
-
errorData: TBaseErrorData;
|
|
104
|
-
};
|
|
105
|
-
options: ExtraOptions;
|
|
106
|
-
}) => void | Promise<void>;
|
|
107
|
-
};
|
|
108
|
-
interface FetchConfig<TData = unknown, TErrorData = unknown, TResultMode extends ResultStyleUnion = undefined> extends Omit<RequestInit, "method" | "body">, ExtraOptions<TData, TErrorData, TResultMode> {
|
|
109
|
-
}
|
|
110
|
-
interface BaseConfig<TBaseData = unknown, TBaseErrorData = unknown, TBaseResultMode extends ResultStyleUnion = undefined> extends Omit<FetchConfig<TBaseData, TBaseErrorData, TBaseResultMode>, "body"> {
|
|
111
|
-
}
|
|
112
|
-
type ApiSuccessVariant<TData> = {
|
|
113
|
-
dataInfo: TData;
|
|
114
|
-
errorInfo: null;
|
|
115
|
-
response: Response;
|
|
116
|
-
};
|
|
117
|
-
type PossibleErrors = "AbortError" | "TimeoutError" | "SyntaxError" | "TypeError" | "Error" | "UnknownError";
|
|
118
|
-
type ApiErrorVariant<TErrorData> = {
|
|
119
|
-
dataInfo: null;
|
|
120
|
-
errorInfo: {
|
|
121
|
-
errorName: "HTTPError";
|
|
122
|
-
errorData: TErrorData;
|
|
123
|
-
message: string;
|
|
124
|
-
};
|
|
125
|
-
response: Response;
|
|
126
|
-
} | {
|
|
127
|
-
dataInfo: null;
|
|
128
|
-
errorInfo: {
|
|
129
|
-
errorName: PossibleErrors;
|
|
130
|
-
message: string;
|
|
131
|
-
};
|
|
132
|
-
response: null;
|
|
133
|
-
};
|
|
134
|
-
type ResultStyleMap<TData = unknown, TErrorData = unknown> = {
|
|
135
|
-
all: ApiSuccessVariant<TData> | ApiErrorVariant<TErrorData>;
|
|
136
|
-
onlySuccess: TData;
|
|
137
|
-
onlyError: TErrorData;
|
|
138
|
-
onlyResponse: Response;
|
|
139
|
-
};
|
|
140
|
-
type ResultStyleUnion = {
|
|
141
|
-
_: {
|
|
142
|
-
[Key in keyof ResultStyleMap]: Key;
|
|
143
|
-
}[keyof ResultStyleMap] | undefined;
|
|
144
|
-
}["_"];
|
|
145
|
-
type GetCallApiResult<TData, TErrorData, TResultMode> = TResultMode extends NonNullable<ResultStyleUnion> ? ResultStyleMap<TData, TErrorData>[TResultMode] : ResultStyleMap<TData, TErrorData>["all"];
|
|
146
|
-
|
|
147
|
-
export { $resolveErrorResult as $, type BaseConfig as B, type FetchConfig as F, type GetCallApiResult as G, HTTPError as H, type ResultStyleUnion as R, isHTTPErrorInstance as a, defaultRetryMethods as b, isFormData as c, defaultRetryCodes as d, isObject as e, fetchSpecificKeys as f, getResponseData as g, handleResponseType as h, isHTTPErrorInfo as i, isFunction as j, mergeUrlWithParams as m, objectifyHeaders as o, resolveSuccessResult as r, splitConfig as s, wait as w };
|