@zayne-labs/callapi 1.8.1 → 1.8.3

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.
@@ -74,27 +74,6 @@ type Auth = BearerOrTokenAuth | BasicAuth | CustomAuth;
74
74
  //#region src/constants/common.d.ts
75
75
  declare const fetchSpecificKeys: (keyof RequestInit | "duplex")[];
76
76
  //#endregion
77
- //#region src/error.d.ts
78
- type ErrorDetails<TErrorData> = {
79
- defaultErrorMessage: CallApiExtraOptions["defaultErrorMessage"];
80
- errorData: TErrorData;
81
- response: Response;
82
- };
83
- declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
84
- errorData: ErrorDetails<TErrorData>["errorData"];
85
- httpErrorSymbol: symbol;
86
- isHTTPError: boolean;
87
- name: "HTTPError";
88
- response: ErrorDetails<TErrorData>["response"];
89
- constructor(errorDetails: ErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
90
- /**
91
- * @description Checks if the given error is an instance of HTTPError
92
- * @param error - The error to check
93
- * @returns true if the error is an instance of HTTPError, false otherwise
94
- */
95
- static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
96
- }
97
- //#endregion
98
77
  //#region src/types/standard-schema.d.ts
99
78
  /**
100
79
  * The Standard Schema interface.
@@ -195,16 +174,34 @@ declare namespace StandardSchemaV1 {
195
174
  type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
196
175
  }
197
176
  //#endregion
198
- //#region src/validation.d.ts
199
- type InferSchemaResult<TSchema, TFallbackResult = NonNullable<unknown>> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? TResult : TFallbackResult;
177
+ //#region src/error.d.ts
178
+ type HTTPErrorDetails<TErrorData> = {
179
+ defaultErrorMessage: CallApiExtraOptions["defaultErrorMessage"];
180
+ errorData: TErrorData;
181
+ response: Response;
182
+ };
183
+ declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
184
+ errorData: HTTPErrorDetails<TErrorData>["errorData"];
185
+ httpErrorSymbol: symbol;
186
+ isHTTPError: boolean;
187
+ name: "HTTPError";
188
+ response: HTTPErrorDetails<TErrorData>["response"];
189
+ constructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
190
+ /**
191
+ * @description Checks if the given error is an instance of HTTPError
192
+ * @param error - The error to check
193
+ * @returns true if the error is an instance of HTTPError, false otherwise
194
+ */
195
+ static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
196
+ }
200
197
  type ValidationErrorDetails = {
201
198
  issues: readonly StandardSchemaV1.Issue[];
202
199
  response: Response | null;
203
200
  };
204
201
  declare class ValidationError extends Error {
205
- errorData: readonly StandardSchemaV1.Issue[];
202
+ errorData: ValidationErrorDetails["issues"];
206
203
  name: string;
207
- response: Response | null;
204
+ response: ValidationErrorDetails["response"];
208
205
  validationErrorSymbol: symbol;
209
206
  constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
210
207
  /**
@@ -214,6 +211,9 @@ declare class ValidationError extends Error {
214
211
  */
215
212
  static isError(error: unknown): error is ValidationError;
216
213
  }
214
+ //#endregion
215
+ //#region src/validation.d.ts
216
+ type InferSchemaResult<TSchema, TFallbackResult = NonNullable<unknown>> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
217
217
  interface CallApiSchemaConfig {
218
218
  /**
219
219
  * The base url of the schema. By default it's the baseURL of the fetch instance.
@@ -299,7 +299,7 @@ type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
299
299
  type Params = UnmaskType<Record<string, AllowedQueryParamValues> | AllowedQueryParamValues[]>;
300
300
  type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;
301
301
  type InitURLOrURLObject = string | URL;
302
- interface UrlOptions {
302
+ interface URLOptions {
303
303
  /**
304
304
  * Base URL to be prepended to all request URLs
305
305
  */
@@ -571,6 +571,13 @@ type ResponseStreamContext = UnmaskType<RequestContext & {
571
571
  //#endregion
572
572
  //#region src/dedupe.d.ts
573
573
  type DedupeOptions = {
574
+ /**
575
+ * Defines the scope of the deduplication cache, can be set to "global" | "local".
576
+ * - If set to "global", the deduplication cache will be shared across all requests, regardless of whether they shared the same `createFetchClient` or not.
577
+ * - If set to "local", the deduplication cache will be scoped to the current request.
578
+ * @default "local"
579
+ */
580
+ dedupeCacheScope?: "global" | "local";
574
581
  /**
575
582
  * Custom request key to be used to identify a request in the fetch deduplication strategy.
576
583
  * @default the full request url + string formed from the request options
@@ -669,7 +676,7 @@ type InferMethodOption<TSchema extends CallApiSchema, TSchemaConfig extends Call
669
676
  */
670
677
  method?: InferSchemaResult<TSchema["method"], InferMethodFromURL<TInitURL>>;
671
678
  }>>;
672
- type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | RequestInit["headers"]>;
679
+ type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | RequestInit["headers"]>;
673
680
  type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequired<TSchema["headers"], {
674
681
  /**
675
682
  * Headers to be used in the request.
@@ -837,7 +844,7 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
837
844
  * Request timeout in milliseconds
838
845
  */
839
846
  timeout?: number;
840
- } & DedupeOptions & HooksOrHooksArray<TData, TErrorData, Partial<InferPluginOptions<TPluginArray>>> & Partial<InferPluginOptions<TPluginArray>> & RetryOptions<TErrorData> & ResultModeOption<TErrorData, TResultMode> & ThrowOnErrorOption<TErrorData> & UrlOptions;
847
+ } & DedupeOptions & HooksOrHooksArray<TData, TErrorData, Partial<InferPluginOptions<TPluginArray>>> & Partial<InferPluginOptions<TPluginArray>> & RetryOptions<TErrorData> & ResultModeOption<TErrorData, TResultMode> & ThrowOnErrorOption<TErrorData> & URLOptions;
841
848
  type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig> = SharedExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
842
849
  baseURL?: string;
843
850
  /**
@@ -874,7 +881,7 @@ type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = Defau
874
881
  */
875
882
  skipAutoMergeFor?: "all" | "options" | "request";
876
883
  };
877
- type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchema extends CallApiSchema = CallApiSchema, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteKey extends string = string> = SharedExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
884
+ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteKey extends string = string> = SharedExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
878
885
  /**
879
886
  * An array of instance CallApi plugins. It allows you to extend the behavior of the library.
880
887
  */
@@ -896,14 +903,14 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
896
903
  }) => Writeable<TSchemaConfig, "deep">);
897
904
  };
898
905
  interface CombinedCallApiExtraOptions extends Omit<CallApiExtraOptions, keyof Hooks>, Hooks {}
899
- type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchema, TBaseSchemaConfig>) | ((context: {
906
+ type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchema, TBaseSchemaConfig>) | ((context: {
900
907
  initURL: string;
901
908
  options: CallApiExtraOptions;
902
909
  request: CallApiRequestOptions;
903
910
  }) => CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchema, TBaseSchemaConfig>);
904
- type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchema extends CallApiSchema = CallApiSchema, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends string = string> = InferExtraOptions<TSchema, TCurrentRouteKey> & InferRequestOptions<TSchema, TSchemaConfig, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchema, TBaseSchemaConfig, TSchema, TSchemaConfig, TCurrentRouteKey>, keyof InferExtraOptions<CallApiSchema, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, CallApiSchemaConfig, string>>;
905
- type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchema extends CallApiSchema = CallApiSchema, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends string = string> = [initURL: TInitURL, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchema, TBaseSchemaConfig, TSchema, TSchemaConfig, TInitURL, TCurrentRouteKey>];
911
+ type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema, TCurrentRouteKey> & InferRequestOptions<TSchema, TSchemaConfig, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchema, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteKey>, keyof InferExtraOptions<CallApiSchema, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, CallApiSchemaConfig, string>>;
912
+ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = [initURL: TInitURL, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchema, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteKey, TBasePluginArray, TPluginArray>];
906
913
  type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
907
914
  //#endregion
908
- export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchema, CallApiConfig, CallApiExtraOptions, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, CombinedCallApiExtraOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamFromPath, InferSchemaResult, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ValidationError, definePlugin, defineSchema };
909
- //# sourceMappingURL=common-B_Me8xq2.d.ts.map
915
+ export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchema, CallApiConfig, CallApiExtraOptions, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, CombinedCallApiExtraOptions, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamFromPath, InferSchemaResult, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, URLOptions, ValidationError, definePlugin, defineSchema };
916
+ //# sourceMappingURL=common-B3EViRqL.d.ts.map
@@ -1,12 +1,12 @@
1
- import { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchema, CallApiConfig, CallApiExtraOptions, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, CombinedCallApiExtraOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamFromPath, InferSchemaResult, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ValidationError, definePlugin, defineSchema } from "./common-B_Me8xq2.js";
1
+ import { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchema, CallApiConfig, CallApiExtraOptions, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, CombinedCallApiExtraOptions, DedupeOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamFromPath, InferSchemaResult, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, URLOptions, ValidationError, definePlugin, defineSchema } from "./common-B3EViRqL.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 boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, const TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchema, TBaseSchemaConfig>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends boolean = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, TSchemaConfig extends CallApiSchemaConfig = TBaseSchemaConfig, TInitURL extends InferInitURL<TBaseSchema, TSchemaConfig> = InferInitURL<TBaseSchema, TSchemaConfig>, TCurrentRouteKey extends GetCurrentRouteKey<TSchemaConfig, TInitURL> = GetCurrentRouteKey<TSchemaConfig, TInitURL>, TComputedRouteSchema extends CallApiSchema = NonNullable<TBaseSchema[TCurrentRouteKey]>, TSchema extends CallApiSchema = TComputedRouteSchema, TPluginArray extends CallApiPlugin[] = TBasePluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchema, TBaseSchemaConfig, TSchema, TSchemaConfig, TInitURL, TCurrentRouteKey> | 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 boolean = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends GetCurrentRouteKey<TSchemaConfig, TInitURL> = GetCurrentRouteKey<TSchemaConfig, TInitURL>, TComputedRouteSchema extends CallApiSchema = NonNullable<BaseCallApiSchema[TCurrentRouteKey]>, TSchema extends CallApiSchema = TComputedRouteSchema, TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, DefaultPluginArray, TPluginArray, BaseCallApiSchema, CallApiSchemaConfig, TSchema, TSchemaConfig, TInitURL, TCurrentRouteKey> | undefined) => CallApiResult<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
5
+ declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, const TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchema, TBaseSchemaConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends boolean = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, TSchemaConfig extends CallApiSchemaConfig = TBaseSchemaConfig, TInitURL extends InferInitURL<TBaseSchema, TSchemaConfig> = InferInitURL<TBaseSchema, TSchemaConfig>, TCurrentRouteKey extends GetCurrentRouteKey<TSchemaConfig, TInitURL> = GetCurrentRouteKey<TSchemaConfig, TInitURL>, TSchema extends CallApiSchema = NonNullable<TBaseSchema[TCurrentRouteKey]>, TPluginArray extends CallApiPlugin[] = TBasePluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, TBaseSchema, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteKey, 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 boolean = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends GetCurrentRouteKey<TSchemaConfig, TInitURL> = GetCurrentRouteKey<TSchemaConfig, TInitURL>, TSchema extends CallApiSchema = NonNullable<BaseCallApiSchema[TCurrentRouteKey]>, TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(initURL: TInitURL, config?: CallApiConfig<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, BaseCallApiSchema, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteKey, DefaultPluginArray, TPluginArray> | undefined) => CallApiResult<InferSchemaResult<TSchema["data"], TData>, InferSchemaResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
7
7
  //#endregion
8
8
  //#region src/defineParameters.d.ts
9
- declare const defineParameters: <TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchema extends CallApiSchema = CallApiSchema, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends string = string>(...parameters: CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchema, TBaseSchemaConfig, TSchema, TSchemaConfig, TInitURL, TCurrentRouteKey>) => CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchema, TBaseSchemaConfig, TSchema, TSchemaConfig, TInitURL, TCurrentRouteKey>;
9
+ declare const defineParameters: <TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(...parameters: CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchema, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteKey, TBasePluginArray, TPluginArray>) => CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchema, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteKey, TBasePluginArray, TPluginArray>;
10
10
  //#endregion
11
- export { BaseCallApiExtraOptions, BaseCallApiSchema, CallApiExtraOptions, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, CombinedCallApiExtraOptions, ErrorContext, HTTPError, Hooks, HooksOrHooksArray, InferParamFromPath, InferSchemaResult, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ValidationError, callApi, createFetchClient, defineParameters, definePlugin, defineSchema };
11
+ export { BaseCallApiExtraOptions, BaseCallApiSchema, CallApiExtraOptions, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, CombinedCallApiExtraOptions, DedupeOptions, ErrorContext, HTTPError, Hooks, HooksOrHooksArray, InferParamFromPath, InferSchemaResult, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, URLOptions, ValidationError, callApi, createFetchClient, defineParameters, definePlugin, defineSchema };
12
12
  //# sourceMappingURL=index.d.ts.map
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { HTTPError, ValidationError, commonDefaults, createCombinedSignal, createTimeoutSignal, dedupeDefaults, defineSchema, getBody, getFetchImpl, getHeaders, handleOptionsValidation, handleValidation, hookDefaults, isArray, isFunction, isHTTPError, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, requestOptionDefaults, responseDefaults, retryDefaults, routeKeyMethods, splitBaseConfig, splitConfig, toQueryString, waitFor } from "./utils-D6Sax78G.js";
1
+ import { HTTPError, ValidationError, commonDefaults, createCombinedSignal, createTimeoutSignal, dedupeDefaults, defineEnum, getBody, getFetchImpl, getHeaders, hookDefaults, isArray, isFunction, isHTTPError, isHTTPErrorInstance, isObject, isPlainObject, isReadableStream, isString, isValidationErrorInstance, requestOptionDefaults, responseDefaults, retryDefaults, splitBaseConfig, splitConfig, toQueryString, waitFor } from "./utils-BbmhntpS.js";
2
2
 
3
3
  //#region src/result.ts
4
4
  const getResponseType = (response, parser) => ({
@@ -248,7 +248,7 @@ const getAbortErrorMessage = (dedupeKey, fullURL) => {
248
248
  return dedupeKey ? `Duplicate request detected - Aborting previous request with key '${dedupeKey}' as a new request was initiated` : `Duplicate request detected - Aborting previous request to '${fullURL}' as a new request with identical options was initiated`;
249
249
  };
250
250
  const createDedupeStrategy = async (context) => {
251
- const { $RequestInfoCache, baseConfig, config, newFetchController, options: globalOptions, request: globalRequest } = context;
251
+ const { $GlobalRequestInfoCache: $GlobalRequestInfoCache$1, $LocalRequestInfoCache, baseConfig, config, newFetchController, options: globalOptions, request: globalRequest } = context;
252
252
  const dedupeStrategy = globalOptions.dedupeStrategy ?? dedupeDefaults.dedupeStrategy;
253
253
  const generateDedupeKey = () => {
254
254
  const shouldHaveDedupeKey = dedupeStrategy === "cancel" || dedupeStrategy === "defer";
@@ -259,6 +259,11 @@ const createDedupeStrategy = async (context) => {
259
259
  })}`;
260
260
  };
261
261
  const dedupeKey = globalOptions.dedupeKey ?? generateDedupeKey();
262
+ const dedupeCacheScope = globalOptions.dedupeCacheScope ?? dedupeDefaults.dedupeCacheScope;
263
+ const $RequestInfoCache = {
264
+ global: $GlobalRequestInfoCache$1,
265
+ local: $LocalRequestInfoCache
266
+ }[dedupeCacheScope];
262
267
  const $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;
263
268
  /******
264
269
  * == Add a small delay to the execution to ensure proper request deduplication when multiple requests with the same key start simultaneously.
@@ -274,24 +279,25 @@ const createDedupeStrategy = async (context) => {
274
279
  prevRequestInfo.controller.abort(reason);
275
280
  return Promise.resolve();
276
281
  };
277
- const handleRequestDeferStrategy = async (options, request) => {
278
- const fetchApi = getFetchImpl(options.customFetchImpl);
282
+ const handleRequestDeferStrategy = async (deferContext) => {
283
+ const { options: localOptions, request: localRequest } = deferContext;
284
+ const fetchApi = getFetchImpl(localOptions.customFetchImpl);
279
285
  const shouldUsePromiseFromCache = prevRequestInfo && dedupeStrategy === "defer";
280
- const requestObjectForStream = isReadableStream(request.body) ? {
281
- ...request,
282
- duplex: request.duplex ?? "half"
283
- } : request;
284
- const requestInstance = new Request(options.fullURL, requestObjectForStream);
286
+ const requestObjectForStream = isReadableStream(localRequest.body) ? {
287
+ ...localRequest,
288
+ duplex: localRequest.duplex ?? "half"
289
+ } : localRequest;
290
+ const requestInstance = new Request(localOptions.fullURL, requestObjectForStream);
285
291
  await toStreamableRequest({
286
292
  baseConfig,
287
293
  config,
288
- options,
289
- request,
294
+ options: localOptions,
295
+ request: localRequest,
290
296
  requestInstance: requestInstance.clone()
291
297
  });
292
298
  const getFetchApiPromise = () => {
293
- if (isReadableStream(request.body)) return fetchApi(requestInstance.clone());
294
- return fetchApi(options.fullURL, request);
299
+ if (isReadableStream(localRequest.body)) return fetchApi(requestInstance.clone());
300
+ return fetchApi(localOptions.fullURL, localRequest);
295
301
  };
296
302
  const responsePromise = shouldUsePromiseFromCache ? prevRequestInfo.responsePromise : getFetchApiPromise();
297
303
  $RequestInfoCacheOrNull?.set(dedupeKey, {
@@ -301,8 +307,8 @@ const createDedupeStrategy = async (context) => {
301
307
  const streamableResponse = toStreamableResponse({
302
308
  baseConfig,
303
309
  config,
304
- options,
305
- request,
310
+ options: localOptions,
311
+ request: localRequest,
306
312
  response: await responsePromise
307
313
  });
308
314
  return streamableResponse;
@@ -439,6 +445,105 @@ const createRetryStrategy = (ctx) => {
439
445
  };
440
446
  };
441
447
 
448
+ //#endregion
449
+ //#region src/validation.ts
450
+ const handleValidatorFunction = async (validator, inputData) => {
451
+ try {
452
+ const result = await validator(inputData);
453
+ return {
454
+ issues: void 0,
455
+ value: result
456
+ };
457
+ } catch (error) {
458
+ return {
459
+ issues: error,
460
+ value: void 0
461
+ };
462
+ }
463
+ };
464
+ const standardSchemaParser = async (schema, inputData, response) => {
465
+ const result = isFunction(schema) ? await handleValidatorFunction(schema, inputData) : await schema["~standard"].validate(inputData);
466
+ if (result.issues) throw new ValidationError({
467
+ issues: result.issues,
468
+ response: response ?? null
469
+ }, { cause: result.issues });
470
+ return result.value;
471
+ };
472
+ const routeKeyMethods = defineEnum([
473
+ "delete",
474
+ "get",
475
+ "patch",
476
+ "post",
477
+ "put"
478
+ ]);
479
+ const defineSchema = (baseSchema) => {
480
+ return baseSchema;
481
+ };
482
+ const handleValidation = async (schema, validationOptions) => {
483
+ const { inputValue, response, schemaConfig } = validationOptions;
484
+ if (!schema || schemaConfig?.disableRuntimeValidation) return inputValue;
485
+ const validResult = await standardSchemaParser(schema, inputValue, response);
486
+ return validResult;
487
+ };
488
+ const extraOptionsToBeValidated = [
489
+ "meta",
490
+ "params",
491
+ "query"
492
+ ];
493
+ const handleExtraOptionsValidation = async (validationOptions) => {
494
+ const { extraOptions, schema, schemaConfig } = validationOptions;
495
+ const validationResultArray = await Promise.all(extraOptionsToBeValidated.map((propertyKey) => handleValidation(schema?.[propertyKey], {
496
+ inputValue: extraOptions[propertyKey],
497
+ schemaConfig
498
+ })));
499
+ const validatedResultObject = {};
500
+ for (const [index, propertyKey] of extraOptionsToBeValidated.entries()) {
501
+ const validationResult = validationResultArray[index];
502
+ if (validationResult === void 0) continue;
503
+ validatedResultObject[propertyKey] = validationResult;
504
+ }
505
+ return validatedResultObject;
506
+ };
507
+ const requestOptionsToBeValidated = [
508
+ "body",
509
+ "headers",
510
+ "method"
511
+ ];
512
+ const handleRequestOptionsValidation = async (validationOptions) => {
513
+ const { requestOptions, schema, schemaConfig } = validationOptions;
514
+ const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((propertyKey) => handleValidation(schema?.[propertyKey], {
515
+ inputValue: requestOptions[propertyKey],
516
+ schemaConfig
517
+ })));
518
+ const validatedResultObject = {};
519
+ for (const [index, propertyKey] of requestOptionsToBeValidated.entries()) {
520
+ const validationResult = validationResultArray[index];
521
+ if (validationResult === void 0) continue;
522
+ validatedResultObject[propertyKey] = validationResult;
523
+ }
524
+ return validatedResultObject;
525
+ };
526
+ const handleOptionsValidation = async (validationOptions) => {
527
+ const { extraOptions, requestOptions, schema, schemaConfig } = validationOptions;
528
+ if (schemaConfig?.disableRuntimeValidation) return {
529
+ extraOptionsValidationResult: null,
530
+ requestOptionsValidationResult: null
531
+ };
532
+ const [extraOptionsValidationResult, requestOptionsValidationResult] = await Promise.all([handleExtraOptionsValidation({
533
+ extraOptions,
534
+ schema,
535
+ schemaConfig
536
+ }), handleRequestOptionsValidation({
537
+ requestOptions,
538
+ schema,
539
+ schemaConfig
540
+ })]);
541
+ return {
542
+ extraOptionsValidationResult,
543
+ requestOptionsValidationResult
544
+ };
545
+ };
546
+
442
547
  //#endregion
443
548
  //#region src/url.ts
444
549
  const slash = "/";
@@ -507,8 +612,9 @@ const getFullURL = (options) => {
507
612
 
508
613
  //#endregion
509
614
  //#region src/createFetchClient.ts
615
+ const $GlobalRequestInfoCache = /* @__PURE__ */ new Map();
510
616
  const createFetchClient = (initBaseConfig = {}) => {
511
- const $RequestInfoCache = /* @__PURE__ */ new Map();
617
+ const $LocalRequestInfoCache = /* @__PURE__ */ new Map();
512
618
  const callApi$1 = async (...parameters) => {
513
619
  const [initURLOrURLObject, initConfig = {}] = parameters;
514
620
  const [fetchOptions, extraOptions] = splitConfig(initConfig);
@@ -563,7 +669,8 @@ const createFetchClient = (initBaseConfig = {}) => {
563
669
  signal: combinedSignal
564
670
  };
565
671
  const { dedupeStrategy, handleRequestCancelStrategy, handleRequestDeferStrategy, removeDedupeKeyFromCache } = await createDedupeStrategy({
566
- $RequestInfoCache,
672
+ $GlobalRequestInfoCache,
673
+ $LocalRequestInfoCache,
567
674
  baseConfig,
568
675
  config,
569
676
  newFetchController,
@@ -589,15 +696,16 @@ const createFetchClient = (initBaseConfig = {}) => {
589
696
  ...options,
590
697
  ...extraOptionsValidationResult
591
698
  };
699
+ const rawBody = shouldApplySchemaOutput ? requestOptionsValidationResult?.body : request.body;
592
700
  const validBody = getBody({
593
- body: shouldApplySchemaOutput ? requestOptionsValidationResult?.body : request.body,
701
+ body: rawBody,
594
702
  bodySerializer: options.bodySerializer
595
703
  });
704
+ const resolvedHeaders = isFunction(fetchOptions.headers) ? fetchOptions.headers({ baseHeaders: baseFetchOptions.headers ?? {} }) : fetchOptions.headers ?? baseFetchOptions.headers;
596
705
  const validHeaders = await getHeaders({
597
706
  auth: options.auth,
598
- baseHeaders: request.headers,
599
- body: request.body,
600
- headers: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : request.headers
707
+ body: rawBody,
708
+ headers: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : resolvedHeaders
601
709
  });
602
710
  const validMethod = getMethod({
603
711
  initURL: resolvedInitURL,
@@ -610,7 +718,10 @@ const createFetchClient = (initBaseConfig = {}) => {
610
718
  ...Boolean(validHeaders) && { headers: validHeaders },
611
719
  ...Boolean(validMethod) && { method: validMethod }
612
720
  };
613
- const response = await handleRequestDeferStrategy(options, request);
721
+ const response = await handleRequestDeferStrategy({
722
+ options,
723
+ request
724
+ });
614
725
  const shouldCloneResponse = dedupeStrategy === "defer" || options.cloneResponse;
615
726
  if (!response.ok) {
616
727
  const errorData = await resolveResponseData(shouldCloneResponse ? response.clone() : response, options.responseType, options.responseParser);