@zayne-labs/callapi 1.11.40 → 1.11.42

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.
@@ -678,40 +678,41 @@ interface CallApiSchemaConfig {
678
678
  */
679
679
  strict?: boolean;
680
680
  }
681
+ type CallApiSchemaType<TInput> = StandardSchemaV1<TInput | undefined> | ((value: TInput) => Awaitable<TInput | undefined>);
681
682
  interface CallApiSchema {
682
- auth?: StandardSchemaV1<AuthOption | undefined> | ((auth: AuthOption) => Awaitable<AuthOption | undefined>);
683
+ auth?: CallApiSchemaType<AuthOption>;
683
684
  /**
684
685
  * The schema to use for validating the request body.
685
686
  */
686
- body?: StandardSchemaV1<Body | undefined> | ((body: Body) => Awaitable<Body | undefined>);
687
+ body?: CallApiSchemaType<Body>;
687
688
  /**
688
689
  * The schema to use for validating the response data.
689
690
  */
690
- data?: StandardSchemaV1 | ((data: unknown) => unknown);
691
+ data?: CallApiSchemaType<unknown>;
691
692
  /**
692
693
  * The schema to use for validating the response error data.
693
694
  */
694
- errorData?: StandardSchemaV1 | ((errorData: unknown) => unknown);
695
+ errorData?: CallApiSchemaType<unknown>;
695
696
  /**
696
697
  * The schema to use for validating the request headers.
697
698
  */
698
- headers?: StandardSchemaV1<HeadersOption | undefined> | ((headers: HeadersOption) => Awaitable<HeadersOption | undefined>);
699
+ headers?: CallApiSchemaType<HeadersOption>;
699
700
  /**
700
701
  * The schema to use for validating the meta option.
701
702
  */
702
- meta?: StandardSchemaV1<GlobalMeta | undefined> | ((meta: GlobalMeta) => Awaitable<GlobalMeta | undefined>);
703
+ meta?: CallApiSchemaType<GlobalMeta>;
703
704
  /**
704
705
  * The schema to use for validating the request method.
705
706
  */
706
- method?: StandardSchemaV1<MethodUnion | undefined> | ((method: MethodUnion) => Awaitable<MethodUnion | undefined>);
707
+ method?: CallApiSchemaType<MethodUnion>;
707
708
  /**
708
709
  * The schema to use for validating the request url parameters.
709
710
  */
710
- params?: StandardSchemaV1<Params | undefined> | ((params: Params) => Awaitable<Params | undefined>);
711
+ params?: CallApiSchemaType<Params>;
711
712
  /**
712
713
  * The schema to use for validating the request url queries.
713
714
  */
714
- query?: StandardSchemaV1<Query | undefined> | ((query: Query) => Awaitable<Query | undefined>);
715
+ query?: CallApiSchemaType<Query>;
715
716
  }
716
717
  declare const routeKeyMethods: readonly ["delete", "get", "patch", "post", "put"];
717
718
  type RouteKeyMethods = (typeof routeKeyMethods)[number];
@@ -730,7 +731,7 @@ type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
730
731
  type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
731
732
  type TupleStyleParams = UnmaskType<AllowedQueryParamValues[]>;
732
733
  type Params = UnmaskType<RecordStyleParams | TupleStyleParams>;
733
- type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;
734
+ type Query = UnmaskType<Record<string, AllowedQueryParamValues> | URLSearchParams>;
734
735
  type InitURLOrURLObject = AnyString | RouteKeyMethodsURLUnion | URL;
735
736
  interface URLOptions {
736
737
  /**
@@ -856,8 +857,8 @@ type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKe
856
857
  // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
857
858
  TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
858
859
  type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, TSchemaRouteKeys>>;
859
- type InferAllRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Exclude<Extract<keyof TBaseSchemaRoutes, string>, FallBackRouteSchemaKey>>;
860
- type InferInitURL<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes, TSchemaConfig>;
860
+ type InferAllMainRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Exclude<Extract<keyof TBaseSchemaRoutes, string>, FallBackRouteSchemaKey>>;
861
+ type InferInitURL<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes extends never ? InitURLOrURLObject : InferAllMainRouteKeys<TBaseSchemaRoutes, TSchemaConfig>;
861
862
  type GetCurrentRouteSchemaKey<TSchemaConfig extends CallApiSchemaConfig, TPath> = TPath extends URL ? string : TSchemaConfig["prefix"] extends string ? TPath extends (`${AtSymbol}${infer TMethod extends RouteKeyMethods}/${RemoveLeadingSlash<TSchemaConfig["prefix"]>}${infer TCurrentRoute}`) ? `${AtSymbol}${TMethod}/${RemoveLeadingSlash<TCurrentRoute>}` : TPath extends `${TSchemaConfig["prefix"]}${infer TCurrentRoute}` ? TCurrentRoute : string : TSchemaConfig["baseURL"] extends string ? TPath extends (`${AtSymbol}${infer TMethod extends RouteKeyMethods}/${TSchemaConfig["baseURL"]}${infer TCurrentRoute}`) ? `${AtSymbol}${TMethod}/${RemoveLeadingSlash<TCurrentRoute>}` : TPath extends `${TSchemaConfig["baseURL"]}${infer TCurrentRoute}` ? TCurrentRoute : string : TPath;
862
863
  type GetCurrentRouteSchema<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
863
864
  type JsonPrimitive = boolean | number | string | null | undefined;
@@ -992,11 +993,11 @@ type ResultModeOption<TErrorData, TResultMode extends ResultModeType> = TErrorDa
992
993
  } : {
993
994
  resultMode?: TResultMode;
994
995
  };
995
- type ThrowOnErrorUnion = boolean;
996
- type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<{
996
+ type ThrowOnErrorBoolean = boolean;
997
+ type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorBoolean> = TThrowOnError | ((context: ErrorContext<{
997
998
  ErrorData: TErrorData;
998
999
  }>) => TThrowOnError);
999
- type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TErrorData extends false ? {
1000
+ type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorBoolean> = TErrorData extends false ? {
1000
1001
  throwOnError: true;
1001
1002
  } : TErrorData extends false | undefined ? {
1002
1003
  throwOnError?: true;
@@ -1086,7 +1087,7 @@ type ValidationErrorDetails = {
1086
1087
  *
1087
1088
  * It's either the name the schema for which validation failed, or the name of the schema config option that led to the validation error.
1088
1089
  */
1089
- issueCause: "unknown" | `schemaConfig-(${SafeExtract<keyof CallApiSchemaConfig, "strict">})` | keyof CallApiSchema;
1090
+ issueCause: "toFormData" | "toQueryString" | "unknown" | `schemaConfig-(${SafeExtract<keyof CallApiSchemaConfig, "strict">})` | keyof CallApiSchema;
1090
1091
  /**
1091
1092
  * The issues that caused the validation error.
1092
1093
  */
@@ -1146,9 +1147,9 @@ type CallApiRequestOptions = {
1146
1147
  method?: MethodUnion;
1147
1148
  } & Pick<ModifiedRequestInit, FetchSpecificKeysUnion>;
1148
1149
  type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
1149
- headers: Record<string, string | undefined>;
1150
+ headers: Record<"Authorization" | "Content-Type" | CommonRequestHeaders, string | undefined>;
1150
1151
  };
1151
- type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedMergedPluginExtraOptions = Partial<InferPluginExtraOptions<TPluginArray> & InferSchemaOutput<TCallApiContext["InferredExtraOptions"], TCallApiContext["InferredExtraOptions"]>>, TComputedCallApiContext extends CallApiContext = OverrideCallApiContext<TCallApiContext, {
1152
+ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedMergedPluginExtraOptions = Partial<InferPluginExtraOptions<TPluginArray> & InferSchemaOutput<TCallApiContext["InferredExtraOptions"], TCallApiContext["InferredExtraOptions"]>>, TComputedCallApiContext extends CallApiContext = OverrideCallApiContext<TCallApiContext, {
1152
1153
  Data: TData;
1153
1154
  ErrorData: TErrorData;
1154
1155
  InferredExtraOptions: TComputedMergedPluginExtraOptions;
@@ -1174,7 +1175,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
1174
1175
  * ```ts
1175
1176
  * // Custom form data serialization
1176
1177
  * bodySerializer: (data) => {
1177
- * const formData = new URLSearchParams();
1178
+ * const formData = new FormData();
1178
1179
  * Object.entries(data).forEach(([key, value]) => {
1179
1180
  * formData.append(key, String(value));
1180
1181
  * });
@@ -1336,20 +1337,20 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
1336
1337
  *
1337
1338
  * @example
1338
1339
  * ```ts
1339
- * responseParser: (responseString) => {
1340
- * return JSON.parse(responseString);
1340
+ * responseParser: (text) => {
1341
+ * return JSON.parse(text);
1341
1342
  * }
1342
1343
  *
1343
1344
  * // Parse XML responses
1344
- * responseParser: (responseString) => {
1345
+ * responseParser: (text) => {
1345
1346
  * const parser = new DOMParser();
1346
- * const doc = parser.parseFromString(responseString, "text/xml");
1347
+ * const doc = parser.parseFromString(text, "text/xml");
1347
1348
  * return xmlToObject(doc);
1348
1349
  * }
1349
1350
  *
1350
1351
  * // Parse CSV responses
1351
- * responseParser: (responseString) => {
1352
- * const lines = responseString.split('\n');
1352
+ * responseParser: (text) => {
1353
+ * const lines = text.split('\n');
1353
1354
  * const headers = lines[0].split(',');
1354
1355
  * const data = lines.slice(1).map(line => {
1355
1356
  * const values = line.split(',');
@@ -1363,7 +1364,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
1363
1364
  *
1364
1365
  * ```
1365
1366
  */
1366
- responseParser?: (responseString: string) => Awaitable<TData>;
1367
+ responseParser?: ResponseParser<TData>;
1367
1368
  /**
1368
1369
  * Expected response type, determines how the response body is parsed.
1369
1370
  *
@@ -1400,58 +1401,23 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
1400
1401
  */
1401
1402
  responseType?: TResponseType;
1402
1403
  /**
1403
- * Controls what data is included in the returned result object.
1404
+ * Dictates how CallApi processes and returns the final result
1404
1405
  *
1405
- * Different modes return different combinations of data, error, and response:
1406
- * - **"all"**: Returns { data, error, response } - complete result information
1407
- * - **"onlyData"**: Returns only data (null for errors)
1406
+ - **"all"** (default): Returns `{ data, error, response }`. Standard lifecycle.
1407
+ - **"onlyData"**: Returns only the data from the response.
1408
+ - **"onlyResponse"**: Returns only the `Response` object.
1409
+ - **"fetchApi"**: Also returns only the `Response` object, but also skips parsing of the response body internally and data/errorData schema validation.
1410
+ - **"withoutResponse"**: Returns `{ data, error }`. Standard lifecycle, but omits the `response` property.
1408
1411
  *
1409
- * When combined with throwOnError: true, null/error variants are automatically removed:
1410
- * - **"all" + throwOnError: true**: Returns { data, error: null, response } (error property is null, throws instead)
1411
- * - **"onlyData" + throwOnError: true**: Returns data (never null, throws on error)
1412
1412
  *
1413
- * @default "all"
1413
+ * **Note:**
1414
+ * By default, simplified modes (`"onlyData"`, `"onlyResponse"`, `"fetchApi"`) do not throw errors.
1415
+ * Success/failure should be handled via hooks or by checking the return value (e.g., `if (data)` or `if (response?.ok)`).
1416
+ * To force an exception instead, set `throwOnError: true`.
1414
1417
  *
1415
- * @example
1416
- * ```ts
1417
- * // Complete result with all information (default)
1418
- * const { data, error, response } = await callApi("/users", { resultMode: "all" });
1419
- * if (error) {
1420
- * console.error("Request failed:", error);
1421
- * } else {
1422
- * console.log("Users:", data);
1423
- * }
1424
1418
  *
1425
- * // Complete result but throws on errors (throwOnError removes error from type)
1426
- * try {
1427
- * const { data, response } = await callApi("/users", {
1428
- * resultMode: "all",
1429
- * throwOnError: true
1430
- * });
1431
- * console.log("Users:", data); // data is never null here
1432
- * } catch (error) {
1433
- * console.error("Request failed:", error);
1434
- * }
1435
- *
1436
- * // Only data, returns null on errors
1437
- * const users = await callApi("/users", { resultMode: "onlyData" });
1438
- * if (users) {
1439
- * console.log("Users:", users);
1440
- * } else {
1441
- * console.log("Request failed");
1442
- * }
1419
+ * @default "all"
1443
1420
  *
1444
- * // Only data, throws on errors (throwOnError removes null from type)
1445
- * try {
1446
- * const users = await callApi("/users", {
1447
- * resultMode: "onlyData",
1448
- * throwOnError: true
1449
- * });
1450
- * console.log("Users:", users); // users is never null here
1451
- * } catch (error) {
1452
- * console.error("Request failed:", error);
1453
- * }
1454
- * ```
1455
1421
  */
1456
1422
  resultMode?: TResultMode;
1457
1423
  /**
@@ -1524,7 +1490,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
1524
1490
  */
1525
1491
  timeout?: number;
1526
1492
  };
1527
- type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
1493
+ type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
1528
1494
  /**
1529
1495
  * Array of base CallApi plugins to extend library functionality.
1530
1496
  *
@@ -1637,7 +1603,7 @@ type GetExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfig>
1637
1603
  type InferExtendPluginContext<TBasePluginArray extends CallApiPlugin[]> = {
1638
1604
  basePlugins: TBasePluginArray;
1639
1605
  };
1640
- type CallApiExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string> = SharedExtraOptions<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
1606
+ type CallApiExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string> = SharedExtraOptions<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
1641
1607
  /**
1642
1608
  * Array of instance-specific CallApi plugins or a function to configure plugins.
1643
1609
  *
@@ -1671,28 +1637,28 @@ type InstanceContext = {
1671
1637
  options: CallApiExtraOptions;
1672
1638
  request: CallApiRequestOptions;
1673
1639
  };
1674
- type BaseCallApiConfig<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
1675
- type CallApiConfig<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, 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, TCallApiContext> & InferRequestOptions<TSchema, TInitURL> & Omit<CallApiExtraOptions<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string, CallApiContext>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
1676
- type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TCallApiContext extends CallApiContext = DefaultCallApiContext, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, 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<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
1677
- type CallApiResult<TData, TErrorData, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorUnion> = InferCallApiResult<TData, TErrorData, TResultMode, TThrowOnError>;
1678
- type CallApiResultLoose<TData, TErrorData, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = ThrowOnErrorUnion> = InferCallApiResult<TData, TErrorData, TResultMode, TThrowOnError>;
1640
+ type BaseCallApiConfig<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
1641
+ type CallApiConfig<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, 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, TCallApiContext> & InferRequestOptions<TSchema, TInitURL> & Omit<CallApiExtraOptions<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string, CallApiContext>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
1642
+ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TCallApiContext extends CallApiContext = DefaultCallApiContext, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, 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<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
1643
+ type CallApiResult<TData, TErrorData, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorBoolean> = InferCallApiResult<TData, TErrorData, TResultMode, TThrowOnError>;
1644
+ type CallApiResultLoose<TData, TErrorData, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = ThrowOnErrorBoolean> = InferCallApiResult<TData, TErrorData, TResultMode, TThrowOnError>;
1679
1645
  //#endregion
1680
1646
  //#region src/result.d.ts
1681
- type Parser<TData> = (responseString: string) => Awaitable<TData>;
1682
- declare const getResponseType: <TResponse>(response: Response, parser: Parser<TResponse>) => {
1647
+ type ResponseParser<TData> = (text: string) => Awaitable<TData>;
1648
+ declare const getResponseType: <TData>(response: Response, responseParser: ResponseParser<TData>) => {
1683
1649
  arrayBuffer: () => Promise<ArrayBuffer>;
1684
1650
  blob: () => Promise<Blob>;
1685
1651
  formData: () => Promise<FormData>;
1686
- json: () => Promise<TResponse>;
1652
+ json: () => Promise<TData>;
1687
1653
  stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
1688
1654
  text: () => Promise<string>;
1689
1655
  };
1690
- type InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;
1656
+ type InitResponseTypeMap<TData = unknown> = ReturnType<typeof getResponseType<TData>>;
1691
1657
  type ResponseTypeUnion = keyof InitResponseTypeMap;
1692
1658
  type ResponseTypePlaceholder = null;
1693
1659
  type ResponseTypeType = ResponseTypePlaceholder | ResponseTypeUnion;
1694
- type ResponseTypeMap<TResponse> = { [Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>> };
1695
- type GetResponseType<TResponse, TResponseType extends ResponseTypeType, TComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeType> ? TComputedResponseTypeMap[TResponseType] : never;
1660
+ type ResponseTypeMap<TData> = { [Key in keyof InitResponseTypeMap<TData>]: Awaited<ReturnType<InitResponseTypeMap<TData>[Key]>> };
1661
+ type GetResponseType<TData, TResponseType extends ResponseTypeType, TComputedResponseTypeMap extends ResponseTypeMap<TData> = ResponseTypeMap<TData>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeType> ? TComputedResponseTypeMap[TResponseType] : never;
1696
1662
  type CallApiResultSuccessVariant<TData> = {
1697
1663
  data: NoInferUnMasked<TData>;
1698
1664
  error: null;
@@ -1731,8 +1697,10 @@ type CallApiResultErrorVariant<TErrorData> = {
1731
1697
  response: Response | null;
1732
1698
  };
1733
1699
  type CallApiResultSuccessOrErrorVariant<TData, TError> = CallApiResultErrorVariant<TError> | CallApiResultSuccessVariant<TData>;
1734
- type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TComputedResultWithoutException extends CallApiResultSuccessOrErrorVariant<TData, TErrorData> = CallApiResultSuccessOrErrorVariant<TData, TErrorData>, TComputedResultWithException extends CallApiResultSuccessVariant<TData> = CallApiResultSuccessVariant<TData>, TComputedResult extends (TThrowOnError extends true ? TComputedResultWithException : TComputedResultWithoutException) = (TThrowOnError extends true ? TComputedResultWithException : TComputedResultWithoutException)> = UnmaskType<{
1700
+ type GetCallApiResult<TThrowOnError extends ThrowOnErrorBoolean, TResultWithException extends CallApiResultSuccessVariant<unknown>, TResultWithoutException extends CallApiResultSuccessOrErrorVariant<unknown, unknown>> = TThrowOnError extends true ? TResultWithException : TResultWithoutException;
1701
+ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TComputedResult extends GetCallApiResult<TThrowOnError, CallApiResultSuccessVariant<TData>, CallApiResultSuccessOrErrorVariant<TData, TErrorData>> = GetCallApiResult<TThrowOnError, CallApiResultSuccessVariant<TData>, CallApiResultSuccessOrErrorVariant<TData, TErrorData>>> = UnmaskType<{
1735
1702
  all: TComputedResult;
1703
+ fetchApi: TComputedResult["response"];
1736
1704
  onlyData: TComputedResult["data"];
1737
1705
  onlyResponse: TComputedResult["response"];
1738
1706
  withoutResponse: Prettify<DistributiveOmit<TComputedResult, "response">>;
@@ -1740,7 +1708,7 @@ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TThrow
1740
1708
  type ResultModePlaceholder = null;
1741
1709
  type ResultModeUnion = keyof ResultModeMap;
1742
1710
  type ResultModeType = ResultModePlaceholder | ResultModeUnion;
1743
- type InferCallApiResult<TData, TErrorData, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorUnion, TComputedResultModeMapWithException extends ResultModeMap<TData, TErrorData, true> = ResultModeMap<TData, TErrorData, true>, TComputedResultModeMapWithoutException extends ResultModeMap<TData, TErrorData, TThrowOnError> = ResultModeMap<TData, TErrorData, TThrowOnError>> = TErrorData extends false ? TComputedResultModeMapWithException["onlyData"] : TErrorData extends false | undefined ? TComputedResultModeMapWithException["onlyData"] : ResultModePlaceholder extends TResultMode ? TComputedResultModeMapWithoutException["all"] : TResultMode extends ResultModeUnion ? TComputedResultModeMapWithoutException[TResultMode] : never;
1711
+ type InferCallApiResult<TData, TErrorData, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorBoolean, TComputedResultModeMapWithException extends ResultModeMap<TData, TErrorData, true> = ResultModeMap<TData, TErrorData, true>, TComputedResultModeMapWithoutException extends ResultModeMap<TData, TErrorData, TThrowOnError> = ResultModeMap<TData, TErrorData, TThrowOnError>> = TErrorData extends false ? TComputedResultModeMapWithException["onlyData"] : TErrorData extends false | undefined ? TComputedResultModeMapWithException["onlyData"] : ResultModePlaceholder extends TResultMode ? TComputedResultModeMapWithoutException["all"] : TResultMode extends ResultModeUnion ? TComputedResultModeMapWithoutException[TResultMode] : never;
1744
1712
  //#endregion
1745
1713
  //#region src/plugins.d.ts
1746
1714
  type PluginSetupContext<TCallApiContext extends CallApiContext = DefaultCallApiContext> = RequestContext<TCallApiContext> & {
@@ -1771,7 +1739,7 @@ interface CallApiPlugin<TCallApiContext extends CallApiContext = DefaultCallApiC
1771
1739
  /**
1772
1740
  * Hooks for the plugin
1773
1741
  */
1774
- hooks?: PluginHooks<TCallApiContext> | ((context: PluginSetupContext<TCallApiContext>) => Awaitable<PluginHooks<TCallApiContext>>);
1742
+ hooks?: PluginHooks<TCallApiContext> | ((context: PluginSetupContext<TCallApiContext>) => Awaitable<PluginHooks<TCallApiContext>> | Awaitable<void>);
1775
1743
  /**
1776
1744
  * A unique id for the plugin
1777
1745
  */
@@ -1779,7 +1747,7 @@ interface CallApiPlugin<TCallApiContext extends CallApiContext = DefaultCallApiC
1779
1747
  /**
1780
1748
  * Middlewares that for the plugin
1781
1749
  */
1782
- middlewares?: PluginMiddlewares<TCallApiContext> | ((context: PluginSetupContext<TCallApiContext>) => Awaitable<PluginMiddlewares<TCallApiContext>>);
1750
+ middlewares?: PluginMiddlewares<TCallApiContext> | ((context: PluginSetupContext<TCallApiContext>) => Awaitable<PluginMiddlewares<TCallApiContext>> | Awaitable<void>);
1783
1751
  /**
1784
1752
  * A name for the plugin
1785
1753
  */
@@ -1809,15 +1777,16 @@ type DefaultCallApiContext = Prettify<OverrideCallApiContext<Required<CallApiCon
1809
1777
  }>>;
1810
1778
  //#endregion
1811
1779
  //#region src/createFetchClient.d.ts
1812
- declare const createFetchClientWithContext: <TOuterCallApiContext extends CallApiContext = DefaultCallApiContext>() => <TBaseCallApiContext extends CallApiContext = TOuterCallApiContext, TBaseData = TBaseCallApiContext["Data"], TBaseErrorData = TBaseCallApiContext["ErrorData"], TBaseResultMode extends ResultModeType = (TBaseCallApiContext["ResultMode"] extends ResultModeType ? TBaseCallApiContext["ResultMode"] : ResultModeType), TBaseThrowOnError extends ThrowOnErrorUnion = boolean, TBaseResponseType extends ResponseTypeType = ResponseTypeType, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeType = TBaseResultMode, TCallApiContext extends CallApiContext = TBaseCallApiContext, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeType = 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, TComputedData = InferSchemaOutput<TSchema["data"], GetResponseType<TData, TResponseType>>, TComputedErrorData = InferSchemaOutput<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TComputedResult = CallApiResult<TComputedData, TComputedErrorData, TResultMode, TThrowOnError>>(initURL: TInitURL, initConfig?: CallApiConfig<TCallApiContext, TComputedData, TComputedErrorData, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
1780
+ declare const createFetchClientWithContext: <TOuterCallApiContext extends CallApiContext = DefaultCallApiContext>() => <TBaseCallApiContext extends CallApiContext = TOuterCallApiContext, TBaseData = TBaseCallApiContext["Data"], TBaseErrorData = TBaseCallApiContext["ErrorData"], TBaseResultMode extends ResultModeType = (TBaseCallApiContext["ResultMode"] extends ResultModeType ? TBaseCallApiContext["ResultMode"] : ResultModeType), TBaseThrowOnError extends ThrowOnErrorBoolean = boolean, TBaseResponseType extends ResponseTypeType = ResponseTypeType, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeType = TBaseResultMode, TCallApiContext extends CallApiContext = TBaseCallApiContext, TThrowOnError extends ThrowOnErrorBoolean = TBaseThrowOnError, TResponseType extends ResponseTypeType = 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, TComputedData = InferSchemaOutput<TSchema["data"], GetResponseType<TData, TResponseType>>, TComputedErrorData = InferSchemaOutput<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TComputedResult = CallApiResult<TComputedData, TComputedErrorData, TResultMode, TThrowOnError>>(initURL: TInitURL, initConfig?: CallApiConfig<TCallApiContext, TComputedData, TComputedErrorData, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
1813
1781
  declare const createFetchClient: <TBaseCallApiContext extends CallApiContext = {
1814
1782
  InferredExtraOptions: unknown;
1815
1783
  Data: DefaultDataType;
1816
1784
  ErrorData: DefaultDataType;
1817
1785
  ResultMode: ResultModeType;
1818
1786
  Meta: GlobalMeta;
1819
- }, TBaseData = TBaseCallApiContext["Data"], TBaseErrorData = TBaseCallApiContext["ErrorData"], TBaseResultMode extends ResultModeType = (TBaseCallApiContext["ResultMode"] extends ResultModeType ? TBaseCallApiContext["ResultMode"] : ResultModeType), TBaseThrowOnError extends ThrowOnErrorUnion = boolean, TBaseResponseType extends ResponseTypeType = ResponseTypeType, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = Writeable<NonNullable<TBaseSchemaAndConfig["config"]>, "deep">, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = Writeable<TBaseSchemaAndConfig["routes"], "deep">>(initBaseConfig?: BaseCallApiConfig<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeType = TBaseResultMode, TCallApiContext extends CallApiContext = TBaseCallApiContext, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeType = 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, TComputedBaseSchemaRoutes["@default"], TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey], NonNullable<Omit<TComputedBaseSchemaRoutes["@default"], keyof TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey]> & TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey]>>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedData = InferSchemaResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>, "infer-output">, TComputedErrorData = InferSchemaResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>, "infer-output">, TComputedResult = InferCallApiResult<TComputedData, TComputedErrorData, TResultMode, TThrowOnError, {
1787
+ }, TBaseData = TBaseCallApiContext["Data"], TBaseErrorData = TBaseCallApiContext["ErrorData"], TBaseResultMode extends ResultModeType = (TBaseCallApiContext["ResultMode"] extends ResultModeType ? TBaseCallApiContext["ResultMode"] : ResultModeType), TBaseThrowOnError extends ThrowOnErrorBoolean = boolean, TBaseResponseType extends ResponseTypeType = ResponseTypeType, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = Writeable<NonNullable<TBaseSchemaAndConfig["config"]>, "deep">, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = Writeable<TBaseSchemaAndConfig["routes"], "deep">>(initBaseConfig?: BaseCallApiConfig<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeType = TBaseResultMode, TCallApiContext extends CallApiContext = TBaseCallApiContext, TThrowOnError extends ThrowOnErrorBoolean = TBaseThrowOnError, TResponseType extends ResponseTypeType = 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, TComputedBaseSchemaRoutes["@default"], TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey], NonNullable<Omit<TComputedBaseSchemaRoutes["@default"], keyof TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey]> & TComputedBaseSchemaRoutes[TCurrentRouteSchemaKey]>>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedData = InferSchemaResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>, "infer-output">, TComputedErrorData = InferSchemaResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>, "infer-output">, TComputedResult = InferCallApiResult<TComputedData, TComputedErrorData, TResultMode, TThrowOnError, {
1820
1788
  all: CallApiResultSuccessVariant<TComputedData>;
1789
+ fetchApi: Response;
1821
1790
  onlyData: NoInferUnMasked<TComputedData>;
1822
1791
  onlyResponse: Response;
1823
1792
  withoutResponse: {
@@ -1826,6 +1795,7 @@ declare const createFetchClient: <TBaseCallApiContext extends CallApiContext = {
1826
1795
  };
1827
1796
  }, {
1828
1797
  all: TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>;
1798
+ fetchApi: (TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>)["response"];
1829
1799
  onlyData: (TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>)["data"];
1830
1800
  onlyResponse: (TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>)["response"];
1831
1801
  withoutResponse: DistributiveOmit<TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>, "response"> extends infer T ? { [Key in keyof T]: T[Key] } : never;
@@ -1836,7 +1806,7 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
1836
1806
  ErrorData: DefaultDataType;
1837
1807
  ResultMode: ResultModeType;
1838
1808
  Meta: GlobalMeta;
1839
- }, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeType = ResponseTypeType, 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<{
1809
+ }, TThrowOnError extends ThrowOnErrorBoolean = boolean, TResponseType extends ResponseTypeType = ResponseTypeType, 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<{
1840
1810
  [x: AnyString]: CallApiSchema | undefined;
1841
1811
  "@default"?: CallApiSchema | undefined;
1842
1812
  "@delete/"?: CallApiSchema | undefined;
@@ -1870,6 +1840,7 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
1870
1840
  "@put/"?: CallApiSchema | undefined;
1871
1841
  }[TCurrentRouteSchemaKey]>>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedData = InferSchemaResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>, "infer-output">, TComputedErrorData = InferSchemaResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>, "infer-output">, TComputedResult = InferCallApiResult<TComputedData, TComputedErrorData, TResultMode, TThrowOnError, {
1872
1842
  all: CallApiResultSuccessVariant<TComputedData>;
1843
+ fetchApi: Response;
1873
1844
  onlyData: NoInferUnMasked<TComputedData>;
1874
1845
  onlyResponse: Response;
1875
1846
  withoutResponse: {
@@ -1878,6 +1849,7 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
1878
1849
  };
1879
1850
  }, {
1880
1851
  all: TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>;
1852
+ fetchApi: (TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>)["response"];
1881
1853
  onlyData: (TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>)["data"];
1882
1854
  onlyResponse: (TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>)["response"];
1883
1855
  withoutResponse: DistributiveOmit<TThrowOnError extends true ? CallApiResultSuccessVariant<TComputedData> : CallApiResultSuccessOrErrorVariant<TComputedData, TComputedErrorData>, "response"> extends infer T ? { [Key in keyof T]: T[Key] } : never;
@@ -1891,5 +1863,5 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
1891
1863
  "@put/"?: CallApiSchema | undefined;
1892
1864
  }, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray>) => Promise<TComputedResult>;
1893
1865
  //#endregion
1894
- export { ResponseErrorContext as $, HTTPError as A, InferSchemaOutput as B, CallApiRequestOptions as C, GetCallApiContextRequired as D, GetCallApiContext as E, BaseCallApiSchemaRoutes as F, Middlewares as G, fallBackRouteSchemaKey as H, BaseSchemaRouteKeyPrefixes as I, Hooks as J, DedupeOptions as K, CallApiSchema as L, RetryOptions as M, InferParamsFromRoute as N, InstanceContext as O, URLOptions as P, ResponseContext as Q, CallApiSchemaConfig as R, CallApiParameters as S, CallApiResultLoose as T, FetchImpl as U, FallBackRouteSchemaKey as V, FetchMiddlewareContext as W, RequestContext as X, HooksOrHooksArray as Y, RequestStreamContext as Z, BaseCallApiConfig as _, CallApiPlugin as a, fetchSpecificKeys as at, CallApiExtraOptions as b, PluginSetupContext as c, CallApiResultSuccessVariant as d, ResponseStreamContext as et, PossibleHTTPError as f, ResultModeType as g, ResponseTypeType as h, DefaultCallApiContext as i, Writeable as it, ValidationError as j, Register as k, CallApiResultErrorVariant as l, PossibleValidationError as m, createFetchClient as n, AnyFunction as nt, PluginHooks as o, PossibleJavaScriptError as p, ErrorContext as q, createFetchClientWithContext as r, Satisfies as rt, PluginMiddlewares as s, callApi as t, SuccessContext as tt, CallApiResultSuccessOrErrorVariant as u, BaseCallApiExtraOptions as v, CallApiRequestOptionsForHooks as w, CallApiExtraOptionsForHooks as x, CallApiConfig as y, InferSchemaInput as z };
1895
- //# sourceMappingURL=index-CzrxZYrH.d.ts.map
1866
+ export { HooksOrHooksArray as $, HTTPError as A, CallApiSchema as B, CallApiRequestOptions as C, GetCallApiContextRequired as D, GetCallApiContext as E, InferInitURL as F, FallBackRouteSchemaKey as G, CallApiSchemaType as H, InferParamsFromRoute as I, FetchMiddlewareContext as J, fallBackRouteSchemaKey as K, URLOptions as L, RetryOptions as M, GetCurrentRouteSchemaKey as N, InstanceContext as O, InferAllMainRouteKeys as P, Hooks as Q, BaseCallApiSchemaRoutes as R, CallApiParameters as S, CallApiResultLoose as T, InferSchemaInput as U, CallApiSchemaConfig as V, InferSchemaOutput as W, DedupeOptions as X, Middlewares as Y, ErrorContext as Z, BaseCallApiConfig as _, CallApiPlugin as a, SuccessContext as at, CallApiExtraOptions as b, PluginSetupContext as c, Writeable as ct, CallApiResultSuccessVariant as d, RequestContext as et, PossibleHTTPError as f, ResultModeType as g, ResponseTypeType as h, DefaultCallApiContext as i, ResponseStreamContext as it, ValidationError as j, Register as k, CallApiResultErrorVariant as l, fetchSpecificKeys as lt, PossibleValidationError as m, createFetchClient as n, ResponseContext as nt, PluginHooks as o, AnyFunction as ot, PossibleJavaScriptError as p, FetchImpl as q, createFetchClientWithContext as r, ResponseErrorContext as rt, PluginMiddlewares as s, Satisfies as st, callApi as t, RequestStreamContext as tt, CallApiResultSuccessOrErrorVariant as u, BaseCallApiExtraOptions as v, CallApiRequestOptionsForHooks as w, CallApiExtraOptionsForHooks as x, CallApiConfig as y, BaseSchemaRouteKeyPrefixes as z };
1867
+ //# sourceMappingURL=index-UfuQFNcf.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as ResponseErrorContext, B as InferSchemaOutput, C as CallApiRequestOptions, D as GetCallApiContextRequired, E as GetCallApiContext, F as BaseCallApiSchemaRoutes, G as Middlewares, I as BaseSchemaRouteKeyPrefixes, J as Hooks, K as DedupeOptions, L as CallApiSchema, M as RetryOptions, N as InferParamsFromRoute, O as InstanceContext, P as URLOptions, Q as ResponseContext, R as CallApiSchemaConfig, S as CallApiParameters, T as CallApiResultLoose, U as FetchImpl, W as FetchMiddlewareContext, X as RequestContext, Y as HooksOrHooksArray, Z as RequestStreamContext, _ as BaseCallApiConfig, a as CallApiPlugin, b as CallApiExtraOptions, c as PluginSetupContext, d as CallApiResultSuccessVariant, et as ResponseStreamContext, f as PossibleHTTPError, g as ResultModeType, h as ResponseTypeType, i as DefaultCallApiContext, k as Register, l as CallApiResultErrorVariant, m as PossibleValidationError, n as createFetchClient, o as PluginHooks, p as PossibleJavaScriptError, q as ErrorContext, r as createFetchClientWithContext, s as PluginMiddlewares, t as callApi, tt as SuccessContext, u as CallApiResultSuccessOrErrorVariant, v as BaseCallApiExtraOptions, w as CallApiRequestOptionsForHooks, x as CallApiExtraOptionsForHooks, y as CallApiConfig, z as InferSchemaInput } from "./index-CzrxZYrH.js";
2
- export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaRoutes, BaseSchemaRouteKeyPrefixes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResultLoose as CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessOrErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultCallApiContext, ErrorContext, FetchImpl, FetchMiddlewareContext, GetCallApiContext, GetCallApiContextRequired, Hooks, HooksOrHooksArray, InferParamsFromRoute, InferSchemaInput, InferSchemaOutput, InstanceContext, Middlewares, PluginHooks, PluginMiddlewares, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeType, ResultModeType, RetryOptions, SuccessContext, URLOptions, callApi, createFetchClient, createFetchClientWithContext };
1
+ import { $ as HooksOrHooksArray, B as CallApiSchema, C as CallApiRequestOptions, D as GetCallApiContextRequired, E as GetCallApiContext, F as InferInitURL, I as InferParamsFromRoute, J as FetchMiddlewareContext, L as URLOptions, M as RetryOptions, N as GetCurrentRouteSchemaKey, O as InstanceContext, P as InferAllMainRouteKeys, Q as Hooks, R as BaseCallApiSchemaRoutes, S as CallApiParameters, T as CallApiResultLoose, U as InferSchemaInput, V as CallApiSchemaConfig, W as InferSchemaOutput, X as DedupeOptions, Y as Middlewares, Z as ErrorContext, _ as BaseCallApiConfig, a as CallApiPlugin, at as SuccessContext, b as CallApiExtraOptions, c as PluginSetupContext, d as CallApiResultSuccessVariant, et as RequestContext, f as PossibleHTTPError, g as ResultModeType, h as ResponseTypeType, i as DefaultCallApiContext, it as ResponseStreamContext, k as Register, l as CallApiResultErrorVariant, m as PossibleValidationError, n as createFetchClient, nt as ResponseContext, o as PluginHooks, p as PossibleJavaScriptError, q as FetchImpl, r as createFetchClientWithContext, rt as ResponseErrorContext, s as PluginMiddlewares, t as callApi, tt as RequestStreamContext, u as CallApiResultSuccessOrErrorVariant, v as BaseCallApiExtraOptions, w as CallApiRequestOptionsForHooks, x as CallApiExtraOptionsForHooks, y as CallApiConfig, z as BaseSchemaRouteKeyPrefixes } from "./index-UfuQFNcf.js";
2
+ export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaRoutes, BaseSchemaRouteKeyPrefixes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResultLoose as CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessOrErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultCallApiContext, ErrorContext, FetchImpl, FetchMiddlewareContext, GetCallApiContext, GetCallApiContextRequired, GetCurrentRouteSchemaKey, Hooks, HooksOrHooksArray, InferAllMainRouteKeys, InferInitURL, InferParamsFromRoute, InferSchemaInput, InferSchemaOutput, InstanceContext, Middlewares, PluginHooks, PluginMiddlewares, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeType, ResultModeType, RetryOptions, SuccessContext, URLOptions, callApi, createFetchClient, createFetchClientWithContext };
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
- import { D as handleConfigValidation, E as getCurrentRouteSchemaKeyAndMainInitURL, F as isArray, I as isBoolean, L as isFunction, O as handleSchemaValidation, R as isReadableStream, T as getFullAndNormalizedURL, a as getBody, c as getMethod, d as splitBaseConfig, f as splitConfig, h as isHTTPErrorInstance, i as createTimeoutSignal, k as HTTPError, l as getResolvedHeaders, o as getFetchImpl, p as waitFor, r as createCombinedSignal, s as getHeaders, t as extraOptionDefaults, u as omitKeys, v as isValidationErrorInstance, z as isString } from "./defaults-CjVryN9a.js";
1
+ import { C as isArray, E as isFunction, O as isReadableStream, T as isBoolean, _ as handleConfigValidation, a as getBody, c as getMethod, d as splitBaseConfig, f as splitConfig, h as getCurrentRouteSchemaKeyAndMainInitURL, i as createTimeoutSignal, k as isString, l as getResolvedHeaders, m as getFullAndNormalizedURL, o as getFetchImpl, p as waitFor, r as createCombinedSignal, s as getHeaders, t as extraOptionDefaults, u as omitKeys, v as handleSchemaValidation, y as HTTPError } from "./defaults-D5uiLm4M.js";
2
+ import { a as isValidationErrorInstance, n as isHTTPErrorInstance } from "./guards-BW5MdHRz.js";
2
3
 
3
4
  //#region src/result.ts
4
- const getResponseType = (response, parser) => ({
5
+ const getResponseType = (response, responseParser) => ({
5
6
  arrayBuffer: () => response.arrayBuffer(),
6
7
  blob: () => response.blob(),
7
8
  formData: () => response.formData(),
8
9
  json: async () => {
9
- return parser(await response.text());
10
+ return responseParser(await response.text());
10
11
  },
11
12
  stream: () => response.body,
12
13
  text: () => response.text()
@@ -26,16 +27,19 @@ const detectResponseType = (response) => {
26
27
  if (textTypes.has(contentType) || contentType.startsWith("text/")) return "text";
27
28
  return "blob";
28
29
  };
29
- const resolveResponseData = (response, responseType, parser) => {
30
- const selectedParser = parser ?? extraOptionDefaults.responseParser;
30
+ const resolveResponseData = async (options) => {
31
+ const { response, responseParser, responseType, resultMode } = options;
32
+ if (resultMode === "fetchApi") return null;
33
+ const selectedParser = responseParser ?? extraOptionDefaults.responseParser;
31
34
  const selectedResponseType = responseType ?? detectResponseType(response);
32
35
  const RESPONSE_TYPE_LOOKUP = getResponseType(response, selectedParser);
33
- if (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) throw new Error(`Invalid response type: ${responseType}`);
36
+ if (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) throw new Error(`Invalid response type: ${selectedResponseType}`);
34
37
  return RESPONSE_TYPE_LOOKUP[selectedResponseType]();
35
38
  };
36
39
  const getResultModeMap = (details) => {
37
40
  return {
38
41
  all: () => details,
42
+ fetchApi: () => details.response,
39
43
  onlyData: () => details.data,
40
44
  onlyResponse: () => details.response,
41
45
  withoutResponse: () => omitKeys(details, ["response"])
@@ -131,7 +135,7 @@ const composeHooksFromArray = (hooksArray, hooksExecutionMode) => {
131
135
  const composedHook = async (ctx) => {
132
136
  switch (hooksExecutionMode) {
133
137
  case "parallel":
134
- await Promise.all(hooksArray.map((uniqueHook) => uniqueHook?.(ctx)));
138
+ await Promise.all(hooksArray.map((hook) => hook?.(ctx)));
135
139
  break;
136
140
  case "sequential":
137
141
  for (const hook of hooksArray) await hook?.(ctx);
@@ -317,7 +321,7 @@ const createDedupeStrategy = async (context) => {
317
321
  const prevRequestInfo = $RequestInfoCache?.get();
318
322
  const getAbortErrorMessage = () => {
319
323
  if (globalOptions.dedupeKey) return `Duplicate request detected - Aborted previous request with key '${dedupeKey}'`;
320
- return `Duplicate request aborted - Aborted previous request to '${globalOptions.fullURL}'`;
324
+ return `Duplicate request detected - Aborted previous request to '${globalOptions.fullURL}'`;
321
325
  };
322
326
  const handleRequestCancelStrategy = () => {
323
327
  if (!(prevRequestInfo && resolvedDedupeStrategy === "cancel")) return;
@@ -692,11 +696,17 @@ const createFetchClientWithContext = () => {
692
696
  options,
693
697
  request
694
698
  });
695
- const shouldCloneResponse = resolvedDedupeStrategy === "defer" || options.cloneResponse;
699
+ const responseData = await resolveResponseData({
700
+ response: Boolean(resolvedDedupeStrategy === "defer" || options.cloneResponse) ? response.clone() : response,
701
+ responseParser: options.responseParser,
702
+ responseType: options.responseType,
703
+ resultMode: options.resultMode
704
+ });
696
705
  if (!response.ok) {
697
706
  const validErrorData = await handleSchemaValidation(resolvedSchema, "errorData", {
698
- inputValue: await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser),
707
+ inputValue: responseData,
699
708
  response,
709
+ resultMode: options.resultMode,
700
710
  schemaConfig: resolvedSchemaConfig
701
711
  });
702
712
  throw new HTTPError({
@@ -709,8 +719,9 @@ const createFetchClientWithContext = () => {
709
719
  baseConfig,
710
720
  config,
711
721
  data: await handleSchemaValidation(resolvedSchema, "data", {
712
- inputValue: await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser),
722
+ inputValue: responseData,
713
723
  response,
724
+ resultMode: options.resultMode,
714
725
  schemaConfig: resolvedSchemaConfig
715
726
  }),
716
727
  options,