@zayne-labs/callapi 1.8.22 → 1.9.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.
- package/README.md +3 -1
- package/dist/esm/{common-C-kIzPcz.d.ts → common-xKdPFzy4.d.ts} +85 -130
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +47 -39
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/{utils-DZe23qYR.js → utils-DUbIqsYh.js} +28 -44
- package/dist/esm/utils-DUbIqsYh.js.map +1 -0
- package/package.json +6 -5
- package/dist/esm/utils-DZe23qYR.js.map +0 -1
package/README.md
CHANGED
@@ -13,7 +13,9 @@
|
|
13
13
|
<a href="https://github.com/zayne-labs/callapi/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="license"></a>
|
14
14
|
<a href="https://github.com/zayne-labs/callapi/graphs/commit-activity"><img src="https://img.shields.io/github/commit-activity/m/zayne-labs/callapi?style=flat&color=EFBA5F" alt="commit activity"></a>
|
15
15
|
<a href="https://www.npmjs.com/package/@zayne-labs/callapi"><img src="https://img.shields.io/npm/dm/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="downloads per month"></a>
|
16
|
-
|
16
|
+
<a href="https://deepwiki.com/zayne-labs/callapi"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
|
17
|
+
<a href="https://code2tutorial.com/tutorial/02b6c57c-4847-4e76-b91e-d64dde370609/index.md"><img src="https://img.shields.io/badge/Code2Tutorial-blue?color=blue&logo=victoriametrics" alt="Code2Tutorial"></a>
|
18
|
+
</p>
|
17
19
|
|
18
20
|
<p align="center">
|
19
21
|
CallApi Fetch is an extra-lightweight wrapper over fetch that provides quality of life improvements beyond the bare fetch api, while keeping the API familiar.</p>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
//#region src/types/type-helpers.d.ts
|
2
2
|
type AnyString = string & NonNullable<unknown>;
|
3
|
+
type AnyNumber = number & NonNullable<unknown>;
|
3
4
|
type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;
|
4
5
|
type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };
|
5
6
|
type WriteableLevel = "deep" | "shallow";
|
@@ -213,43 +214,54 @@ declare class ValidationError extends Error {
|
|
213
214
|
//#endregion
|
214
215
|
//#region src/url.d.ts
|
215
216
|
type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
|
216
|
-
type
|
217
|
+
type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
|
218
|
+
type TupleStyleParams = UnmaskType<AllowedQueryParamValues[]>;
|
219
|
+
type Params = UnmaskType<RecordStyleParams | TupleStyleParams>;
|
217
220
|
type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;
|
218
221
|
type InitURLOrURLObject = AnyString | RouteKeyMethodsURLUnion | URL;
|
219
222
|
interface URLOptions {
|
220
223
|
/**
|
221
|
-
* Base URL
|
224
|
+
* Base URL for all API requests. Will only be prepended to relative URLs.
|
222
225
|
*
|
223
|
-
*
|
226
|
+
* Absolute URLs (starting with http/https) will not be prepended by the baseURL.
|
224
227
|
*
|
228
|
+
* @example
|
229
|
+
* ```ts
|
230
|
+
* // Set base URL for all requests
|
231
|
+
* baseURL: "https://api.example.com/v1"
|
232
|
+
*
|
233
|
+
* // Then use relative URLs in requests
|
234
|
+
* callApi("/users") // → https://api.example.com/v1/users
|
235
|
+
* callApi("/posts/123") // → https://api.example.com/v1/posts/123
|
236
|
+
*
|
237
|
+
* // Environment-specific base URLs
|
238
|
+
* baseURL: process.env.NODE_ENV === "production"
|
239
|
+
* ? "https://api.example.com"
|
240
|
+
* : "http://localhost:3000/api"
|
241
|
+
* ```
|
225
242
|
*/
|
226
243
|
baseURL?: string;
|
227
244
|
/**
|
228
|
-
* Resolved request URL after processing baseURL, parameters, and query strings
|
245
|
+
* Resolved request URL after processing baseURL, parameters, and query strings (readonly)
|
229
246
|
*
|
230
247
|
* This is the final URL that will be used for the HTTP request, computed from
|
231
248
|
* baseURL, initURL, params, and query parameters.
|
232
249
|
*
|
233
|
-
* @readonly
|
234
250
|
*/
|
235
251
|
readonly fullURL?: string;
|
236
252
|
/**
|
237
|
-
* The original URL string passed to the callApi instance
|
253
|
+
* The original URL string passed to the callApi instance (readonly)
|
238
254
|
*
|
239
255
|
* This preserves the original URL as provided, including any method modifiers like "@get/" or "@post/".
|
240
256
|
*
|
241
|
-
* @readonly
|
242
257
|
*/
|
243
258
|
readonly initURL?: string;
|
244
259
|
/**
|
245
|
-
* The URL string after normalization, with method modifiers removed
|
260
|
+
* The URL string after normalization, with method modifiers removed(readonly)
|
246
261
|
*
|
247
262
|
* Method modifiers like "@get/", "@post/" are stripped to create a clean URL
|
248
263
|
* for parameter substitution and final URL construction.
|
249
264
|
*
|
250
|
-
* @readonly
|
251
|
-
*
|
252
|
-
*
|
253
265
|
*/
|
254
266
|
readonly initURLNormalized?: string;
|
255
267
|
/**
|
@@ -345,14 +357,6 @@ interface CallApiSchemaConfig {
|
|
345
357
|
* swapping between `/api/v1` and `/api/v2`) without redefining the entire schema.
|
346
358
|
*/
|
347
359
|
prefix?: string;
|
348
|
-
/**
|
349
|
-
*Determines the inference or requirement of the method option based on the route modifiers (`@get/`, `@post/`, `@put/`, `@patch/`, `@delete/`).
|
350
|
-
*
|
351
|
-
* - When `true`, the method option is made required on the type level and is not automatically added to the request options.
|
352
|
-
* - When `false` or `undefined` (default), the method option is not required on the type level, and is automatically added to the request options.
|
353
|
-
*
|
354
|
-
*/
|
355
|
-
requireMethodProvision?: boolean;
|
356
360
|
/**
|
357
361
|
* Controls the strictness of API route validation.
|
358
362
|
*
|
@@ -410,10 +414,10 @@ type BaseCallApiSchemaAndConfig = {
|
|
410
414
|
};
|
411
415
|
//#endregion
|
412
416
|
//#region src/plugins.d.ts
|
413
|
-
type
|
417
|
+
type PluginSetupContext<TPluginExtraOptions = unknown> = RequestContext & PluginExtraOptions<TPluginExtraOptions> & {
|
414
418
|
initURL: string;
|
415
419
|
};
|
416
|
-
type PluginInitResult = Partial<Omit<
|
420
|
+
type PluginInitResult = Partial<Omit<PluginSetupContext, "initURL" | "request"> & {
|
417
421
|
initURL: InitURLOrURLObject;
|
418
422
|
request: CallApiRequestOptions;
|
419
423
|
}>;
|
@@ -436,10 +440,6 @@ interface CallApiPlugin {
|
|
436
440
|
* A unique id for the plugin
|
437
441
|
*/
|
438
442
|
id: string;
|
439
|
-
/**
|
440
|
-
* A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
|
441
|
-
*/
|
442
|
-
init?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;
|
443
443
|
/**
|
444
444
|
* A name for the plugin
|
445
445
|
*/
|
@@ -448,6 +448,10 @@ interface CallApiPlugin {
|
|
448
448
|
* Base schema for the client.
|
449
449
|
*/
|
450
450
|
schema?: BaseCallApiSchemaAndConfig;
|
451
|
+
/**
|
452
|
+
* A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
|
453
|
+
*/
|
454
|
+
setup?: (context: PluginSetupContext) => Awaitable<PluginInitResult> | Awaitable<void>;
|
451
455
|
/**
|
452
456
|
* A version for the plugin
|
453
457
|
*/
|
@@ -460,13 +464,13 @@ type DefaultPluginArray = CallApiPlugin[];
|
|
460
464
|
type DefaultThrowOnError = boolean;
|
461
465
|
//#endregion
|
462
466
|
//#region src/result.d.ts
|
463
|
-
type Parser = (responseString: string) => Awaitable<
|
464
|
-
declare const getResponseType: <TResponse>(response: Response, parser: Parser) => {
|
467
|
+
type Parser<TData> = (responseString: string) => Awaitable<TData>;
|
468
|
+
declare const getResponseType: <TResponse>(response: Response, parser: Parser<TResponse>) => {
|
465
469
|
arrayBuffer: () => Promise<ArrayBuffer>;
|
466
470
|
blob: () => Promise<Blob>;
|
467
471
|
formData: () => Promise<FormData>;
|
468
472
|
json: () => Promise<TResponse>;
|
469
|
-
stream: () => ReadableStream<Uint8Array<
|
473
|
+
stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
|
470
474
|
text: () => Promise<string>;
|
471
475
|
};
|
472
476
|
type InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;
|
@@ -815,7 +819,7 @@ type ValidationErrorContext = UnmaskType<RequestContext & {
|
|
815
819
|
}>;
|
816
820
|
type SuccessContext<TData> = UnmaskType<RequestContext & {
|
817
821
|
/** Parsed response data with the expected success type */
|
818
|
-
data: TData
|
822
|
+
data: NoInfer<TData>;
|
819
823
|
/** HTTP response object for the successful request */
|
820
824
|
response: Response;
|
821
825
|
}>;
|
@@ -860,6 +864,7 @@ type ResponseStreamContext = UnmaskType<RequestContext & {
|
|
860
864
|
}>;
|
861
865
|
//#endregion
|
862
866
|
//#region src/dedupe.d.ts
|
867
|
+
type DedupeStrategyUnion = UnmaskType<"cancel" | "defer" | "none">;
|
863
868
|
type DedupeOptions = {
|
864
869
|
/**
|
865
870
|
* Controls the scope of request deduplication caching.
|
@@ -1016,98 +1021,70 @@ type DedupeOptions = {
|
|
1016
1021
|
*/
|
1017
1022
|
dedupeKey?: string | ((context: RequestContext) => string);
|
1018
1023
|
/**
|
1019
|
-
* Strategy for handling duplicate requests.
|
1020
|
-
*
|
1021
|
-
* **Strategy Details:**
|
1022
|
-
* - `"cancel"`: Aborts any in-flight request with the same key when a new request starts.
|
1023
|
-
* The previous request will throw an AbortError, and the new request proceeds normally.
|
1024
|
-
* Best for scenarios where only the latest request matters.
|
1025
|
-
*
|
1026
|
-
* - `"defer"`: Returns the existing promise for duplicate requests, effectively sharing
|
1027
|
-
* the same response across multiple callers. All callers receive the same result.
|
1028
|
-
* Ideal for expensive operations that shouldn't be repeated.
|
1029
|
-
*
|
1030
|
-
* - `"none"`: Disables request deduplication entirely. Every request executes independently
|
1031
|
-
* regardless of similarity. Use when you need guaranteed request execution.
|
1032
|
-
*
|
1033
|
-
* **Real-world Use Cases:**
|
1034
|
-
*
|
1035
|
-
* **Cancel Strategy:**
|
1036
|
-
* - Search-as-you-type functionality (cancel previous searches)
|
1037
|
-
* - Real-time data updates (only latest request matters)
|
1038
|
-
* - User navigation (cancel previous page loads)
|
1039
|
-
* - Form submissions where rapid clicks should cancel previous attempts
|
1040
|
-
*
|
1041
|
-
* **Defer Strategy:**
|
1042
|
-
* - Configuration/settings loading (share across components)
|
1043
|
-
* - User profile data (multiple components need same data)
|
1044
|
-
* - Expensive computations or reports
|
1045
|
-
* - Authentication token refresh (prevent multiple refresh attempts)
|
1046
|
-
*
|
1047
|
-
* **None Strategy:**
|
1048
|
-
* - Analytics events (every event should be sent)
|
1049
|
-
* - Logging requests (each log entry is unique)
|
1050
|
-
* - File uploads (each upload is independent)
|
1051
|
-
* - Critical business operations that must not be deduplicated
|
1024
|
+
* Strategy for handling duplicate requests. Can be a static string or callback function.
|
1052
1025
|
*
|
1026
|
+
* **Available Strategies:**
|
1027
|
+
* - `"cancel"`: Cancel previous request when new one starts (good for search)
|
1028
|
+
* - `"defer"`: Share response between duplicate requests (good for config loading)
|
1029
|
+
* - `"none"`: No deduplication, all requests execute independently
|
1053
1030
|
*
|
1054
1031
|
* @example
|
1055
1032
|
* ```ts
|
1056
|
-
* //
|
1033
|
+
* // Static strategies
|
1057
1034
|
* const searchClient = createFetchClient({
|
1058
|
-
* baseURL: "/api/search",
|
1059
1035
|
* dedupeStrategy: "cancel" // Cancel previous searches
|
1060
1036
|
* });
|
1061
1037
|
*
|
1062
|
-
* // Defer strategy - shared configuration
|
1063
1038
|
* const configClient = createFetchClient({
|
1064
1039
|
* dedupeStrategy: "defer" // Share config across components
|
1065
1040
|
* });
|
1066
1041
|
*
|
1067
|
-
* //
|
1068
|
-
* const
|
1069
|
-
*
|
1070
|
-
*
|
1071
|
-
*
|
1072
|
-
*
|
1073
|
-
* // None strategy - analytics
|
1074
|
-
* const analyticsClient = createFetchClient({
|
1075
|
-
* baseURL: "/api/analytics",
|
1076
|
-
* dedupeStrategy: "none" // Every event must be sent
|
1042
|
+
* // Dynamic strategy based on request
|
1043
|
+
* const smartClient = createFetchClient({
|
1044
|
+
* dedupeStrategy: (context) => {
|
1045
|
+
* return context.options.method === "GET" ? "defer" : "cancel";
|
1046
|
+
* }
|
1077
1047
|
* });
|
1078
1048
|
*
|
1079
|
-
* //
|
1049
|
+
* // Search-as-you-type with cancel strategy
|
1080
1050
|
* const handleSearch = async (query: string) => {
|
1081
1051
|
* try {
|
1082
|
-
* const
|
1052
|
+
* const { data } = await callApi("/api/search", {
|
1083
1053
|
* method: "POST",
|
1084
1054
|
* body: { query },
|
1085
1055
|
* dedupeStrategy: "cancel",
|
1086
|
-
* dedupeKey: "search" //
|
1056
|
+
* dedupeKey: "search" // Cancel previous searches, only latest one goes through
|
1087
1057
|
* });
|
1088
|
-
*
|
1058
|
+
*
|
1059
|
+
* updateSearchResults(data);
|
1089
1060
|
* } catch (error) {
|
1090
1061
|
* if (error.name === "AbortError") {
|
1091
|
-
* // Previous search
|
1062
|
+
* // Previous search cancelled - (expected behavior)
|
1092
1063
|
* return;
|
1093
1064
|
* }
|
1094
|
-
*
|
1065
|
+
* console.error("Search failed:", error);
|
1095
1066
|
* }
|
1096
1067
|
* };
|
1097
1068
|
*
|
1098
|
-
* // Authentication token refresh with defer
|
1099
|
-
* const refreshToken = () => callApi("/api/auth/refresh", {
|
1100
|
-
* dedupeStrategy: "defer",
|
1101
|
-
* dedupeKey: "token-refresh" // Ensure only one refresh happens
|
1102
|
-
* });
|
1103
1069
|
* ```
|
1104
1070
|
*
|
1105
1071
|
* @default "cancel"
|
1106
1072
|
*/
|
1107
|
-
dedupeStrategy?:
|
1073
|
+
dedupeStrategy?: DedupeStrategyUnion | ((context: RequestContext) => DedupeStrategyUnion);
|
1108
1074
|
};
|
1109
1075
|
//#endregion
|
1110
1076
|
//#region src/retry.d.ts
|
1077
|
+
declare const defaultRetryStatusCodesLookup: () => {
|
1078
|
+
408: "Request Timeout";
|
1079
|
+
409: "Conflict";
|
1080
|
+
425: "Too Early";
|
1081
|
+
429: "Too Many Requests";
|
1082
|
+
500: "Internal Server Error";
|
1083
|
+
502: "Bad Gateway";
|
1084
|
+
503: "Service Unavailable";
|
1085
|
+
504: "Gateway Timeout";
|
1086
|
+
};
|
1087
|
+
type RetryStatusCodes = UnmaskType<AnyNumber | keyof ReturnType<typeof defaultRetryStatusCodesLookup>>;
|
1111
1088
|
type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
|
1112
1089
|
type InnerRetryKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, "~retryAttemptCount" | "retry">;
|
1113
1090
|
type InnerRetryOptions<TErrorData> = { [Key in InnerRetryKeys<TErrorData> as Key extends `retry${infer TRest}` ? Uncapitalize<TRest> extends "attempts" ? never : Uncapitalize<TRest> : Key]?: RetryOptions<TErrorData>[Key] } & {
|
@@ -1151,7 +1128,7 @@ interface RetryOptions<TErrorData> {
|
|
1151
1128
|
/**
|
1152
1129
|
* HTTP status codes that trigger a retry
|
1153
1130
|
*/
|
1154
|
-
retryStatusCodes?:
|
1131
|
+
retryStatusCodes?: RetryStatusCodes[];
|
1155
1132
|
/**
|
1156
1133
|
* Strategy to use when retrying
|
1157
1134
|
* @default "linear"
|
@@ -1185,8 +1162,7 @@ type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIf
|
|
1185
1162
|
}>;
|
1186
1163
|
type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
|
1187
1164
|
type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
|
1188
|
-
type
|
1189
|
-
type InferMethodOption<TSchema extends CallApiSchema, TSchemaConfig extends CallApiSchemaConfig, TInitURL> = MakeMethodOptionRequired<TSchema["method"], TInitURL, TSchemaConfig, {
|
1165
|
+
type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema["method"], {
|
1190
1166
|
/**
|
1191
1167
|
* HTTP method for the request.
|
1192
1168
|
* @default "GET"
|
@@ -1202,7 +1178,7 @@ type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequire
|
|
1202
1178
|
baseHeaders: NonNullable<HeadersOption>;
|
1203
1179
|
}) => InferSchemaResult<TSchema["headers"], HeadersOption>);
|
1204
1180
|
}>;
|
1205
|
-
type InferRequestOptions<TSchema extends CallApiSchema,
|
1181
|
+
type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
|
1206
1182
|
interface Register {}
|
1207
1183
|
type GlobalMeta = Register extends {
|
1208
1184
|
meta?: infer TMeta extends Record<string, unknown>;
|
@@ -1240,8 +1216,13 @@ type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredI
|
|
1240
1216
|
query?: InferSchemaResult<TSchema["query"], Query>;
|
1241
1217
|
}>;
|
1242
1218
|
type EmptyString = "";
|
1243
|
-
type
|
1244
|
-
type
|
1219
|
+
type EmptyTuple = readonly [];
|
1220
|
+
type StringTuple = readonly string[];
|
1221
|
+
type ExtractRouteParamNames<TCurrentRoute, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute extends `${string}:${string}` | `${string}{${string}}${string}` ? TCurrentRoute extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
|
1222
|
+
type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
|
1223
|
+
type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
|
1224
|
+
type InferParamsFromRoute<TCurrentRoute> = ExtractRouteParamNames<TCurrentRoute> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute>> : Params;
|
1225
|
+
type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, TCurrentRouteSchemaKey extends (`${string}:${string}${"" | "/"}${"" | AnyString}` | `${string}{${string}}${"" | "/"}${"" | AnyString}`) ? TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaResult<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject : TObject>;
|
1245
1226
|
type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
|
1246
1227
|
/**
|
1247
1228
|
* Parameters to be appended to the URL (i.e: /:id)
|
@@ -1321,25 +1302,6 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
1321
1302
|
* ```
|
1322
1303
|
*/
|
1323
1304
|
auth?: string | Auth | null;
|
1324
|
-
/**
|
1325
|
-
* Base URL for all API requests. Will be prepended to relative URLs.
|
1326
|
-
*
|
1327
|
-
* @example
|
1328
|
-
* ```ts
|
1329
|
-
* // Set base URL for all requests
|
1330
|
-
* baseURL: "https://api.example.com/v1"
|
1331
|
-
*
|
1332
|
-
* // Then use relative URLs in requests
|
1333
|
-
* callApi("/users") // → https://api.example.com/v1/users
|
1334
|
-
* callApi("/posts/123") // → https://api.example.com/v1/posts/123
|
1335
|
-
*
|
1336
|
-
* // Environment-specific base URLs
|
1337
|
-
* baseURL: process.env.NODE_ENV === "production"
|
1338
|
-
* ? "https://api.example.com"
|
1339
|
-
* : "http://localhost:3000/api"
|
1340
|
-
* ```
|
1341
|
-
*/
|
1342
|
-
baseURL?: string;
|
1343
1305
|
/**
|
1344
1306
|
* Custom function to serialize request body objects into strings.
|
1345
1307
|
*
|
@@ -1509,13 +1471,16 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
1509
1471
|
*/
|
1510
1472
|
meta?: GlobalMeta;
|
1511
1473
|
/**
|
1512
|
-
* Custom function to parse response strings into objects.
|
1474
|
+
* Custom function to parse response strings into objects instead of the default response.json().
|
1513
1475
|
*
|
1514
|
-
* Useful when
|
1515
|
-
* custom parsing logic for specific response formats.
|
1476
|
+
* Useful when you need custom parsing logic for specific response formats.
|
1516
1477
|
*
|
1517
1478
|
* @example
|
1518
1479
|
* ```ts
|
1480
|
+
* responseParser: (responseString) => {
|
1481
|
+
* return JSON.parse(responseString);
|
1482
|
+
* }
|
1483
|
+
*
|
1519
1484
|
* // Parse XML responses
|
1520
1485
|
* responseParser: (responseString) => {
|
1521
1486
|
* const parser = new DOMParser();
|
@@ -1534,22 +1499,12 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
1534
1499
|
* return obj;
|
1535
1500
|
* }, {});
|
1536
1501
|
* });
|
1537
|
-
* return
|
1502
|
+
* return data;
|
1538
1503
|
* }
|
1539
1504
|
*
|
1540
|
-
* // Parse custom format with error handling
|
1541
|
-
* responseParser: async (responseString) => {
|
1542
|
-
* try {
|
1543
|
-
* // Custom parsing logic
|
1544
|
-
* const parsed = customFormat.parse(responseString);
|
1545
|
-
* return { success: true, data: parsed };
|
1546
|
-
* } catch (error) {
|
1547
|
-
* return { success: false, error: error.message };
|
1548
|
-
* }
|
1549
|
-
* }
|
1550
1505
|
* ```
|
1551
1506
|
*/
|
1552
|
-
responseParser?: (responseString: string) => Awaitable<
|
1507
|
+
responseParser?: (responseString: string) => Awaitable<unknown>;
|
1553
1508
|
/**
|
1554
1509
|
* Expected response type, determines how the response body is parsed.
|
1555
1510
|
*
|
@@ -1848,9 +1803,9 @@ type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultData
|
|
1848
1803
|
options: CallApiExtraOptions;
|
1849
1804
|
request: CallApiRequestOptions;
|
1850
1805
|
}) => CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>);
|
1851
|
-
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema,
|
1806
|
+
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
1852
1807
|
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = [initURL: TInitURL, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
1853
1808
|
type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
|
1854
1809
|
//#endregion
|
1855
|
-
export { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions,
|
1856
|
-
//# sourceMappingURL=common-
|
1810
|
+
export { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable };
|
1811
|
+
//# sourceMappingURL=common-xKdPFzy4.d.ts.map
|
package/dist/esm/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions,
|
1
|
+
import { AnyFunction, AnyString, ApplyStrictConfig, ApplyURLBasedConfig, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable } from "./common-xKdPFzy4.js";
|
2
2
|
|
3
3
|
//#region src/createFetchClient.d.ts
|
4
4
|
|
@@ -30,5 +30,5 @@ declare const definePlugin: <const TPlugin extends CallApiPlugin | AnyFunction<C
|
|
30
30
|
declare const defineBaseConfig: <const TBaseConfig extends BaseCallApiConfig>(baseConfig: TBaseConfig) => Writeable<typeof baseConfig, "deep">;
|
31
31
|
declare const defineParameters: <TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig> = InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(...parameters: CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>;
|
32
32
|
//#endregion
|
33
|
-
export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type DedupeOptions, type ErrorContext, HTTPError, type Hooks, type HooksOrHooksArray, type InferParamsFromRoute, type InferSchemaResult, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type
|
33
|
+
export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type DedupeOptions, type ErrorContext, HTTPError, type Hooks, type HooksOrHooksArray, type InferParamsFromRoute, type InferSchemaResult, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeUnion, type ResultModeUnion, type RetryOptions, type SuccessContext, type URLOptions, ValidationError, callApi, createFetchClient, defineBaseConfig, defineParameters, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes };
|
34
34
|
//# sourceMappingURL=index.d.ts.map
|