@zayne-labs/callapi 1.8.21 → 1.9.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 +3 -1
- package/dist/esm/{common-C-kIzPcz.d.ts → common-Byku1Sji.d.ts} +83 -129
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +59 -93
- 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 +5 -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,53 @@ 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 be prepended to relative URLs.
|
225
|
+
* Absolute URLs (starting with http/https) will not be prepended by the baseURL.
|
222
226
|
*
|
223
|
-
*
|
227
|
+
* @example
|
228
|
+
* ```ts
|
229
|
+
* // Set base URL for all requests
|
230
|
+
* baseURL: "https://api.example.com/v1"
|
231
|
+
*
|
232
|
+
* // Then use relative URLs in requests
|
233
|
+
* callApi("/users") // → https://api.example.com/v1/users
|
234
|
+
* callApi("/posts/123") // → https://api.example.com/v1/posts/123
|
224
235
|
*
|
236
|
+
* // Environment-specific base URLs
|
237
|
+
* baseURL: process.env.NODE_ENV === "production"
|
238
|
+
* ? "https://api.example.com"
|
239
|
+
* : "http://localhost:3000/api"
|
240
|
+
* ```
|
225
241
|
*/
|
226
242
|
baseURL?: string;
|
227
243
|
/**
|
228
|
-
* Resolved request URL after processing baseURL, parameters, and query strings
|
244
|
+
* Resolved request URL after processing baseURL, parameters, and query strings (readonly)
|
229
245
|
*
|
230
246
|
* This is the final URL that will be used for the HTTP request, computed from
|
231
247
|
* baseURL, initURL, params, and query parameters.
|
232
248
|
*
|
233
|
-
* @readonly
|
234
249
|
*/
|
235
250
|
readonly fullURL?: string;
|
236
251
|
/**
|
237
|
-
* The original URL string passed to the callApi instance
|
252
|
+
* The original URL string passed to the callApi instance (readonly)
|
238
253
|
*
|
239
254
|
* This preserves the original URL as provided, including any method modifiers like "@get/" or "@post/".
|
240
255
|
*
|
241
|
-
* @readonly
|
242
256
|
*/
|
243
257
|
readonly initURL?: string;
|
244
258
|
/**
|
245
|
-
* The URL string after normalization, with method modifiers removed
|
259
|
+
* The URL string after normalization, with method modifiers removed(readonly)
|
246
260
|
*
|
247
261
|
* Method modifiers like "@get/", "@post/" are stripped to create a clean URL
|
248
262
|
* for parameter substitution and final URL construction.
|
249
263
|
*
|
250
|
-
* @readonly
|
251
|
-
*
|
252
|
-
*
|
253
264
|
*/
|
254
265
|
readonly initURLNormalized?: string;
|
255
266
|
/**
|
@@ -345,14 +356,6 @@ interface CallApiSchemaConfig {
|
|
345
356
|
* swapping between `/api/v1` and `/api/v2`) without redefining the entire schema.
|
346
357
|
*/
|
347
358
|
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
359
|
/**
|
357
360
|
* Controls the strictness of API route validation.
|
358
361
|
*
|
@@ -410,10 +413,10 @@ type BaseCallApiSchemaAndConfig = {
|
|
410
413
|
};
|
411
414
|
//#endregion
|
412
415
|
//#region src/plugins.d.ts
|
413
|
-
type
|
416
|
+
type PluginSetupContext<TPluginExtraOptions = unknown> = RequestContext & PluginExtraOptions<TPluginExtraOptions> & {
|
414
417
|
initURL: string;
|
415
418
|
};
|
416
|
-
type PluginInitResult = Partial<Omit<
|
419
|
+
type PluginInitResult = Partial<Omit<PluginSetupContext, "initURL" | "request"> & {
|
417
420
|
initURL: InitURLOrURLObject;
|
418
421
|
request: CallApiRequestOptions;
|
419
422
|
}>;
|
@@ -436,10 +439,6 @@ interface CallApiPlugin {
|
|
436
439
|
* A unique id for the plugin
|
437
440
|
*/
|
438
441
|
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
442
|
/**
|
444
443
|
* A name for the plugin
|
445
444
|
*/
|
@@ -448,6 +447,10 @@ interface CallApiPlugin {
|
|
448
447
|
* Base schema for the client.
|
449
448
|
*/
|
450
449
|
schema?: BaseCallApiSchemaAndConfig;
|
450
|
+
/**
|
451
|
+
* A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
|
452
|
+
*/
|
453
|
+
setup?: (context: PluginSetupContext) => Awaitable<PluginInitResult> | Awaitable<void>;
|
451
454
|
/**
|
452
455
|
* A version for the plugin
|
453
456
|
*/
|
@@ -460,13 +463,13 @@ type DefaultPluginArray = CallApiPlugin[];
|
|
460
463
|
type DefaultThrowOnError = boolean;
|
461
464
|
//#endregion
|
462
465
|
//#region src/result.d.ts
|
463
|
-
type Parser = (responseString: string) => Awaitable<
|
464
|
-
declare const getResponseType: <TResponse>(response: Response, parser: Parser) => {
|
466
|
+
type Parser<TData> = (responseString: string) => Awaitable<TData>;
|
467
|
+
declare const getResponseType: <TResponse>(response: Response, parser: Parser<TResponse>) => {
|
465
468
|
arrayBuffer: () => Promise<ArrayBuffer>;
|
466
469
|
blob: () => Promise<Blob>;
|
467
470
|
formData: () => Promise<FormData>;
|
468
471
|
json: () => Promise<TResponse>;
|
469
|
-
stream: () => ReadableStream<Uint8Array<
|
472
|
+
stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
|
470
473
|
text: () => Promise<string>;
|
471
474
|
};
|
472
475
|
type InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;
|
@@ -860,6 +863,7 @@ type ResponseStreamContext = UnmaskType<RequestContext & {
|
|
860
863
|
}>;
|
861
864
|
//#endregion
|
862
865
|
//#region src/dedupe.d.ts
|
866
|
+
type DedupeStrategyUnion = UnmaskType<"cancel" | "defer" | "none">;
|
863
867
|
type DedupeOptions = {
|
864
868
|
/**
|
865
869
|
* Controls the scope of request deduplication caching.
|
@@ -1016,98 +1020,70 @@ type DedupeOptions = {
|
|
1016
1020
|
*/
|
1017
1021
|
dedupeKey?: string | ((context: RequestContext) => string);
|
1018
1022
|
/**
|
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
|
1023
|
+
* Strategy for handling duplicate requests. Can be a static string or callback function.
|
1052
1024
|
*
|
1025
|
+
* **Available Strategies:**
|
1026
|
+
* - `"cancel"`: Cancel previous request when new one starts (good for search)
|
1027
|
+
* - `"defer"`: Share response between duplicate requests (good for config loading)
|
1028
|
+
* - `"none"`: No deduplication, all requests execute independently
|
1053
1029
|
*
|
1054
1030
|
* @example
|
1055
1031
|
* ```ts
|
1056
|
-
* //
|
1032
|
+
* // Static strategies
|
1057
1033
|
* const searchClient = createFetchClient({
|
1058
|
-
* baseURL: "/api/search",
|
1059
1034
|
* dedupeStrategy: "cancel" // Cancel previous searches
|
1060
1035
|
* });
|
1061
1036
|
*
|
1062
|
-
* // Defer strategy - shared configuration
|
1063
1037
|
* const configClient = createFetchClient({
|
1064
1038
|
* dedupeStrategy: "defer" // Share config across components
|
1065
1039
|
* });
|
1066
1040
|
*
|
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
|
1041
|
+
* // Dynamic strategy based on request
|
1042
|
+
* const smartClient = createFetchClient({
|
1043
|
+
* dedupeStrategy: (context) => {
|
1044
|
+
* return context.options.method === "GET" ? "defer" : "cancel";
|
1045
|
+
* }
|
1077
1046
|
* });
|
1078
1047
|
*
|
1079
|
-
* //
|
1048
|
+
* // Search-as-you-type with cancel strategy
|
1080
1049
|
* const handleSearch = async (query: string) => {
|
1081
1050
|
* try {
|
1082
|
-
* const
|
1051
|
+
* const { data } = await callApi("/api/search", {
|
1083
1052
|
* method: "POST",
|
1084
1053
|
* body: { query },
|
1085
1054
|
* dedupeStrategy: "cancel",
|
1086
|
-
* dedupeKey: "search" //
|
1055
|
+
* dedupeKey: "search" // Cancel previous searches, only latest one goes through
|
1087
1056
|
* });
|
1088
|
-
*
|
1057
|
+
*
|
1058
|
+
* updateSearchResults(data);
|
1089
1059
|
* } catch (error) {
|
1090
1060
|
* if (error.name === "AbortError") {
|
1091
|
-
* // Previous search
|
1061
|
+
* // Previous search cancelled - (expected behavior)
|
1092
1062
|
* return;
|
1093
1063
|
* }
|
1094
|
-
*
|
1064
|
+
* console.error("Search failed:", error);
|
1095
1065
|
* }
|
1096
1066
|
* };
|
1097
1067
|
*
|
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
1068
|
* ```
|
1104
1069
|
*
|
1105
1070
|
* @default "cancel"
|
1106
1071
|
*/
|
1107
|
-
dedupeStrategy?:
|
1072
|
+
dedupeStrategy?: DedupeStrategyUnion | ((context: RequestContext) => DedupeStrategyUnion);
|
1108
1073
|
};
|
1109
1074
|
//#endregion
|
1110
1075
|
//#region src/retry.d.ts
|
1076
|
+
declare const defaultRetryStatusCodesLookup: () => {
|
1077
|
+
408: "Request Timeout";
|
1078
|
+
409: "Conflict";
|
1079
|
+
425: "Too Early";
|
1080
|
+
429: "Too Many Requests";
|
1081
|
+
500: "Internal Server Error";
|
1082
|
+
502: "Bad Gateway";
|
1083
|
+
503: "Service Unavailable";
|
1084
|
+
504: "Gateway Timeout";
|
1085
|
+
};
|
1086
|
+
type RetryStatusCodes = UnmaskType<AnyNumber | keyof ReturnType<typeof defaultRetryStatusCodesLookup>>;
|
1111
1087
|
type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
|
1112
1088
|
type InnerRetryKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, "~retryAttemptCount" | "retry">;
|
1113
1089
|
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 +1127,7 @@ interface RetryOptions<TErrorData> {
|
|
1151
1127
|
/**
|
1152
1128
|
* HTTP status codes that trigger a retry
|
1153
1129
|
*/
|
1154
|
-
retryStatusCodes?:
|
1130
|
+
retryStatusCodes?: RetryStatusCodes[];
|
1155
1131
|
/**
|
1156
1132
|
* Strategy to use when retrying
|
1157
1133
|
* @default "linear"
|
@@ -1185,8 +1161,7 @@ type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIf
|
|
1185
1161
|
}>;
|
1186
1162
|
type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
|
1187
1163
|
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, {
|
1164
|
+
type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema["method"], {
|
1190
1165
|
/**
|
1191
1166
|
* HTTP method for the request.
|
1192
1167
|
* @default "GET"
|
@@ -1202,7 +1177,7 @@ type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequire
|
|
1202
1177
|
baseHeaders: NonNullable<HeadersOption>;
|
1203
1178
|
}) => InferSchemaResult<TSchema["headers"], HeadersOption>);
|
1204
1179
|
}>;
|
1205
|
-
type InferRequestOptions<TSchema extends CallApiSchema,
|
1180
|
+
type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
|
1206
1181
|
interface Register {}
|
1207
1182
|
type GlobalMeta = Register extends {
|
1208
1183
|
meta?: infer TMeta extends Record<string, unknown>;
|
@@ -1240,8 +1215,13 @@ type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredI
|
|
1240
1215
|
query?: InferSchemaResult<TSchema["query"], Query>;
|
1241
1216
|
}>;
|
1242
1217
|
type EmptyString = "";
|
1243
|
-
type
|
1244
|
-
type
|
1218
|
+
type EmptyTuple = readonly [];
|
1219
|
+
type StringTuple = readonly string[];
|
1220
|
+
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;
|
1221
|
+
type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
|
1222
|
+
type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
|
1223
|
+
type InferParamsFromRoute<TCurrentRoute> = ExtractRouteParamNames<TCurrentRoute> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute>> : Params;
|
1224
|
+
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
1225
|
type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
|
1246
1226
|
/**
|
1247
1227
|
* Parameters to be appended to the URL (i.e: /:id)
|
@@ -1321,25 +1301,6 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
1321
1301
|
* ```
|
1322
1302
|
*/
|
1323
1303
|
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
1304
|
/**
|
1344
1305
|
* Custom function to serialize request body objects into strings.
|
1345
1306
|
*
|
@@ -1509,13 +1470,16 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
1509
1470
|
*/
|
1510
1471
|
meta?: GlobalMeta;
|
1511
1472
|
/**
|
1512
|
-
* Custom function to parse response strings into objects.
|
1473
|
+
* Custom function to parse response strings into objects instead of the default response.json().
|
1513
1474
|
*
|
1514
|
-
* Useful when
|
1515
|
-
* custom parsing logic for specific response formats.
|
1475
|
+
* Useful when you need custom parsing logic for specific response formats.
|
1516
1476
|
*
|
1517
1477
|
* @example
|
1518
1478
|
* ```ts
|
1479
|
+
* responseParser: (responseString) => {
|
1480
|
+
* return JSON.parse(responseString);
|
1481
|
+
* }
|
1482
|
+
*
|
1519
1483
|
* // Parse XML responses
|
1520
1484
|
* responseParser: (responseString) => {
|
1521
1485
|
* const parser = new DOMParser();
|
@@ -1534,22 +1498,12 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
1534
1498
|
* return obj;
|
1535
1499
|
* }, {});
|
1536
1500
|
* });
|
1537
|
-
* return
|
1501
|
+
* return data;
|
1538
1502
|
* }
|
1539
1503
|
*
|
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
1504
|
* ```
|
1551
1505
|
*/
|
1552
|
-
responseParser?: (responseString: string) => Awaitable<
|
1506
|
+
responseParser?: (responseString: string) => Awaitable<TData>;
|
1553
1507
|
/**
|
1554
1508
|
* Expected response type, determines how the response body is parsed.
|
1555
1509
|
*
|
@@ -1848,9 +1802,9 @@ type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultData
|
|
1848
1802
|
options: CallApiExtraOptions;
|
1849
1803
|
request: CallApiRequestOptions;
|
1850
1804
|
}) => 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,
|
1805
|
+
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
1806
|
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
1807
|
type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
|
1854
1808
|
//#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-
|
1809
|
+
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 };
|
1810
|
+
//# sourceMappingURL=common-Byku1Sji.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-Byku1Sji.js";
|
2
2
|
|
3
3
|
//#region src/createFetchClient.d.ts
|
4
4
|
|
@@ -21,14 +21,14 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
21
21
|
//#endregion
|
22
22
|
//#region src/defineHelpers.d.ts
|
23
23
|
declare const defineSchema: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, const TSchemaConfig extends CallApiSchemaConfig>(routes: TBaseSchemaRoutes, config?: TSchemaConfig) => {
|
24
|
-
config: TSchemaConfig
|
25
|
-
routes: Writeable<
|
24
|
+
config: Writeable<TSchemaConfig, "deep"> & {};
|
25
|
+
routes: Writeable<TBaseSchemaRoutes, "deep">;
|
26
26
|
};
|
27
|
-
declare const defineSchemaConfig: <const TConfig extends CallApiExtraOptions["schemaConfig"]>(config: TConfig) => Writeable<typeof config, "deep"
|
27
|
+
declare const defineSchemaConfig: <const TConfig extends CallApiExtraOptions["schemaConfig"]>(config: TConfig) => NonNullable<Writeable<typeof config, "deep">>;
|
28
28
|
declare const defineSchemaRoutes: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes>(routes: TBaseSchemaRoutes) => Writeable<typeof routes, "deep">;
|
29
29
|
declare const definePlugin: <const TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => Writeable<TPlugin, "deep">;
|
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
|