@zayne-labs/callapi 1.10.0 → 1.10.2

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 CHANGED
@@ -11,8 +11,8 @@
11
11
  <!-- <a href="https://deno.bundlejs.com/badge?q=@zayne-labs/callapi,@zayne-labs/callapi&treeshake=%5B*%5D,%5B%7B+createFetchClient+%7D%5D&config=%7B%22compression%22:%7B%22type%22:%22brotli%22,%22quality%22:11%7D%7D"><img src="https://deno.bundlejs.com/badge?q=@zayne-labs/callapi,@zayne-labs/callapi&treeshake=%5B*%5D,%5B%7B+createFetchClient+%7D%5D&config=%7B%22compression%22:%7B%22type%22:%22brotli%22,%22quality%22:11%7D%7D" alt="bundle size"></a> -->
12
12
  <a href="https://www.npmjs.com/package/@zayne-labs/callapi"><img src="https://img.shields.io/npm/v/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="npm version"></a>
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
- <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
14
  <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>
15
+ <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>
16
16
  <a href="https://deepwiki.com/zayne-labs/callapi"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
17
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
18
  </p>
@@ -58,7 +58,7 @@ type CustomAuth = {
58
58
  prefix: PossibleAuthValueOrGetter;
59
59
  value: PossibleAuthValueOrGetter;
60
60
  };
61
- type Auth = BearerOrTokenAuth | BasicAuth | CustomAuth;
61
+ type Auth = PossibleAuthValueOrGetter | BearerOrTokenAuth | BasicAuth | CustomAuth;
62
62
  //#endregion
63
63
  //#region src/constants/common.d.ts
64
64
  declare const fetchSpecificKeys: (keyof RequestInit | "duplex")[];
@@ -170,8 +170,7 @@ type HTTPErrorDetails<TErrorData> = Pick<CallApiExtraOptions, "defaultHTTPErrorM
170
170
  };
171
171
  declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
172
172
  errorData: HTTPErrorDetails<TErrorData>["errorData"];
173
- httpErrorSymbol: symbol;
174
- isHTTPError: boolean;
173
+ readonly httpErrorSymbol: symbol;
175
174
  name: "HTTPError";
176
175
  response: HTTPErrorDetails<TErrorData>["response"];
177
176
  constructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
@@ -188,14 +187,14 @@ type ValidationErrorDetails = {
188
187
  };
189
188
  declare class ValidationError extends Error {
190
189
  errorData: ValidationErrorDetails["issues"];
191
- name: string;
190
+ name: "ValidationError";
192
191
  response: ValidationErrorDetails["response"];
193
- validationErrorSymbol: symbol;
192
+ readonly validationErrorSymbol: symbol;
194
193
  constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
195
194
  /**
196
- * @description Checks if the given error is an instance of HTTPError
195
+ * @description Checks if the given error is an instance of ValidationError
197
196
  * @param error - The error to check
198
- * @returns true if the error is an instance of HTTPError, false otherwise
197
+ * @returns true if the error is an instance of ValidationError, false otherwise
199
198
  */
200
199
  static isError(error: unknown): error is ValidationError;
201
200
  }
@@ -321,7 +320,8 @@ interface URLOptions {
321
320
  }
322
321
  //#endregion
323
322
  //#region src/validation.d.ts
324
- type InferSchemaResult<TSchema, TFallbackResult = unknown> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
323
+ type InferSchemaOutputResult<TSchema, TFallbackResult = unknown> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
324
+ type InferSchemaInputResult<TSchema, TFallbackResult = unknown> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
325
325
  interface CallApiSchemaConfig {
326
326
  /**
327
327
  * The base url of the schema. By default it's the baseURL of the callApi instance.
@@ -500,14 +500,18 @@ type CallApiResultErrorVariant<TErrorData> = {
500
500
  error: PossibleJavaScriptOrValidationError;
501
501
  response: Response | null;
502
502
  };
503
- type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedErrorData = GetResponseType<TErrorData, TResponseType>> = UnmaskType<{
504
- all: CallApiResultSuccessVariant<TComputedData> | CallApiResultErrorVariant<TComputedErrorData>;
505
- allWithException: CallApiResultSuccessVariant<TComputedData>;
506
- onlySuccess: CallApiResultErrorVariant<TComputedErrorData>["data"] | CallApiResultSuccessVariant<TComputedData>["data"];
507
- onlySuccessWithException: CallApiResultSuccessVariant<TComputedData>["data"];
503
+ type ResultModeMapWithoutException<TData, TErrorData, TResponseType extends ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedErrorData = GetResponseType<TErrorData, TResponseType>> = UnmaskType<{
504
+ all: CallApiResultErrorVariant<TComputedErrorData> | CallApiResultSuccessVariant<TComputedData>;
505
+ onlyData: CallApiResultErrorVariant<TComputedErrorData>["data"] | CallApiResultSuccessVariant<TComputedData>["data"];
508
506
  }>;
509
- type ResultModeUnion = keyof ResultModeMap | null;
510
- type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = TErrorData extends false ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : TErrorData extends false | undefined ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : TErrorData extends false | null ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccess"] : null extends TResultMode ? TThrowOnError extends true ? ResultModeMap<TData, TErrorData, TResponseType>["allWithException"] : ResultModeMap<TData, TErrorData, TResponseType>["all"] : TResultMode extends NonNullable<ResultModeUnion> ? ResultModeMap<TData, TErrorData, TResponseType>[TResultMode] : never;
507
+ type ResultModeMapWithException<TData, TResponseType extends ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>> = {
508
+ all: CallApiResultSuccessVariant<TComputedData>;
509
+ onlyData: CallApiResultSuccessVariant<TComputedData>["data"];
510
+ };
511
+ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TThrowOnError extends ThrowOnErrorUnion = false> = TThrowOnError extends true ? ResultModeMapWithException<TData, TResponseType> : ResultModeMapWithoutException<TData, TErrorData, TResponseType>;
512
+ type ResultModePlaceholder = null;
513
+ type ResultModeUnion = keyof ResultModeMap | ResultModePlaceholder;
514
+ type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = TErrorData extends false ? ResultModeMapWithException<TData, TResponseType>["onlyData"] : TErrorData extends false | undefined ? ResultModeMapWithException<TData, TResponseType>["onlyData"] : ResultModePlaceholder extends TResultMode ? ResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>["all"] : TResultMode extends Exclude<ResultModeUnion, ResultModePlaceholder> ? ResultModeMap<TData, TErrorData, TResponseType, TThrowOnError>[TResultMode] : never;
511
515
  //#endregion
512
516
  //#region src/stream.d.ts
513
517
  type StreamProgressEvent = {
@@ -1130,7 +1134,7 @@ interface RetryOptions<TErrorData> {
1130
1134
  /**
1131
1135
  * @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
1132
1136
  */
1133
- type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaResult<TSchemaOption, undefined> ? TObject : Required<TObject>;
1137
+ type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaInputResult<TSchemaOption, undefined> ? TObject : Required<TObject>;
1134
1138
  type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["prefix"] extends string ? `${TSchemaConfig["prefix"]}${TSchemaRouteKeys}` : TSchemaConfig["baseURL"] extends string ? `${TSchemaConfig["baseURL"]}${TSchemaRouteKeys}` : TSchemaRouteKeys;
1135
1139
  type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["strict"] extends true ? TSchemaRouteKeys :
1136
1140
  // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
@@ -1148,7 +1152,7 @@ type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIf
1148
1152
  /**
1149
1153
  * Body of the request, can be a object or any other supported body type.
1150
1154
  */
1151
- body?: InferSchemaResult<TSchema["body"], Body>;
1155
+ body?: InferSchemaInputResult<TSchema["body"], Body>;
1152
1156
  }>;
1153
1157
  type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
1154
1158
  type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
@@ -1157,16 +1161,16 @@ type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOpti
1157
1161
  * HTTP method for the request.
1158
1162
  * @default "GET"
1159
1163
  */
1160
- method?: InferSchemaResult<TSchema["method"], InferMethodFromURL<TInitURL>>;
1164
+ method?: InferSchemaInputResult<TSchema["method"], InferMethodFromURL<TInitURL>>;
1161
1165
  }>;
1162
1166
  type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
1163
1167
  type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["headers"], {
1164
1168
  /**
1165
1169
  * Headers to be used in the request.
1166
1170
  */
1167
- headers?: InferSchemaResult<TSchema["headers"], HeadersOption> | ((context: {
1171
+ headers?: InferSchemaInputResult<TSchema["headers"], HeadersOption> | ((context: {
1168
1172
  baseHeaders: NonNullable<HeadersOption>;
1169
- }) => InferSchemaResult<TSchema["headers"], HeadersOption>);
1173
+ }) => InferSchemaInputResult<TSchema["headers"], HeadersOption>);
1170
1174
  }>;
1171
1175
  type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
1172
1176
  interface Register {}
@@ -1197,13 +1201,13 @@ type InferMetaOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIf
1197
1201
  * });
1198
1202
  * ```
1199
1203
  */
1200
- meta?: InferSchemaResult<TSchema["meta"], GlobalMeta>;
1204
+ meta?: InferSchemaInputResult<TSchema["meta"], GlobalMeta>;
1201
1205
  }>;
1202
1206
  type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["query"], {
1203
1207
  /**
1204
1208
  * Parameters to be appended to the URL (i.e: /:id)
1205
1209
  */
1206
- query?: InferSchemaResult<TSchema["query"], Query>;
1210
+ query?: InferSchemaInputResult<TSchema["query"], Query>;
1207
1211
  }>;
1208
1212
  type EmptyString = "";
1209
1213
  type EmptyTuple = readonly [];
@@ -1213,22 +1217,19 @@ type ExtractRouteParamNames<TCurrentRoute, TParamNamesAccumulator extends String
1213
1217
  type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
1214
1218
  type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
1215
1219
  type InferParamsFromRoute<TCurrentRoute> = ExtractRouteParamNames<TCurrentRoute> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute>> : Params;
1216
- type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaResult<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
1220
+ type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaInputResult<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
1217
1221
  type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
1218
1222
  /**
1219
1223
  * Parameters to be appended to the URL (i.e: /:id)
1220
1224
  */
1221
- params?: InferSchemaResult<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
1225
+ params?: InferSchemaInputResult<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
1222
1226
  }>;
1223
1227
  type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
1224
- type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction<infer TReturnedSchema> ? InferSchemaResult<TReturnedSchema> : never : never : never>;
1225
- type ExtractKeys<TUnion, TSelectedUnion extends TUnion> = Extract<TUnion, TSelectedUnion>;
1228
+ type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction<infer TReturnedSchema> ? InferSchemaOutputResult<TReturnedSchema> : never : never : never>;
1226
1229
  type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
1227
- resultMode: "onlySuccessWithException";
1230
+ resultMode: "onlyData";
1228
1231
  } : TErrorData extends false | undefined ? {
1229
- resultMode?: "onlySuccessWithException";
1230
- } : TErrorData extends false | null ? {
1231
- resultMode?: ExtractKeys<ResultModeUnion, "onlySuccess" | "onlySuccessWithException">;
1232
+ resultMode?: "onlyData";
1232
1233
  } : {
1233
1234
  resultMode?: TResultMode;
1234
1235
  };
@@ -1272,27 +1273,10 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
1272
1273
  * Supports multiple authentication patterns:
1273
1274
  * - String: Direct authorization header value
1274
1275
  * - Auth object: Structured authentication configuration
1275
- * - null: Explicitly removes authorization
1276
- *
1277
- * @example
1278
- * ```ts
1279
- * // Bearer token authentication
1280
- * auth: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
1281
1276
  *
1282
- * // Basic authentication
1283
- * auth: "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
1284
- *
1285
- * // Using Auth object for dynamic authentication
1286
- * auth: {
1287
- * type: "bearer",
1288
- * token: () => getAccessToken()
1289
- * }
1290
- *
1291
- * // Remove inherited auth from base config
1292
- * auth: null
1293
1277
  * ```
1294
1278
  */
1295
- auth?: string | Auth | null;
1279
+ auth?: Auth;
1296
1280
  /**
1297
1281
  * Custom function to serialize request body objects into strings.
1298
1282
  *
@@ -1536,46 +1520,50 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
1536
1520
  *
1537
1521
  * Different modes return different combinations of data, error, and response:
1538
1522
  * - **"all"**: Returns { data, error, response } - complete result information
1539
- * - **"allWithException"**: Returns { data, error, response } but throws on errors
1540
- * - **"onlySuccess"**: Returns only data (null for errors), never throws
1541
- * - **"onlySuccessWithException"**: Returns only data but throws on errors
1523
+ * - **"onlyData"**: Returns only data (null for errors)
1524
+ *
1525
+ * When combined with throwOnError: true, null/error variants are automatically removed:
1526
+ * - **"all" + throwOnError: true**: Returns { data, error: null, response } (error property is null, throws instead)
1527
+ * - **"onlyData" + throwOnError: true**: Returns data (never null, throws on error)
1542
1528
  *
1543
1529
  * @default "all"
1544
1530
  *
1545
1531
  * @example
1546
1532
  * ```ts
1547
1533
  * // Complete result with all information (default)
1548
- * resultMode: "all"
1549
- * const { data, error, response } = await callApi("/users");
1534
+ * const { data, error, response } = await callApi("/users", { resultMode: "all" });
1550
1535
  * if (error) {
1551
1536
  * console.error("Request failed:", error);
1552
1537
  * } else {
1553
1538
  * console.log("Users:", data);
1554
1539
  * }
1555
1540
  *
1556
- * // Complete result but throws on errors
1557
- * resultMode: "allWithException"
1541
+ * // Complete result but throws on errors (throwOnError removes error from type)
1558
1542
  * try {
1559
- * const { data, response } = await callApi("/users", { resultMode: "allWithException" });
1560
- * console.log("Users:", data);
1543
+ * const { data, response } = await callApi("/users", {
1544
+ * resultMode: "all",
1545
+ * throwOnError: true
1546
+ * });
1547
+ * console.log("Users:", data); // data is never null here
1561
1548
  * } catch (error) {
1562
1549
  * console.error("Request failed:", error);
1563
1550
  * }
1564
1551
  *
1565
1552
  * // Only data, returns null on errors
1566
- * resultMode: "onlySuccess"
1567
- * const users = await callApi("/users", { resultMode: "onlySuccess" });
1553
+ * const users = await callApi("/users", { resultMode: "onlyData" });
1568
1554
  * if (users) {
1569
1555
  * console.log("Users:", users);
1570
1556
  * } else {
1571
1557
  * console.log("Request failed");
1572
1558
  * }
1573
1559
  *
1574
- * // Only data with null, throws on errors
1575
- * resultMode: "onlySuccessWithException"
1560
+ * // Only data, throws on errors (throwOnError removes null from type)
1576
1561
  * try {
1577
- * const users = await callApi("/users", { resultMode: "onlySuccessWithException" });
1578
- * console.log("Users:", users);
1562
+ * const users = await callApi("/users", {
1563
+ * resultMode: "onlyData",
1564
+ * throwOnError: true
1565
+ * });
1566
+ * console.log("Users:", users); // users is never null here
1579
1567
  * } catch (error) {
1580
1568
  * console.error("Request failed:", error);
1581
1569
  * }
@@ -1797,5 +1785,5 @@ type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResul
1797
1785
  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>];
1798
1786
  type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
1799
1787
  //#endregion
1800
- 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, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey };
1801
- //# sourceMappingURL=common-DzOcclPA.d.ts.map
1788
+ 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, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey };
1789
+ //# sourceMappingURL=common-ChqKsMZ2.d.ts.map
@@ -1,8 +1,8 @@
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, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-DzOcclPA.js";
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, GetResponseType, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaOutputResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeMap, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, fallBackRouteSchemaKey } from "./common-ChqKsMZ2.js";
2
2
 
3
3
  //#region src/createFetchClient.d.ts
4
4
 
5
- declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = NonNullable<Writeable<TBaseSchemaAndConfig["config"], "deep">>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = Writeable<TBaseSchemaAndConfig["routes"], "deep">>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaResult<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray> | undefined) => CallApiResult<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
5
+ declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = NonNullable<Writeable<TBaseSchemaAndConfig["config"], "deep">>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = Writeable<TBaseSchemaAndConfig["routes"], "deep">>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray> | undefined) => CallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
6
6
  declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<{
7
7
  [x: AnyString]: CallApiSchema | undefined;
8
8
  "@delete/"?: CallApiSchema | undefined;
@@ -38,14 +38,14 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
38
38
  "@patch/"?: CallApiSchema | undefined;
39
39
  "@post/"?: CallApiSchema | undefined;
40
40
  "@put/"?: CallApiSchema | undefined;
41
- }[TCurrentRouteSchemaKey], "deep">>>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>>, InferSchemaResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>>, TResultMode, TThrowOnError, TResponseType, {
41
+ }[TCurrentRouteSchemaKey], "deep">>>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>>, TResultMode, TThrowOnError, TResponseType, {
42
42
  [x: AnyString]: CallApiSchema | undefined;
43
43
  "@delete/"?: CallApiSchema | undefined;
44
44
  "@get/"?: CallApiSchema | undefined;
45
45
  "@patch/"?: CallApiSchema | undefined;
46
46
  "@post/"?: CallApiSchema | undefined;
47
47
  "@put/"?: CallApiSchema | undefined;
48
- }, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray> | undefined) => CallApiResult<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
48
+ }, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray> | undefined) => CallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
49
49
  //#endregion
50
50
  //#region src/defineHelpers.d.ts
51
51
  declare const defineSchema: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, const TSchemaConfig extends CallApiSchemaConfig>(routes: TBaseSchemaRoutes, config?: TSchemaConfig) => {
@@ -58,5 +58,5 @@ declare const definePlugin: <const TPlugin extends CallApiPlugin | AnyFunction<C
58
58
  declare const defineBaseConfig: <const TBaseConfig extends BaseCallApiConfig>(baseConfig: TBaseConfig) => Writeable<typeof baseConfig, "deep">;
59
59
  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>;
60
60
  //#endregion
61
- 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, fallBackRouteSchemaKey };
61
+ 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 InferSchemaOutputResult, 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, fallBackRouteSchemaKey };
62
62
  //# sourceMappingURL=index.d.ts.map
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { HTTPError, ValidationError, createCombinedSignal, createTimeoutSignal, defineEnum, deterministicHashFn, extraOptionDefaults, getBody, getFetchImpl, getHeaders, isArray, isBoolean, isFunction, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, requestOptionDefaults, splitBaseConfig, splitConfig, toArray, toQueryString, waitFor } from "./utils-B5rSU71M.js";
1
+ import { HTTPError, ValidationError, createCombinedSignal, createTimeoutSignal, defineEnum, deterministicHashFn, extraOptionDefaults, getBody, getFetchImpl, getHeaders, isArray, isBoolean, isFunction, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, requestOptionDefaults, splitBaseConfig, splitConfig, toArray, toQueryString, waitFor } from "./utils-zvYT8TK8.js";
2
2
 
3
3
  //#region src/result.ts
4
4
  const getResponseType = (response, parser) => ({
@@ -35,24 +35,18 @@ const resolveResponseData = (response, responseType, parser) => {
35
35
  return RESPONSE_TYPE_LOOKUP[selectedResponseType]();
36
36
  };
37
37
  const getResultModeMap = (details) => {
38
- const resultModeMap = {
38
+ return {
39
39
  all: () => details,
40
- allWithException: () => resultModeMap.all(),
41
- onlySuccess: () => details.data,
42
- onlySuccessWithException: () => resultModeMap.onlySuccess()
40
+ onlyData: () => details.data
43
41
  };
44
- return resultModeMap;
45
42
  };
46
43
  const resolveSuccessResult = (data, info) => {
47
44
  const { response, resultMode } = info;
48
- const details = {
45
+ return getResultModeMap({
49
46
  data,
50
47
  error: null,
51
48
  response
52
- };
53
- const resultModeMap = getResultModeMap(details);
54
- const successResult = resultModeMap[resultMode ?? "all"]();
55
- return successResult;
49
+ })[resultMode ?? "all"]();
56
50
  };
57
51
  const resolveErrorResult = (error, info) => {
58
52
  const { cloneResponse, message: customErrorMessage, resultMode } = info;
@@ -92,8 +86,7 @@ const resolveErrorResult = (error, info) => {
92
86
  response: cloneResponse ? response.clone() : response
93
87
  };
94
88
  }
95
- const resultModeMap = getResultModeMap(errorDetails);
96
- const generalErrorResult = resultModeMap[resultMode ?? "all"]();
89
+ const generalErrorResult = getResultModeMap(errorDetails)[resultMode ?? "all"]();
97
90
  return {
98
91
  errorDetails,
99
92
  generalErrorResult
@@ -270,12 +263,8 @@ const createDedupeStrategy = async (context) => {
270
263
  const dedupeStrategy = globalOptions.dedupeStrategy ?? extraOptionDefaults().dedupeStrategy;
271
264
  const resolvedDedupeStrategy = isFunction(dedupeStrategy) ? dedupeStrategy(context) : dedupeStrategy;
272
265
  const getDedupeKey = () => {
273
- const shouldHaveDedupeKey = resolvedDedupeStrategy === "cancel" || resolvedDedupeStrategy === "defer";
274
- if (!shouldHaveDedupeKey) return null;
275
- if (globalOptions.dedupeKey) {
276
- const resolvedDedupeKey = isFunction(globalOptions.dedupeKey) ? globalOptions.dedupeKey(context) : globalOptions.dedupeKey;
277
- return resolvedDedupeKey;
278
- }
266
+ if (!(resolvedDedupeStrategy === "cancel" || resolvedDedupeStrategy === "defer")) return null;
267
+ if (globalOptions.dedupeKey) return isFunction(globalOptions.dedupeKey) ? globalOptions.dedupeKey(context) : globalOptions.dedupeKey;
279
268
  return `${globalOptions.fullURL}-${deterministicHashFn({
280
269
  options: globalOptions,
281
270
  request: globalRequest
@@ -298,8 +287,7 @@ const createDedupeStrategy = async (context) => {
298
287
  return `Duplicate request detected - Aborted previous request to '${globalOptions.fullURL}' as a new request with identical options was initiated`;
299
288
  };
300
289
  const handleRequestCancelStrategy = () => {
301
- const shouldCancelRequest = prevRequestInfo && resolvedDedupeStrategy === "cancel";
302
- if (!shouldCancelRequest) return;
290
+ if (!(prevRequestInfo && resolvedDedupeStrategy === "cancel")) return;
303
291
  const message = getAbortErrorMessage();
304
292
  const reason = new DOMException(message, "AbortError");
305
293
  prevRequestInfo.controller.abort(reason);
@@ -321,11 +309,10 @@ const createDedupeStrategy = async (context) => {
321
309
  controller: newFetchController,
322
310
  responsePromise
323
311
  });
324
- const streamableResponse = toStreamableResponse({
312
+ return toStreamableResponse({
325
313
  ...streamableContext,
326
314
  response: await responsePromise
327
315
  });
328
- return streamableResponse;
329
316
  };
330
317
  const removeDedupeKeyFromCache = () => {
331
318
  $RequestInfoCacheOrNull?.delete(dedupeKey);
@@ -343,10 +330,9 @@ const createDedupeStrategy = async (context) => {
343
330
  //#region src/validation.ts
344
331
  const handleValidatorFunction = async (validator, inputData) => {
345
332
  try {
346
- const result = await validator(inputData);
347
333
  return {
348
334
  issues: void 0,
349
- value: result
335
+ value: await validator(inputData)
350
336
  };
351
337
  } catch (error) {
352
338
  return {
@@ -373,8 +359,7 @@ const routeKeyMethods = defineEnum([
373
359
  const handleSchemaValidation = async (schema, validationOptions) => {
374
360
  const { inputValue, response, schemaConfig } = validationOptions;
375
361
  if (!schema || schemaConfig?.disableRuntimeValidation) return inputValue;
376
- const validResult = await standardSchemaParser(schema, inputValue, response);
377
- return validResult;
362
+ return await standardSchemaParser(schema, inputValue, response);
378
363
  };
379
364
  const extraOptionsToBeValidated = [
380
365
  "meta",
@@ -474,8 +459,7 @@ const getResolvedSchema = (context) => {
474
459
  };
475
460
  const getResolvedSchemaConfig = (context) => {
476
461
  const { baseExtraOptions, extraOptions } = context;
477
- const resolvedSchemaConfig = isFunction(extraOptions.schemaConfig) ? extraOptions.schemaConfig({ baseSchemaConfig: baseExtraOptions.schema?.config ?? {} }) : extraOptions.schemaConfig ?? baseExtraOptions.schema?.config;
478
- return resolvedSchemaConfig;
462
+ return isFunction(extraOptions.schemaConfig) ? extraOptions.schemaConfig({ baseSchemaConfig: baseExtraOptions.schema?.config ?? {} }) : extraOptions.schemaConfig ?? baseExtraOptions.schema?.config;
479
463
  };
480
464
  const getCurrentRouteSchemaKeyAndMainInitURL = (context) => {
481
465
  const { baseExtraOptions, extraOptions, initURL } = context;
@@ -500,8 +484,7 @@ const getCurrentRouteSchemaKeyAndMainInitURL = (context) => {
500
484
  //#region src/plugins.ts
501
485
  const getResolvedPlugins = (context) => {
502
486
  const { baseConfig, options } = context;
503
- const resolvedPlugins = isFunction(options.plugins) ? options.plugins({ basePlugins: baseConfig.plugins ?? [] }) : options.plugins ?? [];
504
- return resolvedPlugins;
487
+ return isFunction(options.plugins) ? options.plugins({ basePlugins: baseConfig.plugins ?? [] }) : options.plugins ?? [];
505
488
  };
506
489
  const initializePlugins = async (context) => {
507
490
  const { baseConfig, config, initURL, options, request } = context;
@@ -574,8 +557,7 @@ const initializePlugins = async (context) => {
574
557
  const flattenedHookArray = [...hookRegistry].flat();
575
558
  if (flattenedHookArray.length === 0) continue;
576
559
  const hooksExecutionMode = options.hooksExecutionMode ?? extraOptionDefaults().hooksExecutionMode;
577
- const composedHook = composeAllHooks(flattenedHookArray, hooksExecutionMode);
578
- resolvedHooks[key] = composedHook;
560
+ resolvedHooks[key] = composeAllHooks(flattenedHookArray, hooksExecutionMode);
579
561
  }
580
562
  return {
581
563
  resolvedCurrentRouteSchemaKey,
@@ -590,8 +572,7 @@ const initializePlugins = async (context) => {
590
572
  //#region src/retry.ts
591
573
  const getLinearDelay = (currentAttemptCount, options) => {
592
574
  const retryDelay = options.retryDelay ?? options.retry?.delay;
593
- const resolveRetryDelay = (isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay) ?? extraOptionDefaults().retryDelay;
594
- return resolveRetryDelay;
575
+ return (isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay) ?? extraOptionDefaults().retryDelay;
595
576
  };
596
577
  const getExponentialDelay = (currentAttemptCount, options) => {
597
578
  const retryDelay = options.retryDelay ?? options.retry?.delay ?? extraOptionDefaults().retryDelay;
@@ -616,14 +597,12 @@ const createRetryStrategy = (ctx) => {
616
597
  const retryCondition = options.retryCondition ?? options.retry?.condition ?? extraOptionDefaults().retryCondition;
617
598
  const maximumRetryAttempts = options.retryAttempts ?? options.retry?.attempts ?? extraOptionDefaults().retryAttempts;
618
599
  const customRetryCondition = await retryCondition(ctx);
619
- const baseShouldRetry = currentAttemptCount <= maximumRetryAttempts && customRetryCondition;
620
- if (!baseShouldRetry) return false;
600
+ if (!(currentAttemptCount <= maximumRetryAttempts && customRetryCondition)) return false;
621
601
  const retryMethods = new Set(options.retryMethods ?? options.retry?.methods ?? extraOptionDefaults().retryMethods);
622
602
  const includesMethod = isString(ctx.request.method) && retryMethods.size > 0 ? retryMethods.has(ctx.request.method) : true;
623
603
  const retryStatusCodes = new Set(options.retryStatusCodes ?? options.retry?.statusCodes ?? extraOptionDefaults().retryStatusCodes);
624
604
  const includesStatusCodes = Boolean(ctx.response) && retryStatusCodes.size > 0 ? retryStatusCodes.has(ctx.response.status) : true;
625
- const shouldRetry = includesMethod && includesStatusCodes;
626
- return shouldRetry;
605
+ return includesMethod && includesStatusCodes;
627
606
  };
628
607
  return {
629
608
  currentAttemptCount,
@@ -642,8 +621,7 @@ const mergeUrlWithParams = (url, params) => {
642
621
  if (!params) return url;
643
622
  let newUrl = url;
644
623
  if (isArray(params)) {
645
- const urlParts = newUrl.split(slash);
646
- const matchedParamsArray = urlParts.filter((part) => part.startsWith(colon) || part.startsWith(openBrace) && part.endsWith(closeBrace));
624
+ const matchedParamsArray = newUrl.split(slash).filter((part) => part.startsWith(colon) || part.startsWith(openBrace) && part.endsWith(closeBrace));
647
625
  for (const [paramIndex, matchedParam] of matchedParamsArray.entries()) {
648
626
  const stringParamValue = String(params[paramIndex]);
649
627
  newUrl = newUrl.replace(matchedParam, stringParamValue);
@@ -714,18 +692,15 @@ const getMethod = (ctx) => {
714
692
  const normalizeURL = (initURL) => {
715
693
  const methodFromURL = extractMethodFromURL(initURL);
716
694
  if (!methodFromURL) return initURL;
717
- const normalizedURL = initURL.replace(`@${methodFromURL}/`, "/");
718
- return normalizedURL;
695
+ return initURL.replace(`@${methodFromURL}/`, "/");
719
696
  };
720
697
  const getFullAndNormalizedURL = (options) => {
721
698
  const { baseURL, initURL, params, query } = options;
722
699
  const normalizedInitURL = normalizeURL(initURL);
723
700
  const urlWithMergedParams = mergeUrlWithParams(normalizedInitURL, params);
724
701
  const urlWithMergedQueryAndParams = mergeUrlWithQuery(urlWithMergedParams, query);
725
- const shouldPrependBaseURL = !urlWithMergedQueryAndParams.startsWith("http") && baseURL;
726
- const fullURL = shouldPrependBaseURL ? `${baseURL}${urlWithMergedQueryAndParams}` : urlWithMergedQueryAndParams;
727
702
  return {
728
- fullURL,
703
+ fullURL: !urlWithMergedQueryAndParams.startsWith("http") && baseURL ? `${baseURL}${urlWithMergedQueryAndParams}` : urlWithMergedQueryAndParams,
729
704
  normalizedInitURL
730
705
  };
731
706
  };
@@ -738,12 +713,11 @@ const createFetchClient = (initBaseConfig = {}) => {
738
713
  const callApi$1 = async (...parameters) => {
739
714
  const [initURLOrURLObject, initConfig = {}] = parameters;
740
715
  const [fetchOptions, extraOptions] = splitConfig(initConfig);
741
- const resolvedBaseConfig = isFunction(initBaseConfig) ? initBaseConfig({
716
+ const baseConfig = isFunction(initBaseConfig) ? initBaseConfig({
742
717
  initURL: initURLOrURLObject.toString(),
743
718
  options: extraOptions,
744
719
  request: fetchOptions
745
720
  }) : initBaseConfig;
746
- const baseConfig = resolvedBaseConfig;
747
721
  const config = initConfig;
748
722
  const [baseFetchOptions, baseExtraOptions] = splitBaseConfig(baseConfig);
749
723
  const shouldSkipAutoMergeForOptions = baseExtraOptions.skipAutoMergeFor === "all" || baseExtraOptions.skipAutoMergeFor === "options";
@@ -870,11 +844,10 @@ const createFetchClient = (initBaseConfig = {}) => {
870
844
  ...successContext,
871
845
  error: null
872
846
  }));
873
- const successResult = resolveSuccessResult(successContext.data, {
847
+ return resolveSuccessResult(successContext.data, {
874
848
  response: successContext.response,
875
849
  resultMode: options.resultMode
876
850
  });
877
- return successResult;
878
851
  } catch (error) {
879
852
  const errorInfo = {
880
853
  cloneResponse: options.cloneResponse,
@@ -896,14 +869,13 @@ const createFetchClient = (initBaseConfig = {}) => {
896
869
  };
897
870
  const handleRetryOrGetErrorResult = async () => {
898
871
  const { currentAttemptCount, getDelay, shouldAttemptRetry } = createRetryStrategy(errorContext);
899
- const shouldRetry = await shouldAttemptRetry();
900
- if (shouldRetry) {
872
+ if (await shouldAttemptRetry()) {
901
873
  const retryContext = {
902
874
  ...errorContext,
903
875
  retryAttemptCount: currentAttemptCount
904
876
  };
905
- const hookError$1 = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);
906
- if (hookError$1) return hookError$1;
877
+ const hookError = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);
878
+ if (hookError) return hookError;
907
879
  const delay = getDelay();
908
880
  await waitFor(delay);
909
881
  const updatedOptions = {
@@ -915,25 +887,19 @@ const createFetchClient = (initBaseConfig = {}) => {
915
887
  if (shouldThrowOnError) throw error;
916
888
  return generalErrorResult;
917
889
  };
918
- if (isValidationErrorInstance(error)) {
919
- const hookError$1 = await executeHooksInCatchBlock([
920
- options.onValidationError?.(errorContext),
921
- options.onRequestError?.(errorContext),
922
- options.onError?.(errorContext)
923
- ], hookInfo);
924
- return hookError$1 ?? await handleRetryOrGetErrorResult();
925
- }
926
- if (isHTTPErrorInstance(error)) {
927
- const hookError$1 = await executeHooksInCatchBlock([
928
- options.onResponseError?.(errorContext),
929
- options.onError?.(errorContext),
930
- options.onResponse?.({
931
- ...errorContext,
932
- data: null
933
- })
934
- ], hookInfo);
935
- return hookError$1 ?? await handleRetryOrGetErrorResult();
936
- }
890
+ if (isValidationErrorInstance(error)) return await executeHooksInCatchBlock([
891
+ options.onValidationError?.(errorContext),
892
+ options.onRequestError?.(errorContext),
893
+ options.onError?.(errorContext)
894
+ ], hookInfo) ?? await handleRetryOrGetErrorResult();
895
+ if (isHTTPErrorInstance(error)) return await executeHooksInCatchBlock([
896
+ options.onResponseError?.(errorContext),
897
+ options.onError?.(errorContext),
898
+ options.onResponse?.({
899
+ ...errorContext,
900
+ data: null
901
+ })
902
+ ], hookInfo) ?? await handleRetryOrGetErrorResult();
937
903
  let message = error?.message;
938
904
  if (error instanceof DOMException && error.name === "AbortError") {
939
905
  message = getAbortErrorMessage();
@@ -943,8 +909,7 @@ const createFetchClient = (initBaseConfig = {}) => {
943
909
  message = `Request timed out after ${options.timeout}ms`;
944
910
  !shouldThrowOnError && console.error(`${error.name}:`, message);
945
911
  }
946
- const hookError = await executeHooksInCatchBlock([options.onRequestError?.(errorContext), options.onError?.(errorContext)], hookInfo);
947
- return hookError ?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message });
912
+ return await executeHooksInCatchBlock([options.onRequestError?.(errorContext), options.onError?.(errorContext)], hookInfo) ?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message });
948
913
  } finally {
949
914
  removeDedupeKeyFromCache();
950
915
  }