@zayne-labs/callapi 1.8.14 → 1.8.16
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.
@@ -249,7 +249,7 @@ interface URLOptions {
|
|
249
249
|
type InferSchemaResult<TSchema, TFallbackResult = unknown> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
250
250
|
interface CallApiSchemaConfig {
|
251
251
|
/**
|
252
|
-
* The base url of the schema. By default it's the baseURL of the
|
252
|
+
* The base url of the schema. By default it's the baseURL of the callApi instance.
|
253
253
|
*/
|
254
254
|
baseURL?: string;
|
255
255
|
/**
|
@@ -263,6 +263,13 @@ interface CallApiSchemaConfig {
|
|
263
263
|
* applied by the validation schema (e.g., type coercion, default values, etc).
|
264
264
|
*/
|
265
265
|
disableValidationOutputApplication?: boolean;
|
266
|
+
/**
|
267
|
+
* Optional url prefix that will be substituted for the `baseURL` of the schemaConfig at runtime.
|
268
|
+
*
|
269
|
+
* This allows you to reuse the same schema against different base URLs (for example,
|
270
|
+
* swapping between `/api/v1` and `/api/v2`) without redefining the entire schema.
|
271
|
+
*/
|
272
|
+
prefix?: string;
|
266
273
|
/**
|
267
274
|
*Determines the inference or requirement of the method option based on the route modifiers (`@get/`, `@post/`, `@put/`, `@patch/`, `@delete/`).
|
268
275
|
*
|
@@ -275,8 +282,8 @@ interface CallApiSchemaConfig {
|
|
275
282
|
* Controls the strictness of API route validation.
|
276
283
|
*
|
277
284
|
* When true:
|
278
|
-
* - Only routes explicitly defined in the schema will be considered valid to typescript and runtime.
|
279
|
-
* - Attempting to call
|
285
|
+
* - Only routes explicitly defined in the schema will be considered valid to typescript and the runtime.
|
286
|
+
* - Attempting to call routes not defined in the schema will result in both type errors and runtime validation errors.
|
280
287
|
* - Useful for ensuring API calls conform exactly to your schema definition
|
281
288
|
*
|
282
289
|
* When false or undefined (default):
|
@@ -320,9 +327,19 @@ interface CallApiSchema {
|
|
320
327
|
}
|
321
328
|
declare const routeKeyMethods: ["delete", "get", "patch", "post", "put"];
|
322
329
|
type RouteKeyMethods = (typeof routeKeyMethods)[number];
|
323
|
-
type
|
324
|
-
type
|
325
|
-
|
330
|
+
type RouteKeyMethodsURLUnion = `${RouteKeyMethods}/`;
|
331
|
+
type PossibleRouteKey = AnyString | RouteKeyMethodsURLUnion;
|
332
|
+
type BaseCallApiSchemaRoutes = Partial<Record<PossibleRouteKey, CallApiSchema>>;
|
333
|
+
type BaseCallApiSchemaAndConfig = {
|
334
|
+
config?: CallApiSchemaConfig;
|
335
|
+
routes: BaseCallApiSchemaRoutes;
|
336
|
+
};
|
337
|
+
declare const defineSchema: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, const TSchemaConfig extends CallApiSchemaConfig>(routes: TBaseSchemaRoutes, config?: TSchemaConfig) => {
|
338
|
+
config: TSchemaConfig | undefined;
|
339
|
+
routes: Writeable<typeof routes, "deep">;
|
340
|
+
};
|
341
|
+
declare const defineSchemaConfig: <const TConfig extends CallApiExtraOptions["schemaConfig"]>(config: TConfig) => Writeable<typeof config, "deep">;
|
342
|
+
declare const defineSchemaRoutes: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes>(routes: TBaseSchemaRoutes) => Writeable<typeof routes, "deep">;
|
326
343
|
//#endregion
|
327
344
|
//#region src/plugins.d.ts
|
328
345
|
type PluginInitContext<TPluginExtraOptions = unknown> = RequestContext & PluginExtraOptions<TPluginExtraOptions> & {
|
@@ -359,12 +376,16 @@ interface CallApiPlugin {
|
|
359
376
|
* A name for the plugin
|
360
377
|
*/
|
361
378
|
name: string;
|
379
|
+
/**
|
380
|
+
* Base schema for the client.
|
381
|
+
*/
|
382
|
+
schema?: BaseCallApiSchemaAndConfig;
|
362
383
|
/**
|
363
384
|
* A version for the plugin
|
364
385
|
*/
|
365
386
|
version?: string;
|
366
387
|
}
|
367
|
-
declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => TPlugin
|
388
|
+
declare const definePlugin: <const TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => Writeable<TPlugin, "deep">;
|
368
389
|
//#endregion
|
369
390
|
//#region src/types/default-types.d.ts
|
370
391
|
type DefaultDataType = unknown;
|
@@ -637,13 +658,13 @@ interface RetryOptions<TErrorData> {
|
|
637
658
|
* @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
|
638
659
|
*/
|
639
660
|
type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaResult<TSchemaOption, undefined> ? TObject : Required<TObject>;
|
640
|
-
type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig,
|
641
|
-
type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig,
|
642
|
-
type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig,
|
643
|
-
type InferAllRouteKeys<
|
644
|
-
type InferInitURL<
|
645
|
-
type
|
646
|
-
type GetCurrentRouteSchema<
|
661
|
+
type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig, TCurrentRouteSchemaKeys extends string> = TSchemaConfig["prefix"] extends string ? `${TSchemaConfig["prefix"]}${TCurrentRouteSchemaKeys}` : TSchemaConfig["baseURL"] extends string ? `${TSchemaConfig["baseURL"]}${TCurrentRouteSchemaKeys}` : TCurrentRouteSchemaKeys;
|
662
|
+
type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TCurrentRouteSchemaKeys extends string> = TSchemaConfig["strict"] extends true ? TCurrentRouteSchemaKeys : TCurrentRouteSchemaKeys | AnyString;
|
663
|
+
type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TCurrentRouteSchemaKeys extends string> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, TCurrentRouteSchemaKeys>>;
|
664
|
+
type InferAllRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Exclude<keyof TBaseSchemaRoutes, number | symbol | RouteKeyMethodsURLUnion>>;
|
665
|
+
type InferInitURL<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = InferAllRouteKeys<TBaseSchemaRoutes, TSchemaConfig> | URL;
|
666
|
+
type GetCurrentRouteSchemaKey<TSchemaConfig extends CallApiSchemaConfig, TPath> = TPath extends URL ? string : TSchemaConfig["baseURL"] extends string ? TPath extends `${TSchemaConfig["baseURL"]}${infer TCurrentRoute}` ? TCurrentRoute extends string ? TCurrentRoute : string : TPath extends `${TSchemaConfig["prefix"]}${infer TCurrentRoute}` ? TCurrentRoute extends string ? TCurrentRoute : string : string : TPath;
|
667
|
+
type GetCurrentRouteSchema<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = TBaseSchemaRoutes[TCurrentRouteSchemaKey] extends CallApiSchema ? NonNullable<Writeable<TBaseSchemaRoutes[TCurrentRouteSchemaKey], "deep">> : CallApiSchema;
|
647
668
|
type JsonPrimitive = boolean | number | string | null | undefined;
|
648
669
|
type SerializableObject = Record<keyof object, unknown>;
|
649
670
|
type SerializableArray = Array<JsonPrimitive | SerializableArray | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableArray | SerializableObject>;
|
@@ -673,7 +694,7 @@ type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequire
|
|
673
694
|
baseHeaders: NonNullable<HeadersOption>;
|
674
695
|
}) => InferSchemaResult<TSchema["headers"], HeadersOption>);
|
675
696
|
}>;
|
676
|
-
type InferRequestOptions<TSchema extends CallApiSchema, TSchemaConfig extends CallApiSchemaConfig, TInitURL extends InferInitURL<
|
697
|
+
type InferRequestOptions<TSchema extends CallApiSchema, TSchemaConfig extends CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TSchemaConfig, TInitURL>;
|
677
698
|
interface Register {}
|
678
699
|
type GlobalMeta = Register extends {
|
679
700
|
meta?: infer TMeta extends Record<string, unknown>;
|
@@ -711,15 +732,15 @@ type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredI
|
|
711
732
|
query?: InferSchemaResult<TSchema["query"], Query>;
|
712
733
|
}>;
|
713
734
|
type EmptyString = "";
|
714
|
-
type
|
715
|
-
type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"],
|
716
|
-
type InferParamsOption<TSchema extends CallApiSchema,
|
735
|
+
type InferParamsFromRoute<TCurrentRoute> = TCurrentRoute extends `${infer IgnoredPrefix}:${infer TCurrentParam}/${infer TRemainingPath}` ? TCurrentParam extends EmptyString ? InferParamsFromRoute<TRemainingPath> : Prettify<Record<TCurrentParam | (Params extends InferParamsFromRoute<TRemainingPath> ? never : keyof Extract<InferParamsFromRoute<TRemainingPath>, Record<string, unknown>>), AllowedQueryParamValues>> | [AllowedQueryParamValues, ...(Params extends InferParamsFromRoute<TRemainingPath> ? [] : Extract<InferParamsFromRoute<TRemainingPath>, unknown[]>)] : TCurrentRoute extends `${infer IgnoredPrefix}:${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? Params : Prettify<Record<TCurrentParam, AllowedQueryParamValues>> | [AllowedQueryParamValues] : Params;
|
736
|
+
type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, TCurrentRouteSchemaKey extends `${string}:${string}${"" | "/"}${"" | AnyString}` ? TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaResult<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject : TObject>;
|
737
|
+
type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
|
717
738
|
/**
|
718
739
|
* Parameters to be appended to the URL (i.e: /:id)
|
719
740
|
*/
|
720
|
-
params?: InferSchemaResult<TSchema["params"],
|
741
|
+
params?: InferSchemaResult<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
|
721
742
|
}>;
|
722
|
-
type InferExtraOptions<TSchema extends CallApiSchema,
|
743
|
+
type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
|
723
744
|
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>;
|
724
745
|
type ExtractKeys<TUnion, TSelectedUnion extends TUnion> = Extract<TUnion, TSelectedUnion>;
|
725
746
|
type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
|
@@ -862,7 +883,7 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
862
883
|
*/
|
863
884
|
timeout?: number;
|
864
885
|
};
|
865
|
-
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,
|
886
|
+
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
|
866
887
|
/**
|
867
888
|
* An array of base callApi plugins. It allows you to extend the behavior of the library.
|
868
889
|
*/
|
@@ -870,11 +891,7 @@ type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = Defau
|
|
870
891
|
/**
|
871
892
|
* Base schemas for the client.
|
872
893
|
*/
|
873
|
-
schema?:
|
874
|
-
/**
|
875
|
-
* Schema Configuration
|
876
|
-
*/
|
877
|
-
schemaConfig?: Writeable<TBaseSchemaConfig, "deep">;
|
894
|
+
schema?: TBaseSchemaAndConfig;
|
878
895
|
/**
|
879
896
|
* Specifies which configuration parts should skip automatic merging between base and main configs.
|
880
897
|
* Use this when you need manual control over how configs are combined.
|
@@ -897,36 +914,36 @@ type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = Defau
|
|
897
914
|
*/
|
898
915
|
skipAutoMergeFor?: "all" | "options" | "request";
|
899
916
|
};
|
900
|
-
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray,
|
917
|
+
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, 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<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
901
918
|
/**
|
902
919
|
* An array of instance CallApi plugins. It allows you to extend the behavior of the library.
|
903
920
|
*/
|
904
921
|
plugins?: TPluginArray | ((context: {
|
905
|
-
basePlugins: TBasePluginArray
|
922
|
+
basePlugins: Writeable<TBasePluginArray, "deep">;
|
906
923
|
}) => TPluginArray);
|
907
924
|
/**
|
908
925
|
* Schemas for the callapi instance
|
909
926
|
*/
|
910
|
-
schema?:
|
911
|
-
baseSchema: Writeable<
|
912
|
-
currentRouteSchema: GetCurrentRouteSchema<
|
913
|
-
}) =>
|
927
|
+
schema?: TSchema | ((context: {
|
928
|
+
baseSchema: Writeable<TBaseSchemaRoutes, "deep">;
|
929
|
+
currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes, TCurrentRouteSchemaKey>;
|
930
|
+
}) => TSchema);
|
914
931
|
/**
|
915
932
|
* Schema config for the callapi instance
|
916
933
|
*/
|
917
|
-
schemaConfig?:
|
934
|
+
schemaConfig?: TSchemaConfig | ((context: {
|
918
935
|
baseSchemaConfig: NonNullable<Writeable<TBaseSchemaConfig, "deep">>;
|
919
|
-
}) =>
|
936
|
+
}) => TSchemaConfig);
|
920
937
|
};
|
921
938
|
type CallApiExtraOptionsForHooks = Hooks & Omit<CallApiExtraOptions, keyof Hooks>;
|
922
|
-
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion,
|
939
|
+
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>) | ((context: {
|
923
940
|
initURL: string;
|
924
941
|
options: CallApiExtraOptions;
|
925
942
|
request: CallApiRequestOptions;
|
926
|
-
}) => CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray,
|
927
|
-
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion,
|
928
|
-
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion,
|
943
|
+
}) => CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>);
|
944
|
+
type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig> = InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema, TSchemaConfig, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, CallApiSchemaConfig, string>>;
|
945
|
+
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 InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig> = InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig>, 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>];
|
929
946
|
type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
|
930
947
|
//#endregion
|
931
|
-
export { AnyString, BaseCallApiConfig, BaseCallApiExtraOptions,
|
932
|
-
//# sourceMappingURL=common-
|
948
|
+
export { AnyString, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes };
|
949
|
+
//# sourceMappingURL=common-Bw8cm62H.d.ts.map
|
package/dist/esm/index.d.ts
CHANGED
@@ -1,12 +1,47 @@
|
|
1
|
-
import { AnyString, BaseCallApiConfig, BaseCallApiExtraOptions,
|
1
|
+
import { AnyString, BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaAndConfig, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteSchema, GetCurrentRouteSchemaKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ThrowOnErrorUnion, URLOptions, ValidationError, Writeable, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes } from "./common-Bw8cm62H.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
|
6
|
-
declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<
|
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 = NonNullable<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 GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey> = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray> | undefined) => CallApiResult<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
|
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 InferInitURL<{
|
7
|
+
[x: AnyString]: CallApiSchema | undefined;
|
8
|
+
"delete/"?: CallApiSchema | undefined;
|
9
|
+
"get/"?: CallApiSchema | undefined;
|
10
|
+
"patch/"?: CallApiSchema | undefined;
|
11
|
+
"post/"?: CallApiSchema | undefined;
|
12
|
+
"put/"?: CallApiSchema | undefined;
|
13
|
+
}, TSchemaConfig> = InferInitURL<{
|
14
|
+
[x: AnyString]: CallApiSchema | undefined;
|
15
|
+
"delete/"?: CallApiSchema | undefined;
|
16
|
+
"get/"?: CallApiSchema | undefined;
|
17
|
+
"patch/"?: CallApiSchema | undefined;
|
18
|
+
"post/"?: CallApiSchema | undefined;
|
19
|
+
"put/"?: CallApiSchema | undefined;
|
20
|
+
}, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends GetCurrentRouteSchema<{
|
21
|
+
[x: AnyString]: CallApiSchema | undefined;
|
22
|
+
"delete/"?: CallApiSchema | undefined;
|
23
|
+
"get/"?: CallApiSchema | undefined;
|
24
|
+
"patch/"?: CallApiSchema | undefined;
|
25
|
+
"post/"?: CallApiSchema | undefined;
|
26
|
+
"put/"?: CallApiSchema | undefined;
|
27
|
+
}, TCurrentRouteSchemaKey> = GetCurrentRouteSchema<{
|
28
|
+
[x: AnyString]: CallApiSchema | undefined;
|
29
|
+
"delete/"?: CallApiSchema | undefined;
|
30
|
+
"get/"?: CallApiSchema | undefined;
|
31
|
+
"patch/"?: CallApiSchema | undefined;
|
32
|
+
"post/"?: CallApiSchema | undefined;
|
33
|
+
"put/"?: CallApiSchema | undefined;
|
34
|
+
}, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, {
|
35
|
+
[x: AnyString]: CallApiSchema | undefined;
|
36
|
+
"delete/"?: CallApiSchema | undefined;
|
37
|
+
"get/"?: CallApiSchema | undefined;
|
38
|
+
"patch/"?: CallApiSchema | undefined;
|
39
|
+
"post/"?: CallApiSchema | undefined;
|
40
|
+
"put/"?: CallApiSchema | undefined;
|
41
|
+
}, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray> | undefined) => CallApiResult<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
|
7
42
|
//#endregion
|
8
43
|
//#region src/defineParameters.d.ts
|
9
|
-
declare const defineParameters: <TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion,
|
44
|
+
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>;
|
10
45
|
//#endregion
|
11
|
-
export { BaseCallApiConfig, BaseCallApiExtraOptions,
|
46
|
+
export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaRoutes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, ErrorContext, HTTPError, Hooks, HooksOrHooksArray, InferParamsFromRoute, InferSchemaResult, PluginExtraOptions, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, URLOptions, ValidationError, callApi, createFetchClient, defineParameters, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes };
|
12
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.js
CHANGED
@@ -242,7 +242,7 @@ const toStreamableResponse = async (context) => {
|
|
242
242
|
//#endregion
|
243
243
|
//#region src/dedupe.ts
|
244
244
|
const getAbortErrorMessage = (dedupeKey, fullURL) => {
|
245
|
-
return dedupeKey ? `Duplicate request detected -
|
245
|
+
return dedupeKey ? `Duplicate request detected - Aborted previous request with key '${dedupeKey}' as a new request was initiated` : `Duplicate request detected - Aborted previous request to '${fullURL}' as a new request with identical options was initiated`;
|
246
246
|
};
|
247
247
|
const createDedupeStrategy = async (context) => {
|
248
248
|
const { $GlobalRequestInfoCache: $GlobalRequestInfoCache$1, $LocalRequestInfoCache, baseConfig, config, newFetchController, options: globalOptions, request: globalRequest } = context;
|
@@ -309,11 +309,179 @@ const createDedupeStrategy = async (context) => {
|
|
309
309
|
};
|
310
310
|
};
|
311
311
|
|
312
|
+
//#endregion
|
313
|
+
//#region src/validation.ts
|
314
|
+
const handleValidatorFunction = async (validator, inputData) => {
|
315
|
+
try {
|
316
|
+
const result = await validator(inputData);
|
317
|
+
return {
|
318
|
+
issues: void 0,
|
319
|
+
value: result
|
320
|
+
};
|
321
|
+
} catch (error) {
|
322
|
+
return {
|
323
|
+
issues: error,
|
324
|
+
value: void 0
|
325
|
+
};
|
326
|
+
}
|
327
|
+
};
|
328
|
+
const standardSchemaParser = async (schema, inputData, response) => {
|
329
|
+
const result = isFunction(schema) ? await handleValidatorFunction(schema, inputData) : await schema["~standard"].validate(inputData);
|
330
|
+
if (result.issues) throw new ValidationError({
|
331
|
+
issues: result.issues,
|
332
|
+
response: response ?? null
|
333
|
+
}, { cause: result.issues });
|
334
|
+
return result.value;
|
335
|
+
};
|
336
|
+
const routeKeyMethods = defineEnum([
|
337
|
+
"delete",
|
338
|
+
"get",
|
339
|
+
"patch",
|
340
|
+
"post",
|
341
|
+
"put"
|
342
|
+
]);
|
343
|
+
const defineSchema = (routes, config) => {
|
344
|
+
return {
|
345
|
+
config,
|
346
|
+
routes
|
347
|
+
};
|
348
|
+
};
|
349
|
+
const defineSchemaConfig = (config) => {
|
350
|
+
return config;
|
351
|
+
};
|
352
|
+
const defineSchemaRoutes = (routes) => {
|
353
|
+
return routes;
|
354
|
+
};
|
355
|
+
const handleValidation = async (schema, validationOptions) => {
|
356
|
+
const { inputValue, response, schemaConfig } = validationOptions;
|
357
|
+
if (!schema || schemaConfig?.disableRuntimeValidation) return inputValue;
|
358
|
+
const validResult = await standardSchemaParser(schema, inputValue, response);
|
359
|
+
return validResult;
|
360
|
+
};
|
361
|
+
const extraOptionsToBeValidated = [
|
362
|
+
"meta",
|
363
|
+
"params",
|
364
|
+
"query"
|
365
|
+
];
|
366
|
+
const handleExtraOptionsValidation = async (validationOptions) => {
|
367
|
+
const { extraOptions, schema, schemaConfig } = validationOptions;
|
368
|
+
const validationResultArray = await Promise.all(extraOptionsToBeValidated.map((propertyKey) => handleValidation(schema?.[propertyKey], {
|
369
|
+
inputValue: extraOptions[propertyKey],
|
370
|
+
schemaConfig
|
371
|
+
})));
|
372
|
+
const validatedResultObject = {};
|
373
|
+
for (const [index, propertyKey] of extraOptionsToBeValidated.entries()) {
|
374
|
+
const validationResult = validationResultArray[index];
|
375
|
+
if (validationResult === void 0) continue;
|
376
|
+
validatedResultObject[propertyKey] = validationResult;
|
377
|
+
}
|
378
|
+
return validatedResultObject;
|
379
|
+
};
|
380
|
+
const requestOptionsToBeValidated = [
|
381
|
+
"body",
|
382
|
+
"headers",
|
383
|
+
"method"
|
384
|
+
];
|
385
|
+
const handleRequestOptionsValidation = async (validationOptions) => {
|
386
|
+
const { requestOptions, schema, schemaConfig } = validationOptions;
|
387
|
+
const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((propertyKey) => handleValidation(schema?.[propertyKey], {
|
388
|
+
inputValue: requestOptions[propertyKey],
|
389
|
+
schemaConfig
|
390
|
+
})));
|
391
|
+
const validatedResultObject = {};
|
392
|
+
for (const [index, propertyKey] of requestOptionsToBeValidated.entries()) {
|
393
|
+
const validationResult = validationResultArray[index];
|
394
|
+
if (validationResult === void 0) continue;
|
395
|
+
validatedResultObject[propertyKey] = validationResult;
|
396
|
+
}
|
397
|
+
return validatedResultObject;
|
398
|
+
};
|
399
|
+
const handleConfigValidation = async (validationOptions) => {
|
400
|
+
const { baseExtraOptions, currentRouteSchemaKey, extraOptions, requestOptions } = validationOptions;
|
401
|
+
const { currentRouteSchema, resolvedSchema } = getResolvedSchema({
|
402
|
+
baseExtraOptions,
|
403
|
+
currentRouteSchemaKey,
|
404
|
+
extraOptions
|
405
|
+
});
|
406
|
+
const resolvedSchemaConfig = getResolvedSchemaConfig({
|
407
|
+
baseExtraOptions,
|
408
|
+
extraOptions
|
409
|
+
});
|
410
|
+
if (!currentRouteSchema && resolvedSchemaConfig?.strict === true) throw new ValidationError({
|
411
|
+
issues: [{ message: `Strict Mode - No schema found for route '${currentRouteSchemaKey}' ` }],
|
412
|
+
response: null
|
413
|
+
});
|
414
|
+
if (resolvedSchemaConfig?.disableRuntimeValidation) return {
|
415
|
+
extraOptionsValidationResult: null,
|
416
|
+
requestOptionsValidationResult: null,
|
417
|
+
resolvedSchema,
|
418
|
+
resolvedSchemaConfig,
|
419
|
+
shouldApplySchemaOutput: false
|
420
|
+
};
|
421
|
+
const [extraOptionsValidationResult, requestOptionsValidationResult] = await Promise.all([handleExtraOptionsValidation({
|
422
|
+
extraOptions,
|
423
|
+
schema: resolvedSchema,
|
424
|
+
schemaConfig: resolvedSchemaConfig
|
425
|
+
}), handleRequestOptionsValidation({
|
426
|
+
requestOptions,
|
427
|
+
schema: resolvedSchema,
|
428
|
+
schemaConfig: resolvedSchemaConfig
|
429
|
+
})]);
|
430
|
+
const shouldApplySchemaOutput = (Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult)) && !resolvedSchemaConfig?.disableValidationOutputApplication;
|
431
|
+
return {
|
432
|
+
extraOptionsValidationResult,
|
433
|
+
requestOptionsValidationResult,
|
434
|
+
resolvedSchema,
|
435
|
+
resolvedSchemaConfig,
|
436
|
+
shouldApplySchemaOutput
|
437
|
+
};
|
438
|
+
};
|
439
|
+
const getResolvedSchema = (context) => {
|
440
|
+
const { baseExtraOptions, currentRouteSchemaKey, extraOptions } = context;
|
441
|
+
const currentRouteSchema = baseExtraOptions.schema?.routes[currentRouteSchemaKey];
|
442
|
+
const resolvedSchema = isFunction(extraOptions.schema) ? extraOptions.schema({
|
443
|
+
baseSchema: baseExtraOptions.schema?.routes ?? {},
|
444
|
+
currentRouteSchema: currentRouteSchema ?? {}
|
445
|
+
}) : extraOptions.schema ?? currentRouteSchema;
|
446
|
+
return {
|
447
|
+
currentRouteSchema,
|
448
|
+
resolvedSchema
|
449
|
+
};
|
450
|
+
};
|
451
|
+
const getResolvedSchemaConfig = (context) => {
|
452
|
+
const { baseExtraOptions, extraOptions } = context;
|
453
|
+
const resolvedSchemaConfig = isFunction(extraOptions.schemaConfig) ? extraOptions.schemaConfig({ baseSchemaConfig: baseExtraOptions.schema?.config ?? {} }) : extraOptions.schemaConfig ?? baseExtraOptions.schema?.config;
|
454
|
+
return resolvedSchemaConfig;
|
455
|
+
};
|
456
|
+
const getCurrentRouteSchemaKeyAndMainInitURL = (context) => {
|
457
|
+
const { baseExtraOptions, extraOptions, initURL } = context;
|
458
|
+
const schemaConfig = getResolvedSchemaConfig({
|
459
|
+
baseExtraOptions,
|
460
|
+
extraOptions
|
461
|
+
});
|
462
|
+
let currentRouteSchemaKey = initURL;
|
463
|
+
let mainInitURL = initURL;
|
464
|
+
if (schemaConfig?.prefix && currentRouteSchemaKey.startsWith(schemaConfig.prefix)) {
|
465
|
+
currentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.prefix, "");
|
466
|
+
mainInitURL = mainInitURL.replace(schemaConfig.prefix, schemaConfig.baseURL ?? "");
|
467
|
+
}
|
468
|
+
if (schemaConfig?.baseURL && currentRouteSchemaKey.startsWith(schemaConfig.baseURL)) currentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.baseURL, "");
|
469
|
+
return {
|
470
|
+
currentRouteSchemaKey,
|
471
|
+
mainInitURL
|
472
|
+
};
|
473
|
+
};
|
474
|
+
|
312
475
|
//#endregion
|
313
476
|
//#region src/plugins.ts
|
314
477
|
const definePlugin = (plugin) => {
|
315
478
|
return plugin;
|
316
479
|
};
|
480
|
+
const getResolvedPlugins = (context) => {
|
481
|
+
const { baseConfig, options } = context;
|
482
|
+
const resolvedPlugins = isFunction(options.plugins) ? options.plugins({ basePlugins: baseConfig.plugins ?? [] }) : options.plugins ?? [];
|
483
|
+
return resolvedPlugins;
|
484
|
+
};
|
317
485
|
const initializePlugins = async (context) => {
|
318
486
|
const { baseConfig, config, initURL, options, request } = context;
|
319
487
|
const clonedHookRegistries = structuredClone(hookRegistries);
|
@@ -336,8 +504,13 @@ const initializePlugins = async (context) => {
|
|
336
504
|
};
|
337
505
|
const mergedHooksExecutionOrder = options.mergedHooksExecutionOrder ?? hookDefaults.mergedHooksExecutionOrder;
|
338
506
|
if (mergedHooksExecutionOrder === "mainHooksBeforePlugins") addMainHooks();
|
339
|
-
const
|
340
|
-
|
507
|
+
const { currentRouteSchemaKey, mainInitURL } = getCurrentRouteSchemaKeyAndMainInitURL({
|
508
|
+
baseExtraOptions: baseConfig,
|
509
|
+
extraOptions: config,
|
510
|
+
initURL
|
511
|
+
});
|
512
|
+
let resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;
|
513
|
+
let resolvedInitURL = mainInitURL;
|
341
514
|
let resolvedOptions = options;
|
342
515
|
let resolvedRequestOptions = request;
|
343
516
|
const executePluginInit = async (pluginInit) => {
|
@@ -351,10 +524,22 @@ const initializePlugins = async (context) => {
|
|
351
524
|
});
|
352
525
|
if (!isPlainObject(initResult)) return;
|
353
526
|
const urlString = initResult.initURL?.toString();
|
354
|
-
if (isString(urlString))
|
527
|
+
if (isString(urlString)) {
|
528
|
+
const newResult = getCurrentRouteSchemaKeyAndMainInitURL({
|
529
|
+
baseExtraOptions: baseConfig,
|
530
|
+
extraOptions: config,
|
531
|
+
initURL: urlString
|
532
|
+
});
|
533
|
+
resolvedCurrentRouteSchemaKey = newResult.currentRouteSchemaKey;
|
534
|
+
resolvedInitURL = newResult.mainInitURL;
|
535
|
+
}
|
355
536
|
if (isPlainObject(initResult.request)) resolvedRequestOptions = initResult.request;
|
356
537
|
if (isPlainObject(initResult.options)) resolvedOptions = initResult.options;
|
357
538
|
};
|
539
|
+
const resolvedPlugins = getResolvedPlugins({
|
540
|
+
baseConfig,
|
541
|
+
options
|
542
|
+
});
|
358
543
|
for (const plugin of resolvedPlugins) {
|
359
544
|
await executePluginInit(plugin.init);
|
360
545
|
if (!plugin.hooks) continue;
|
@@ -371,6 +556,7 @@ const initializePlugins = async (context) => {
|
|
371
556
|
resolvedHooks[key] = composedHook;
|
372
557
|
}
|
373
558
|
return {
|
559
|
+
resolvedCurrentRouteSchemaKey,
|
374
560
|
resolvedHooks,
|
375
561
|
resolvedInitURL,
|
376
562
|
resolvedOptions,
|
@@ -424,105 +610,6 @@ const createRetryStrategy = (ctx) => {
|
|
424
610
|
};
|
425
611
|
};
|
426
612
|
|
427
|
-
//#endregion
|
428
|
-
//#region src/validation.ts
|
429
|
-
const handleValidatorFunction = async (validator, inputData) => {
|
430
|
-
try {
|
431
|
-
const result = await validator(inputData);
|
432
|
-
return {
|
433
|
-
issues: void 0,
|
434
|
-
value: result
|
435
|
-
};
|
436
|
-
} catch (error) {
|
437
|
-
return {
|
438
|
-
issues: error,
|
439
|
-
value: void 0
|
440
|
-
};
|
441
|
-
}
|
442
|
-
};
|
443
|
-
const standardSchemaParser = async (schema, inputData, response) => {
|
444
|
-
const result = isFunction(schema) ? await handleValidatorFunction(schema, inputData) : await schema["~standard"].validate(inputData);
|
445
|
-
if (result.issues) throw new ValidationError({
|
446
|
-
issues: result.issues,
|
447
|
-
response: response ?? null
|
448
|
-
}, { cause: result.issues });
|
449
|
-
return result.value;
|
450
|
-
};
|
451
|
-
const routeKeyMethods = defineEnum([
|
452
|
-
"delete",
|
453
|
-
"get",
|
454
|
-
"patch",
|
455
|
-
"post",
|
456
|
-
"put"
|
457
|
-
]);
|
458
|
-
const defineSchema = (baseSchema) => {
|
459
|
-
return baseSchema;
|
460
|
-
};
|
461
|
-
const handleValidation = async (schema, validationOptions) => {
|
462
|
-
const { inputValue, response, schemaConfig } = validationOptions;
|
463
|
-
if (!schema || schemaConfig?.disableRuntimeValidation) return inputValue;
|
464
|
-
const validResult = await standardSchemaParser(schema, inputValue, response);
|
465
|
-
return validResult;
|
466
|
-
};
|
467
|
-
const extraOptionsToBeValidated = [
|
468
|
-
"meta",
|
469
|
-
"params",
|
470
|
-
"query"
|
471
|
-
];
|
472
|
-
const handleExtraOptionsValidation = async (validationOptions) => {
|
473
|
-
const { extraOptions, schema, schemaConfig } = validationOptions;
|
474
|
-
const validationResultArray = await Promise.all(extraOptionsToBeValidated.map((propertyKey) => handleValidation(schema?.[propertyKey], {
|
475
|
-
inputValue: extraOptions[propertyKey],
|
476
|
-
schemaConfig
|
477
|
-
})));
|
478
|
-
const validatedResultObject = {};
|
479
|
-
for (const [index, propertyKey] of extraOptionsToBeValidated.entries()) {
|
480
|
-
const validationResult = validationResultArray[index];
|
481
|
-
if (validationResult === void 0) continue;
|
482
|
-
validatedResultObject[propertyKey] = validationResult;
|
483
|
-
}
|
484
|
-
return validatedResultObject;
|
485
|
-
};
|
486
|
-
const requestOptionsToBeValidated = [
|
487
|
-
"body",
|
488
|
-
"headers",
|
489
|
-
"method"
|
490
|
-
];
|
491
|
-
const handleRequestOptionsValidation = async (validationOptions) => {
|
492
|
-
const { requestOptions, schema, schemaConfig } = validationOptions;
|
493
|
-
const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((propertyKey) => handleValidation(schema?.[propertyKey], {
|
494
|
-
inputValue: requestOptions[propertyKey],
|
495
|
-
schemaConfig
|
496
|
-
})));
|
497
|
-
const validatedResultObject = {};
|
498
|
-
for (const [index, propertyKey] of requestOptionsToBeValidated.entries()) {
|
499
|
-
const validationResult = validationResultArray[index];
|
500
|
-
if (validationResult === void 0) continue;
|
501
|
-
validatedResultObject[propertyKey] = validationResult;
|
502
|
-
}
|
503
|
-
return validatedResultObject;
|
504
|
-
};
|
505
|
-
const handleOptionsValidation = async (validationOptions) => {
|
506
|
-
const { extraOptions, requestOptions, schema, schemaConfig } = validationOptions;
|
507
|
-
if (schemaConfig?.disableRuntimeValidation) return {
|
508
|
-
extraOptionsValidationResult: null,
|
509
|
-
requestOptionsValidationResult: null
|
510
|
-
};
|
511
|
-
const [extraOptionsValidationResult, requestOptionsValidationResult] = await Promise.all([handleExtraOptionsValidation({
|
512
|
-
extraOptions,
|
513
|
-
schema,
|
514
|
-
schemaConfig
|
515
|
-
}), handleRequestOptionsValidation({
|
516
|
-
requestOptions,
|
517
|
-
schema,
|
518
|
-
schemaConfig
|
519
|
-
})]);
|
520
|
-
return {
|
521
|
-
extraOptionsValidationResult,
|
522
|
-
requestOptionsValidationResult
|
523
|
-
};
|
524
|
-
};
|
525
|
-
|
526
613
|
//#endregion
|
527
614
|
//#region src/url.ts
|
528
615
|
const slash = "/";
|
@@ -551,11 +638,6 @@ const mergeUrlWithQuery = (url, query) => {
|
|
551
638
|
if (url.includes(questionMark)) return `${url}${ampersand}${queryString}`;
|
552
639
|
return `${url}${questionMark}${queryString}`;
|
553
640
|
};
|
554
|
-
const getCurrentRouteKey = (url, schemaConfig) => {
|
555
|
-
let currentRouteKey = url;
|
556
|
-
if (schemaConfig?.baseURL && currentRouteKey.startsWith(schemaConfig.baseURL)) currentRouteKey = currentRouteKey.replace(schemaConfig.baseURL, "");
|
557
|
-
return currentRouteKey;
|
558
|
-
};
|
559
641
|
/**
|
560
642
|
* @description
|
561
643
|
* Extracts the method from the URL if it is a schema modifier.
|
@@ -582,11 +664,15 @@ const normalizeURL = (initURL) => {
|
|
582
664
|
};
|
583
665
|
const getFullURL = (options) => {
|
584
666
|
const { baseURL, initURL, params, query } = options;
|
585
|
-
const
|
586
|
-
const urlWithMergedParams = mergeUrlWithParams(
|
667
|
+
const normalizedInitURL = normalizeURL(initURL);
|
668
|
+
const urlWithMergedParams = mergeUrlWithParams(normalizedInitURL, params);
|
587
669
|
const urlWithMergedQueryAndParams = mergeUrlWithQuery(urlWithMergedParams, query);
|
588
|
-
|
589
|
-
|
670
|
+
const shouldNotPrependBaseURL = urlWithMergedQueryAndParams.startsWith("http") || !baseURL;
|
671
|
+
const fullURL = shouldNotPrependBaseURL ? urlWithMergedQueryAndParams : `${baseURL}${urlWithMergedQueryAndParams}`;
|
672
|
+
return {
|
673
|
+
fullURL,
|
674
|
+
normalizedInitURL
|
675
|
+
};
|
590
676
|
};
|
591
677
|
|
592
678
|
//#endregion
|
@@ -616,14 +702,14 @@ const createFetchClient = (initBaseConfig = {}) => {
|
|
616
702
|
...baseFetchOptions,
|
617
703
|
...!shouldSkipAutoMergeForRequest && fetchOptions
|
618
704
|
};
|
619
|
-
const { resolvedHooks, resolvedInitURL, resolvedOptions, resolvedRequestOptions } = await initializePlugins({
|
705
|
+
const { resolvedCurrentRouteSchemaKey, resolvedHooks, resolvedInitURL, resolvedOptions, resolvedRequestOptions } = await initializePlugins({
|
620
706
|
baseConfig,
|
621
707
|
config,
|
622
708
|
initURL: initURLOrURLObject.toString(),
|
623
709
|
options: mergedExtraOptions,
|
624
710
|
request: mergedRequestOptions
|
625
711
|
});
|
626
|
-
const fullURL = getFullURL({
|
712
|
+
const { fullURL, normalizedInitURL } = getFullURL({
|
627
713
|
baseURL: resolvedOptions.baseURL,
|
628
714
|
initURL: resolvedInitURL,
|
629
715
|
params: resolvedOptions.params,
|
@@ -634,7 +720,7 @@ const createFetchClient = (initBaseConfig = {}) => {
|
|
634
720
|
...resolvedHooks,
|
635
721
|
fullURL,
|
636
722
|
initURL: resolvedInitURL,
|
637
|
-
initURLNormalized:
|
723
|
+
initURLNormalized: normalizedInitURL
|
638
724
|
};
|
639
725
|
const newFetchController = new AbortController();
|
640
726
|
const timeoutSignal = options.timeout != null ? createTimeoutSignal(options.timeout) : null;
|
@@ -660,27 +746,12 @@ const createFetchClient = (initBaseConfig = {}) => {
|
|
660
746
|
options,
|
661
747
|
request
|
662
748
|
}));
|
663
|
-
const
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
throw new ValidationError({
|
669
|
-
issues,
|
670
|
-
response: null
|
671
|
-
});
|
672
|
-
}
|
673
|
-
const resolvedSchema = isFunction(extraOptions.schema) ? extraOptions.schema({
|
674
|
-
baseSchema: baseExtraOptions.schema ?? {},
|
675
|
-
currentRouteSchema: routeSchema ?? {}
|
676
|
-
}) : extraOptions.schema ?? routeSchema;
|
677
|
-
const { extraOptionsValidationResult, requestOptionsValidationResult } = await handleOptionsValidation({
|
678
|
-
extraOptions: options,
|
679
|
-
requestOptions: request,
|
680
|
-
schema: resolvedSchema,
|
681
|
-
schemaConfig: resolvedSchemaConfig
|
749
|
+
const { extraOptionsValidationResult, requestOptionsValidationResult, resolvedSchema, resolvedSchemaConfig, shouldApplySchemaOutput } = await handleConfigValidation({
|
750
|
+
baseExtraOptions,
|
751
|
+
currentRouteSchemaKey: resolvedCurrentRouteSchemaKey,
|
752
|
+
extraOptions,
|
753
|
+
requestOptions: request
|
682
754
|
});
|
683
|
-
const shouldApplySchemaOutput = Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult) || !resolvedSchemaConfig?.disableValidationOutputApplication;
|
684
755
|
if (shouldApplySchemaOutput) options = {
|
685
756
|
...options,
|
686
757
|
...extraOptionsValidationResult
|
@@ -833,5 +904,5 @@ const defineParameters = (...parameters) => {
|
|
833
904
|
};
|
834
905
|
|
835
906
|
//#endregion
|
836
|
-
export { HTTPError, ValidationError, callApi, createFetchClient, defineParameters, definePlugin, defineSchema };
|
907
|
+
export { HTTPError, ValidationError, callApi, createFetchClient, defineParameters, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes };
|
837
908
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","names":["response: Response","parser: Parser","responseType?: ResponseTypeUnion","parser?: Parser","details: CallApiResultErrorVariant<unknown> | CallApiResultSuccessVariant<unknown>","data: unknown","info: SuccessInfo","error: unknown","info: ErrorInfo","errorResult: ErrorResult","customErrorInfo: { message: string | undefined }","hooksArray: Array<AnyFunction | undefined>","mergedHooksExecutionMode: CallApiExtraOptionsForHooks[\"mergedHooksExecutionMode\"]","ctx: unknown","hookResultsOrPromise: Array<Awaitable<unknown>>","hookInfo: ExecuteHookInfo","options: {\n\tchunk: Uint8Array;\n\ttotalBytes: number;\n\ttransferredBytes: number;\n}","requestBody: Request[\"body\"] | null","existingTotalBytes: number","context: ToStreamableRequestContext","context: StreamableResponseContext","dedupeKey: DedupeOptions[\"dedupeKey\"]","fullURL: DedupeContext[\"options\"][\"fullURL\"]","context: DedupeContext","$GlobalRequestInfoCache","deferContext: {\n\t\toptions: DedupeContext[\"options\"];\n\t\trequest: DedupeContext[\"request\"];\n\t}","plugin: TPlugin","context: PluginInitContext","pluginHooks: Required<CallApiPlugin>[\"hooks\"]","pluginInit: CallApiPlugin[\"init\"]","resolvedHooks: Hooks","currentAttemptCount: number","options: RetryOptions<unknown>","ctx: ErrorContext<unknown> & RequestContext","validator: Extract<CallApiSchema[keyof CallApiSchema], AnyFunction>","inputData: TInput","schema: TSchema","inputData: InferSchemaInput<TSchema>","response?: Response | null","baseSchema: TBaseSchema","schema: TSchema | undefined","validationOptions: ValidationOptions<TSchema>","validationOptions: ExtraOptionsValidationOptions","validatedResultObject: Prettify<\n\t\tPick<CallApiExtraOptions, (typeof extraOptionsToBeValidated)[number]>\n\t>","validationOptions: RequestOptionsValidationOptions","validatedResultObject: Prettify<\n\t\tPick<CallApiRequestOptions, (typeof requestOptionsToBeValidated)[number]>\n\t>","validationOptions: ExtraOptionsValidationOptions & RequestOptionsValidationOptions","url: string","params: CallApiExtraOptions[\"params\"]","query: CallApiExtraOptions[\"query\"]","schemaConfig: CallApiSchemaConfig | undefined","initURL: string | undefined","options: GetMethodOptions","initURL: string","options: GetFullURLOptions","$GlobalRequestInfoCache: RequestInfoCache","initBaseConfig: BaseCallApiConfig<\n\t\tTBaseData,\n\t\tTBaseErrorData,\n\t\tTBaseResultMode,\n\t\tTBaseThrowOnError,\n\t\tTBaseResponseType,\n\t\tTBaseSchema,\n\t\tTBaseSchemaConfig,\n\t\tTBasePluginArray\n\t>","$LocalRequestInfoCache: RequestInfoCache","callApi","hookError","message: string | undefined"],"sources":["../../src/result.ts","../../src/hooks.ts","../../src/stream.ts","../../src/dedupe.ts","../../src/plugins.ts","../../src/retry.ts","../../src/validation.ts","../../src/url.ts","../../src/createFetchClient.ts","../../src/defineParameters.ts"],"sourcesContent":["import { responseDefaults } from \"./constants/default-options\";\nimport type { HTTPError, ValidationError } from \"./error\";\nimport type { CallApiExtraOptions, ThrowOnErrorUnion } from \"./types\";\nimport type { DefaultDataType } from \"./types/default-types\";\nimport type { AnyString, Awaitable, UnmaskType } from \"./types/type-helpers\";\nimport { isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/guards\";\n\ntype Parser = (responseString: string) => Awaitable<Record<string, unknown>>;\n\nexport const getResponseType = <TResponse>(response: Response, parser: Parser) => ({\n\tarrayBuffer: () => response.arrayBuffer(),\n\tblob: () => response.blob(),\n\tformData: () => response.formData(),\n\tjson: async () => {\n\t\tconst text = await response.text();\n\t\treturn parser(text) as TResponse;\n\t},\n\tstream: () => response.body,\n\ttext: () => response.text(),\n});\n\ntype InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;\n\nexport type ResponseTypeUnion = keyof InitResponseTypeMap | null;\n\nexport type ResponseTypeMap<TResponse> = {\n\t[Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>>;\n};\n\nexport type GetResponseType<\n\tTResponse,\n\tTResponseType extends ResponseTypeUnion,\n\tTComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>,\n> =\n\tnull extends TResponseType ? TComputedResponseTypeMap[\"json\"]\n\t: TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType]\n\t: never;\n\nexport const resolveResponseData = <TResponse>(\n\tresponse: Response,\n\tresponseType?: ResponseTypeUnion,\n\tparser?: Parser\n) => {\n\tconst selectedParser = parser ?? responseDefaults.responseParser;\n\tconst selectedResponseType = responseType ?? responseDefaults.responseType;\n\n\tconst RESPONSE_TYPE_LOOKUP = getResponseType<TResponse>(response, selectedParser);\n\n\tif (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) {\n\t\tthrow new Error(`Invalid response type: ${responseType}`);\n\t}\n\n\treturn RESPONSE_TYPE_LOOKUP[selectedResponseType]();\n};\n\nexport type CallApiResultSuccessVariant<TData> = {\n\tdata: NoInfer<TData>;\n\terror: null;\n\tresponse: Response;\n};\n\nexport type PossibleJavaScriptError = UnmaskType<{\n\terrorData: false;\n\tmessage: string;\n\tname: \"AbortError\" | \"Error\" | \"SyntaxError\" | \"TimeoutError\" | \"TypeError\" | AnyString;\n\toriginalError: DOMException | Error | SyntaxError | TypeError;\n}>;\n\nexport type PossibleHTTPError<TErrorData> = UnmaskType<{\n\terrorData: NoInfer<TErrorData>;\n\tmessage: string;\n\tname: \"HTTPError\";\n\toriginalError: HTTPError;\n}>;\n\nexport type PossibleValidationError = UnmaskType<{\n\terrorData: ValidationError[\"errorData\"];\n\tmessage: string;\n\tname: \"ValidationError\";\n\toriginalError: ValidationError;\n}>;\n\nexport type PossibleJavaScriptOrValidationError = UnmaskType<\n\tPossibleJavaScriptError | PossibleValidationError\n>;\n\nexport type CallApiResultErrorVariant<TErrorData> =\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\tresponse: Response;\n\t }\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleJavaScriptOrValidationError;\n\t\t\tresponse: Response | null;\n\t };\n\nexport type ResultModeMap<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTComputedData = GetResponseType<TData, TResponseType>,\n\tTComputedErrorData = GetResponseType<TErrorData, TResponseType>,\n> = UnmaskType<{\n\t/* eslint-disable perfectionist/sort-union-types -- I need the first one to be first */\n\tall: CallApiResultSuccessVariant<TComputedData> | CallApiResultErrorVariant<TComputedErrorData>;\n\n\tallWithException: CallApiResultSuccessVariant<TComputedData>;\n\n\tonlySuccess:\n\t\t| CallApiResultErrorVariant<TComputedErrorData>[\"data\"]\n\t\t| CallApiResultSuccessVariant<TComputedData>[\"data\"];\n\n\tonlySuccessWithException: CallApiResultSuccessVariant<TComputedData>[\"data\"];\n\t/* eslint-enable perfectionist/sort-union-types -- I need the first one to be first */\n}>;\n\nexport type ResultModeUnion = keyof ResultModeMap | null;\n\nexport type GetCallApiResult<\n\tTData,\n\tTErrorData,\n\tTResultMode extends ResultModeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion,\n\tTResponseType extends ResponseTypeUnion,\n> =\n\tTErrorData extends false ? ResultModeMap<TData, TErrorData, TResponseType>[\"onlySuccessWithException\"]\n\t: TErrorData extends false | undefined ?\n\t\tResultModeMap<TData, TErrorData, TResponseType>[\"onlySuccessWithException\"]\n\t: TErrorData extends false | null ? ResultModeMap<TData, TErrorData, TResponseType>[\"onlySuccess\"]\n\t: null extends TResultMode ?\n\t\tTThrowOnError extends true ?\n\t\t\tResultModeMap<TData, TErrorData, TResponseType>[\"allWithException\"]\n\t\t:\tResultModeMap<TData, TErrorData, TResponseType>[\"all\"]\n\t: TResultMode extends NonNullable<ResultModeUnion> ?\n\t\tResultModeMap<TData, TErrorData, TResponseType>[TResultMode]\n\t:\tnever;\n\ntype SuccessInfo = {\n\tresponse: Response;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n};\n\ntype LazyResultModeMap = {\n\t[key in keyof ResultModeMap]: () => ResultModeMap[key];\n};\n\nconst getResultModeMap = (\n\tdetails: CallApiResultErrorVariant<unknown> | CallApiResultSuccessVariant<unknown>\n) => {\n\tconst resultModeMap = {\n\t\tall: () => details,\n\t\tallWithException: () => resultModeMap.all() as never,\n\t\tonlySuccess: () => details.data,\n\t\tonlySuccessWithException: () => resultModeMap.onlySuccess(),\n\t} satisfies LazyResultModeMap as LazyResultModeMap;\n\n\treturn resultModeMap;\n};\n\ntype SuccessResult = CallApiResultSuccessVariant<unknown> | null;\n\n// == The CallApiResult type is used to cast all return statements due to a design limitation in ts.\n// LINK - See https://www.zhenghao.io/posts/type-functions for more info\nexport const resolveSuccessResult = (data: unknown, info: SuccessInfo): SuccessResult => {\n\tconst { response, resultMode } = info;\n\n\tconst details = {\n\t\tdata,\n\t\terror: null,\n\t\tresponse,\n\t} satisfies CallApiResultSuccessVariant<unknown>;\n\n\tconst resultModeMap = getResultModeMap(details);\n\n\tconst successResult = resultModeMap[resultMode ?? \"all\"]();\n\n\treturn successResult as SuccessResult;\n};\n\nexport type ErrorInfo = {\n\tcloneResponse: CallApiExtraOptions[\"cloneResponse\"];\n\tmessage?: string;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n};\n\ntype ErrorResult = CallApiResultErrorVariant<unknown> | null;\n\nexport const resolveErrorResult = (error: unknown, info: ErrorInfo): ErrorResult => {\n\tconst { cloneResponse, message: customErrorMessage, resultMode } = info;\n\n\tlet details = {\n\t\tdata: null,\n\t\terror: {\n\t\t\terrorData: false,\n\t\t\tmessage: customErrorMessage ?? (error as Error).message,\n\t\t\tname: (error as Error).name,\n\t\t\toriginalError: error as Error,\n\t\t},\n\t\tresponse: null,\n\t} satisfies CallApiResultErrorVariant<unknown> as CallApiResultErrorVariant<unknown>;\n\n\tif (isValidationErrorInstance(error)) {\n\t\tconst { errorData, message, response } = error;\n\n\t\tdetails = {\n\t\t\tdata: null,\n\t\t\terror: { errorData, message, name: \"ValidationError\", originalError: error },\n\t\t\tresponse,\n\t\t};\n\t}\n\n\tif (isHTTPErrorInstance<never>(error)) {\n\t\tconst { errorData, message, name, response } = error;\n\n\t\tdetails = {\n\t\t\tdata: null,\n\t\t\terror: { errorData, message, name, originalError: error },\n\t\t\tresponse: cloneResponse ? response.clone() : response,\n\t\t};\n\t}\n\n\tconst resultModeMap = getResultModeMap(details);\n\n\tconst errorResult = resultModeMap[resultMode ?? \"all\"]();\n\n\treturn errorResult as ErrorResult;\n};\n\nexport const getCustomizedErrorResult = (\n\terrorResult: ErrorResult,\n\tcustomErrorInfo: { message: string | undefined }\n): ErrorResult => {\n\tif (!errorResult) {\n\t\treturn null;\n\t}\n\n\tconst { message = errorResult.error.message } = customErrorInfo;\n\n\treturn {\n\t\t...errorResult,\n\t\terror: {\n\t\t\t...errorResult.error,\n\t\t\tmessage,\n\t\t} satisfies NonNullable<ErrorResult>[\"error\"] as never,\n\t};\n};\n","import type { ValidationError } from \"./error\";\nimport {\n\ttype CallApiResultErrorVariant,\n\ttype CallApiResultSuccessVariant,\n\ttype ErrorInfo,\n\ttype PossibleHTTPError,\n\ttype PossibleJavaScriptOrValidationError,\n\tresolveErrorResult,\n} from \"./result\";\nimport type { StreamProgressEvent } from \"./stream\";\nimport type {\n\tBaseCallApiExtraOptions,\n\tCallApiExtraOptions,\n\tCallApiExtraOptionsForHooks,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n} from \"./types/common\";\nimport type { DefaultDataType } from \"./types/default-types\";\nimport type { AnyFunction, Awaitable, Prettify, UnmaskType } from \"./types/type-helpers\";\n\nexport type PluginExtraOptions<TPluginOptions = unknown> = {\n\toptions: Partial<TPluginOptions>;\n};\n\n/* eslint-disable perfectionist/sort-intersection-types -- Plugin options should come last */\nexport interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOptions = unknown> {\n\t/**\n\t * Hook that will be called when any error occurs within the request/response lifecycle, regardless of whether the error is from the api or not.\n\t * It is basically a combination of `onRequestError` and `onResponseError` hooks\n\t */\n\tonError?: (\n\t\tcontext: ErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called just before the request is being made.\n\t */\n\tonRequest?: (context: RequestContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when an error occurs during the fetch request.\n\t */\n\tonRequestError?: (\n\t\tcontext: RequestErrorContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when upload stream progress is tracked\n\t */\n\tonRequestStream?: (\n\t\tcontext: RequestStreamContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when any response is received from the api, whether successful or not\n\t */\n\tonResponse?: (\n\t\tcontext: ResponseContext<TData, TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when an error response is received from the api.\n\t */\n\tonResponseError?: (\n\t\tcontext: ResponseErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when download stream progress is tracked\n\t */\n\tonResponseStream?: (\n\t\tcontext: ResponseStreamContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when a request is retried.\n\t */\n\tonRetry?: (\n\t\tresponse: RetryContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when a successful response is received from the api.\n\t */\n\tonSuccess?: (context: SuccessContext<TData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when a validation error occurs.\n\t */\n\tonValidationError?: (\n\t\tcontext: ValidationErrorContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n}\n/* eslint-enable perfectionist/sort-intersection-types -- Plugin options should come last */\n\nexport type HooksOrHooksArray<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTMoreOptions = unknown,\n> = {\n\t[Key in keyof Hooks<TData, TErrorData, TMoreOptions>]:\n\t\t| Hooks<TData, TErrorData, TMoreOptions>[Key]\n\t\t// eslint-disable-next-line perfectionist/sort-union-types -- I need arrays to be last\n\t\t| Array<Hooks<TData, TErrorData, TMoreOptions>[Key]>;\n};\n\nexport type RequestContext = {\n\t/**\n\t * Config object passed to createFetchClient\n\t */\n\tbaseConfig: BaseCallApiExtraOptions & CallApiRequestOptions;\n\t/**\n\t * Config object passed to the callApi instance\n\t */\n\tconfig: CallApiExtraOptions & CallApiRequestOptions;\n\t/**\n\t * Merged options consisting of extra options from createFetchClient, the callApi instance and default options.\n\t *\n\t */\n\toptions: CallApiExtraOptionsForHooks;\n\t/**\n\t * Merged request consisting of request options from createFetchClient, the callApi instance and default request options.\n\t */\n\trequest: CallApiRequestOptionsForHooks;\n};\n\nexport type ValidationErrorContext = UnmaskType<\n\tRequestContext & {\n\t\terror: ValidationError;\n\t\tresponse: Response | null;\n\t}\n>;\n\nexport type SuccessContext<TData> = UnmaskType<\n\tRequestContext & {\n\t\tdata: TData;\n\t\tresponse: Response;\n\t}\n>;\n\nexport type ResponseContext<TData, TErrorData> = UnmaskType<\n\tRequestContext\n\t\t& (\n\t\t\t| Prettify<CallApiResultSuccessVariant<TData>>\n\t\t\t| Prettify<\n\t\t\t\t\tExtract<CallApiResultErrorVariant<TErrorData>, { error: PossibleHTTPError<TErrorData> }>\n\t\t\t >\n\t\t)\n>;\n\nexport type RequestErrorContext = RequestContext & {\n\terror: PossibleJavaScriptOrValidationError;\n\tresponse: null;\n};\n\nexport type ErrorContext<TErrorData> = UnmaskType<\n\tRequestContext\n\t\t& (\n\t\t\t| {\n\t\t\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\t\t\tresponse: Response;\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\terror: PossibleJavaScriptOrValidationError;\n\t\t\t\t\tresponse: Response | null;\n\t\t\t }\n\t\t)\n>;\n\nexport type ResponseErrorContext<TErrorData> = UnmaskType<\n\tExtract<ErrorContext<TErrorData>, { error: PossibleHTTPError<TErrorData> }> & RequestContext\n>;\n\nexport type RetryContext<TErrorData> = UnmaskType<\n\tErrorContext<TErrorData> & { retryAttemptCount: number }\n>;\n\nexport type RequestStreamContext = UnmaskType<\n\tRequestContext & {\n\t\tevent: StreamProgressEvent;\n\t\trequestInstance: Request;\n\t}\n>;\n\nexport type ResponseStreamContext = UnmaskType<\n\tRequestContext & {\n\t\tevent: StreamProgressEvent;\n\t\tresponse: Response;\n\t}\n>;\n\ntype HookRegistries = Required<{\n\t[Key in keyof Hooks]: Set<Hooks[Key]>;\n}>;\n\nexport const hookRegistries = {\n\tonError: new Set(),\n\tonRequest: new Set(),\n\tonRequestError: new Set(),\n\tonRequestStream: new Set(),\n\tonResponse: new Set(),\n\tonResponseError: new Set(),\n\tonResponseStream: new Set(),\n\tonRetry: new Set(),\n\tonSuccess: new Set(),\n\tonValidationError: new Set(),\n} satisfies HookRegistries;\n\nexport const composeAllHooks = (\n\thooksArray: Array<AnyFunction | undefined>,\n\tmergedHooksExecutionMode: CallApiExtraOptionsForHooks[\"mergedHooksExecutionMode\"]\n) => {\n\tconst mergedHook = async (ctx: unknown) => {\n\t\tif (mergedHooksExecutionMode === \"sequential\") {\n\t\t\tfor (const hook of hooksArray) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop -- This is necessary in this case\n\t\t\t\tawait hook?.(ctx);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (mergedHooksExecutionMode === \"parallel\") {\n\t\t\tawait Promise.all(hooksArray.map((uniqueHook) => uniqueHook?.(ctx)));\n\t\t}\n\t};\n\n\treturn mergedHook;\n};\n\nexport const executeHooksInTryBlock = async (...hookResultsOrPromise: Array<Awaitable<unknown>>) => {\n\tawait Promise.all(hookResultsOrPromise);\n};\n\nexport type ExecuteHookInfo = {\n\terrorInfo: ErrorInfo;\n\tshouldThrowOnError: boolean | undefined;\n};\n\nexport const executeHooksInCatchBlock = async (\n\thookResultsOrPromise: Array<Awaitable<unknown>>,\n\thookInfo: ExecuteHookInfo\n) => {\n\tconst { errorInfo, shouldThrowOnError } = hookInfo;\n\n\ttry {\n\t\tawait Promise.all(hookResultsOrPromise);\n\n\t\treturn null;\n\t} catch (hookError) {\n\t\tconst hookErrorResult = resolveErrorResult(hookError, errorInfo);\n\n\t\tif (shouldThrowOnError) {\n\t\t\tthrow hookError;\n\t\t}\n\n\t\treturn hookErrorResult;\n\t}\n};\n","import {\n\texecuteHooksInTryBlock,\n\ttype RequestContext,\n\ttype RequestStreamContext,\n\ttype ResponseStreamContext,\n} from \"./hooks\";\nimport { isObject, isReadableStream } from \"./utils/guards\";\n\nexport type StreamProgressEvent = {\n\t/**\n\t * Current chunk of data being streamed\n\t */\n\tchunk: Uint8Array;\n\t/**\n\t * Progress in percentage\n\t */\n\tprogress: number;\n\t/**\n\t * Total size of data in bytes\n\t */\n\ttotalBytes: number;\n\t/**\n\t * Amount of data transferred so far\n\t */\n\ttransferredBytes: number;\n};\n\ndeclare global {\n\tinterface ReadableStream<R> {\n\t\t[Symbol.asyncIterator]: () => AsyncIterableIterator<R>;\n\t}\n}\n\nconst createProgressEvent = (options: {\n\tchunk: Uint8Array;\n\ttotalBytes: number;\n\ttransferredBytes: number;\n}): StreamProgressEvent => {\n\tconst { chunk, totalBytes, transferredBytes } = options;\n\n\treturn {\n\t\tchunk,\n\t\tprogress: Math.round((transferredBytes / totalBytes) * 100) || 0,\n\t\ttotalBytes,\n\t\ttransferredBytes,\n\t};\n};\n\nconst calculateTotalBytesFromBody = async (\n\trequestBody: Request[\"body\"] | null,\n\texistingTotalBytes: number\n) => {\n\tlet totalBytes = existingTotalBytes;\n\n\tif (!requestBody) {\n\t\treturn totalBytes;\n\t}\n\n\tfor await (const chunk of requestBody) {\n\t\ttotalBytes += chunk.byteLength;\n\t}\n\n\treturn totalBytes;\n};\n\ntype ToStreamableRequestContext = RequestContext;\n\nexport const toStreamableRequest = async (\n\tcontext: ToStreamableRequestContext\n): Promise<Request | RequestInit> => {\n\tconst { baseConfig, config, options, request } = context;\n\n\tif (!options.onRequestStream || !isReadableStream(request.body)) {\n\t\treturn request as RequestInit;\n\t}\n\n\tconst requestInstance = new Request(\n\t\toptions.fullURL as NonNullable<typeof options.fullURL>,\n\t\t{ ...request, duplex: \"half\" } as RequestInit\n\t);\n\n\tconst contentLength = requestInstance.headers.get(\"content-length\");\n\n\tlet totalBytes = Number(contentLength ?? 0);\n\n\tconst shouldForcefullyCalcStreamSize =\n\t\tisObject(options.forcefullyCalculateStreamSize) ?\n\t\t\toptions.forcefullyCalculateStreamSize.request\n\t\t:\toptions.forcefullyCalculateStreamSize;\n\n\t// == If no content length is present, we read the total bytes from the body\n\tif (!contentLength && shouldForcefullyCalcStreamSize) {\n\t\ttotalBytes = await calculateTotalBytesFromBody(requestInstance.clone().body, totalBytes);\n\t}\n\n\tlet transferredBytes = 0;\n\n\tconst stream = new ReadableStream({\n\t\tstart: async (controller) => {\n\t\t\tconst body = requestInstance.body;\n\n\t\t\tif (!body) return;\n\n\t\t\tconst requestStreamContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tevent: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\trequestInstance,\n\t\t\t} satisfies RequestStreamContext;\n\n\t\t\tawait executeHooksInTryBlock(options.onRequestStream?.(requestStreamContext));\n\n\t\t\tfor await (const chunk of body) {\n\t\t\t\ttransferredBytes += chunk.byteLength;\n\n\t\t\t\ttotalBytes = Math.max(totalBytes, transferredBytes);\n\n\t\t\t\tawait executeHooksInTryBlock(\n\t\t\t\t\toptions.onRequestStream?.({\n\t\t\t\t\t\t...requestStreamContext,\n\t\t\t\t\t\tevent: createProgressEvent({ chunk, totalBytes, transferredBytes }),\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t}\n\n\t\t\tcontroller.close();\n\t\t},\n\t});\n\n\treturn new Request(requestInstance, { body: stream, duplex: \"half\" } as RequestInit);\n};\n\ntype StreamableResponseContext = RequestContext & { response: Response };\n\nexport const toStreamableResponse = async (context: StreamableResponseContext): Promise<Response> => {\n\tconst { baseConfig, config, options, request, response } = context;\n\n\tif (!options.onResponseStream || !response.body) {\n\t\treturn response;\n\t}\n\n\tconst contentLength = response.headers.get(\"content-length\");\n\n\tlet totalBytes = Number(contentLength ?? 0);\n\n\tconst shouldForceContentLengthCalc =\n\t\tisObject(options.forcefullyCalculateStreamSize) ?\n\t\t\toptions.forcefullyCalculateStreamSize.response\n\t\t:\toptions.forcefullyCalculateStreamSize;\n\n\t// == If no content length is present and `forceContentLengthCalculation` is enabled, we read the total bytes from the body\n\tif (!contentLength && shouldForceContentLengthCalc) {\n\t\ttotalBytes = await calculateTotalBytesFromBody(response.clone().body, totalBytes);\n\t}\n\n\tlet transferredBytes = 0;\n\n\tconst stream = new ReadableStream({\n\t\tstart: async (controller) => {\n\t\t\tconst body = response.body;\n\n\t\t\tif (!body) return;\n\n\t\t\tconst responseStreamContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tevent: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse,\n\t\t\t} satisfies ResponseStreamContext;\n\n\t\t\tawait executeHooksInTryBlock(options.onResponseStream?.(responseStreamContext));\n\n\t\t\tfor await (const chunk of body) {\n\t\t\t\ttransferredBytes += chunk.byteLength;\n\n\t\t\t\ttotalBytes = Math.max(totalBytes, transferredBytes);\n\n\t\t\t\tawait executeHooksInTryBlock(\n\t\t\t\t\toptions.onResponseStream?.({\n\t\t\t\t\t\t...responseStreamContext,\n\t\t\t\t\t\tevent: createProgressEvent({ chunk, totalBytes, transferredBytes }),\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t}\n\n\t\t\tcontroller.close();\n\t\t},\n\t});\n\n\treturn new Response(stream, response);\n};\n","import { dedupeDefaults } from \"./constants/default-options\";\nimport type { RequestContext } from \"./hooks\";\nimport { toStreamableRequest, toStreamableResponse } from \"./stream\";\nimport { deterministicHashFn, getFetchImpl, waitFor } from \"./utils/common\";\n\ntype RequestInfo = {\n\tcontroller: AbortController;\n\tresponsePromise: Promise<Response>;\n};\n\nexport type RequestInfoCache = Map<string | null, RequestInfo>;\n\ntype DedupeContext = RequestContext & {\n\t$GlobalRequestInfoCache: RequestInfoCache;\n\t$LocalRequestInfoCache: RequestInfoCache;\n\tnewFetchController: AbortController;\n};\n\nexport const getAbortErrorMessage = (\n\tdedupeKey: DedupeOptions[\"dedupeKey\"],\n\tfullURL: DedupeContext[\"options\"][\"fullURL\"]\n) => {\n\treturn dedupeKey ?\n\t\t\t`Duplicate request detected - Aborting previous request with key '${dedupeKey}' as a new request was initiated`\n\t\t:\t`Duplicate request detected - Aborting previous request to '${fullURL}' as a new request with identical options was initiated`;\n};\n\nexport const createDedupeStrategy = async (context: DedupeContext) => {\n\tconst {\n\t\t$GlobalRequestInfoCache,\n\t\t$LocalRequestInfoCache,\n\t\tbaseConfig,\n\t\tconfig,\n\t\tnewFetchController,\n\t\toptions: globalOptions,\n\t\trequest: globalRequest,\n\t} = context;\n\n\tconst dedupeStrategy = globalOptions.dedupeStrategy ?? dedupeDefaults.dedupeStrategy;\n\n\tconst generateDedupeKey = () => {\n\t\tconst shouldHaveDedupeKey = dedupeStrategy === \"cancel\" || dedupeStrategy === \"defer\";\n\n\t\tif (!shouldHaveDedupeKey) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn `${globalOptions.fullURL}-${deterministicHashFn({ options: globalOptions, request: globalRequest })}`;\n\t};\n\n\tconst dedupeKey = globalOptions.dedupeKey ?? generateDedupeKey();\n\n\tconst dedupeCacheScope = globalOptions.dedupeCacheScope ?? dedupeDefaults.dedupeCacheScope;\n\n\tconst $RequestInfoCache = (\n\t\t{\n\t\t\tglobal: $GlobalRequestInfoCache,\n\t\t\tlocal: $LocalRequestInfoCache,\n\t\t} satisfies Record<NonNullable<DedupeOptions[\"dedupeCacheScope\"]>, RequestInfoCache>\n\t)[dedupeCacheScope];\n\n\t// == This is to ensure cache operations only occur when key is available\n\tconst $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;\n\n\t/******\n\t * == Add a small delay to the execution to ensure proper request deduplication when multiple requests with the same key start simultaneously.\n\t * == This gives time for the cache to be updated with the previous request info before the next request checks it.\n\t ******/\n\tif (dedupeKey !== null) {\n\t\tawait waitFor(0.1);\n\t}\n\n\tconst prevRequestInfo = $RequestInfoCacheOrNull?.get(dedupeKey);\n\n\tconst handleRequestCancelStrategy = () => {\n\t\tconst shouldCancelRequest = prevRequestInfo && dedupeStrategy === \"cancel\";\n\n\t\tif (!shouldCancelRequest) return;\n\n\t\tconst message = getAbortErrorMessage(globalOptions.dedupeKey, globalOptions.fullURL);\n\n\t\tconst reason = new DOMException(message, \"AbortError\");\n\n\t\tprevRequestInfo.controller.abort(reason);\n\n\t\t// == Adding this just so that eslint forces me put await when calling the function (it looks better that way tbh)\n\t\treturn Promise.resolve();\n\t};\n\n\tconst handleRequestDeferStrategy = async (deferContext: {\n\t\toptions: DedupeContext[\"options\"];\n\t\trequest: DedupeContext[\"request\"];\n\t}) => {\n\t\t// == Local options and request are needed so that transformations are applied can be applied to both from call site\n\t\tconst { options: localOptions, request: localRequest } = deferContext;\n\n\t\tconst fetchApi = getFetchImpl(localOptions.customFetchImpl);\n\n\t\tconst shouldUsePromiseFromCache = prevRequestInfo && dedupeStrategy === \"defer\";\n\n\t\tconst streamableContext = {\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\toptions: localOptions,\n\t\t\trequest: localRequest,\n\t\t} satisfies RequestContext;\n\n\t\tconst streamableRequest = await toStreamableRequest(streamableContext);\n\n\t\tconst responsePromise =\n\t\t\tshouldUsePromiseFromCache ?\n\t\t\t\tprevRequestInfo.responsePromise\n\t\t\t:\tfetchApi(localOptions.fullURL as NonNullable<typeof localOptions.fullURL>, streamableRequest);\n\n\t\t$RequestInfoCacheOrNull?.set(dedupeKey, { controller: newFetchController, responsePromise });\n\n\t\tconst streamableResponse = toStreamableResponse({\n\t\t\t...streamableContext,\n\t\t\tresponse: await responsePromise,\n\t\t});\n\n\t\treturn streamableResponse;\n\t};\n\n\tconst removeDedupeKeyFromCache = () => {\n\t\t$RequestInfoCacheOrNull?.delete(dedupeKey);\n\t};\n\n\treturn {\n\t\tdedupeStrategy,\n\t\thandleRequestCancelStrategy,\n\t\thandleRequestDeferStrategy,\n\t\tremoveDedupeKeyFromCache,\n\t};\n};\n\nexport type DedupeOptions = {\n\t/**\n\t * Defines the scope of the deduplication cache, can be set to \"global\" | \"local\".\n\t * - If set to \"global\", the deduplication cache will be shared across all requests, regardless of whether they shared the same `createFetchClient` or not.\n\t * - If set to \"local\", the deduplication cache will be scoped to the current request.\n\t * @default \"local\"\n\t */\n\tdedupeCacheScope?: \"global\" | \"local\";\n\n\t/**\n\t * Custom request key to be used to identify a request in the fetch deduplication strategy.\n\t * @default the full request url + string formed from the request options\n\t */\n\tdedupeKey?: string;\n\n\t/**\n\t * Defines the deduplication strategy for the request, can be set to \"none\" | \"defer\" | \"cancel\".\n\t * - If set to \"cancel\", the previous pending request with the same request key will be cancelled and lets the new request through.\n\t * - If set to \"defer\", all new request with the same request key will be share the same response, until the previous one is completed.\n\t * - If set to \"none\", deduplication is disabled.\n\t * @default \"cancel\"\n\t */\n\tdedupeStrategy?: \"cancel\" | \"defer\" | \"none\";\n};\n","import { hookDefaults } from \"./constants/default-options\";\nimport {\n\tcomposeAllHooks,\n\ttype Hooks,\n\ttype HooksOrHooksArray,\n\thookRegistries,\n\ttype PluginExtraOptions,\n\ttype RequestContext,\n} from \"./hooks\";\nimport type { CallApiRequestOptions, CallApiRequestOptionsForHooks } from \"./types/common\";\nimport type { AnyFunction, Awaitable } from \"./types/type-helpers\";\nimport type { InitURLOrURLObject } from \"./url\";\nimport { isArray, isFunction, isPlainObject, isString } from \"./utils/guards\";\n\nexport type PluginInitContext<TPluginExtraOptions = unknown> = RequestContext // eslint-disable-next-line perfectionist/sort-intersection-types -- Allow\n\t& PluginExtraOptions<TPluginExtraOptions> & { initURL: string };\n\nexport type PluginInitResult = Partial<\n\tOmit<PluginInitContext, \"initURL\" | \"request\"> & {\n\t\tinitURL: InitURLOrURLObject;\n\t\trequest: CallApiRequestOptions;\n\t}\n>;\n\nexport type PluginHooksWithMoreOptions<TMoreOptions = unknown> = HooksOrHooksArray<\n\tnever,\n\tnever,\n\tTMoreOptions\n>;\n\nexport type PluginHooks<TData = never, TErrorData = never, TMoreOptions = unknown> = HooksOrHooksArray<\n\tTData,\n\tTErrorData,\n\tTMoreOptions\n>;\n\nexport interface CallApiPlugin {\n\t/**\n\t * Defines additional options that can be passed to callApi\n\t */\n\tdefineExtraOptions?: (...params: never[]) => unknown;\n\n\t/**\n\t * A description for the plugin\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Hooks / Interceptors for the plugin\n\t */\n\thooks?: PluginHooks;\n\n\t/**\n\t * A unique id for the plugin\n\t */\n\tid: string;\n\n\t/**\n\t * A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.\n\t */\n\tinit?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;\n\n\t/**\n\t * A name for the plugin\n\t */\n\tname: string;\n\n\t/**\n\t * A version for the plugin\n\t */\n\tversion?: string;\n}\n\nexport const definePlugin = <\n\t// eslint-disable-next-line perfectionist/sort-union-types -- Let the first one be first\n\tTPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>,\n>(\n\tplugin: TPlugin\n) => {\n\treturn plugin;\n};\n\nexport const initializePlugins = async (context: PluginInitContext) => {\n\tconst { baseConfig, config, initURL, options, request } = context;\n\n\tconst clonedHookRegistries = structuredClone(hookRegistries);\n\n\tconst addMainHooks = () => {\n\t\tfor (const key of Object.keys(clonedHookRegistries) as Array<keyof Hooks>) {\n\t\t\tconst overriddenHook = options[key];\n\t\t\tconst baseHook = baseConfig[key];\n\t\t\tconst instanceHook = config[key];\n\n\t\t\t// == If the base hook is an array and instance hook is defined, we need to compose the base hook with the instance hook\n\t\t\tconst mainHook =\n\t\t\t\tisArray(baseHook) && Boolean(instanceHook) ? [baseHook, instanceHook].flat() : overriddenHook;\n\n\t\t\tif (!mainHook) continue;\n\n\t\t\tclonedHookRegistries[key].add(mainHook as never);\n\t\t}\n\t};\n\n\tconst addPluginHooks = (pluginHooks: Required<CallApiPlugin>[\"hooks\"]) => {\n\t\tfor (const key of Object.keys(clonedHookRegistries) as Array<keyof Hooks>) {\n\t\t\tconst pluginHook = pluginHooks[key];\n\n\t\t\tif (!pluginHook) continue;\n\n\t\t\tclonedHookRegistries[key].add(pluginHook as never);\n\t\t}\n\t};\n\n\tconst mergedHooksExecutionOrder =\n\t\toptions.mergedHooksExecutionOrder ?? hookDefaults.mergedHooksExecutionOrder;\n\n\tif (mergedHooksExecutionOrder === \"mainHooksBeforePlugins\") {\n\t\taddMainHooks();\n\t}\n\n\tconst resolvedPlugins =\n\t\tisFunction(options.plugins) ?\n\t\t\toptions.plugins({ basePlugins: baseConfig.plugins ?? [] })\n\t\t:\t(options.plugins ?? []);\n\n\tlet resolvedInitURL = initURL;\n\tlet resolvedOptions = options;\n\tlet resolvedRequestOptions = request;\n\n\tconst executePluginInit = async (pluginInit: CallApiPlugin[\"init\"]) => {\n\t\tif (!pluginInit) return;\n\n\t\tconst initResult = await pluginInit({\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tinitURL,\n\t\t\toptions,\n\t\t\trequest,\n\t\t});\n\n\t\tif (!isPlainObject(initResult)) return;\n\n\t\tconst urlString = initResult.initURL?.toString();\n\n\t\tif (isString(urlString)) {\n\t\t\tresolvedInitURL = urlString;\n\t\t}\n\n\t\tif (isPlainObject(initResult.request)) {\n\t\t\tresolvedRequestOptions = initResult.request as CallApiRequestOptionsForHooks;\n\t\t}\n\n\t\tif (isPlainObject(initResult.options)) {\n\t\t\tresolvedOptions = initResult.options;\n\t\t}\n\t};\n\n\tfor (const plugin of resolvedPlugins) {\n\t\t// eslint-disable-next-line no-await-in-loop -- Await is necessary in this case.\n\t\tawait executePluginInit(plugin.init);\n\n\t\tif (!plugin.hooks) continue;\n\n\t\taddPluginHooks(plugin.hooks);\n\t}\n\n\tif (mergedHooksExecutionOrder === \"mainHooksAfterPlugins\") {\n\t\taddMainHooks();\n\t}\n\n\tconst resolvedHooks: Hooks = {};\n\n\tfor (const [key, hookRegistry] of Object.entries(clonedHookRegistries)) {\n\t\tif (hookRegistry.size === 0) continue;\n\n\t\t// == Flatten the hook registry to remove any nested arrays, incase an array of hooks is passed to any of the hooks\n\t\tconst flattenedHookArray = [...hookRegistry].flat();\n\n\t\tif (flattenedHookArray.length === 0) continue;\n\n\t\tconst mergedHooksExecutionMode =\n\t\t\toptions.mergedHooksExecutionMode ?? hookDefaults.mergedHooksExecutionMode;\n\n\t\tconst composedHook = composeAllHooks(flattenedHookArray, mergedHooksExecutionMode);\n\n\t\tresolvedHooks[key as keyof Hooks] = composedHook;\n\t}\n\n\treturn {\n\t\tresolvedHooks,\n\t\tresolvedInitURL,\n\t\tresolvedOptions,\n\t\tresolvedRequestOptions,\n\t};\n};\n","import { requestOptionDefaults, retryDefaults } from \"./constants/default-options\";\nimport type { ErrorContext, RequestContext } from \"./hooks\";\nimport type { MethodUnion } from \"./types\";\nimport type { Awaitable } from \"./types/type-helpers\";\nimport { isFunction } from \"./utils/guards\";\n\ntype RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;\n\ntype InnerRetryKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, \"~retryAttemptCount\" | \"retry\">;\n\ntype InnerRetryOptions<TErrorData> = {\n\t[Key in InnerRetryKeys<TErrorData> as Key extends `retry${infer TRest}` ?\n\t\tUncapitalize<TRest> extends \"attempts\" ?\n\t\t\tnever\n\t\t:\tUncapitalize<TRest>\n\t:\tKey]?: RetryOptions<TErrorData>[Key];\n} & {\n\tattempts: NonNullable<RetryOptions<TErrorData>[\"retryAttempts\"]>;\n};\n\nexport interface RetryOptions<TErrorData> {\n\t/**\n\t * Keeps track of the number of times the request has already been retried\n\t *\n\t * @deprecated **NOTE**: This property is used internally to track retries. Please abstain from modifying it.\n\t */\n\treadonly [\"~retryAttemptCount\"]?: number;\n\n\t/**\n\t * All retry options in a single object instead of separate properties\n\t */\n\tretry?: InnerRetryOptions<TErrorData>;\n\n\t/**\n\t * Number of allowed retry attempts on HTTP errors\n\t * @default 0\n\t */\n\tretryAttempts?: number;\n\n\t/**\n\t * Callback whose return value determines if a request should be retried or not\n\t */\n\tretryCondition?: RetryCondition<TErrorData>;\n\n\t/**\n\t * Delay between retries in milliseconds\n\t * @default 1000\n\t */\n\tretryDelay?: number | ((currentAttemptCount: number) => number);\n\n\t/**\n\t * Maximum delay in milliseconds. Only applies to exponential strategy\n\t * @default 10000\n\t */\n\tretryMaxDelay?: number;\n\n\t/**\n\t * HTTP methods that are allowed to retry\n\t * @default [\"GET\", \"POST\"]\n\t */\n\tretryMethods?: MethodUnion[];\n\n\t/**\n\t * HTTP status codes that trigger a retry\n\t */\n\tretryStatusCodes?: number[];\n\n\t/**\n\t * Strategy to use when retrying\n\t * @default \"linear\"\n\t */\n\tretryStrategy?: \"exponential\" | \"linear\";\n}\n\nconst getLinearDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? options.retry?.delay;\n\n\tconst resolveRetryDelay =\n\t\t(isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay) ?? retryDefaults.delay;\n\n\treturn resolveRetryDelay;\n};\n\nconst getExponentialDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? options.retry?.delay ?? retryDefaults.delay;\n\n\tconst resolvedRetryDelay = isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay;\n\n\tconst maxDelay = options.retryMaxDelay ?? options.retry?.maxDelay ?? retryDefaults.maxDelay;\n\n\tconst exponentialDelay = resolvedRetryDelay * 2 ** currentAttemptCount;\n\n\treturn Math.min(exponentialDelay, maxDelay);\n};\n\nexport const createRetryStrategy = (ctx: ErrorContext<unknown> & RequestContext) => {\n\tconst { options } = ctx;\n\n\t// eslint-disable-next-line ts-eslint/no-deprecated -- Allowed for internal use\n\tconst currentAttemptCount = options[\"~retryAttemptCount\"] ?? 1;\n\n\tconst retryStrategy = options.retryStrategy ?? options.retry?.strategy ?? retryDefaults.strategy;\n\n\tconst getDelay = () => {\n\t\tswitch (retryStrategy) {\n\t\t\tcase \"exponential\": {\n\t\t\t\treturn getExponentialDelay(currentAttemptCount, options);\n\t\t\t}\n\t\t\tcase \"linear\": {\n\t\t\t\treturn getLinearDelay(currentAttemptCount, options);\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(`Invalid retry strategy: ${String(retryStrategy)}`);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst shouldAttemptRetry = async () => {\n\t\tconst retryCondition = options.retryCondition ?? options.retry?.condition ?? retryDefaults.condition;\n\n\t\tconst maximumRetryAttempts =\n\t\t\toptions.retryAttempts ?? options.retry?.attempts ?? retryDefaults.attempts;\n\n\t\tconst customRetryCondition = await retryCondition(ctx);\n\n\t\tconst baseShouldRetry = maximumRetryAttempts >= currentAttemptCount && customRetryCondition;\n\n\t\tif (!baseShouldRetry) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst retryMethods = new Set(\n\t\t\toptions.retryMethods ?? options.retry?.methods ?? retryDefaults.methods\n\t\t);\n\n\t\tconst resolvedMethod = ctx.request.method ?? requestOptionDefaults.method;\n\n\t\tconst includesMethod = retryMethods.has(resolvedMethod);\n\n\t\tconst retryStatusCodes = new Set(options.retryStatusCodes ?? options.retry?.statusCodes ?? []);\n\n\t\tconst includesStatusCodes =\n\t\t\tBoolean(ctx.response?.status)\n\t\t\t&& (retryStatusCodes.size > 0 ? retryStatusCodes.has(ctx.response.status) : true);\n\n\t\tconst shouldRetry = includesMethod && includesStatusCodes;\n\n\t\treturn shouldRetry;\n\t};\n\n\treturn {\n\t\tcurrentAttemptCount,\n\t\tgetDelay,\n\t\tshouldAttemptRetry,\n\t};\n};\n","import { ValidationError } from \"./error\";\nimport type {\n\tBody,\n\tCallApiExtraOptions,\n\tCallApiRequestOptions,\n\tGlobalMeta,\n\tHeadersOption,\n\tMethodUnion,\n} from \"./types\";\nimport type { StandardSchemaV1 } from \"./types/standard-schema\";\nimport {\n\ttype AnyFunction,\n\ttype AnyString,\n\ttype Awaitable,\n\tdefineEnum,\n\ttype Prettify,\n\ttype UnionToIntersection,\n\ttype Writeable,\n} from \"./types/type-helpers\";\nimport type { Params, Query } from \"./url\";\nimport { isFunction } from \"./utils/guards\";\n\ntype InferSchemaInput<TSchema extends CallApiSchema[keyof CallApiSchema]> =\n\tTSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema>\n\t: TSchema extends (value: infer TInput) => unknown ? TInput\n\t: never;\n\nexport type InferSchemaResult<TSchema, TFallbackResult = unknown> =\n\t// == Checking for undefined first and returning fallback to avoid type errors when passing the config around (weird tbh)\n\tundefined extends TSchema ? TFallbackResult\n\t: TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema>\n\t: TSchema extends AnyFunction<infer TResult> ? Awaited<TResult>\n\t: TFallbackResult;\n\nconst handleValidatorFunction = async <TInput>(\n\tvalidator: Extract<CallApiSchema[keyof CallApiSchema], AnyFunction>,\n\tinputData: TInput\n): Promise<StandardSchemaV1.Result<TInput>> => {\n\ttry {\n\t\tconst result = await validator(inputData as never);\n\n\t\treturn {\n\t\t\tissues: undefined,\n\t\t\tvalue: result as never,\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\tissues: error as never,\n\t\t\tvalue: undefined,\n\t\t};\n\t}\n};\n\nexport const standardSchemaParser = async <\n\tTSchema extends NonNullable<CallApiSchema[keyof CallApiSchema]>,\n>(\n\tschema: TSchema,\n\tinputData: InferSchemaInput<TSchema>,\n\tresponse?: Response | null\n): Promise<InferSchemaResult<TSchema>> => {\n\tconst result =\n\t\tisFunction(schema) ?\n\t\t\tawait handleValidatorFunction(schema, inputData)\n\t\t:\tawait schema[\"~standard\"].validate(inputData);\n\n\t// == If the `issues` field exists, it means the validation failed\n\tif (result.issues) {\n\t\tthrow new ValidationError(\n\t\t\t{ issues: result.issues, response: response ?? null },\n\t\t\t{ cause: result.issues }\n\t\t);\n\t}\n\n\treturn result.value as never;\n};\n\nexport interface CallApiSchemaConfig {\n\t/**\n\t * The base url of the schema. By default it's the baseURL of the fetch instance.\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Disables runtime validation for the schema.\n\t */\n\tdisableRuntimeValidation?: boolean;\n\n\t/**\n\t * If `true`, the original input value will be used instead of the transformed/validated output.\n\t *\n\t * This is useful when you want to validate the input but don't want any transformations\n\t * applied by the validation schema (e.g., type coercion, default values, etc).\n\t */\n\tdisableValidationOutputApplication?: boolean;\n\n\t/**\n\t *Determines the inference or requirement of the method option based on the route modifiers (`@get/`, `@post/`, `@put/`, `@patch/`, `@delete/`).\n\t *\n\t * - When `true`, the method option is made required on the type level and is not automatically added to the request options.\n\t * - When `false` or `undefined` (default), the method option is not required on the type level, and is automatically added to the request options.\n\t *\n\t */\n\trequireMethodProvision?: boolean;\n\n\t/**\n\t * Controls the strictness of API route validation.\n\t *\n\t * When true:\n\t * - Only routes explicitly defined in the schema will be considered valid to typescript and runtime.\n\t * - Attempting to call undefined routes will result in type errors and runtime validation errors.\n\t * - Useful for ensuring API calls conform exactly to your schema definition\n\t *\n\t * When false or undefined (default):\n\t * - All routes will be allowed, whether they are defined in the schema or not\n\t */\n\tstrict?: boolean;\n}\n\nexport interface CallApiSchema {\n\t/**\n\t * The schema to use for validating the request body.\n\t */\n\tbody?: StandardSchemaV1<Body> | ((body: Body) => Awaitable<Body>);\n\n\t/**\n\t * The schema to use for validating the response data.\n\t */\n\tdata?: StandardSchemaV1 | ((data: unknown) => unknown);\n\n\t/**\n\t * The schema to use for validating the response error data.\n\t */\n\terrorData?: StandardSchemaV1 | ((errorData: unknown) => unknown);\n\n\t/**\n\t * The schema to use for validating the request headers.\n\t */\n\theaders?:\n\t\t| StandardSchemaV1<HeadersOption | undefined>\n\t\t| ((headers: HeadersOption) => Awaitable<HeadersOption | undefined>);\n\n\t/**\n\t * The schema to use for validating the meta option.\n\t */\n\tmeta?:\n\t\t| StandardSchemaV1<GlobalMeta | undefined>\n\t\t| ((meta: GlobalMeta) => Awaitable<GlobalMeta | undefined>);\n\n\t/**\n\t * The schema to use for validating the request method.\n\t */\n\tmethod?:\n\t\t| StandardSchemaV1<MethodUnion | undefined>\n\t\t| ((method: MethodUnion) => Awaitable<MethodUnion | undefined>);\n\n\t/**\n\t * The schema to use for validating the request url parameters.\n\t */\n\tparams?: StandardSchemaV1<Params | undefined> | ((params: Params) => Awaitable<Params | undefined>);\n\n\t/**\n\t * The schema to use for validating the request url queries.\n\t */\n\tquery?: StandardSchemaV1<Query | undefined> | ((query: Query) => Awaitable<Query | undefined>);\n}\n\nexport const routeKeyMethods = defineEnum([\"delete\", \"get\", \"patch\", \"post\", \"put\"]);\n\nexport type RouteKeyMethods = (typeof routeKeyMethods)[number];\n\ntype PossibleRouteKey = `@${RouteKeyMethods}/` | AnyString;\n\nexport type BaseCallApiSchema = Partial<Record<PossibleRouteKey, CallApiSchema>>;\n\nexport const defineSchema = <const TBaseSchema extends BaseCallApiSchema>(baseSchema: TBaseSchema) => {\n\treturn baseSchema as Writeable<typeof baseSchema, \"deep\">;\n};\n\ntype ValidationOptions<\n\tTSchema extends CallApiSchema[keyof CallApiSchema] = CallApiSchema[keyof CallApiSchema],\n> = {\n\tinputValue: InferSchemaInput<TSchema>;\n\tresponse?: Response | null;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nexport const handleValidation = async <TSchema extends CallApiSchema[keyof CallApiSchema]>(\n\tschema: TSchema | undefined,\n\tvalidationOptions: ValidationOptions<TSchema>\n): Promise<InferSchemaResult<TSchema>> => {\n\tconst { inputValue, response, schemaConfig } = validationOptions;\n\n\tif (!schema || schemaConfig?.disableRuntimeValidation) {\n\t\treturn inputValue as never;\n\t}\n\n\tconst validResult = await standardSchemaParser(schema, inputValue, response);\n\n\treturn validResult as never;\n};\n\ntype LastOf<TValue> =\n\tUnionToIntersection<TValue extends unknown ? () => TValue : never> extends () => infer R ? R : never;\n\ntype Push<TArray extends unknown[], TArrayItem> = [...TArray, TArrayItem];\n\ntype UnionToTuple<\n\tTUnion,\n\tTComputedLastUnion = LastOf<TUnion>,\n\tTComputedIsUnionEqualToNever = [TUnion] extends [never] ? true : false,\n> =\n\ttrue extends TComputedIsUnionEqualToNever ? []\n\t:\tPush<UnionToTuple<Exclude<TUnion, TComputedLastUnion>>, TComputedLastUnion>;\n\nexport type Tuple<TTuple, TArray extends TTuple[] = []> =\n\tUnionToTuple<TTuple>[\"length\"] extends TArray[\"length\"] ? [...TArray]\n\t:\tTuple<TTuple, [TTuple, ...TArray]>;\n\nconst extraOptionsToBeValidated = [\"meta\", \"params\", \"query\"] satisfies Tuple<\n\tExtract<keyof CallApiSchema, keyof CallApiExtraOptions>\n>;\n\ntype ExtraOptionsValidationOptions = {\n\textraOptions: CallApiExtraOptions;\n\tschema: CallApiSchema | undefined;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nconst handleExtraOptionsValidation = async (validationOptions: ExtraOptionsValidationOptions) => {\n\tconst { extraOptions, schema, schemaConfig } = validationOptions;\n\n\tconst validationResultArray = await Promise.all(\n\t\textraOptionsToBeValidated.map((propertyKey) =>\n\t\t\thandleValidation(schema?.[propertyKey], {\n\t\t\t\tinputValue: extraOptions[propertyKey],\n\t\t\t\tschemaConfig,\n\t\t\t})\n\t\t)\n\t);\n\n\tconst validatedResultObject: Prettify<\n\t\tPick<CallApiExtraOptions, (typeof extraOptionsToBeValidated)[number]>\n\t> = {};\n\n\tfor (const [index, propertyKey] of extraOptionsToBeValidated.entries()) {\n\t\tconst validationResult = validationResultArray[index];\n\n\t\tif (validationResult === undefined) continue;\n\n\t\tvalidatedResultObject[propertyKey] = validationResult as never;\n\t}\n\n\treturn validatedResultObject;\n};\n\nconst requestOptionsToBeValidated = [\"body\", \"headers\", \"method\"] satisfies Tuple<\n\tExtract<keyof CallApiSchema, keyof CallApiRequestOptions>\n>;\n\ntype RequestOptionsValidationOptions = {\n\trequestOptions: CallApiRequestOptions;\n\tschema: CallApiSchema | undefined;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nconst handleRequestOptionsValidation = async (validationOptions: RequestOptionsValidationOptions) => {\n\tconst { requestOptions, schema, schemaConfig } = validationOptions;\n\n\tconst validationResultArray = await Promise.all(\n\t\trequestOptionsToBeValidated.map((propertyKey) =>\n\t\t\thandleValidation(schema?.[propertyKey], {\n\t\t\t\tinputValue: requestOptions[propertyKey],\n\t\t\t\tschemaConfig,\n\t\t\t})\n\t\t)\n\t);\n\n\tconst validatedResultObject: Prettify<\n\t\tPick<CallApiRequestOptions, (typeof requestOptionsToBeValidated)[number]>\n\t> = {};\n\n\tfor (const [index, propertyKey] of requestOptionsToBeValidated.entries()) {\n\t\tconst validationResult = validationResultArray[index];\n\n\t\tif (validationResult === undefined) continue;\n\n\t\tvalidatedResultObject[propertyKey] = validationResult as never;\n\t}\n\n\treturn validatedResultObject;\n};\n\nexport const handleOptionsValidation = async (\n\tvalidationOptions: ExtraOptionsValidationOptions & RequestOptionsValidationOptions\n) => {\n\tconst { extraOptions, requestOptions, schema, schemaConfig } = validationOptions;\n\n\tif (schemaConfig?.disableRuntimeValidation) {\n\t\treturn {\n\t\t\textraOptionsValidationResult: null,\n\t\t\trequestOptionsValidationResult: null,\n\t\t};\n\t}\n\n\tconst [extraOptionsValidationResult, requestOptionsValidationResult] = await Promise.all([\n\t\thandleExtraOptionsValidation({ extraOptions, schema, schemaConfig }),\n\t\thandleRequestOptionsValidation({ requestOptions, schema, schemaConfig }),\n\t]);\n\n\treturn { extraOptionsValidationResult, requestOptionsValidationResult };\n};\n","import { requestOptionDefaults } from \"./constants/default-options\";\nimport type { CallApiExtraOptions, CallApiRequestOptions } from \"./types/common\";\nimport type { UnmaskType } from \"./types/type-helpers\";\nimport { toQueryString } from \"./utils\";\nimport { isArray } from \"./utils/guards\";\nimport { type CallApiSchemaConfig, routeKeyMethods } from \"./validation\";\n\nconst slash = \"/\";\nconst column = \":\";\nconst mergeUrlWithParams = (url: string, params: CallApiExtraOptions[\"params\"]) => {\n\tif (!params) {\n\t\treturn url;\n\t}\n\n\tlet newUrl = url;\n\n\tif (isArray(params)) {\n\t\tconst matchedParamArray = newUrl.split(slash).filter((param) => param.startsWith(column));\n\n\t\tfor (const [index, matchedParam] of matchedParamArray.entries()) {\n\t\t\tconst realParam = params[index] as string;\n\t\t\tnewUrl = newUrl.replace(matchedParam, realParam);\n\t\t}\n\n\t\treturn newUrl;\n\t}\n\n\tfor (const [key, value] of Object.entries(params)) {\n\t\tnewUrl = newUrl.replace(`${column}${key}`, String(value));\n\t}\n\n\treturn newUrl;\n};\n\nconst questionMark = \"?\";\nconst ampersand = \"&\";\nconst mergeUrlWithQuery = (url: string, query: CallApiExtraOptions[\"query\"]): string => {\n\tif (!query) {\n\t\treturn url;\n\t}\n\n\tconst queryString = toQueryString(query);\n\n\tif (queryString?.length === 0) {\n\t\treturn url;\n\t}\n\n\tif (url.endsWith(questionMark)) {\n\t\treturn `${url}${queryString}`;\n\t}\n\n\tif (url.includes(questionMark)) {\n\t\treturn `${url}${ampersand}${queryString}`;\n\t}\n\n\treturn `${url}${questionMark}${queryString}`;\n};\n\nexport const getCurrentRouteKey = (url: string, schemaConfig: CallApiSchemaConfig | undefined) => {\n\tlet currentRouteKey = url;\n\n\tif (schemaConfig?.baseURL && currentRouteKey.startsWith(schemaConfig.baseURL)) {\n\t\tcurrentRouteKey = currentRouteKey.replace(schemaConfig.baseURL, \"\");\n\t}\n\n\treturn currentRouteKey;\n};\n\n/**\n * @description\n * Extracts the method from the URL if it is a schema modifier.\n *\n * @param initURL - The URL to extract the method from.\n * @returns The method if it is a schema modifier, otherwise undefined.\n */\nexport const extractMethodFromURL = (initURL: string | undefined) => {\n\tif (!initURL?.startsWith(\"@\")) return;\n\n\tconst method = initURL.split(\"@\")[1]?.split(\"/\")[0];\n\n\tif (!method || !routeKeyMethods.includes(method)) return;\n\n\treturn method;\n};\n\nexport type GetMethodOptions = {\n\tinitURL: string | undefined;\n\tmethod: CallApiRequestOptions[\"method\"];\n\tschemaConfig?: CallApiSchemaConfig;\n};\n\nexport const getMethod = (options: GetMethodOptions) => {\n\tconst { initURL, method, schemaConfig } = options;\n\n\tif (schemaConfig?.requireMethodProvision === true) {\n\t\treturn method?.toUpperCase() ?? requestOptionDefaults.method;\n\t}\n\n\treturn (\n\t\tmethod?.toUpperCase() ?? extractMethodFromURL(initURL)?.toUpperCase() ?? requestOptionDefaults.method\n\t);\n};\n\nexport const normalizeURL = (initURL: string) => {\n\tconst methodFromURL = extractMethodFromURL(initURL);\n\n\tif (!methodFromURL) {\n\t\treturn initURL;\n\t}\n\n\tconst normalizedURL = initURL.replace(`@${methodFromURL}/`, \"/\");\n\n\treturn normalizedURL;\n};\n\ntype GetFullURLOptions = {\n\tbaseURL: string | undefined;\n\tinitURL: string;\n\tparams: CallApiExtraOptions[\"params\"];\n\tquery: CallApiExtraOptions[\"query\"];\n};\n\nexport const getFullURL = (options: GetFullURLOptions) => {\n\tconst { baseURL, initURL, params, query } = options;\n\n\tconst normalizedURL = normalizeURL(initURL);\n\n\tconst urlWithMergedParams = mergeUrlWithParams(normalizedURL, params);\n\n\tconst urlWithMergedQueryAndParams = mergeUrlWithQuery(urlWithMergedParams, query);\n\n\tif (urlWithMergedQueryAndParams.startsWith(\"http\") || !baseURL) {\n\t\treturn urlWithMergedQueryAndParams;\n\t}\n\n\treturn `${baseURL}${urlWithMergedQueryAndParams}`;\n};\n\nexport type AllowedQueryParamValues = UnmaskType<boolean | number | string>;\n\nexport type Params = UnmaskType<\n\t// eslint-disable-next-line perfectionist/sort-union-types -- I need the Record to be first\n\tRecord<string, AllowedQueryParamValues> | AllowedQueryParamValues[]\n>;\n\nexport type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;\n\nexport type InitURLOrURLObject = string | URL;\n\nexport interface URLOptions {\n\t/**\n\t * Base URL to be prepended to all request URLs\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Resolved request URL\n\t */\n\treadonly fullURL?: string;\n\n\t/**\n\t * The url string passed to the callApi instance\n\t */\n\treadonly initURL?: string;\n\n\t/**\n\t * The URL string passed to the callApi instance, but normalized (removed any method modifiers etc)\n\t */\n\treadonly initURLNormalized?: string;\n\n\t/**\n\t * Parameters to be appended to the URL (i.e: /:id)\n\t *\n\t * If url is defined as `/path/:id`, params will be `{ id: string }`\n\t */\n\tparams?: Params;\n\n\t/**\n\t * Query parameters to append to the URL.\n\t */\n\tquery?: Query;\n}\n","import { createDedupeStrategy, getAbortErrorMessage, type RequestInfoCache } from \"./dedupe\";\nimport { HTTPError, ValidationError } from \"./error\";\nimport {\n\ttype ErrorContext,\n\ttype ExecuteHookInfo,\n\texecuteHooksInCatchBlock,\n\texecuteHooksInTryBlock,\n\ttype RetryContext,\n\ttype SuccessContext,\n} from \"./hooks\";\nimport { type CallApiPlugin, initializePlugins } from \"./plugins\";\nimport {\n\ttype ErrorInfo,\n\tgetCustomizedErrorResult,\n\ttype ResponseTypeUnion,\n\ttype ResultModeUnion,\n\tresolveErrorResult,\n\tresolveResponseData,\n\tresolveSuccessResult,\n} from \"./result\";\nimport { createRetryStrategy } from \"./retry\";\nimport type {\n\tGetCurrentRouteKey,\n\tGetCurrentRouteSchema,\n\tInferHeadersOption,\n\tInferInitURL,\n\tThrowOnErrorUnion,\n} from \"./types\";\nimport type {\n\tBaseCallApiConfig,\n\tBaseCallApiExtraOptions,\n\tCallApiExtraOptions,\n\tCallApiExtraOptionsForHooks,\n\tCallApiParameters,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n\tCallApiResult,\n} from \"./types/common\";\nimport type { DefaultDataType, DefaultPluginArray, DefaultThrowOnError } from \"./types/default-types\";\nimport type { AnyFunction } from \"./types/type-helpers\";\nimport { getCurrentRouteKey, getFullURL, getMethod, normalizeURL } from \"./url\";\nimport {\n\tcreateCombinedSignal,\n\tcreateTimeoutSignal,\n\tgetBody,\n\tgetHeaders,\n\tsplitBaseConfig,\n\tsplitConfig,\n\twaitFor,\n} from \"./utils/common\";\nimport { isFunction, isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/guards\";\nimport {\n\ttype BaseCallApiSchema,\n\ttype CallApiSchema,\n\ttype CallApiSchemaConfig,\n\thandleOptionsValidation,\n\thandleValidation,\n\ttype InferSchemaResult,\n} from \"./validation\";\n\nconst $GlobalRequestInfoCache: RequestInfoCache = new Map();\n\nexport const createFetchClient = <\n\tTBaseData = DefaultDataType,\n\tTBaseErrorData = DefaultDataType,\n\tTBaseResultMode extends ResultModeUnion = ResultModeUnion,\n\tTBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n\tTBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tconst TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema,\n\tconst TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n>(\n\tinitBaseConfig: BaseCallApiConfig<\n\t\tTBaseData,\n\t\tTBaseErrorData,\n\t\tTBaseResultMode,\n\t\tTBaseThrowOnError,\n\t\tTBaseResponseType,\n\t\tTBaseSchema,\n\t\tTBaseSchemaConfig,\n\t\tTBasePluginArray\n\t> = {} as never\n) => {\n\tconst $LocalRequestInfoCache: RequestInfoCache = new Map();\n\n\tconst callApi = async <\n\t\tTData = TBaseData,\n\t\tTErrorData = TBaseErrorData,\n\t\tTResultMode extends ResultModeUnion = TBaseResultMode,\n\t\tTThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError,\n\t\tTResponseType extends ResponseTypeUnion = TBaseResponseType,\n\t\tTSchemaConfig extends CallApiSchemaConfig = TBaseSchemaConfig,\n\t\tTInitURL extends InferInitURL<TBaseSchema, TSchemaConfig> = InferInitURL<TBaseSchema, TSchemaConfig>,\n\t\tTCurrentRouteKey extends GetCurrentRouteKey<TSchemaConfig, TInitURL> = GetCurrentRouteKey<\n\t\t\tTSchemaConfig,\n\t\t\tTInitURL\n\t\t>,\n\t\tTSchema extends CallApiSchema = GetCurrentRouteSchema<TBaseSchema, TCurrentRouteKey>,\n\t\tTPluginArray extends CallApiPlugin[] = TBasePluginArray,\n\t>(\n\t\t...parameters: CallApiParameters<\n\t\t\tInferSchemaResult<TSchema[\"data\"], TData>,\n\t\t\tInferSchemaResult<TSchema[\"errorData\"], TErrorData>,\n\t\t\tTResultMode,\n\t\t\tTThrowOnError,\n\t\t\tTResponseType,\n\t\t\tTBaseSchema,\n\t\t\tTSchema,\n\t\t\tTBaseSchemaConfig,\n\t\t\tTSchemaConfig,\n\t\t\tTInitURL,\n\t\t\tTCurrentRouteKey,\n\t\t\tTBasePluginArray,\n\t\t\tTPluginArray\n\t\t>\n\t): CallApiResult<\n\t\tInferSchemaResult<TSchema[\"data\"], TData>,\n\t\tInferSchemaResult<TSchema[\"errorData\"], TErrorData>,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType\n\t> => {\n\t\tconst [initURLOrURLObject, initConfig = {}] = parameters;\n\n\t\tconst [fetchOptions, extraOptions] = splitConfig(initConfig);\n\n\t\tconst resolvedBaseConfig =\n\t\t\tisFunction(initBaseConfig) ?\n\t\t\t\tinitBaseConfig({\n\t\t\t\t\tinitURL: initURLOrURLObject.toString(),\n\t\t\t\t\toptions: extraOptions,\n\t\t\t\t\trequest: fetchOptions,\n\t\t\t\t})\n\t\t\t:\tinitBaseConfig;\n\n\t\tconst baseConfig = resolvedBaseConfig as BaseCallApiExtraOptions & CallApiRequestOptions;\n\t\tconst config = initConfig as CallApiExtraOptions & CallApiRequestOptions;\n\n\t\tconst [baseFetchOptions, baseExtraOptions] = splitBaseConfig(baseConfig);\n\n\t\tconst shouldSkipAutoMergeForOptions =\n\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"options\";\n\n\t\tconst shouldSkipAutoMergeForRequest =\n\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"request\";\n\n\t\t// == Merged Extra Options\n\t\tconst mergedExtraOptions = {\n\t\t\t...baseExtraOptions,\n\t\t\t...(!shouldSkipAutoMergeForOptions && extraOptions),\n\t\t};\n\n\t\t// == Merged Request Options\n\t\tconst mergedRequestOptions = {\n\t\t\t// == Making sure headers is always an object\n\t\t\theaders: {},\n\t\t\t...baseFetchOptions,\n\t\t\t...(!shouldSkipAutoMergeForRequest && fetchOptions),\n\t\t} satisfies CallApiRequestOptions;\n\n\t\tconst { resolvedHooks, resolvedInitURL, resolvedOptions, resolvedRequestOptions } =\n\t\t\tawait initializePlugins({\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tinitURL: initURLOrURLObject.toString(),\n\t\t\t\toptions: mergedExtraOptions as CallApiExtraOptionsForHooks,\n\t\t\t\trequest: mergedRequestOptions as CallApiRequestOptionsForHooks,\n\t\t\t});\n\n\t\tconst fullURL = getFullURL({\n\t\t\tbaseURL: resolvedOptions.baseURL,\n\t\t\tinitURL: resolvedInitURL,\n\t\t\tparams: resolvedOptions.params,\n\t\t\tquery: resolvedOptions.query,\n\t\t});\n\n\t\tlet options = {\n\t\t\t...resolvedOptions,\n\t\t\t...resolvedHooks,\n\n\t\t\tfullURL,\n\t\t\tinitURL: resolvedInitURL,\n\t\t\tinitURLNormalized: normalizeURL(resolvedInitURL),\n\t\t} satisfies CallApiExtraOptionsForHooks;\n\n\t\tconst newFetchController = new AbortController();\n\n\t\tconst timeoutSignal = options.timeout != null ? createTimeoutSignal(options.timeout) : null;\n\n\t\tconst combinedSignal = createCombinedSignal(\n\t\t\tresolvedRequestOptions.signal,\n\t\t\ttimeoutSignal,\n\t\t\tnewFetchController.signal\n\t\t);\n\n\t\tlet request = {\n\t\t\t...resolvedRequestOptions,\n\n\t\t\tsignal: combinedSignal,\n\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\tconst {\n\t\t\tdedupeStrategy,\n\t\t\thandleRequestCancelStrategy,\n\t\t\thandleRequestDeferStrategy,\n\t\t\tremoveDedupeKeyFromCache,\n\t\t} = await createDedupeStrategy({\n\t\t\t$GlobalRequestInfoCache,\n\t\t\t$LocalRequestInfoCache,\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tnewFetchController,\n\t\t\toptions,\n\t\t\trequest,\n\t\t});\n\n\t\ttry {\n\t\t\tawait handleRequestCancelStrategy();\n\n\t\t\tawait executeHooksInTryBlock(options.onRequest?.({ baseConfig, config, options, request }));\n\n\t\t\tconst resolvedSchemaConfig =\n\t\t\t\tisFunction(extraOptions.schemaConfig) ?\n\t\t\t\t\textraOptions.schemaConfig({ baseSchemaConfig: baseExtraOptions.schemaConfig ?? {} })\n\t\t\t\t:\t(extraOptions.schemaConfig ?? baseExtraOptions.schemaConfig);\n\n\t\t\tconst currentRouteKey = getCurrentRouteKey(resolvedInitURL, resolvedSchemaConfig);\n\n\t\t\tconst routeSchema = baseExtraOptions.schema?.[currentRouteKey];\n\n\t\t\tif (resolvedSchemaConfig?.strict === true && !routeSchema) {\n\t\t\t\tconst issues = [\n\t\t\t\t\t{ message: `No schema found for route '${currentRouteKey}' and strict mode is enabled` },\n\t\t\t\t] satisfies ValidationError[\"errorData\"];\n\n\t\t\t\tthrow new ValidationError({\n\t\t\t\t\tissues,\n\t\t\t\t\tresponse: null,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst resolvedSchema =\n\t\t\t\tisFunction(extraOptions.schema) ?\n\t\t\t\t\textraOptions.schema({\n\t\t\t\t\t\tbaseSchema: baseExtraOptions.schema ?? {},\n\t\t\t\t\t\tcurrentRouteSchema: routeSchema ?? {},\n\t\t\t\t\t})\n\t\t\t\t:\t(extraOptions.schema ?? routeSchema);\n\n\t\t\tconst { extraOptionsValidationResult, requestOptionsValidationResult } =\n\t\t\t\tawait handleOptionsValidation({\n\t\t\t\t\textraOptions: options,\n\t\t\t\t\trequestOptions: request,\n\t\t\t\t\tschema: resolvedSchema,\n\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t});\n\n\t\t\tconst shouldApplySchemaOutput =\n\t\t\t\tBoolean(extraOptionsValidationResult)\n\t\t\t\t|| Boolean(requestOptionsValidationResult)\n\t\t\t\t|| !resolvedSchemaConfig?.disableValidationOutputApplication;\n\n\t\t\t// == Apply Schema Output for Extra Options\n\t\t\tif (shouldApplySchemaOutput) {\n\t\t\t\toptions = { ...options, ...extraOptionsValidationResult };\n\t\t\t}\n\n\t\t\t// == Apply Schema Output for Request Options\n\t\t\tconst rawBody = shouldApplySchemaOutput ? requestOptionsValidationResult?.body : request.body;\n\n\t\t\tconst validBody = getBody({\n\t\t\t\tbody: rawBody,\n\t\t\t\tbodySerializer: options.bodySerializer,\n\t\t\t});\n\n\t\t\ttype HeaderFn = Extract<InferHeadersOption<CallApiSchema>[\"headers\"], AnyFunction>;\n\n\t\t\tconst resolvedHeaders =\n\t\t\t\tisFunction<HeaderFn>(fetchOptions.headers) ?\n\t\t\t\t\tfetchOptions.headers({ baseHeaders: baseFetchOptions.headers ?? {} })\n\t\t\t\t:\t(fetchOptions.headers ?? baseFetchOptions.headers);\n\n\t\t\tconst validHeaders = await getHeaders({\n\t\t\t\tauth: options.auth,\n\t\t\t\tbody: rawBody,\n\t\t\t\theaders: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : resolvedHeaders,\n\t\t\t});\n\n\t\t\tconst validMethod = getMethod({\n\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\tmethod: shouldApplySchemaOutput ? requestOptionsValidationResult?.method : request.method,\n\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t});\n\n\t\t\trequest = {\n\t\t\t\t...request,\n\t\t\t\t...(Boolean(validBody) && { body: validBody }),\n\t\t\t\t...(Boolean(validHeaders) && { headers: validHeaders }),\n\t\t\t\t...(Boolean(validMethod) && { method: validMethod }),\n\t\t\t};\n\n\t\t\tconst response = await handleRequestDeferStrategy({ options, request });\n\n\t\t\t// == Also clone response when dedupeStrategy is set to \"defer\" to avoid error thrown from reading response.(whatever) more than once\n\t\t\tconst shouldCloneResponse = dedupeStrategy === \"defer\" || options.cloneResponse;\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorData = await resolveResponseData<TErrorData>(\n\t\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\t\toptions.responseType,\n\t\t\t\t\toptions.responseParser\n\t\t\t\t);\n\n\t\t\t\tconst validErrorData = await handleValidation(resolvedSchema?.errorData, {\n\t\t\t\t\tinputValue: errorData,\n\t\t\t\t\tresponse,\n\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t});\n\n\t\t\t\t// == Push all error handling responsibilities to the catch block if not retrying\n\t\t\t\tthrow new HTTPError(\n\t\t\t\t\t{\n\t\t\t\t\t\tdefaultHTTPErrorMessage: options.defaultHTTPErrorMessage,\n\t\t\t\t\t\terrorData: validErrorData,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t},\n\t\t\t\t\t{ cause: validErrorData }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst successData = await resolveResponseData<TData>(\n\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\toptions.responseType,\n\t\t\t\toptions.responseParser\n\t\t\t);\n\n\t\t\tconst validSuccessData = await handleValidation(resolvedSchema?.data, {\n\t\t\t\tinputValue: successData,\n\t\t\t\tresponse,\n\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t});\n\n\t\t\tconst successContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tdata: validSuccessData,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse,\n\t\t\t} satisfies SuccessContext<unknown>;\n\n\t\t\tawait executeHooksInTryBlock(\n\t\t\t\toptions.onSuccess?.(successContext),\n\n\t\t\t\toptions.onResponse?.({ ...successContext, error: null })\n\t\t\t);\n\n\t\t\tconst successResult = resolveSuccessResult(successContext.data, {\n\t\t\t\tresponse: successContext.response,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t});\n\n\t\t\treturn successResult as never;\n\n\t\t\t// == Exhaustive Error handling\n\t\t} catch (error) {\n\t\t\tconst errorInfo = {\n\t\t\t\tcloneResponse: options.cloneResponse,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t} satisfies ErrorInfo;\n\n\t\t\tconst generalErrorResult = resolveErrorResult(error, errorInfo);\n\n\t\t\tconst errorContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\terror: generalErrorResult?.error as never,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse: generalErrorResult?.response as never,\n\t\t\t} satisfies ErrorContext<unknown>;\n\n\t\t\tconst shouldThrowOnError = (\n\t\t\t\tisFunction(options.throwOnError) ?\n\t\t\t\t\toptions.throwOnError(errorContext)\n\t\t\t\t:\toptions.throwOnError) as boolean;\n\n\t\t\tconst hookInfo = {\n\t\t\t\terrorInfo,\n\t\t\t\tshouldThrowOnError,\n\t\t\t} satisfies ExecuteHookInfo;\n\n\t\t\tconst handleRetryOrGetErrorResult = async () => {\n\t\t\t\tconst { currentAttemptCount, getDelay, shouldAttemptRetry } =\n\t\t\t\t\tcreateRetryStrategy(errorContext);\n\n\t\t\t\tconst shouldRetry = !combinedSignal.aborted && (await shouldAttemptRetry());\n\n\t\t\t\tif (shouldRetry) {\n\t\t\t\t\tconst retryContext = {\n\t\t\t\t\t\t...errorContext,\n\t\t\t\t\t\tretryAttemptCount: currentAttemptCount,\n\t\t\t\t\t} satisfies RetryContext<unknown>;\n\n\t\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t\t[options.onRetry?.(retryContext)],\n\t\t\t\t\t\thookInfo\n\t\t\t\t\t);\n\n\t\t\t\t\tif (hookError) {\n\t\t\t\t\t\treturn hookError;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst delay = getDelay();\n\n\t\t\t\t\tawait waitFor(delay);\n\n\t\t\t\t\tconst updatedOptions = {\n\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\"~retryAttemptCount\": currentAttemptCount + 1,\n\t\t\t\t\t} satisfies typeof config;\n\n\t\t\t\t\treturn callApi(initURLOrURLObject as never, updatedOptions as never) as never;\n\t\t\t\t}\n\n\t\t\t\tif (shouldThrowOnError) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\n\t\t\t\treturn generalErrorResult;\n\t\t\t};\n\n\t\t\tif (isHTTPErrorInstance<TErrorData>(error)) {\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[\n\t\t\t\t\t\toptions.onResponseError?.(errorContext),\n\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t\toptions.onResponse?.({ ...errorContext, data: null }),\n\t\t\t\t\t],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t}\n\n\t\t\tif (isValidationErrorInstance(error)) {\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[\n\t\t\t\t\t\toptions.onValidationError?.(errorContext),\n\t\t\t\t\t\toptions.onRequestError?.(errorContext),\n\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t}\n\n\t\t\tlet message: string | undefined = (error as Error | undefined)?.message;\n\n\t\t\tif (error instanceof DOMException && error.name === \"AbortError\") {\n\t\t\t\tmessage = getAbortErrorMessage(options.dedupeKey, options.fullURL);\n\n\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t}\n\n\t\t\tif (error instanceof DOMException && error.name === \"TimeoutError\") {\n\t\t\t\tmessage = `Request timed out after ${options.timeout}ms`;\n\n\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t}\n\n\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t[options.onRequestError?.(errorContext), options.onError?.(errorContext)],\n\t\t\t\thookInfo\n\t\t\t);\n\n\t\t\treturn (hookError\n\t\t\t\t?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message })) as never;\n\n\t\t\t// == Removing the now unneeded AbortController from store\n\t\t} finally {\n\t\t\tremoveDedupeKeyFromCache();\n\t\t}\n\t};\n\n\treturn callApi;\n};\n\nexport const callApi = createFetchClient();\n","import type { CallApiPlugin } from \"./plugins\";\nimport type { ResponseTypeUnion, ResultModeUnion } from \"./result\";\nimport type { CallApiParameters, InferInitURL, ThrowOnErrorUnion } from \"./types\";\nimport type { DefaultDataType, DefaultPluginArray, DefaultThrowOnError } from \"./types/default-types\";\nimport type { BaseCallApiSchema, CallApiSchema, CallApiSchemaConfig } from \"./validation\";\n\nconst defineParameters = <\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResultMode extends ResultModeUnion = ResultModeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTBaseSchema extends BaseCallApiSchema = BaseCallApiSchema,\n\tTSchema extends CallApiSchema = CallApiSchema,\n\tTBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<\n\t\tBaseCallApiSchema,\n\t\tTSchemaConfig\n\t>,\n\tTCurrentRouteKey extends string = string,\n\tTBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTPluginArray extends CallApiPlugin[] = DefaultPluginArray,\n>(\n\t...parameters: CallApiParameters<\n\t\tTData,\n\t\tTErrorData,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType,\n\t\tTBaseSchema,\n\t\tTSchema,\n\t\tTBaseSchemaConfig,\n\t\tTSchemaConfig,\n\t\tTInitURL,\n\t\tTCurrentRouteKey,\n\t\tTBasePluginArray,\n\t\tTPluginArray\n\t>\n) => {\n\treturn parameters;\n};\n\nexport { defineParameters };\n"],"mappings":";;;AASA,MAAa,kBAAkB,CAAYA,UAAoBC,YAAoB;CAClF,aAAa,MAAM,SAAS,aAAa;CACzC,MAAM,MAAM,SAAS,MAAM;CAC3B,UAAU,MAAM,SAAS,UAAU;CACnC,MAAM,YAAY;EACjB,MAAM,OAAO,MAAM,SAAS,MAAM;AAClC,SAAO,OAAO,KAAK;CACnB;CACD,QAAQ,MAAM,SAAS;CACvB,MAAM,MAAM,SAAS,MAAM;AAC3B;AAmBD,MAAa,sBAAsB,CAClCD,UACAE,cACAC,WACI;CACJ,MAAM,iBAAiB,UAAU,iBAAiB;CAClD,MAAM,uBAAuB,gBAAgB,iBAAiB;CAE9D,MAAM,uBAAuB,gBAA2B,UAAU,eAAe;AAEjF,MAAK,OAAO,OAAO,sBAAsB,qBAAqB,CAC7D,OAAM,IAAI,OAAO,yBAAyB;AAG3C,QAAO,qBAAqB,uBAAuB;AACnD;AA+FD,MAAM,mBAAmB,CACxBC,YACI;CACJ,MAAM,gBAAgB;EACrB,KAAK,MAAM;EACX,kBAAkB,MAAM,cAAc,KAAK;EAC3C,aAAa,MAAM,QAAQ;EAC3B,0BAA0B,MAAM,cAAc,aAAa;CAC3D;AAED,QAAO;AACP;AAMD,MAAa,uBAAuB,CAACC,MAAeC,SAAqC;CACxF,MAAM,EAAE,UAAU,YAAY,GAAG;CAEjC,MAAM,UAAU;EACf;EACA,OAAO;EACP;CACA;CAED,MAAM,gBAAgB,iBAAiB,QAAQ;CAE/C,MAAM,gBAAgB,cAA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ponseTypeUnion","parser?: Parser","details: CallApiResultErrorVariant<unknown> | CallApiResultSuccessVariant<unknown>","data: unknown","info: SuccessInfo","error: unknown","info: ErrorInfo","errorResult: ErrorResult","customErrorInfo: { message: string | undefined }","hooksArray: Array<AnyFunction | undefined>","mergedHooksExecutionMode: CallApiExtraOptionsForHooks[\"mergedHooksExecutionMode\"]","ctx: unknown","hookResultsOrPromise: Array<Awaitable<unknown>>","hookInfo: ExecuteHookInfo","options: {\n\tchunk: Uint8Array;\n\ttotalBytes: number;\n\ttransferredBytes: number;\n}","requestBody: Request[\"body\"] | null","existingTotalBytes: number","context: ToStreamableRequestContext","context: StreamableResponseContext","dedupeKey: DedupeOptions[\"dedupeKey\"]","fullURL: DedupeContext[\"options\"][\"fullURL\"]","context: DedupeContext","$GlobalRequestInfoCache","deferContext: {\n\t\toptions: DedupeContext[\"options\"];\n\t\trequest: DedupeContext[\"request\"];\n\t}","validator: Extract<CallApiSchema[keyof CallApiSchema], AnyFunction>","inputData: TInput","schema: TSchema","inputData: InferSchemaInput<TSchema>","response?: Response | null","routes: TBaseSchemaRoutes","config?: TSchemaConfig","config: TConfig","schema: TSchema | undefined","validationOptions: ValidationOptions<TSchema>","validationOptions: ExtraOptionsValidationOptions","validatedResultObject: Prettify<\n\t\tPick<CallApiExtraOptions, (typeof extraOptionsToBeValidated)[number]>\n\t>","validationOptions: RequestOptionsValidationOptions","validatedResultObject: Prettify<\n\t\tPick<CallApiRequestOptions, (typeof requestOptionsToBeValidated)[number]>\n\t>","validationOptions: GetResolvedSchemaContext\n\t\t& Omit<ExtraOptionsValidationOptions & RequestOptionsValidationOptions, \"schema\" | \"schemaConfig\">","context: GetResolvedSchemaContext","context: Omit<GetResolvedSchemaContext, \"currentRouteSchemaKey\">","context: Pick<GetResolvedSchemaContext, \"baseExtraOptions\" | \"extraOptions\"> & { initURL: string }","plugin: TPlugin","context: Pick<RequestContext, \"baseConfig\" | \"options\">","context: PluginInitContext","pluginHooks: Required<CallApiPlugin>[\"hooks\"]","pluginInit: CallApiPlugin[\"init\"]","resolvedHooks: Hooks","currentAttemptCount: number","options: RetryOptions<unknown>","ctx: ErrorContext<unknown> & RequestContext","url: string","params: CallApiExtraOptions[\"params\"]","query: CallApiExtraOptions[\"query\"]","initURL: string | undefined","options: GetMethodOptions","initURL: string","options: GetFullURLOptions","$GlobalRequestInfoCache: RequestInfoCache","initBaseConfig: BaseCallApiConfig<\n\t\tTBaseData,\n\t\tTBaseErrorData,\n\t\tTBaseResultMode,\n\t\tTBaseThrowOnError,\n\t\tTBaseResponseType,\n\t\tTBaseSchemaAndConfig,\n\t\tTBasePluginArray\n\t>","$LocalRequestInfoCache: RequestInfoCache","callApi","hookError","message: string | undefined"],"sources":["../../src/result.ts","../../src/hooks.ts","../../src/stream.ts","../../src/dedupe.ts","../../src/validation.ts","../../src/plugins.ts","../../src/retry.ts","../../src/url.ts","../../src/createFetchClient.ts","../../src/defineParameters.ts"],"sourcesContent":["import { responseDefaults } from \"./constants/default-options\";\nimport type { HTTPError, ValidationError } from \"./error\";\nimport type { CallApiExtraOptions, ThrowOnErrorUnion } from \"./types\";\nimport type { DefaultDataType } from \"./types/default-types\";\nimport type { AnyString, Awaitable, UnmaskType } from \"./types/type-helpers\";\nimport { isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/guards\";\n\ntype Parser = (responseString: string) => Awaitable<Record<string, unknown>>;\n\nexport const getResponseType = <TResponse>(response: Response, parser: Parser) => ({\n\tarrayBuffer: () => response.arrayBuffer(),\n\tblob: () => response.blob(),\n\tformData: () => response.formData(),\n\tjson: async () => {\n\t\tconst text = await response.text();\n\t\treturn parser(text) as TResponse;\n\t},\n\tstream: () => response.body,\n\ttext: () => response.text(),\n});\n\ntype InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;\n\nexport type ResponseTypeUnion = keyof InitResponseTypeMap | null;\n\nexport type ResponseTypeMap<TResponse> = {\n\t[Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>>;\n};\n\nexport type GetResponseType<\n\tTResponse,\n\tTResponseType extends ResponseTypeUnion,\n\tTComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>,\n> =\n\tnull extends TResponseType ? TComputedResponseTypeMap[\"json\"]\n\t: TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType]\n\t: never;\n\nexport const resolveResponseData = <TResponse>(\n\tresponse: Response,\n\tresponseType?: ResponseTypeUnion,\n\tparser?: Parser\n) => {\n\tconst selectedParser = parser ?? responseDefaults.responseParser;\n\tconst selectedResponseType = responseType ?? responseDefaults.responseType;\n\n\tconst RESPONSE_TYPE_LOOKUP = getResponseType<TResponse>(response, selectedParser);\n\n\tif (!Object.hasOwn(RESPONSE_TYPE_LOOKUP, selectedResponseType)) {\n\t\tthrow new Error(`Invalid response type: ${responseType}`);\n\t}\n\n\treturn RESPONSE_TYPE_LOOKUP[selectedResponseType]();\n};\n\nexport type CallApiResultSuccessVariant<TData> = {\n\tdata: NoInfer<TData>;\n\terror: null;\n\tresponse: Response;\n};\n\nexport type PossibleJavaScriptError = UnmaskType<{\n\terrorData: false;\n\tmessage: string;\n\tname: \"AbortError\" | \"Error\" | \"SyntaxError\" | \"TimeoutError\" | \"TypeError\" | AnyString;\n\toriginalError: DOMException | Error | SyntaxError | TypeError;\n}>;\n\nexport type PossibleHTTPError<TErrorData> = UnmaskType<{\n\terrorData: NoInfer<TErrorData>;\n\tmessage: string;\n\tname: \"HTTPError\";\n\toriginalError: HTTPError;\n}>;\n\nexport type PossibleValidationError = UnmaskType<{\n\terrorData: ValidationError[\"errorData\"];\n\tmessage: string;\n\tname: \"ValidationError\";\n\toriginalError: ValidationError;\n}>;\n\nexport type PossibleJavaScriptOrValidationError = UnmaskType<\n\tPossibleJavaScriptError | PossibleValidationError\n>;\n\nexport type CallApiResultErrorVariant<TErrorData> =\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\tresponse: Response;\n\t }\n\t| {\n\t\t\tdata: null;\n\t\t\terror: PossibleJavaScriptOrValidationError;\n\t\t\tresponse: Response | null;\n\t };\n\nexport type ResultModeMap<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTComputedData = GetResponseType<TData, TResponseType>,\n\tTComputedErrorData = GetResponseType<TErrorData, TResponseType>,\n> = UnmaskType<{\n\t/* eslint-disable perfectionist/sort-union-types -- I need the first one to be first */\n\tall: CallApiResultSuccessVariant<TComputedData> | CallApiResultErrorVariant<TComputedErrorData>;\n\n\tallWithException: CallApiResultSuccessVariant<TComputedData>;\n\n\tonlySuccess:\n\t\t| CallApiResultErrorVariant<TComputedErrorData>[\"data\"]\n\t\t| CallApiResultSuccessVariant<TComputedData>[\"data\"];\n\n\tonlySuccessWithException: CallApiResultSuccessVariant<TComputedData>[\"data\"];\n\t/* eslint-enable perfectionist/sort-union-types -- I need the first one to be first */\n}>;\n\nexport type ResultModeUnion = keyof ResultModeMap | null;\n\nexport type GetCallApiResult<\n\tTData,\n\tTErrorData,\n\tTResultMode extends ResultModeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion,\n\tTResponseType extends ResponseTypeUnion,\n> =\n\tTErrorData extends false ? ResultModeMap<TData, TErrorData, TResponseType>[\"onlySuccessWithException\"]\n\t: TErrorData extends false | undefined ?\n\t\tResultModeMap<TData, TErrorData, TResponseType>[\"onlySuccessWithException\"]\n\t: TErrorData extends false | null ? ResultModeMap<TData, TErrorData, TResponseType>[\"onlySuccess\"]\n\t: null extends TResultMode ?\n\t\tTThrowOnError extends true ?\n\t\t\tResultModeMap<TData, TErrorData, TResponseType>[\"allWithException\"]\n\t\t:\tResultModeMap<TData, TErrorData, TResponseType>[\"all\"]\n\t: TResultMode extends NonNullable<ResultModeUnion> ?\n\t\tResultModeMap<TData, TErrorData, TResponseType>[TResultMode]\n\t:\tnever;\n\ntype SuccessInfo = {\n\tresponse: Response;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n};\n\ntype LazyResultModeMap = {\n\t[key in keyof ResultModeMap]: () => ResultModeMap[key];\n};\n\nconst getResultModeMap = (\n\tdetails: CallApiResultErrorVariant<unknown> | CallApiResultSuccessVariant<unknown>\n) => {\n\tconst resultModeMap = {\n\t\tall: () => details,\n\t\tallWithException: () => resultModeMap.all() as never,\n\t\tonlySuccess: () => details.data,\n\t\tonlySuccessWithException: () => resultModeMap.onlySuccess(),\n\t} satisfies LazyResultModeMap as LazyResultModeMap;\n\n\treturn resultModeMap;\n};\n\ntype SuccessResult = CallApiResultSuccessVariant<unknown> | null;\n\n// == The CallApiResult type is used to cast all return statements due to a design limitation in ts.\n// LINK - See https://www.zhenghao.io/posts/type-functions for more info\nexport const resolveSuccessResult = (data: unknown, info: SuccessInfo): SuccessResult => {\n\tconst { response, resultMode } = info;\n\n\tconst details = {\n\t\tdata,\n\t\terror: null,\n\t\tresponse,\n\t} satisfies CallApiResultSuccessVariant<unknown>;\n\n\tconst resultModeMap = getResultModeMap(details);\n\n\tconst successResult = resultModeMap[resultMode ?? \"all\"]();\n\n\treturn successResult as SuccessResult;\n};\n\nexport type ErrorInfo = {\n\tcloneResponse: CallApiExtraOptions[\"cloneResponse\"];\n\tmessage?: string;\n\tresultMode: CallApiExtraOptions[\"resultMode\"];\n};\n\ntype ErrorResult = CallApiResultErrorVariant<unknown> | null;\n\nexport const resolveErrorResult = (error: unknown, info: ErrorInfo): ErrorResult => {\n\tconst { cloneResponse, message: customErrorMessage, resultMode } = info;\n\n\tlet details = {\n\t\tdata: null,\n\t\terror: {\n\t\t\terrorData: false,\n\t\t\tmessage: customErrorMessage ?? (error as Error).message,\n\t\t\tname: (error as Error).name,\n\t\t\toriginalError: error as Error,\n\t\t},\n\t\tresponse: null,\n\t} satisfies CallApiResultErrorVariant<unknown> as CallApiResultErrorVariant<unknown>;\n\n\tif (isValidationErrorInstance(error)) {\n\t\tconst { errorData, message, response } = error;\n\n\t\tdetails = {\n\t\t\tdata: null,\n\t\t\terror: { errorData, message, name: \"ValidationError\", originalError: error },\n\t\t\tresponse,\n\t\t};\n\t}\n\n\tif (isHTTPErrorInstance<never>(error)) {\n\t\tconst { errorData, message, name, response } = error;\n\n\t\tdetails = {\n\t\t\tdata: null,\n\t\t\terror: { errorData, message, name, originalError: error },\n\t\t\tresponse: cloneResponse ? response.clone() : response,\n\t\t};\n\t}\n\n\tconst resultModeMap = getResultModeMap(details);\n\n\tconst errorResult = resultModeMap[resultMode ?? \"all\"]();\n\n\treturn errorResult as ErrorResult;\n};\n\nexport const getCustomizedErrorResult = (\n\terrorResult: ErrorResult,\n\tcustomErrorInfo: { message: string | undefined }\n): ErrorResult => {\n\tif (!errorResult) {\n\t\treturn null;\n\t}\n\n\tconst { message = errorResult.error.message } = customErrorInfo;\n\n\treturn {\n\t\t...errorResult,\n\t\terror: {\n\t\t\t...errorResult.error,\n\t\t\tmessage,\n\t\t} satisfies NonNullable<ErrorResult>[\"error\"] as never,\n\t};\n};\n","import type { ValidationError } from \"./error\";\nimport {\n\ttype CallApiResultErrorVariant,\n\ttype CallApiResultSuccessVariant,\n\ttype ErrorInfo,\n\ttype PossibleHTTPError,\n\ttype PossibleJavaScriptOrValidationError,\n\tresolveErrorResult,\n} from \"./result\";\nimport type { StreamProgressEvent } from \"./stream\";\nimport type {\n\tBaseCallApiExtraOptions,\n\tCallApiExtraOptions,\n\tCallApiExtraOptionsForHooks,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n} from \"./types/common\";\nimport type { DefaultDataType } from \"./types/default-types\";\nimport type { AnyFunction, Awaitable, Prettify, UnmaskType } from \"./types/type-helpers\";\n\nexport type PluginExtraOptions<TPluginOptions = unknown> = {\n\toptions: Partial<TPluginOptions>;\n};\n\n/* eslint-disable perfectionist/sort-intersection-types -- Plugin options should come last */\nexport interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOptions = unknown> {\n\t/**\n\t * Hook that will be called when any error occurs within the request/response lifecycle, regardless of whether the error is from the api or not.\n\t * It is basically a combination of `onRequestError` and `onResponseError` hooks\n\t */\n\tonError?: (\n\t\tcontext: ErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called just before the request is being made.\n\t */\n\tonRequest?: (context: RequestContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when an error occurs during the fetch request.\n\t */\n\tonRequestError?: (\n\t\tcontext: RequestErrorContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when upload stream progress is tracked\n\t */\n\tonRequestStream?: (\n\t\tcontext: RequestStreamContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when any response is received from the api, whether successful or not\n\t */\n\tonResponse?: (\n\t\tcontext: ResponseContext<TData, TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when an error response is received from the api.\n\t */\n\tonResponseError?: (\n\t\tcontext: ResponseErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when download stream progress is tracked\n\t */\n\tonResponseStream?: (\n\t\tcontext: ResponseStreamContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when a request is retried.\n\t */\n\tonRetry?: (\n\t\tresponse: RetryContext<TErrorData> & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when a successful response is received from the api.\n\t */\n\tonSuccess?: (context: SuccessContext<TData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;\n\n\t/**\n\t * Hook that will be called when a validation error occurs.\n\t */\n\tonValidationError?: (\n\t\tcontext: ValidationErrorContext & PluginExtraOptions<TPluginOptions>\n\t) => Awaitable<unknown>;\n}\n/* eslint-enable perfectionist/sort-intersection-types -- Plugin options should come last */\n\nexport type HooksOrHooksArray<\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTMoreOptions = unknown,\n> = {\n\t[Key in keyof Hooks<TData, TErrorData, TMoreOptions>]:\n\t\t| Hooks<TData, TErrorData, TMoreOptions>[Key]\n\t\t// eslint-disable-next-line perfectionist/sort-union-types -- I need arrays to be last\n\t\t| Array<Hooks<TData, TErrorData, TMoreOptions>[Key]>;\n};\n\nexport type RequestContext = {\n\t/**\n\t * Config object passed to createFetchClient\n\t */\n\tbaseConfig: BaseCallApiExtraOptions & CallApiRequestOptions;\n\t/**\n\t * Config object passed to the callApi instance\n\t */\n\tconfig: CallApiExtraOptions & CallApiRequestOptions;\n\t/**\n\t * Merged options consisting of extra options from createFetchClient, the callApi instance and default options.\n\t *\n\t */\n\toptions: CallApiExtraOptionsForHooks;\n\t/**\n\t * Merged request consisting of request options from createFetchClient, the callApi instance and default request options.\n\t */\n\trequest: CallApiRequestOptionsForHooks;\n};\n\nexport type ValidationErrorContext = UnmaskType<\n\tRequestContext & {\n\t\terror: ValidationError;\n\t\tresponse: Response | null;\n\t}\n>;\n\nexport type SuccessContext<TData> = UnmaskType<\n\tRequestContext & {\n\t\tdata: TData;\n\t\tresponse: Response;\n\t}\n>;\n\nexport type ResponseContext<TData, TErrorData> = UnmaskType<\n\tRequestContext\n\t\t& (\n\t\t\t| Prettify<CallApiResultSuccessVariant<TData>>\n\t\t\t| Prettify<\n\t\t\t\t\tExtract<CallApiResultErrorVariant<TErrorData>, { error: PossibleHTTPError<TErrorData> }>\n\t\t\t >\n\t\t)\n>;\n\nexport type RequestErrorContext = RequestContext & {\n\terror: PossibleJavaScriptOrValidationError;\n\tresponse: null;\n};\n\nexport type ErrorContext<TErrorData> = UnmaskType<\n\tRequestContext\n\t\t& (\n\t\t\t| {\n\t\t\t\t\terror: PossibleHTTPError<TErrorData>;\n\t\t\t\t\tresponse: Response;\n\t\t\t }\n\t\t\t| {\n\t\t\t\t\terror: PossibleJavaScriptOrValidationError;\n\t\t\t\t\tresponse: Response | null;\n\t\t\t }\n\t\t)\n>;\n\nexport type ResponseErrorContext<TErrorData> = UnmaskType<\n\tExtract<ErrorContext<TErrorData>, { error: PossibleHTTPError<TErrorData> }> & RequestContext\n>;\n\nexport type RetryContext<TErrorData> = UnmaskType<\n\tErrorContext<TErrorData> & { retryAttemptCount: number }\n>;\n\nexport type RequestStreamContext = UnmaskType<\n\tRequestContext & {\n\t\tevent: StreamProgressEvent;\n\t\trequestInstance: Request;\n\t}\n>;\n\nexport type ResponseStreamContext = UnmaskType<\n\tRequestContext & {\n\t\tevent: StreamProgressEvent;\n\t\tresponse: Response;\n\t}\n>;\n\ntype HookRegistries = Required<{\n\t[Key in keyof Hooks]: Set<Hooks[Key]>;\n}>;\n\nexport const hookRegistries = {\n\tonError: new Set(),\n\tonRequest: new Set(),\n\tonRequestError: new Set(),\n\tonRequestStream: new Set(),\n\tonResponse: new Set(),\n\tonResponseError: new Set(),\n\tonResponseStream: new Set(),\n\tonRetry: new Set(),\n\tonSuccess: new Set(),\n\tonValidationError: new Set(),\n} satisfies HookRegistries;\n\nexport const composeAllHooks = (\n\thooksArray: Array<AnyFunction | undefined>,\n\tmergedHooksExecutionMode: CallApiExtraOptionsForHooks[\"mergedHooksExecutionMode\"]\n) => {\n\tconst mergedHook = async (ctx: unknown) => {\n\t\tif (mergedHooksExecutionMode === \"sequential\") {\n\t\t\tfor (const hook of hooksArray) {\n\t\t\t\t// eslint-disable-next-line no-await-in-loop -- This is necessary in this case\n\t\t\t\tawait hook?.(ctx);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tif (mergedHooksExecutionMode === \"parallel\") {\n\t\t\tawait Promise.all(hooksArray.map((uniqueHook) => uniqueHook?.(ctx)));\n\t\t}\n\t};\n\n\treturn mergedHook;\n};\n\nexport const executeHooksInTryBlock = async (...hookResultsOrPromise: Array<Awaitable<unknown>>) => {\n\tawait Promise.all(hookResultsOrPromise);\n};\n\nexport type ExecuteHookInfo = {\n\terrorInfo: ErrorInfo;\n\tshouldThrowOnError: boolean | undefined;\n};\n\nexport const executeHooksInCatchBlock = async (\n\thookResultsOrPromise: Array<Awaitable<unknown>>,\n\thookInfo: ExecuteHookInfo\n) => {\n\tconst { errorInfo, shouldThrowOnError } = hookInfo;\n\n\ttry {\n\t\tawait Promise.all(hookResultsOrPromise);\n\n\t\treturn null;\n\t} catch (hookError) {\n\t\tconst hookErrorResult = resolveErrorResult(hookError, errorInfo);\n\n\t\tif (shouldThrowOnError) {\n\t\t\tthrow hookError;\n\t\t}\n\n\t\treturn hookErrorResult;\n\t}\n};\n","import {\n\texecuteHooksInTryBlock,\n\ttype RequestContext,\n\ttype RequestStreamContext,\n\ttype ResponseStreamContext,\n} from \"./hooks\";\nimport { isObject, isReadableStream } from \"./utils/guards\";\n\nexport type StreamProgressEvent = {\n\t/**\n\t * Current chunk of data being streamed\n\t */\n\tchunk: Uint8Array;\n\t/**\n\t * Progress in percentage\n\t */\n\tprogress: number;\n\t/**\n\t * Total size of data in bytes\n\t */\n\ttotalBytes: number;\n\t/**\n\t * Amount of data transferred so far\n\t */\n\ttransferredBytes: number;\n};\n\ndeclare global {\n\tinterface ReadableStream<R> {\n\t\t[Symbol.asyncIterator]: () => AsyncIterableIterator<R>;\n\t}\n}\n\nconst createProgressEvent = (options: {\n\tchunk: Uint8Array;\n\ttotalBytes: number;\n\ttransferredBytes: number;\n}): StreamProgressEvent => {\n\tconst { chunk, totalBytes, transferredBytes } = options;\n\n\treturn {\n\t\tchunk,\n\t\tprogress: Math.round((transferredBytes / totalBytes) * 100) || 0,\n\t\ttotalBytes,\n\t\ttransferredBytes,\n\t};\n};\n\nconst calculateTotalBytesFromBody = async (\n\trequestBody: Request[\"body\"] | null,\n\texistingTotalBytes: number\n) => {\n\tlet totalBytes = existingTotalBytes;\n\n\tif (!requestBody) {\n\t\treturn totalBytes;\n\t}\n\n\tfor await (const chunk of requestBody) {\n\t\ttotalBytes += chunk.byteLength;\n\t}\n\n\treturn totalBytes;\n};\n\ntype ToStreamableRequestContext = RequestContext;\n\nexport const toStreamableRequest = async (\n\tcontext: ToStreamableRequestContext\n): Promise<Request | RequestInit> => {\n\tconst { baseConfig, config, options, request } = context;\n\n\tif (!options.onRequestStream || !isReadableStream(request.body)) {\n\t\treturn request as RequestInit;\n\t}\n\n\tconst requestInstance = new Request(\n\t\toptions.fullURL as NonNullable<typeof options.fullURL>,\n\t\t{ ...request, duplex: \"half\" } as RequestInit\n\t);\n\n\tconst contentLength = requestInstance.headers.get(\"content-length\");\n\n\tlet totalBytes = Number(contentLength ?? 0);\n\n\tconst shouldForcefullyCalcStreamSize =\n\t\tisObject(options.forcefullyCalculateStreamSize) ?\n\t\t\toptions.forcefullyCalculateStreamSize.request\n\t\t:\toptions.forcefullyCalculateStreamSize;\n\n\t// == If no content length is present, we read the total bytes from the body\n\tif (!contentLength && shouldForcefullyCalcStreamSize) {\n\t\ttotalBytes = await calculateTotalBytesFromBody(requestInstance.clone().body, totalBytes);\n\t}\n\n\tlet transferredBytes = 0;\n\n\tconst stream = new ReadableStream({\n\t\tstart: async (controller) => {\n\t\t\tconst body = requestInstance.body;\n\n\t\t\tif (!body) return;\n\n\t\t\tconst requestStreamContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tevent: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\trequestInstance,\n\t\t\t} satisfies RequestStreamContext;\n\n\t\t\tawait executeHooksInTryBlock(options.onRequestStream?.(requestStreamContext));\n\n\t\t\tfor await (const chunk of body) {\n\t\t\t\ttransferredBytes += chunk.byteLength;\n\n\t\t\t\ttotalBytes = Math.max(totalBytes, transferredBytes);\n\n\t\t\t\tawait executeHooksInTryBlock(\n\t\t\t\t\toptions.onRequestStream?.({\n\t\t\t\t\t\t...requestStreamContext,\n\t\t\t\t\t\tevent: createProgressEvent({ chunk, totalBytes, transferredBytes }),\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t}\n\n\t\t\tcontroller.close();\n\t\t},\n\t});\n\n\treturn new Request(requestInstance, { body: stream, duplex: \"half\" } as RequestInit);\n};\n\ntype StreamableResponseContext = RequestContext & { response: Response };\n\nexport const toStreamableResponse = async (context: StreamableResponseContext): Promise<Response> => {\n\tconst { baseConfig, config, options, request, response } = context;\n\n\tif (!options.onResponseStream || !response.body) {\n\t\treturn response;\n\t}\n\n\tconst contentLength = response.headers.get(\"content-length\");\n\n\tlet totalBytes = Number(contentLength ?? 0);\n\n\tconst shouldForceContentLengthCalc =\n\t\tisObject(options.forcefullyCalculateStreamSize) ?\n\t\t\toptions.forcefullyCalculateStreamSize.response\n\t\t:\toptions.forcefullyCalculateStreamSize;\n\n\t// == If no content length is present and `forceContentLengthCalculation` is enabled, we read the total bytes from the body\n\tif (!contentLength && shouldForceContentLengthCalc) {\n\t\ttotalBytes = await calculateTotalBytesFromBody(response.clone().body, totalBytes);\n\t}\n\n\tlet transferredBytes = 0;\n\n\tconst stream = new ReadableStream({\n\t\tstart: async (controller) => {\n\t\t\tconst body = response.body;\n\n\t\t\tif (!body) return;\n\n\t\t\tconst responseStreamContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tevent: createProgressEvent({ chunk: new Uint8Array(), totalBytes, transferredBytes }),\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse,\n\t\t\t} satisfies ResponseStreamContext;\n\n\t\t\tawait executeHooksInTryBlock(options.onResponseStream?.(responseStreamContext));\n\n\t\t\tfor await (const chunk of body) {\n\t\t\t\ttransferredBytes += chunk.byteLength;\n\n\t\t\t\ttotalBytes = Math.max(totalBytes, transferredBytes);\n\n\t\t\t\tawait executeHooksInTryBlock(\n\t\t\t\t\toptions.onResponseStream?.({\n\t\t\t\t\t\t...responseStreamContext,\n\t\t\t\t\t\tevent: createProgressEvent({ chunk, totalBytes, transferredBytes }),\n\t\t\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t}\n\n\t\t\tcontroller.close();\n\t\t},\n\t});\n\n\treturn new Response(stream, response);\n};\n","import { dedupeDefaults } from \"./constants/default-options\";\nimport type { RequestContext } from \"./hooks\";\nimport { toStreamableRequest, toStreamableResponse } from \"./stream\";\nimport { deterministicHashFn, getFetchImpl, waitFor } from \"./utils/common\";\n\ntype RequestInfo = {\n\tcontroller: AbortController;\n\tresponsePromise: Promise<Response>;\n};\n\nexport type RequestInfoCache = Map<string | null, RequestInfo>;\n\ntype DedupeContext = RequestContext & {\n\t$GlobalRequestInfoCache: RequestInfoCache;\n\t$LocalRequestInfoCache: RequestInfoCache;\n\tnewFetchController: AbortController;\n};\n\nexport const getAbortErrorMessage = (\n\tdedupeKey: DedupeOptions[\"dedupeKey\"],\n\tfullURL: DedupeContext[\"options\"][\"fullURL\"]\n) => {\n\treturn dedupeKey ?\n\t\t\t`Duplicate request detected - Aborted previous request with key '${dedupeKey}' as a new request was initiated`\n\t\t:\t`Duplicate request detected - Aborted previous request to '${fullURL}' as a new request with identical options was initiated`;\n};\n\nexport const createDedupeStrategy = async (context: DedupeContext) => {\n\tconst {\n\t\t$GlobalRequestInfoCache,\n\t\t$LocalRequestInfoCache,\n\t\tbaseConfig,\n\t\tconfig,\n\t\tnewFetchController,\n\t\toptions: globalOptions,\n\t\trequest: globalRequest,\n\t} = context;\n\n\tconst dedupeStrategy = globalOptions.dedupeStrategy ?? dedupeDefaults.dedupeStrategy;\n\n\tconst generateDedupeKey = () => {\n\t\tconst shouldHaveDedupeKey = dedupeStrategy === \"cancel\" || dedupeStrategy === \"defer\";\n\n\t\tif (!shouldHaveDedupeKey) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn `${globalOptions.fullURL}-${deterministicHashFn({ options: globalOptions, request: globalRequest })}`;\n\t};\n\n\tconst dedupeKey = globalOptions.dedupeKey ?? generateDedupeKey();\n\n\tconst dedupeCacheScope = globalOptions.dedupeCacheScope ?? dedupeDefaults.dedupeCacheScope;\n\n\tconst $RequestInfoCache = (\n\t\t{\n\t\t\tglobal: $GlobalRequestInfoCache,\n\t\t\tlocal: $LocalRequestInfoCache,\n\t\t} satisfies Record<NonNullable<DedupeOptions[\"dedupeCacheScope\"]>, RequestInfoCache>\n\t)[dedupeCacheScope];\n\n\t// == This is to ensure cache operations only occur when key is available\n\tconst $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;\n\n\t/******\n\t * == Add a small delay to the execution to ensure proper request deduplication when multiple requests with the same key start simultaneously.\n\t * == This gives time for the cache to be updated with the previous request info before the next request checks it.\n\t ******/\n\tif (dedupeKey !== null) {\n\t\tawait waitFor(0.1);\n\t}\n\n\tconst prevRequestInfo = $RequestInfoCacheOrNull?.get(dedupeKey);\n\n\tconst handleRequestCancelStrategy = () => {\n\t\tconst shouldCancelRequest = prevRequestInfo && dedupeStrategy === \"cancel\";\n\n\t\tif (!shouldCancelRequest) return;\n\n\t\tconst message = getAbortErrorMessage(globalOptions.dedupeKey, globalOptions.fullURL);\n\n\t\tconst reason = new DOMException(message, \"AbortError\");\n\n\t\tprevRequestInfo.controller.abort(reason);\n\n\t\t// == Adding this just so that eslint forces me put await when calling the function (it looks better that way tbh)\n\t\treturn Promise.resolve();\n\t};\n\n\tconst handleRequestDeferStrategy = async (deferContext: {\n\t\toptions: DedupeContext[\"options\"];\n\t\trequest: DedupeContext[\"request\"];\n\t}) => {\n\t\t// == Local options and request are needed so that transformations are applied can be applied to both from call site\n\t\tconst { options: localOptions, request: localRequest } = deferContext;\n\n\t\tconst fetchApi = getFetchImpl(localOptions.customFetchImpl);\n\n\t\tconst shouldUsePromiseFromCache = prevRequestInfo && dedupeStrategy === \"defer\";\n\n\t\tconst streamableContext = {\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\toptions: localOptions,\n\t\t\trequest: localRequest,\n\t\t} satisfies RequestContext;\n\n\t\tconst streamableRequest = await toStreamableRequest(streamableContext);\n\n\t\tconst responsePromise =\n\t\t\tshouldUsePromiseFromCache ?\n\t\t\t\tprevRequestInfo.responsePromise\n\t\t\t:\tfetchApi(localOptions.fullURL as NonNullable<typeof localOptions.fullURL>, streamableRequest);\n\n\t\t$RequestInfoCacheOrNull?.set(dedupeKey, { controller: newFetchController, responsePromise });\n\n\t\tconst streamableResponse = toStreamableResponse({\n\t\t\t...streamableContext,\n\t\t\tresponse: await responsePromise,\n\t\t});\n\n\t\treturn streamableResponse;\n\t};\n\n\tconst removeDedupeKeyFromCache = () => {\n\t\t$RequestInfoCacheOrNull?.delete(dedupeKey);\n\t};\n\n\treturn {\n\t\tdedupeStrategy,\n\t\thandleRequestCancelStrategy,\n\t\thandleRequestDeferStrategy,\n\t\tremoveDedupeKeyFromCache,\n\t};\n};\n\nexport type DedupeOptions = {\n\t/**\n\t * Defines the scope of the deduplication cache, can be set to \"global\" | \"local\".\n\t * - If set to \"global\", the deduplication cache will be shared across all requests, regardless of whether they shared the same `createFetchClient` or not.\n\t * - If set to \"local\", the deduplication cache will be scoped to the current request.\n\t * @default \"local\"\n\t */\n\tdedupeCacheScope?: \"global\" | \"local\";\n\n\t/**\n\t * Custom request key to be used to identify a request in the fetch deduplication strategy.\n\t * @default the full request url + string formed from the request options\n\t */\n\tdedupeKey?: string;\n\n\t/**\n\t * Defines the deduplication strategy for the request, can be set to \"none\" | \"defer\" | \"cancel\".\n\t * - If set to \"cancel\", the previous pending request with the same request key will be cancelled and lets the new request through.\n\t * - If set to \"defer\", all new request with the same request key will be share the same response, until the previous one is completed.\n\t * - If set to \"none\", deduplication is disabled.\n\t * @default \"cancel\"\n\t */\n\tdedupeStrategy?: \"cancel\" | \"defer\" | \"none\";\n};\n","import { ValidationError } from \"./error\";\nimport type {\n\tBaseCallApiExtraOptions,\n\tBody,\n\tCallApiExtraOptions,\n\tCallApiRequestOptions,\n\tGlobalMeta,\n\tHeadersOption,\n\tMethodUnion,\n} from \"./types\";\nimport type { StandardSchemaV1 } from \"./types/standard-schema\";\nimport {\n\ttype AnyFunction,\n\ttype AnyString,\n\ttype Awaitable,\n\tdefineEnum,\n\ttype Prettify,\n\ttype UnionToIntersection,\n\ttype Writeable,\n} from \"./types/type-helpers\";\nimport type { Params, Query } from \"./url\";\nimport { isFunction } from \"./utils/guards\";\n\ntype InferSchemaInput<TSchema extends CallApiSchema[keyof CallApiSchema]> =\n\tTSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema>\n\t: TSchema extends (value: infer TInput) => unknown ? TInput\n\t: never;\n\nexport type InferSchemaResult<TSchema, TFallbackResult = unknown> =\n\t// == Checking for undefined first and returning fallback to avoid type errors when passing the config around (weird tbh)\n\tundefined extends TSchema ? TFallbackResult\n\t: TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema>\n\t: TSchema extends AnyFunction<infer TResult> ? Awaited<TResult>\n\t: TFallbackResult;\n\nconst handleValidatorFunction = async <TInput>(\n\tvalidator: Extract<CallApiSchema[keyof CallApiSchema], AnyFunction>,\n\tinputData: TInput\n): Promise<StandardSchemaV1.Result<TInput>> => {\n\ttry {\n\t\tconst result = await validator(inputData as never);\n\n\t\treturn {\n\t\t\tissues: undefined,\n\t\t\tvalue: result as never,\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\tissues: error as never,\n\t\t\tvalue: undefined,\n\t\t};\n\t}\n};\n\nexport const standardSchemaParser = async <\n\tTSchema extends NonNullable<CallApiSchema[keyof CallApiSchema]>,\n>(\n\tschema: TSchema,\n\tinputData: InferSchemaInput<TSchema>,\n\tresponse?: Response | null\n): Promise<InferSchemaResult<TSchema>> => {\n\tconst result =\n\t\tisFunction(schema) ?\n\t\t\tawait handleValidatorFunction(schema, inputData)\n\t\t:\tawait schema[\"~standard\"].validate(inputData);\n\n\t// == If the `issues` field exists, it means the validation failed\n\tif (result.issues) {\n\t\tthrow new ValidationError(\n\t\t\t{ issues: result.issues, response: response ?? null },\n\t\t\t{ cause: result.issues }\n\t\t);\n\t}\n\n\treturn result.value as never;\n};\n\nexport interface CallApiSchemaConfig {\n\t/**\n\t * The base url of the schema. By default it's the baseURL of the callApi instance.\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Disables runtime validation for the schema.\n\t */\n\tdisableRuntimeValidation?: boolean;\n\n\t/**\n\t * If `true`, the original input value will be used instead of the transformed/validated output.\n\t *\n\t * This is useful when you want to validate the input but don't want any transformations\n\t * applied by the validation schema (e.g., type coercion, default values, etc).\n\t */\n\tdisableValidationOutputApplication?: boolean;\n\n\t/**\n\t * Optional url prefix that will be substituted for the `baseURL` of the schemaConfig at runtime.\n\t *\n\t * This allows you to reuse the same schema against different base URLs (for example,\n\t * swapping between `/api/v1` and `/api/v2`) without redefining the entire schema.\n\t */\n\tprefix?: string;\n\n\t/**\n\t *Determines the inference or requirement of the method option based on the route modifiers (`@get/`, `@post/`, `@put/`, `@patch/`, `@delete/`).\n\t *\n\t * - When `true`, the method option is made required on the type level and is not automatically added to the request options.\n\t * - When `false` or `undefined` (default), the method option is not required on the type level, and is automatically added to the request options.\n\t *\n\t */\n\trequireMethodProvision?: boolean;\n\n\t/**\n\t * Controls the strictness of API route validation.\n\t *\n\t * When true:\n\t * - Only routes explicitly defined in the schema will be considered valid to typescript and the runtime.\n\t * - Attempting to call routes not defined in the schema will result in both type errors and runtime validation errors.\n\t * - Useful for ensuring API calls conform exactly to your schema definition\n\t *\n\t * When false or undefined (default):\n\t * - All routes will be allowed, whether they are defined in the schema or not\n\t */\n\tstrict?: boolean;\n}\n\nexport interface CallApiSchema {\n\t/**\n\t * The schema to use for validating the request body.\n\t */\n\tbody?: StandardSchemaV1<Body> | ((body: Body) => Awaitable<Body>);\n\n\t/**\n\t * The schema to use for validating the response data.\n\t */\n\tdata?: StandardSchemaV1 | ((data: unknown) => unknown);\n\n\t/**\n\t * The schema to use for validating the response error data.\n\t */\n\terrorData?: StandardSchemaV1 | ((errorData: unknown) => unknown);\n\n\t/**\n\t * The schema to use for validating the request headers.\n\t */\n\theaders?:\n\t\t| StandardSchemaV1<HeadersOption | undefined>\n\t\t| ((headers: HeadersOption) => Awaitable<HeadersOption | undefined>);\n\n\t/**\n\t * The schema to use for validating the meta option.\n\t */\n\tmeta?:\n\t\t| StandardSchemaV1<GlobalMeta | undefined>\n\t\t| ((meta: GlobalMeta) => Awaitable<GlobalMeta | undefined>);\n\n\t/**\n\t * The schema to use for validating the request method.\n\t */\n\tmethod?:\n\t\t| StandardSchemaV1<MethodUnion | undefined>\n\t\t| ((method: MethodUnion) => Awaitable<MethodUnion | undefined>);\n\n\t/**\n\t * The schema to use for validating the request url parameters.\n\t */\n\tparams?: StandardSchemaV1<Params | undefined> | ((params: Params) => Awaitable<Params | undefined>);\n\n\t/**\n\t * The schema to use for validating the request url queries.\n\t */\n\tquery?: StandardSchemaV1<Query | undefined> | ((query: Query) => Awaitable<Query | undefined>);\n}\n\nexport const routeKeyMethods = defineEnum([\"delete\", \"get\", \"patch\", \"post\", \"put\"]);\n\nexport type RouteKeyMethods = (typeof routeKeyMethods)[number];\n\nexport type RouteKeyMethodsURLUnion = `${RouteKeyMethods}/`;\n\ntype PossibleRouteKey = AnyString | RouteKeyMethodsURLUnion;\n\nexport type BaseCallApiSchemaRoutes = Partial<Record<PossibleRouteKey, CallApiSchema>>;\n\nexport type BaseCallApiSchemaAndConfig = {\n\tconfig?: CallApiSchemaConfig;\n\troutes: BaseCallApiSchemaRoutes;\n};\n\nexport const defineSchema = <\n\tconst TBaseSchemaRoutes extends BaseCallApiSchemaRoutes,\n\tconst TSchemaConfig extends CallApiSchemaConfig,\n>(\n\troutes: TBaseSchemaRoutes,\n\tconfig?: TSchemaConfig\n) => {\n\treturn {\n\t\tconfig,\n\t\troutes: routes as Writeable<typeof routes, \"deep\">,\n\t} satisfies BaseCallApiSchemaAndConfig;\n};\n\nexport const defineSchemaConfig = <const TConfig extends CallApiExtraOptions[\"schemaConfig\"]>(\n\tconfig: TConfig\n) => {\n\treturn config as Writeable<typeof config, \"deep\">;\n};\n\nexport const defineSchemaRoutes = <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes>(\n\troutes: TBaseSchemaRoutes\n) => {\n\treturn routes as Writeable<typeof routes, \"deep\">;\n};\n\ntype ValidationOptions<\n\tTSchema extends CallApiSchema[keyof CallApiSchema] = CallApiSchema[keyof CallApiSchema],\n> = {\n\tinputValue: InferSchemaInput<TSchema>;\n\tresponse?: Response | null;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nexport const handleValidation = async <TSchema extends CallApiSchema[keyof CallApiSchema]>(\n\tschema: TSchema | undefined,\n\tvalidationOptions: ValidationOptions<TSchema>\n): Promise<InferSchemaResult<TSchema>> => {\n\tconst { inputValue, response, schemaConfig } = validationOptions;\n\n\tif (!schema || schemaConfig?.disableRuntimeValidation) {\n\t\treturn inputValue as never;\n\t}\n\n\tconst validResult = await standardSchemaParser(schema, inputValue, response);\n\n\treturn validResult as never;\n};\n\ntype LastOf<TValue> =\n\tUnionToIntersection<TValue extends unknown ? () => TValue : never> extends () => infer R ? R : never;\n\ntype Push<TArray extends unknown[], TArrayItem> = [...TArray, TArrayItem];\n\ntype UnionToTuple<\n\tTUnion,\n\tTComputedLastUnion = LastOf<TUnion>,\n\tTComputedIsUnionEqualToNever = [TUnion] extends [never] ? true : false,\n> =\n\ttrue extends TComputedIsUnionEqualToNever ? []\n\t:\tPush<UnionToTuple<Exclude<TUnion, TComputedLastUnion>>, TComputedLastUnion>;\n\nexport type Tuple<TTuple, TArray extends TTuple[] = []> =\n\tUnionToTuple<TTuple>[\"length\"] extends TArray[\"length\"] ? [...TArray]\n\t:\tTuple<TTuple, [TTuple, ...TArray]>;\n\nconst extraOptionsToBeValidated = [\"meta\", \"params\", \"query\"] satisfies Tuple<\n\tExtract<keyof CallApiSchema, keyof CallApiExtraOptions>\n>;\n\ntype ExtraOptionsValidationOptions = {\n\textraOptions: CallApiExtraOptions;\n\tschema: CallApiSchema | undefined;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nconst handleExtraOptionsValidation = async (validationOptions: ExtraOptionsValidationOptions) => {\n\tconst { extraOptions, schema, schemaConfig } = validationOptions;\n\n\tconst validationResultArray = await Promise.all(\n\t\textraOptionsToBeValidated.map((propertyKey) =>\n\t\t\thandleValidation(schema?.[propertyKey], {\n\t\t\t\tinputValue: extraOptions[propertyKey],\n\t\t\t\tschemaConfig,\n\t\t\t})\n\t\t)\n\t);\n\n\tconst validatedResultObject: Prettify<\n\t\tPick<CallApiExtraOptions, (typeof extraOptionsToBeValidated)[number]>\n\t> = {};\n\n\tfor (const [index, propertyKey] of extraOptionsToBeValidated.entries()) {\n\t\tconst validationResult = validationResultArray[index];\n\n\t\tif (validationResult === undefined) continue;\n\n\t\tvalidatedResultObject[propertyKey] = validationResult as never;\n\t}\n\n\treturn validatedResultObject;\n};\n\nconst requestOptionsToBeValidated = [\"body\", \"headers\", \"method\"] satisfies Tuple<\n\tExtract<keyof CallApiSchema, keyof CallApiRequestOptions>\n>;\n\ntype RequestOptionsValidationOptions = {\n\trequestOptions: CallApiRequestOptions;\n\tschema: CallApiSchema | undefined;\n\tschemaConfig: CallApiSchemaConfig | undefined;\n};\n\nconst handleRequestOptionsValidation = async (validationOptions: RequestOptionsValidationOptions) => {\n\tconst { requestOptions, schema, schemaConfig } = validationOptions;\n\n\tconst validationResultArray = await Promise.all(\n\t\trequestOptionsToBeValidated.map((propertyKey) =>\n\t\t\thandleValidation(schema?.[propertyKey], {\n\t\t\t\tinputValue: requestOptions[propertyKey],\n\t\t\t\tschemaConfig,\n\t\t\t})\n\t\t)\n\t);\n\n\tconst validatedResultObject: Prettify<\n\t\tPick<CallApiRequestOptions, (typeof requestOptionsToBeValidated)[number]>\n\t> = {};\n\n\tfor (const [index, propertyKey] of requestOptionsToBeValidated.entries()) {\n\t\tconst validationResult = validationResultArray[index];\n\n\t\tif (validationResult === undefined) continue;\n\n\t\tvalidatedResultObject[propertyKey] = validationResult as never;\n\t}\n\n\treturn validatedResultObject;\n};\n\nexport const handleConfigValidation = async (\n\tvalidationOptions: GetResolvedSchemaContext\n\t\t& Omit<ExtraOptionsValidationOptions & RequestOptionsValidationOptions, \"schema\" | \"schemaConfig\">\n) => {\n\tconst { baseExtraOptions, currentRouteSchemaKey, extraOptions, requestOptions } = validationOptions;\n\n\tconst { currentRouteSchema, resolvedSchema } = getResolvedSchema({\n\t\tbaseExtraOptions,\n\t\tcurrentRouteSchemaKey,\n\t\textraOptions,\n\t});\n\n\tconst resolvedSchemaConfig = getResolvedSchemaConfig({ baseExtraOptions, extraOptions });\n\n\tif (!currentRouteSchema && resolvedSchemaConfig?.strict === true) {\n\t\tthrow new ValidationError({\n\t\t\tissues: [{ message: `Strict Mode - No schema found for route '${currentRouteSchemaKey}' ` }],\n\t\t\tresponse: null,\n\t\t});\n\t}\n\n\tif (resolvedSchemaConfig?.disableRuntimeValidation) {\n\t\treturn {\n\t\t\textraOptionsValidationResult: null,\n\t\t\trequestOptionsValidationResult: null,\n\t\t\tresolvedSchema,\n\t\t\tresolvedSchemaConfig,\n\t\t\tshouldApplySchemaOutput: false,\n\t\t};\n\t}\n\n\tconst [extraOptionsValidationResult, requestOptionsValidationResult] = await Promise.all([\n\t\thandleExtraOptionsValidation({\n\t\t\textraOptions,\n\t\t\tschema: resolvedSchema,\n\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t}),\n\t\thandleRequestOptionsValidation({\n\t\t\trequestOptions,\n\t\t\tschema: resolvedSchema,\n\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t}),\n\t]);\n\n\tconst shouldApplySchemaOutput =\n\t\t(Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult))\n\t\t&& !resolvedSchemaConfig?.disableValidationOutputApplication;\n\n\treturn {\n\t\textraOptionsValidationResult,\n\t\trequestOptionsValidationResult,\n\t\tresolvedSchema,\n\t\tresolvedSchemaConfig,\n\t\tshouldApplySchemaOutput,\n\t};\n};\n\ntype GetResolvedSchemaContext = {\n\tbaseExtraOptions: BaseCallApiExtraOptions;\n\tcurrentRouteSchemaKey: string;\n\textraOptions: CallApiExtraOptions;\n};\n\nexport const getResolvedSchema = (context: GetResolvedSchemaContext) => {\n\tconst { baseExtraOptions, currentRouteSchemaKey, extraOptions } = context;\n\n\tconst currentRouteSchema = baseExtraOptions.schema?.routes[currentRouteSchemaKey];\n\n\tconst resolvedSchema =\n\t\tisFunction(extraOptions.schema) ?\n\t\t\textraOptions.schema({\n\t\t\t\tbaseSchema: baseExtraOptions.schema?.routes ?? {},\n\t\t\t\tcurrentRouteSchema: currentRouteSchema ?? {},\n\t\t\t})\n\t\t:\t(extraOptions.schema ?? currentRouteSchema);\n\n\treturn { currentRouteSchema, resolvedSchema };\n};\n\nexport const getResolvedSchemaConfig = (\n\tcontext: Omit<GetResolvedSchemaContext, \"currentRouteSchemaKey\">\n) => {\n\tconst { baseExtraOptions, extraOptions } = context;\n\n\tconst resolvedSchemaConfig =\n\t\tisFunction(extraOptions.schemaConfig) ?\n\t\t\textraOptions.schemaConfig({ baseSchemaConfig: baseExtraOptions.schema?.config ?? {} })\n\t\t:\t(extraOptions.schemaConfig ?? baseExtraOptions.schema?.config);\n\n\treturn resolvedSchemaConfig;\n};\n\nexport const getCurrentRouteSchemaKeyAndMainInitURL = (\n\tcontext: Pick<GetResolvedSchemaContext, \"baseExtraOptions\" | \"extraOptions\"> & { initURL: string }\n) => {\n\tconst { baseExtraOptions, extraOptions, initURL } = context;\n\n\tconst schemaConfig = getResolvedSchemaConfig({ baseExtraOptions, extraOptions });\n\n\tlet currentRouteSchemaKey = initURL;\n\tlet mainInitURL = initURL;\n\n\tif (schemaConfig?.prefix && currentRouteSchemaKey.startsWith(schemaConfig.prefix)) {\n\t\tcurrentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.prefix, \"\");\n\n\t\tmainInitURL = mainInitURL.replace(schemaConfig.prefix, schemaConfig.baseURL ?? \"\");\n\t}\n\n\tif (schemaConfig?.baseURL && currentRouteSchemaKey.startsWith(schemaConfig.baseURL)) {\n\t\tcurrentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.baseURL, \"\");\n\t}\n\n\treturn { currentRouteSchemaKey, mainInitURL };\n};\n","import { hookDefaults } from \"./constants/default-options\";\nimport {\n\tcomposeAllHooks,\n\ttype Hooks,\n\ttype HooksOrHooksArray,\n\thookRegistries,\n\ttype PluginExtraOptions,\n\ttype RequestContext,\n} from \"./hooks\";\nimport type { CallApiRequestOptions, CallApiRequestOptionsForHooks } from \"./types/common\";\nimport type { AnyFunction, Awaitable, Writeable } from \"./types/type-helpers\";\nimport type { InitURLOrURLObject } from \"./url\";\nimport { isArray, isFunction, isPlainObject, isString } from \"./utils/guards\";\nimport { type BaseCallApiSchemaAndConfig, getCurrentRouteSchemaKeyAndMainInitURL } from \"./validation\";\n\nexport type PluginInitContext<TPluginExtraOptions = unknown> = RequestContext // eslint-disable-next-line perfectionist/sort-intersection-types -- Allow\n\t& PluginExtraOptions<TPluginExtraOptions> & { initURL: string };\n\nexport type PluginInitResult = Partial<\n\tOmit<PluginInitContext, \"initURL\" | \"request\"> & {\n\t\tinitURL: InitURLOrURLObject;\n\t\trequest: CallApiRequestOptions;\n\t}\n>;\n\nexport type PluginHooksWithMoreOptions<TMoreOptions = unknown> = HooksOrHooksArray<\n\tnever,\n\tnever,\n\tTMoreOptions\n>;\n\nexport type PluginHooks<TData = never, TErrorData = never, TMoreOptions = unknown> = HooksOrHooksArray<\n\tTData,\n\tTErrorData,\n\tTMoreOptions\n>;\n\nexport interface CallApiPlugin {\n\t/**\n\t * Defines additional options that can be passed to callApi\n\t */\n\tdefineExtraOptions?: (...params: never[]) => unknown;\n\n\t/**\n\t * A description for the plugin\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Hooks / Interceptors for the plugin\n\t */\n\thooks?: PluginHooks;\n\n\t/**\n\t * A unique id for the plugin\n\t */\n\tid: string;\n\n\t/**\n\t * A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.\n\t */\n\tinit?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;\n\n\t/**\n\t * A name for the plugin\n\t */\n\tname: string;\n\n\t/**\n\t * Base schema for the client.\n\t */\n\tschema?: BaseCallApiSchemaAndConfig;\n\n\t/**\n\t * A version for the plugin\n\t */\n\tversion?: string;\n}\n\nexport const definePlugin = <\n\t// eslint-disable-next-line perfectionist/sort-union-types -- Let the first one be first\n\tconst TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>,\n>(\n\tplugin: TPlugin\n) => {\n\treturn plugin as Writeable<TPlugin, \"deep\">;\n};\n\nexport const getResolvedPlugins = (context: Pick<RequestContext, \"baseConfig\" | \"options\">) => {\n\tconst { baseConfig, options } = context;\n\n\tconst resolvedPlugins =\n\t\tisFunction(options.plugins) ?\n\t\t\toptions.plugins({ basePlugins: baseConfig.plugins ?? [] })\n\t\t:\t(options.plugins ?? []);\n\n\treturn resolvedPlugins;\n};\n\nexport const initializePlugins = async (context: PluginInitContext) => {\n\tconst { baseConfig, config, initURL, options, request } = context;\n\n\tconst clonedHookRegistries = structuredClone(hookRegistries);\n\n\tconst addMainHooks = () => {\n\t\tfor (const key of Object.keys(clonedHookRegistries) as Array<keyof Hooks>) {\n\t\t\tconst overriddenHook = options[key];\n\t\t\tconst baseHook = baseConfig[key];\n\t\t\tconst instanceHook = config[key];\n\n\t\t\t// == If the base hook is an array and instance hook is defined, we need to compose the base hook with the instance hook\n\t\t\tconst mainHook =\n\t\t\t\tisArray(baseHook) && Boolean(instanceHook) ? [baseHook, instanceHook].flat() : overriddenHook;\n\n\t\t\tif (!mainHook) continue;\n\n\t\t\tclonedHookRegistries[key].add(mainHook as never);\n\t\t}\n\t};\n\n\tconst addPluginHooks = (pluginHooks: Required<CallApiPlugin>[\"hooks\"]) => {\n\t\tfor (const key of Object.keys(clonedHookRegistries) as Array<keyof Hooks>) {\n\t\t\tconst pluginHook = pluginHooks[key];\n\n\t\t\tif (!pluginHook) continue;\n\n\t\t\tclonedHookRegistries[key].add(pluginHook as never);\n\t\t}\n\t};\n\n\tconst mergedHooksExecutionOrder =\n\t\toptions.mergedHooksExecutionOrder ?? hookDefaults.mergedHooksExecutionOrder;\n\n\tif (mergedHooksExecutionOrder === \"mainHooksBeforePlugins\") {\n\t\taddMainHooks();\n\t}\n\n\tconst { currentRouteSchemaKey, mainInitURL } = getCurrentRouteSchemaKeyAndMainInitURL({\n\t\tbaseExtraOptions: baseConfig,\n\t\textraOptions: config,\n\t\tinitURL,\n\t});\n\n\tlet resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;\n\tlet resolvedInitURL = mainInitURL;\n\tlet resolvedOptions = options;\n\tlet resolvedRequestOptions = request;\n\n\tconst executePluginInit = async (pluginInit: CallApiPlugin[\"init\"]) => {\n\t\tif (!pluginInit) return;\n\n\t\tconst initResult = await pluginInit({\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tinitURL,\n\t\t\toptions,\n\t\t\trequest,\n\t\t});\n\n\t\tif (!isPlainObject(initResult)) return;\n\n\t\tconst urlString = initResult.initURL?.toString();\n\n\t\tif (isString(urlString)) {\n\t\t\tconst newResult = getCurrentRouteSchemaKeyAndMainInitURL({\n\t\t\t\tbaseExtraOptions: baseConfig,\n\t\t\t\textraOptions: config,\n\t\t\t\tinitURL: urlString,\n\t\t\t});\n\n\t\t\tresolvedCurrentRouteSchemaKey = newResult.currentRouteSchemaKey;\n\t\t\tresolvedInitURL = newResult.mainInitURL;\n\t\t}\n\n\t\tif (isPlainObject(initResult.request)) {\n\t\t\tresolvedRequestOptions = initResult.request as CallApiRequestOptionsForHooks;\n\t\t}\n\n\t\tif (isPlainObject(initResult.options)) {\n\t\t\tresolvedOptions = initResult.options;\n\t\t}\n\t};\n\n\tconst resolvedPlugins = getResolvedPlugins({ baseConfig, options });\n\n\tfor (const plugin of resolvedPlugins) {\n\t\t// eslint-disable-next-line no-await-in-loop -- Await is necessary in this case.\n\t\tawait executePluginInit(plugin.init);\n\n\t\tif (!plugin.hooks) continue;\n\n\t\taddPluginHooks(plugin.hooks);\n\t}\n\n\tif (mergedHooksExecutionOrder === \"mainHooksAfterPlugins\") {\n\t\taddMainHooks();\n\t}\n\n\tconst resolvedHooks: Hooks = {};\n\n\tfor (const [key, hookRegistry] of Object.entries(clonedHookRegistries)) {\n\t\tif (hookRegistry.size === 0) continue;\n\n\t\t// == Flatten the hook registry to remove any nested arrays, incase an array of hooks is passed to any of the hooks\n\t\tconst flattenedHookArray = [...hookRegistry].flat();\n\n\t\tif (flattenedHookArray.length === 0) continue;\n\n\t\tconst mergedHooksExecutionMode =\n\t\t\toptions.mergedHooksExecutionMode ?? hookDefaults.mergedHooksExecutionMode;\n\n\t\tconst composedHook = composeAllHooks(flattenedHookArray, mergedHooksExecutionMode);\n\n\t\tresolvedHooks[key as keyof Hooks] = composedHook;\n\t}\n\n\treturn {\n\t\tresolvedCurrentRouteSchemaKey,\n\t\tresolvedHooks,\n\t\tresolvedInitURL,\n\t\tresolvedOptions,\n\t\tresolvedRequestOptions,\n\t};\n};\n","import { requestOptionDefaults, retryDefaults } from \"./constants/default-options\";\nimport type { ErrorContext, RequestContext } from \"./hooks\";\nimport type { MethodUnion } from \"./types\";\nimport type { Awaitable } from \"./types/type-helpers\";\nimport { isFunction } from \"./utils/guards\";\n\ntype RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;\n\ntype InnerRetryKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, \"~retryAttemptCount\" | \"retry\">;\n\ntype InnerRetryOptions<TErrorData> = {\n\t[Key in InnerRetryKeys<TErrorData> as Key extends `retry${infer TRest}` ?\n\t\tUncapitalize<TRest> extends \"attempts\" ?\n\t\t\tnever\n\t\t:\tUncapitalize<TRest>\n\t:\tKey]?: RetryOptions<TErrorData>[Key];\n} & {\n\tattempts: NonNullable<RetryOptions<TErrorData>[\"retryAttempts\"]>;\n};\n\nexport interface RetryOptions<TErrorData> {\n\t/**\n\t * Keeps track of the number of times the request has already been retried\n\t *\n\t * @deprecated **NOTE**: This property is used internally to track retries. Please abstain from modifying it.\n\t */\n\treadonly [\"~retryAttemptCount\"]?: number;\n\n\t/**\n\t * All retry options in a single object instead of separate properties\n\t */\n\tretry?: InnerRetryOptions<TErrorData>;\n\n\t/**\n\t * Number of allowed retry attempts on HTTP errors\n\t * @default 0\n\t */\n\tretryAttempts?: number;\n\n\t/**\n\t * Callback whose return value determines if a request should be retried or not\n\t */\n\tretryCondition?: RetryCondition<TErrorData>;\n\n\t/**\n\t * Delay between retries in milliseconds\n\t * @default 1000\n\t */\n\tretryDelay?: number | ((currentAttemptCount: number) => number);\n\n\t/**\n\t * Maximum delay in milliseconds. Only applies to exponential strategy\n\t * @default 10000\n\t */\n\tretryMaxDelay?: number;\n\n\t/**\n\t * HTTP methods that are allowed to retry\n\t * @default [\"GET\", \"POST\"]\n\t */\n\tretryMethods?: MethodUnion[];\n\n\t/**\n\t * HTTP status codes that trigger a retry\n\t */\n\tretryStatusCodes?: number[];\n\n\t/**\n\t * Strategy to use when retrying\n\t * @default \"linear\"\n\t */\n\tretryStrategy?: \"exponential\" | \"linear\";\n}\n\nconst getLinearDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? options.retry?.delay;\n\n\tconst resolveRetryDelay =\n\t\t(isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay) ?? retryDefaults.delay;\n\n\treturn resolveRetryDelay;\n};\n\nconst getExponentialDelay = (currentAttemptCount: number, options: RetryOptions<unknown>) => {\n\tconst retryDelay = options.retryDelay ?? options.retry?.delay ?? retryDefaults.delay;\n\n\tconst resolvedRetryDelay = isFunction(retryDelay) ? retryDelay(currentAttemptCount) : retryDelay;\n\n\tconst maxDelay = options.retryMaxDelay ?? options.retry?.maxDelay ?? retryDefaults.maxDelay;\n\n\tconst exponentialDelay = resolvedRetryDelay * 2 ** currentAttemptCount;\n\n\treturn Math.min(exponentialDelay, maxDelay);\n};\n\nexport const createRetryStrategy = (ctx: ErrorContext<unknown> & RequestContext) => {\n\tconst { options } = ctx;\n\n\t// eslint-disable-next-line ts-eslint/no-deprecated -- Allowed for internal use\n\tconst currentAttemptCount = options[\"~retryAttemptCount\"] ?? 1;\n\n\tconst retryStrategy = options.retryStrategy ?? options.retry?.strategy ?? retryDefaults.strategy;\n\n\tconst getDelay = () => {\n\t\tswitch (retryStrategy) {\n\t\t\tcase \"exponential\": {\n\t\t\t\treturn getExponentialDelay(currentAttemptCount, options);\n\t\t\t}\n\t\t\tcase \"linear\": {\n\t\t\t\treturn getLinearDelay(currentAttemptCount, options);\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(`Invalid retry strategy: ${String(retryStrategy)}`);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst shouldAttemptRetry = async () => {\n\t\tconst retryCondition = options.retryCondition ?? options.retry?.condition ?? retryDefaults.condition;\n\n\t\tconst maximumRetryAttempts =\n\t\t\toptions.retryAttempts ?? options.retry?.attempts ?? retryDefaults.attempts;\n\n\t\tconst customRetryCondition = await retryCondition(ctx);\n\n\t\tconst baseShouldRetry = maximumRetryAttempts >= currentAttemptCount && customRetryCondition;\n\n\t\tif (!baseShouldRetry) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst retryMethods = new Set(\n\t\t\toptions.retryMethods ?? options.retry?.methods ?? retryDefaults.methods\n\t\t);\n\n\t\tconst resolvedMethod = ctx.request.method ?? requestOptionDefaults.method;\n\n\t\tconst includesMethod = retryMethods.has(resolvedMethod);\n\n\t\tconst retryStatusCodes = new Set(options.retryStatusCodes ?? options.retry?.statusCodes ?? []);\n\n\t\tconst includesStatusCodes =\n\t\t\tBoolean(ctx.response?.status)\n\t\t\t&& (retryStatusCodes.size > 0 ? retryStatusCodes.has(ctx.response.status) : true);\n\n\t\tconst shouldRetry = includesMethod && includesStatusCodes;\n\n\t\treturn shouldRetry;\n\t};\n\n\treturn {\n\t\tcurrentAttemptCount,\n\t\tgetDelay,\n\t\tshouldAttemptRetry,\n\t};\n};\n","import { requestOptionDefaults } from \"./constants/default-options\";\nimport type { CallApiExtraOptions, CallApiRequestOptions } from \"./types/common\";\nimport type { UnmaskType } from \"./types/type-helpers\";\nimport { toQueryString } from \"./utils\";\nimport { isArray } from \"./utils/guards\";\nimport { type CallApiSchemaConfig, routeKeyMethods } from \"./validation\";\n\nconst slash = \"/\";\nconst column = \":\";\nconst mergeUrlWithParams = (url: string, params: CallApiExtraOptions[\"params\"]) => {\n\tif (!params) {\n\t\treturn url;\n\t}\n\n\tlet newUrl = url;\n\n\tif (isArray(params)) {\n\t\tconst matchedParamArray = newUrl.split(slash).filter((param) => param.startsWith(column));\n\n\t\tfor (const [index, matchedParam] of matchedParamArray.entries()) {\n\t\t\tconst realParam = params[index] as string;\n\t\t\tnewUrl = newUrl.replace(matchedParam, realParam);\n\t\t}\n\n\t\treturn newUrl;\n\t}\n\n\tfor (const [key, value] of Object.entries(params)) {\n\t\tnewUrl = newUrl.replace(`${column}${key}`, String(value));\n\t}\n\n\treturn newUrl;\n};\n\nconst questionMark = \"?\";\nconst ampersand = \"&\";\nconst mergeUrlWithQuery = (url: string, query: CallApiExtraOptions[\"query\"]): string => {\n\tif (!query) {\n\t\treturn url;\n\t}\n\n\tconst queryString = toQueryString(query);\n\n\tif (queryString?.length === 0) {\n\t\treturn url;\n\t}\n\n\tif (url.endsWith(questionMark)) {\n\t\treturn `${url}${queryString}`;\n\t}\n\n\tif (url.includes(questionMark)) {\n\t\treturn `${url}${ampersand}${queryString}`;\n\t}\n\n\treturn `${url}${questionMark}${queryString}`;\n};\n\n/**\n * @description\n * Extracts the method from the URL if it is a schema modifier.\n *\n * @param initURL - The URL to extract the method from.\n * @returns The method if it is a schema modifier, otherwise undefined.\n */\nexport const extractMethodFromURL = (initURL: string | undefined) => {\n\tif (!initURL?.startsWith(\"@\")) return;\n\n\tconst method = initURL.split(\"@\")[1]?.split(\"/\")[0];\n\n\tif (!method || !routeKeyMethods.includes(method)) return;\n\n\treturn method;\n};\n\nexport type GetMethodOptions = {\n\tinitURL: string | undefined;\n\tmethod: CallApiRequestOptions[\"method\"];\n\tschemaConfig?: CallApiSchemaConfig;\n};\n\nexport const getMethod = (options: GetMethodOptions) => {\n\tconst { initURL, method, schemaConfig } = options;\n\n\tif (schemaConfig?.requireMethodProvision === true) {\n\t\treturn method?.toUpperCase() ?? requestOptionDefaults.method;\n\t}\n\n\treturn (\n\t\tmethod?.toUpperCase() ?? extractMethodFromURL(initURL)?.toUpperCase() ?? requestOptionDefaults.method\n\t);\n};\n\nconst normalizeURL = (initURL: string) => {\n\tconst methodFromURL = extractMethodFromURL(initURL);\n\n\tif (!methodFromURL) {\n\t\treturn initURL;\n\t}\n\n\tconst normalizedURL = initURL.replace(`@${methodFromURL}/`, \"/\");\n\n\treturn normalizedURL;\n};\n\ntype GetFullURLOptions = {\n\tbaseURL: string | undefined;\n\tinitURL: string;\n\tparams: CallApiExtraOptions[\"params\"];\n\tquery: CallApiExtraOptions[\"query\"];\n};\n\nexport const getFullURL = (options: GetFullURLOptions) => {\n\tconst { baseURL, initURL, params, query } = options;\n\n\tconst normalizedInitURL = normalizeURL(initURL);\n\n\tconst urlWithMergedParams = mergeUrlWithParams(normalizedInitURL, params);\n\n\tconst urlWithMergedQueryAndParams = mergeUrlWithQuery(urlWithMergedParams, query);\n\n\tconst shouldNotPrependBaseURL = urlWithMergedQueryAndParams.startsWith(\"http\") || !baseURL;\n\n\tconst fullURL =\n\t\tshouldNotPrependBaseURL ? urlWithMergedQueryAndParams : `${baseURL}${urlWithMergedQueryAndParams}`;\n\n\treturn {\n\t\tfullURL,\n\t\tnormalizedInitURL,\n\t};\n};\n\nexport type AllowedQueryParamValues = UnmaskType<boolean | number | string>;\n\nexport type Params = UnmaskType<\n\t// eslint-disable-next-line perfectionist/sort-union-types -- I need the Record to be first\n\tRecord<string, AllowedQueryParamValues> | AllowedQueryParamValues[]\n>;\n\nexport type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;\n\nexport type InitURLOrURLObject = string | URL;\n\nexport interface URLOptions {\n\t/**\n\t * Base URL to be prepended to all request URLs\n\t */\n\tbaseURL?: string;\n\n\t/**\n\t * Resolved request URL\n\t */\n\treadonly fullURL?: string;\n\n\t/**\n\t * The url string passed to the callApi instance\n\t */\n\treadonly initURL?: string;\n\n\t/**\n\t * The URL string passed to the callApi instance, but normalized (removed any method modifiers etc)\n\t */\n\treadonly initURLNormalized?: string;\n\n\t/**\n\t * Parameters to be appended to the URL (i.e: /:id)\n\t *\n\t * If url is defined as `/path/:id`, params will be `{ id: string }`\n\t */\n\tparams?: Params;\n\n\t/**\n\t * Query parameters to append to the URL.\n\t */\n\tquery?: Query;\n}\n","import { createDedupeStrategy, getAbortErrorMessage, type RequestInfoCache } from \"./dedupe\";\nimport { HTTPError } from \"./error\";\nimport {\n\ttype ErrorContext,\n\ttype ExecuteHookInfo,\n\texecuteHooksInCatchBlock,\n\texecuteHooksInTryBlock,\n\ttype RetryContext,\n\ttype SuccessContext,\n} from \"./hooks\";\nimport { type CallApiPlugin, initializePlugins } from \"./plugins\";\nimport {\n\ttype ErrorInfo,\n\tgetCustomizedErrorResult,\n\ttype ResponseTypeUnion,\n\ttype ResultModeUnion,\n\tresolveErrorResult,\n\tresolveResponseData,\n\tresolveSuccessResult,\n} from \"./result\";\nimport { createRetryStrategy } from \"./retry\";\nimport type {\n\tGetCurrentRouteSchema,\n\tGetCurrentRouteSchemaKey,\n\tInferHeadersOption,\n\tInferInitURL,\n\tThrowOnErrorUnion,\n} from \"./types\";\nimport type {\n\tBaseCallApiConfig,\n\tBaseCallApiExtraOptions,\n\tCallApiExtraOptions,\n\tCallApiExtraOptionsForHooks,\n\tCallApiParameters,\n\tCallApiRequestOptions,\n\tCallApiRequestOptionsForHooks,\n\tCallApiResult,\n} from \"./types/common\";\nimport type { DefaultDataType, DefaultPluginArray, DefaultThrowOnError } from \"./types/default-types\";\nimport type { AnyFunction, Writeable } from \"./types/type-helpers\";\nimport { getFullURL, getMethod } from \"./url\";\nimport {\n\tcreateCombinedSignal,\n\tcreateTimeoutSignal,\n\tgetBody,\n\tgetHeaders,\n\tsplitBaseConfig,\n\tsplitConfig,\n\twaitFor,\n} from \"./utils/common\";\nimport { isFunction, isHTTPErrorInstance, isValidationErrorInstance } from \"./utils/guards\";\nimport {\n\ttype BaseCallApiSchemaAndConfig,\n\ttype BaseCallApiSchemaRoutes,\n\ttype CallApiSchema,\n\ttype CallApiSchemaConfig,\n\thandleConfigValidation,\n\thandleValidation,\n\ttype InferSchemaResult,\n} from \"./validation\";\n\nconst $GlobalRequestInfoCache: RequestInfoCache = new Map();\n\nexport const createFetchClient = <\n\tTBaseData = DefaultDataType,\n\tTBaseErrorData = DefaultDataType,\n\tTBaseResultMode extends ResultModeUnion = ResultModeUnion,\n\tTBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n\tTBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tconst TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig,\n\tconst TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTComputedBaseSchemaConfig extends CallApiSchemaConfig = NonNullable<\n\t\tWriteable<TBaseSchemaAndConfig[\"config\"], \"deep\">\n\t>,\n\tTComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = NonNullable<\n\t\tWriteable<TBaseSchemaAndConfig[\"routes\"], \"deep\">\n\t>,\n>(\n\tinitBaseConfig: BaseCallApiConfig<\n\t\tTBaseData,\n\t\tTBaseErrorData,\n\t\tTBaseResultMode,\n\t\tTBaseThrowOnError,\n\t\tTBaseResponseType,\n\t\tTBaseSchemaAndConfig,\n\t\tTBasePluginArray\n\t> = {} as never\n) => {\n\tconst $LocalRequestInfoCache: RequestInfoCache = new Map();\n\n\tconst callApi = async <\n\t\tTData = TBaseData,\n\t\tTErrorData = TBaseErrorData,\n\t\tTResultMode extends ResultModeUnion = TBaseResultMode,\n\t\tTThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError,\n\t\tTResponseType extends ResponseTypeUnion = TBaseResponseType,\n\t\tconst TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig,\n\t\tTInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTSchemaConfig\n\t\t>,\n\t\tTCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<\n\t\t\tTSchemaConfig,\n\t\t\tTInitURL\n\t\t> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>,\n\t\tconst TSchema extends GetCurrentRouteSchema<\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTCurrentRouteSchemaKey\n\t\t> = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>,\n\t\tconst TPluginArray extends CallApiPlugin[] = TBasePluginArray,\n\t>(\n\t\t...parameters: CallApiParameters<\n\t\t\tInferSchemaResult<TSchema[\"data\"], TData>,\n\t\t\tInferSchemaResult<TSchema[\"errorData\"], TErrorData>,\n\t\t\tTResultMode,\n\t\t\tTThrowOnError,\n\t\t\tTResponseType,\n\t\t\tTComputedBaseSchemaRoutes,\n\t\t\tTSchema,\n\t\t\tTComputedBaseSchemaConfig,\n\t\t\tTSchemaConfig,\n\t\t\tTInitURL,\n\t\t\tTCurrentRouteSchemaKey,\n\t\t\tTBasePluginArray,\n\t\t\tTPluginArray\n\t\t>\n\t): CallApiResult<\n\t\tInferSchemaResult<TSchema[\"data\"], TData>,\n\t\tInferSchemaResult<TSchema[\"errorData\"], TErrorData>,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType\n\t> => {\n\t\tconst [initURLOrURLObject, initConfig = {}] = parameters;\n\n\t\tconst [fetchOptions, extraOptions] = splitConfig(initConfig);\n\n\t\tconst resolvedBaseConfig =\n\t\t\tisFunction(initBaseConfig) ?\n\t\t\t\tinitBaseConfig({\n\t\t\t\t\tinitURL: initURLOrURLObject.toString(),\n\t\t\t\t\toptions: extraOptions,\n\t\t\t\t\trequest: fetchOptions,\n\t\t\t\t})\n\t\t\t:\tinitBaseConfig;\n\n\t\tconst baseConfig = resolvedBaseConfig as BaseCallApiExtraOptions & CallApiRequestOptions;\n\t\tconst config = initConfig as CallApiExtraOptions & CallApiRequestOptions;\n\n\t\tconst [baseFetchOptions, baseExtraOptions] = splitBaseConfig(baseConfig);\n\n\t\tconst shouldSkipAutoMergeForOptions =\n\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"options\";\n\n\t\tconst shouldSkipAutoMergeForRequest =\n\t\t\tbaseExtraOptions.skipAutoMergeFor === \"all\" || baseExtraOptions.skipAutoMergeFor === \"request\";\n\n\t\t// == Merged Extra Options\n\t\tconst mergedExtraOptions = {\n\t\t\t...baseExtraOptions,\n\t\t\t...(!shouldSkipAutoMergeForOptions && extraOptions),\n\t\t};\n\n\t\t// == Merged Request Options\n\t\tconst mergedRequestOptions = {\n\t\t\t// == Making sure headers is always an object\n\t\t\theaders: {},\n\t\t\t...baseFetchOptions,\n\t\t\t...(!shouldSkipAutoMergeForRequest && fetchOptions),\n\t\t} satisfies CallApiRequestOptions;\n\n\t\tconst {\n\t\t\tresolvedCurrentRouteSchemaKey,\n\t\t\tresolvedHooks,\n\t\t\tresolvedInitURL,\n\t\t\tresolvedOptions,\n\t\t\tresolvedRequestOptions,\n\t\t} = await initializePlugins({\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tinitURL: initURLOrURLObject.toString(),\n\t\t\toptions: mergedExtraOptions as CallApiExtraOptionsForHooks,\n\t\t\trequest: mergedRequestOptions as CallApiRequestOptionsForHooks,\n\t\t});\n\n\t\tconst { fullURL, normalizedInitURL } = getFullURL({\n\t\t\tbaseURL: resolvedOptions.baseURL,\n\t\t\tinitURL: resolvedInitURL,\n\t\t\tparams: resolvedOptions.params,\n\t\t\tquery: resolvedOptions.query,\n\t\t});\n\n\t\tlet options = {\n\t\t\t...resolvedOptions,\n\t\t\t...resolvedHooks,\n\n\t\t\tfullURL,\n\t\t\tinitURL: resolvedInitURL,\n\t\t\tinitURLNormalized: normalizedInitURL,\n\t\t} satisfies CallApiExtraOptionsForHooks;\n\n\t\tconst newFetchController = new AbortController();\n\n\t\tconst timeoutSignal = options.timeout != null ? createTimeoutSignal(options.timeout) : null;\n\n\t\tconst combinedSignal = createCombinedSignal(\n\t\t\tresolvedRequestOptions.signal,\n\t\t\ttimeoutSignal,\n\t\t\tnewFetchController.signal\n\t\t);\n\n\t\tlet request = {\n\t\t\t...resolvedRequestOptions,\n\n\t\t\tsignal: combinedSignal,\n\t\t} satisfies CallApiRequestOptionsForHooks;\n\n\t\tconst {\n\t\t\tdedupeStrategy,\n\t\t\thandleRequestCancelStrategy,\n\t\t\thandleRequestDeferStrategy,\n\t\t\tremoveDedupeKeyFromCache,\n\t\t} = await createDedupeStrategy({\n\t\t\t$GlobalRequestInfoCache,\n\t\t\t$LocalRequestInfoCache,\n\t\t\tbaseConfig,\n\t\t\tconfig,\n\t\t\tnewFetchController,\n\t\t\toptions,\n\t\t\trequest,\n\t\t});\n\n\t\ttry {\n\t\t\tawait handleRequestCancelStrategy();\n\n\t\t\tawait executeHooksInTryBlock(options.onRequest?.({ baseConfig, config, options, request }));\n\n\t\t\tconst {\n\t\t\t\textraOptionsValidationResult,\n\t\t\t\trequestOptionsValidationResult,\n\t\t\t\tresolvedSchema,\n\t\t\t\tresolvedSchemaConfig,\n\t\t\t\tshouldApplySchemaOutput,\n\t\t\t} = await handleConfigValidation({\n\t\t\t\tbaseExtraOptions,\n\t\t\t\tcurrentRouteSchemaKey: resolvedCurrentRouteSchemaKey,\n\t\t\t\textraOptions,\n\t\t\t\trequestOptions: request,\n\t\t\t});\n\n\t\t\t// == Apply Schema Output for Extra Options\n\t\t\tif (shouldApplySchemaOutput) {\n\t\t\t\toptions = { ...options, ...extraOptionsValidationResult };\n\t\t\t}\n\n\t\t\t// == Apply Schema Output for Request Options\n\t\t\tconst rawBody = shouldApplySchemaOutput ? requestOptionsValidationResult?.body : request.body;\n\n\t\t\tconst validBody = getBody({\n\t\t\t\tbody: rawBody,\n\t\t\t\tbodySerializer: options.bodySerializer,\n\t\t\t});\n\n\t\t\ttype HeaderFn = Extract<InferHeadersOption<CallApiSchema>[\"headers\"], AnyFunction>;\n\n\t\t\tconst resolvedHeaders =\n\t\t\t\tisFunction<HeaderFn>(fetchOptions.headers) ?\n\t\t\t\t\tfetchOptions.headers({ baseHeaders: baseFetchOptions.headers ?? {} })\n\t\t\t\t:\t(fetchOptions.headers ?? baseFetchOptions.headers);\n\n\t\t\tconst validHeaders = await getHeaders({\n\t\t\t\tauth: options.auth,\n\t\t\t\tbody: rawBody,\n\t\t\t\theaders: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : resolvedHeaders,\n\t\t\t});\n\n\t\t\tconst validMethod = getMethod({\n\t\t\t\tinitURL: resolvedInitURL,\n\t\t\t\tmethod: shouldApplySchemaOutput ? requestOptionsValidationResult?.method : request.method,\n\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t});\n\n\t\t\trequest = {\n\t\t\t\t...request,\n\t\t\t\t...(Boolean(validBody) && { body: validBody }),\n\t\t\t\t...(Boolean(validHeaders) && { headers: validHeaders }),\n\t\t\t\t...(Boolean(validMethod) && { method: validMethod }),\n\t\t\t};\n\n\t\t\tconst response = await handleRequestDeferStrategy({ options, request });\n\n\t\t\t// == Also clone response when dedupeStrategy is set to \"defer\" to avoid error thrown from reading response.(whatever) more than once\n\t\t\tconst shouldCloneResponse = dedupeStrategy === \"defer\" || options.cloneResponse;\n\n\t\t\tif (!response.ok) {\n\t\t\t\tconst errorData = await resolveResponseData<TErrorData>(\n\t\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\t\toptions.responseType,\n\t\t\t\t\toptions.responseParser\n\t\t\t\t);\n\n\t\t\t\tconst validErrorData = await handleValidation(resolvedSchema?.errorData, {\n\t\t\t\t\tinputValue: errorData,\n\t\t\t\t\tresponse,\n\t\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t\t});\n\n\t\t\t\t// == Push all error handling responsibilities to the catch block if not retrying\n\t\t\t\tthrow new HTTPError(\n\t\t\t\t\t{\n\t\t\t\t\t\tdefaultHTTPErrorMessage: options.defaultHTTPErrorMessage,\n\t\t\t\t\t\terrorData: validErrorData,\n\t\t\t\t\t\tresponse,\n\t\t\t\t\t},\n\t\t\t\t\t{ cause: validErrorData }\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst successData = await resolveResponseData<TData>(\n\t\t\t\tshouldCloneResponse ? response.clone() : response,\n\t\t\t\toptions.responseType,\n\t\t\t\toptions.responseParser\n\t\t\t);\n\n\t\t\tconst validSuccessData = await handleValidation(resolvedSchema?.data, {\n\t\t\t\tinputValue: successData,\n\t\t\t\tresponse,\n\t\t\t\tschemaConfig: resolvedSchemaConfig,\n\t\t\t});\n\n\t\t\tconst successContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\tdata: validSuccessData,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse,\n\t\t\t} satisfies SuccessContext<unknown>;\n\n\t\t\tawait executeHooksInTryBlock(\n\t\t\t\toptions.onSuccess?.(successContext),\n\n\t\t\t\toptions.onResponse?.({ ...successContext, error: null })\n\t\t\t);\n\n\t\t\tconst successResult = resolveSuccessResult(successContext.data, {\n\t\t\t\tresponse: successContext.response,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t});\n\n\t\t\treturn successResult as never;\n\n\t\t\t// == Exhaustive Error handling\n\t\t} catch (error) {\n\t\t\tconst errorInfo = {\n\t\t\t\tcloneResponse: options.cloneResponse,\n\t\t\t\tresultMode: options.resultMode,\n\t\t\t} satisfies ErrorInfo;\n\n\t\t\tconst generalErrorResult = resolveErrorResult(error, errorInfo);\n\n\t\t\tconst errorContext = {\n\t\t\t\tbaseConfig,\n\t\t\t\tconfig,\n\t\t\t\terror: generalErrorResult?.error as never,\n\t\t\t\toptions,\n\t\t\t\trequest,\n\t\t\t\tresponse: generalErrorResult?.response as never,\n\t\t\t} satisfies ErrorContext<unknown>;\n\n\t\t\tconst shouldThrowOnError = (\n\t\t\t\tisFunction(options.throwOnError) ?\n\t\t\t\t\toptions.throwOnError(errorContext)\n\t\t\t\t:\toptions.throwOnError) as boolean;\n\n\t\t\tconst hookInfo = {\n\t\t\t\terrorInfo,\n\t\t\t\tshouldThrowOnError,\n\t\t\t} satisfies ExecuteHookInfo;\n\n\t\t\tconst handleRetryOrGetErrorResult = async () => {\n\t\t\t\tconst { currentAttemptCount, getDelay, shouldAttemptRetry } =\n\t\t\t\t\tcreateRetryStrategy(errorContext);\n\n\t\t\t\tconst shouldRetry = !combinedSignal.aborted && (await shouldAttemptRetry());\n\n\t\t\t\tif (shouldRetry) {\n\t\t\t\t\tconst retryContext = {\n\t\t\t\t\t\t...errorContext,\n\t\t\t\t\t\tretryAttemptCount: currentAttemptCount,\n\t\t\t\t\t} satisfies RetryContext<unknown>;\n\n\t\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t\t[options.onRetry?.(retryContext)],\n\t\t\t\t\t\thookInfo\n\t\t\t\t\t);\n\n\t\t\t\t\tif (hookError) {\n\t\t\t\t\t\treturn hookError;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst delay = getDelay();\n\n\t\t\t\t\tawait waitFor(delay);\n\n\t\t\t\t\tconst updatedOptions = {\n\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\"~retryAttemptCount\": currentAttemptCount + 1,\n\t\t\t\t\t} satisfies typeof config;\n\n\t\t\t\t\treturn callApi(initURLOrURLObject as never, updatedOptions as never) as never;\n\t\t\t\t}\n\n\t\t\t\tif (shouldThrowOnError) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\n\t\t\t\treturn generalErrorResult;\n\t\t\t};\n\n\t\t\tif (isHTTPErrorInstance<TErrorData>(error)) {\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[\n\t\t\t\t\t\toptions.onResponseError?.(errorContext),\n\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t\toptions.onResponse?.({ ...errorContext, data: null }),\n\t\t\t\t\t],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t}\n\n\t\t\tif (isValidationErrorInstance(error)) {\n\t\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t\t[\n\t\t\t\t\t\toptions.onValidationError?.(errorContext),\n\t\t\t\t\t\toptions.onRequestError?.(errorContext),\n\t\t\t\t\t\toptions.onError?.(errorContext),\n\t\t\t\t\t],\n\t\t\t\t\thookInfo\n\t\t\t\t);\n\n\t\t\t\treturn (hookError ?? (await handleRetryOrGetErrorResult())) as never;\n\t\t\t}\n\n\t\t\tlet message: string | undefined = (error as Error | undefined)?.message;\n\n\t\t\tif (error instanceof DOMException && error.name === \"AbortError\") {\n\t\t\t\tmessage = getAbortErrorMessage(options.dedupeKey, options.fullURL);\n\n\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t}\n\n\t\t\tif (error instanceof DOMException && error.name === \"TimeoutError\") {\n\t\t\t\tmessage = `Request timed out after ${options.timeout}ms`;\n\n\t\t\t\t!shouldThrowOnError && console.error(`${error.name}:`, message);\n\t\t\t}\n\n\t\t\tconst hookError = await executeHooksInCatchBlock(\n\t\t\t\t[options.onRequestError?.(errorContext), options.onError?.(errorContext)],\n\t\t\t\thookInfo\n\t\t\t);\n\n\t\t\treturn (hookError\n\t\t\t\t?? getCustomizedErrorResult(await handleRetryOrGetErrorResult(), { message })) as never;\n\n\t\t\t// == Removing the now unneeded AbortController from store\n\t\t} finally {\n\t\t\tremoveDedupeKeyFromCache();\n\t\t}\n\t};\n\n\treturn callApi;\n};\n\nexport const callApi = createFetchClient();\n","import type { CallApiPlugin } from \"./plugins\";\nimport type { ResponseTypeUnion, ResultModeUnion } from \"./result\";\nimport type { CallApiParameters, InferInitURL, ThrowOnErrorUnion } from \"./types\";\nimport type { DefaultDataType, DefaultPluginArray, DefaultThrowOnError } from \"./types/default-types\";\nimport type { BaseCallApiSchemaRoutes, CallApiSchema, CallApiSchemaConfig } from \"./validation\";\n\nconst defineParameters = <\n\tTData = DefaultDataType,\n\tTErrorData = DefaultDataType,\n\tTResultMode extends ResultModeUnion = ResultModeUnion,\n\tTThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError,\n\tTResponseType extends ResponseTypeUnion = ResponseTypeUnion,\n\tTBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes,\n\tTSchema extends CallApiSchema = CallApiSchema,\n\tTBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig,\n\tTInitURL extends InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig> = InferInitURL<\n\t\tBaseCallApiSchemaRoutes,\n\t\tTSchemaConfig\n\t>,\n\tTCurrentRouteSchemaKey extends string = string,\n\tTBasePluginArray extends CallApiPlugin[] = DefaultPluginArray,\n\tTPluginArray extends CallApiPlugin[] = DefaultPluginArray,\n>(\n\t...parameters: CallApiParameters<\n\t\tTData,\n\t\tTErrorData,\n\t\tTResultMode,\n\t\tTThrowOnError,\n\t\tTResponseType,\n\t\tTBaseSchemaRoutes,\n\t\tTSchema,\n\t\tTBaseSchemaConfig,\n\t\tTSchemaConfig,\n\t\tTInitURL,\n\t\tTCurrentRouteSchemaKey,\n\t\tTBasePluginArray,\n\t\tTPluginArray\n\t>\n) => {\n\treturn parameters;\n};\n\nexport { defineParameters };\n"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ED,OAAI,0BAA0B,MAAM,EAAE;IACrC,MAAMA,cAAY,MAAM,yBACvB;KACC,QAAQ,oBAAoB,aAAa;KACzC,QAAQ,iBAAiB,aAAa;KACtC,QAAQ,UAAU,aAAa;IAC/B,GACD,SACA;AAED,WAAQA,eAAc,MAAM,6BAA6B;GACzD;GAED,IAAIC,UAA+B,OAA6B;AAEhE,OAAI,iBAAiB,gBAAgB,MAAM,SAAS,cAAc;AACjE,cAAU,qBAAqB,QAAQ,WAAW,QAAQ,QAAQ;AAElE,KAAC,sBAAsB,QAAQ,SAAS,MAAM,KAAK,IAAI,QAAQ;GAC/D;AAED,OAAI,iBAAiB,gBAAgB,MAAM,SAAS,gBAAgB;AACnE,eAAW,0BAA0B,QAAQ,QAAQ;AAErD,KAAC,sBAAsB,QAAQ,SAAS,MAAM,KAAK,IAAI,QAAQ;GAC/D;GAED,MAAM,YAAY,MAAM,yBACvB,CAAC,QAAQ,iBAAiB,aAAa,EAAE,QAAQ,UAAU,aAAa,AAAC,GACzE,SACA;AAED,UAAQ,aACJ,yBAAyB,MAAM,6BAA6B,EAAE,EAAE,QAAS,EAAC;EAG9E,UAAS;AACT,6BAA0B;EAC1B;CACD;AAED,QAAOF;AACP;AAED,MAAa,UAAU,mBAAmB;;;;ACvd1C,MAAM,mBAAmB,CAkBxB,GAAG,eAeC;AACJ,QAAO;AACP"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { CallApiExtraOptions, CallApiResultErrorVariant, HTTPError, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, ValidationError } from "../common-
|
1
|
+
import { CallApiExtraOptions, CallApiResultErrorVariant, HTTPError, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, ValidationError } from "../common-Bw8cm62H.js";
|
2
2
|
|
3
3
|
//#region src/utils/common.d.ts
|
4
4
|
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@zayne-labs/callapi",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.8.
|
4
|
+
"version": "1.8.16",
|
5
5
|
"description": "A lightweight wrapper over fetch with quality of life improvements like built-in request cancellation, retries, interceptors and more",
|
6
6
|
"author": "Ryan Zayne",
|
7
7
|
"license": "MIT",
|
@@ -57,7 +57,7 @@
|
|
57
57
|
"size-limit": [
|
58
58
|
{
|
59
59
|
"path": "./src/index.ts",
|
60
|
-
"limit": "5.
|
60
|
+
"limit": "5.8 kb"
|
61
61
|
},
|
62
62
|
{
|
63
63
|
"path": "./src/utils/index.ts",
|