@zayne-labs/callapi 1.11.10 → 1.11.12

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.
@@ -0,0 +1,30 @@
1
+ import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "../validation-uPnlxhfx.js";
2
+
3
+ //#region src/constants/defaults.d.ts
4
+ declare const extraOptionDefaults: Readonly<Readonly<{
5
+ bodySerializer: {
6
+ (value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
7
+ (value: any, replacer?: (number | string)[] | null, space?: string | number): string;
8
+ };
9
+ defaultHTTPErrorMessage: string;
10
+ dedupeCacheScope: "local";
11
+ dedupeCacheScopeKey: "default";
12
+ dedupeStrategy: "cancel";
13
+ hooksExecutionMode: "parallel";
14
+ responseParser: (text: string, reviver?: (this: any, key: string, value: any) => any) => any;
15
+ responseType: "json";
16
+ resultMode: "all";
17
+ retryAttempts: number;
18
+ retryCondition: () => true;
19
+ retryDelay: number;
20
+ retryMaxDelay: number;
21
+ retryMethods: ("GET" | "POST")[];
22
+ retryStatusCodes: never[];
23
+ retryStrategy: "linear";
24
+ }>>;
25
+ declare const requestOptionDefaults: Readonly<{
26
+ method: "GET";
27
+ }>;
28
+ //#endregion
29
+ export { extraOptionDefaults, fallBackRouteSchemaKey, fetchSpecificKeys, requestOptionDefaults };
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { n as requestOptionDefaults, t as extraOptionDefaults } from "../defaults-BD3B1uIH.js";
2
+ import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "../validation-MjkoG9bG.js";
3
+
4
+ export { extraOptionDefaults, fallBackRouteSchemaKey, fetchSpecificKeys, requestOptionDefaults };
@@ -0,0 +1,28 @@
1
+ //#region src/types/type-helpers.ts
2
+ const defineEnum = (value) => Object.freeze(value);
3
+
4
+ //#endregion
5
+ //#region src/constants/defaults.ts
6
+ const extraOptionDefaults = Object.freeze(defineEnum({
7
+ bodySerializer: JSON.stringify,
8
+ defaultHTTPErrorMessage: "HTTP request failed unexpectedly",
9
+ dedupeCacheScope: "local",
10
+ dedupeCacheScopeKey: "default",
11
+ dedupeStrategy: "cancel",
12
+ hooksExecutionMode: "parallel",
13
+ responseParser: JSON.parse,
14
+ responseType: "json",
15
+ resultMode: "all",
16
+ retryAttempts: 0,
17
+ retryCondition: () => true,
18
+ retryDelay: 1e3,
19
+ retryMaxDelay: 1e4,
20
+ retryMethods: ["GET", "POST"],
21
+ retryStatusCodes: [],
22
+ retryStrategy: "linear"
23
+ }));
24
+ const requestOptionDefaults = defineEnum({ method: "GET" });
25
+
26
+ //#endregion
27
+ export { requestOptionDefaults as n, defineEnum as r, extraOptionDefaults as t };
28
+ //# sourceMappingURL=defaults-BD3B1uIH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults-BD3B1uIH.js","names":[],"sources":["../../src/types/type-helpers.ts","../../src/constants/defaults.ts"],"sourcesContent":["// == These two types allows for adding arbitrary literal types, while still provided autocomplete for defaults.\n\n// == Usually intersection with \"{}\" or \"NonNullable<unknown>\" would make it work fine, but the placeholder with never type is added to make the AnyWhatever type appear last in a given union.\nexport type AnyString = string & NonNullable<unknown>;\nexport type AnyNumber = number & NonNullable<unknown>;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is fine here\nexport type AnyObject = Record<keyof any, any>;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is required here so that one can pass custom function type without type errors\nexport type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;\n\nexport type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };\n\ntype WriteableLevel = \"deep\" | \"shallow\";\n\n/**\n * Makes all properties in an object type writeable (removes readonly modifiers).\n * Supports both shallow and deep modes, and handles special cases like arrays, tuples, and unions.\n * @template TObject - The object type to make writeable\n * @template TVariant - The level of writeable transformation (\"shallow\" | \"deep\")\n */\n\ntype ArrayOrObject = Record<number | string | symbol, unknown> | unknown[] | readonly unknown[];\n\nexport type Writeable<TObject, TLevel extends WriteableLevel = \"shallow\"> =\n\tTObject extends ArrayOrObject ?\n\t\t{\n\t\t\t-readonly [Key in keyof TObject]: TLevel extends \"deep\" ?\n\t\t\t\tNonNullable<TObject[Key]> extends ArrayOrObject ?\n\t\t\t\t\tWriteable<TObject[Key], \"deep\">\n\t\t\t\t:\tTObject[Key]\n\t\t\t:\tTObject[Key];\n\t\t}\n\t:\tTObject;\n\nexport const defineEnum = <const TValue extends object>(value: TValue) =>\n\tObject.freeze(value) as Readonly<Writeable<TValue>>;\n\nexport type UnionToIntersection<TUnion> =\n\t(TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ?\n\t\tTParam\n\t:\tnever;\n\n// == Using this Immediately Indexed Mapped type helper to help show computed type of anything passed to it instead of just the type name\nexport type UnmaskType<TValue> = { _: TValue }[\"_\"];\n\nexport type RemovePrefix<TPrefix extends \"dedupe\" | \"retry\", TKey extends string> =\n\tTKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;\n\nexport type Awaitable<TValue> = Promise<TValue> | TValue;\n\nexport type MatchExactObjectType<TActualObject extends TExpectedObject, TExpectedObject> = {\n\t[Key in keyof TActualObject]: Key extends keyof TExpectedObject ? TActualObject[Key] : never;\n};\n\nexport type CommonRequestHeaders =\n\t| \"Access-Control-Allow-Credentials\"\n\t| \"Access-Control-Allow-Headers\"\n\t| \"Access-Control-Allow-Methods\"\n\t| \"Access-Control-Allow-Origin\"\n\t| \"Access-Control-Expose-Headers\"\n\t| \"Access-Control-Max-Age\"\n\t| \"Age\"\n\t| \"Allow\"\n\t| \"Cache-Control\"\n\t| \"Clear-Site-Data\"\n\t| \"Content-Disposition\"\n\t| \"Content-Encoding\"\n\t| \"Content-Language\"\n\t| \"Content-Length\"\n\t| \"Content-Location\"\n\t| \"Content-Range\"\n\t| \"Content-Security-Policy-Report-Only\"\n\t| \"Content-Security-Policy\"\n\t| \"Cookie\"\n\t| \"Cross-Origin-Embedder-Policy\"\n\t| \"Cross-Origin-Opener-Policy\"\n\t| \"Cross-Origin-Resource-Policy\"\n\t| \"Date\"\n\t| \"ETag\"\n\t| \"Expires\"\n\t| \"Last-Modified\"\n\t| \"Location\"\n\t| \"Permissions-Policy\"\n\t| \"Pragma\"\n\t| \"Retry-After\"\n\t| \"Save-Data\"\n\t| \"Sec-CH-Prefers-Color-Scheme\"\n\t| \"Sec-CH-Prefers-Reduced-Motion\"\n\t| \"Sec-CH-UA-Arch\"\n\t| \"Sec-CH-UA-Bitness\"\n\t| \"Sec-CH-UA-Form-Factor\"\n\t| \"Sec-CH-UA-Full-Version-List\"\n\t| \"Sec-CH-UA-Full-Version\"\n\t| \"Sec-CH-UA-Mobile\"\n\t| \"Sec-CH-UA-Model\"\n\t| \"Sec-CH-UA-Platform-Version\"\n\t| \"Sec-CH-UA-Platform\"\n\t| \"Sec-CH-UA-WoW64\"\n\t| \"Sec-CH-UA\"\n\t| \"Sec-Fetch-Dest\"\n\t| \"Sec-Fetch-Mode\"\n\t| \"Sec-Fetch-Site\"\n\t| \"Sec-Fetch-User\"\n\t| \"Sec-GPC\"\n\t| \"Server-Timing\"\n\t| \"Server\"\n\t| \"Service-Worker-Navigation-Preload\"\n\t| \"Set-Cookie\"\n\t| \"Strict-Transport-Security\"\n\t| \"Timing-Allow-Origin\"\n\t| \"Trailer\"\n\t| \"Transfer-Encoding\"\n\t| \"Upgrade\"\n\t| \"Vary\"\n\t| \"Warning\"\n\t| \"WWW-Authenticate\"\n\t| \"X-Content-Type-Options\"\n\t| \"X-DNS-Prefetch-Control\"\n\t| \"X-Frame-Options\"\n\t| \"X-Permitted-Cross-Domain-Policies\"\n\t| \"X-Powered-By\"\n\t| \"X-Robots-Tag\"\n\t| \"X-XSS-Protection\"\n\t| AnyString;\n\nexport type CommonAuthorizationHeaders = `${\"Basic\" | \"Bearer\" | \"Token\"} ${string}`;\n\nexport type CommonContentTypes =\n\t| \"application/epub+zip\"\n\t| \"application/gzip\"\n\t| \"application/json\"\n\t| \"application/ld+json\"\n\t| \"application/octet-stream\"\n\t| \"application/ogg\"\n\t| \"application/pdf\"\n\t| \"application/rtf\"\n\t| \"application/vnd.ms-fontobject\"\n\t| \"application/wasm\"\n\t| \"application/xhtml+xml\"\n\t| \"application/xml\"\n\t| \"application/zip\"\n\t| \"audio/aac\"\n\t| \"audio/mpeg\"\n\t| \"audio/ogg\"\n\t| \"audio/opus\"\n\t| \"audio/webm\"\n\t| \"audio/x-midi\"\n\t| \"font/otf\"\n\t| \"font/ttf\"\n\t| \"font/woff\"\n\t| \"font/woff2\"\n\t| \"image/avif\"\n\t| \"image/bmp\"\n\t| \"image/gif\"\n\t| \"image/jpeg\"\n\t| \"image/png\"\n\t| \"image/svg+xml\"\n\t| \"image/tiff\"\n\t| \"image/webp\"\n\t| \"image/x-icon\"\n\t| \"model/gltf-binary\"\n\t| \"model/gltf+json\"\n\t| \"text/calendar\"\n\t| \"text/css\"\n\t| \"text/csv\"\n\t| \"text/html\"\n\t| \"text/javascript\"\n\t| \"text/plain\"\n\t| \"video/3gpp\"\n\t| \"video/3gpp2\"\n\t| \"video/av1\"\n\t| \"video/mp2t\"\n\t| \"video/mp4\"\n\t| \"video/mpeg\"\n\t| \"video/ogg\"\n\t| \"video/webm\"\n\t| \"video/x-msvideo\"\n\t| AnyString;\n","import type { CallApiConfig, CallApiExtraOptions } from \"../types/common\";\nimport { defineEnum } from \"../types/type-helpers\";\n\nexport const extraOptionDefaults = Object.freeze(\n\tdefineEnum({\n\t\t// Common defaults\n\t\tbodySerializer: JSON.stringify,\n\t\tdefaultHTTPErrorMessage: \"HTTP request failed unexpectedly\",\n\n\t\t// Dedupe defaults\n\t\t/* eslint-disable perfectionist/sort-objects -- Allow */\n\t\tdedupeCacheScope: \"local\",\n\t\tdedupeCacheScopeKey: \"default\",\n\t\tdedupeStrategy: \"cancel\",\n\t\t/* eslint-enable perfectionist/sort-objects -- Allow */\n\n\t\t// Hook defaults\n\t\thooksExecutionMode: \"parallel\",\n\n\t\t// Response defaults\n\t\tresponseParser: JSON.parse,\n\t\tresponseType: \"json\",\n\t\tresultMode: \"all\",\n\n\t\t// Retry Defaults\n\t\tretryAttempts: 0,\n\t\tretryCondition: () => true,\n\t\tretryDelay: 1000,\n\t\tretryMaxDelay: 10000,\n\t\tretryMethods: [\"GET\", \"POST\"],\n\t\tretryStatusCodes: [],\n\t\tretryStrategy: \"linear\",\n\t} satisfies CallApiExtraOptions)\n);\n\nexport const requestOptionDefaults = defineEnum({\n\tmethod: \"GET\",\n} satisfies CallApiConfig);\n"],"mappings":";AAoCA,MAAa,cAA2C,UACvD,OAAO,OAAO,MAAM;;;;AClCrB,MAAa,sBAAsB,OAAO,OACzC,WAAW;CAEV,gBAAgB,KAAK;CACrB,yBAAyB;CAIzB,kBAAkB;CAClB,qBAAqB;CACrB,gBAAgB;CAIhB,oBAAoB;CAGpB,gBAAgB,KAAK;CACrB,cAAc;CACd,YAAY;CAGZ,eAAe;CACf,sBAAsB;CACtB,YAAY;CACZ,eAAe;CACf,cAAc,CAAC,OAAO,OAAO;CAC7B,kBAAkB,EAAE;CACpB,eAAe;CACf,CAA+B,CAChC;AAED,MAAa,wBAAwB,WAAW,EAC/C,QAAQ,OACR,CAAyB"}
@@ -1,8 +1,9 @@
1
- import { $ as PluginHooksWithMoreOptions, A as RequestStreamContext, B as PossibleHTTPError, C as RetryOptions, D as HooksOrHooksArray, E as Hooks, F as CallApiResultErrorVariant, G as ResponseTypeUnion, H as PossibleJavaScriptOrValidationError, I as CallApiResultSuccessVariant, J as DefaultDataType, K as ResultModeMap, L as CallApiSuccessOrErrorVariant, M as ResponseErrorContext, N as ResponseStreamContext, O as PluginExtraOptions, P as SuccessContext, Q as PluginHooks, R as GetCallApiResult, S as ThrowOnErrorUnion, T as ErrorContext, U as PossibleValidationError, V as PossibleJavaScriptError, W as ResponseTypeMap, X as DefaultThrowOnError, Y as DefaultPluginArray, Z as CallApiPlugin, _ as GetCurrentRouteSchema, a as CallApiExtraOptions, at as CallApiSchema, b as InferParamsFromRoute, c as CallApiRequestOptions, ct as fallBackRouteSchemaKey, d as GetBaseSchemaConfig, et as PluginSetupContext, f as GetBaseSchemaRoutes, g as ApplyURLBasedConfig, h as ApplyStrictConfig, i as CallApiConfig, it as BaseCallApiSchemaRoutes, j as ResponseContext, k as RequestContext, l as CallApiRequestOptionsForHooks, lt as URLOptions, m as InferExtendSchemaContext, n as BaseCallApiExtraOptions, nt as ValidationError, o as CallApiExtraOptionsForHooks, ot as CallApiSchemaConfig, p as InferExtendSchemaConfigContext, q as ResultModeUnion, r as BaseInstanceContext, rt as BaseCallApiSchemaAndConfig, s as CallApiParameters, st as InferSchemaOutputResult, t as BaseCallApiConfig, tt as HTTPError, u as CallApiResult, ut as AnyString, v as GetCurrentRouteSchemaKey, w as DedupeOptions, x as Register, y as InferInitURL, z as GetResponseType } from "./common-DvPxUh-h.js";
1
+ import "./validation-uPnlxhfx.js";
2
+ import { $ as GetResponseType, A as RequestStreamContext, C as RetryOptions, Ct as AnyFunction, D as HooksOrHooksArray, E as Hooks, G as CallApiPlugin, J as PluginSetupContext, K as PluginHooks, M as ResponseErrorContext, N as ResponseStreamContext, O as PluginExtraOptions, P as SuccessContext, Q as GetCallApiResult, S as ThrowOnErrorUnion, T as ErrorContext, X as CallApiResultSuccessVariant, Y as CallApiResultErrorVariant, Z as CallApiSuccessOrErrorVariant, _ as GetCurrentRouteSchema, _t as StandardSchemaV1, a as CallApiExtraOptions, at as ResponseTypeUnion, b as InferParamsFromRoute, bt as DefaultThrowOnError, c as CallApiRequestOptions, d as GetBaseSchemaConfig, dt as BaseCallApiSchemaRoutes, et as PossibleHTTPError, f as GetBaseSchemaRoutes, ft as CallApiSchema, g as ApplyURLBasedConfig, gt as URLOptions, h as ApplyStrictConfig, ht as InferSchemaOutput, i as CallApiConfig, it as ResponseTypeMap, j as ResponseContext, k as RequestContext, l as CallApiRequestOptionsForHooks, m as InferExtendSchemaContext, mt as InferSchemaInput, n as BaseCallApiExtraOptions, nt as PossibleJavaScriptOrValidationError, o as CallApiExtraOptionsForHooks, ot as ResultModeMap, p as InferExtendSchemaConfigContext, pt as CallApiSchemaConfig, q as PluginHooksWithMoreOptions, r as BaseInstanceContext, rt as PossibleValidationError, s as CallApiParameters, st as ResultModeUnion, t as BaseCallApiConfig, tt as PossibleJavaScriptError, u as CallApiResult, ut as BaseCallApiSchemaAndConfig, v as GetCurrentRouteSchemaKey, vt as DefaultDataType, w as DedupeOptions, wt as AnyString, x as Register, y as InferInitURL, yt as DefaultPluginArray } from "./common-Clx7i8bR.js";
2
3
 
3
4
  //#region src/createFetchClient.d.ts
4
5
 
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 = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedResult = CallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
6
+ 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 = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedResult = CallApiResult<InferSchemaOutput<TSchema["data"], TData>, InferSchemaOutput<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutput<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaOutput<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
6
7
  declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<{
7
8
  [x: AnyString]: CallApiSchema | undefined;
8
9
  "@delete/"?: CallApiSchema | undefined;
@@ -31,11 +32,11 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
31
32
  "@patch/"?: CallApiSchema | undefined;
32
33
  "@post/"?: CallApiSchema | undefined;
33
34
  "@put/"?: CallApiSchema | undefined;
34
- }[TCurrentRouteSchemaKey]>>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedResult = GetCallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, {
35
- all: CallApiResultSuccessVariant<GetResponseType<InferSchemaOutputResult<TSchema["data"], TData>, TResponseType, ResponseTypeMap<InferSchemaOutputResult<TSchema["data"], TData>>>>;
36
- onlyData: NoInfer<GetResponseType<InferSchemaOutputResult<TSchema["data"], TData>, TResponseType, ResponseTypeMap<InferSchemaOutputResult<TSchema["data"], TData>>>>;
35
+ }[TCurrentRouteSchemaKey]>>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedResult = GetCallApiResult<undefined extends TSchema["data"] ? TData : TSchema["data"] extends infer T ? T extends TSchema["data"] ? T extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T> : T extends AnyFunction<infer TResult> ? Awaited<TResult> : TData : never : never, undefined extends TSchema["errorData"] ? TErrorData : TSchema["errorData"] extends infer T_1 ? T_1 extends TSchema["errorData"] ? T_1 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_1> : T_1 extends AnyFunction<infer TResult> ? Awaited<TResult> : TErrorData : never : never, TResultMode, TThrowOnError, TResponseType, {
36
+ all: CallApiResultSuccessVariant<GetResponseType<undefined extends TSchema["data"] ? TData : TSchema["data"] extends infer T_2 ? T_2 extends TSchema["data"] ? T_2 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_2> : T_2 extends AnyFunction<infer TResult> ? Awaited<TResult> : TData : never : never, TResponseType, ResponseTypeMap<undefined extends TSchema["data"] ? TData : TSchema["data"] extends infer T_3 ? T_3 extends TSchema["data"] ? T_3 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_3> : T_3 extends AnyFunction<infer TResult> ? Awaited<TResult> : TData : never : never>>>;
37
+ onlyData: NoInfer<GetResponseType<undefined extends TSchema["data"] ? TData : TSchema["data"] extends infer T_4 ? T_4 extends TSchema["data"] ? T_4 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_4> : T_4 extends AnyFunction<infer TResult> ? Awaited<TResult> : TData : never : never, TResponseType, ResponseTypeMap<undefined extends TSchema["data"] ? TData : TSchema["data"] extends infer T_5 ? T_5 extends TSchema["data"] ? T_5 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_5> : T_5 extends AnyFunction<infer TResult> ? Awaited<TResult> : TData : never : never>>>;
37
38
  onlyResponse: Response;
38
- }, ResultModeMap<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResponseType, TThrowOnError>>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>>, TResultMode, TThrowOnError, TResponseType, {
39
+ }, ResultModeMap<undefined extends TSchema["data"] ? TData : TSchema["data"] extends infer T_6 ? T_6 extends TSchema["data"] ? T_6 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_6> : T_6 extends AnyFunction<infer TResult> ? Awaited<TResult> : TData : never : never, undefined extends TSchema["errorData"] ? TErrorData : TSchema["errorData"] extends infer T_7 ? T_7 extends TSchema["errorData"] ? T_7 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_7> : T_7 extends AnyFunction<infer TResult> ? Awaited<TResult> : TErrorData : never : never, TResponseType, TThrowOnError>>>(initURL: TInitURL, initConfig?: CallApiConfig<undefined extends TSchema["data"] ? GetResponseType<TData, TResponseType, ResponseTypeMap<TData>> : TSchema["data"] extends infer T_8 ? T_8 extends TSchema["data"] ? T_8 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_8> : T_8 extends AnyFunction<infer TResult> ? Awaited<TResult> : GetResponseType<TData, TResponseType, ResponseTypeMap<TData>> : never : never, undefined extends TSchema["errorData"] ? GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>> : TSchema["errorData"] extends infer T_9 ? T_9 extends TSchema["errorData"] ? T_9 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_9> : T_9 extends AnyFunction<infer TResult> ? Awaited<TResult> : GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>> : never : never, TResultMode, TThrowOnError, TResponseType, {
39
40
  [x: AnyString]: CallApiSchema | undefined;
40
41
  "@delete/"?: CallApiSchema | undefined;
41
42
  "@get/"?: CallApiSchema | undefined;
@@ -44,5 +45,5 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
44
45
  "@put/"?: CallApiSchema | undefined;
45
46
  }, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray>) => Promise<TComputedResult>;
46
47
  //#endregion
47
- export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type BaseInstanceContext, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type CallApiSuccessOrErrorVariant, type DedupeOptions, type ErrorContext, HTTPError, type Hooks, type HooksOrHooksArray, type InferExtendSchemaConfigContext, type InferExtendSchemaContext, type InferParamsFromRoute, type InferSchemaOutputResult, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeUnion, type ResultModeUnion, type RetryOptions, type SuccessContext, type URLOptions, ValidationError, callApi, createFetchClient, fallBackRouteSchemaKey };
48
+ export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type BaseInstanceContext, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type CallApiSuccessOrErrorVariant, type DedupeOptions, type ErrorContext, type Hooks, type HooksOrHooksArray, type InferExtendSchemaConfigContext, type InferExtendSchemaContext, type InferParamsFromRoute, type InferSchemaInput, type InferSchemaOutput, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeUnion, type ResultModeUnion, type RetryOptions, type SuccessContext, type URLOptions, callApi, createFetchClient };
48
49
  //# sourceMappingURL=index.d.ts.map
package/dist/esm/index.js CHANGED
@@ -1,4 +1,6 @@
1
- import { C as defineEnum, S as requestOptionDefaults, _ as isReadableStream, b as isValidJsonString, c as HTTPError, d as isBoolean, f as isFunction, g as isQueryString, h as isPromise, i as isHTTPErrorInstance, l as ValidationError, m as isPlainObject, n as toQueryString, p as isObject, s as isValidationErrorInstance, u as isArray, v as isSerializable, x as extraOptionDefaults, y as isString } from "./body-BVMFJoeo.js";
1
+ import { n as requestOptionDefaults, r as defineEnum, t as extraOptionDefaults } from "./defaults-BD3B1uIH.js";
2
+ import { _ as isReadableStream, b as isValidJsonString, c as HTTPError, d as isBoolean, f as isFunction, g as isQueryString, h as isPromise, i as isHTTPErrorInstance, l as ValidationError, m as isPlainObject, n as toQueryString, p as isObject, s as isValidationErrorInstance, u as isArray, v as isSerializable, y as isString } from "./body-B9WKokQt.js";
3
+ import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "./validation-MjkoG9bG.js";
2
4
 
3
5
  //#region src/result.ts
4
6
  const getResponseType = (response, parser) => ({
@@ -149,9 +151,9 @@ const executeHooksInCatchBlock = async (hookResultsOrPromise, hookInfo) => {
149
151
  await Promise.all(hookResultsOrPromise);
150
152
  return null;
151
153
  } catch (hookError) {
152
- const { errorResult: hookErrorResult } = resolveErrorResult(hookError, errorInfo);
153
154
  if (shouldThrowOnError) throw hookError;
154
- return hookErrorResult;
155
+ const { errorResult } = resolveErrorResult(hookError, errorInfo);
156
+ return errorResult;
155
157
  }
156
158
  };
157
159
 
@@ -292,26 +294,6 @@ const getAuthHeader = async (auth) => {
292
294
  }
293
295
  };
294
296
 
295
- //#endregion
296
- //#region src/constants/common.ts
297
- const fetchSpecificKeys = defineEnum([
298
- "body",
299
- "integrity",
300
- "duplex",
301
- "method",
302
- "headers",
303
- "signal",
304
- "cache",
305
- "redirect",
306
- "window",
307
- "credentials",
308
- "keepalive",
309
- "referrer",
310
- "priority",
311
- "mode",
312
- "referrerPolicy"
313
- ]);
314
-
315
297
  //#endregion
316
298
  //#region src/validation.ts
317
299
  const handleValidatorFunction = async (validator, inputData) => {
@@ -428,7 +410,6 @@ const handleConfigValidation = async (validationOptions) => {
428
410
  shouldApplySchemaOutput: (Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult)) && !resolvedSchemaConfig?.disableValidationOutputApplication
429
411
  };
430
412
  };
431
- const fallBackRouteSchemaKey = ".";
432
413
  const getResolvedSchema = (context) => {
433
414
  const { baseExtraOptions, currentRouteSchemaKey, extraOptions } = context;
434
415
  const fallbackRouteSchema = baseExtraOptions.schema?.routes[fallBackRouteSchemaKey];
@@ -644,23 +625,9 @@ const getFetchImpl = (context) => {
644
625
  fetchImpl: initFetchImpl
645
626
  }) : initFetchImpl;
646
627
  };
647
- const PromiseWithResolvers = () => {
648
- let reject;
649
- let resolve;
650
- return {
651
- promise: new Promise((res, rej) => {
652
- resolve = res;
653
- reject = rej;
654
- }),
655
- reject,
656
- resolve
657
- };
658
- };
659
628
  const waitFor = (delay) => {
660
629
  if (delay === 0) return;
661
- const { promise, resolve } = PromiseWithResolvers();
662
- setTimeout(resolve, delay);
663
- return promise;
630
+ return new Promise((resolve) => setTimeout(resolve, delay));
664
631
  };
665
632
  const createCombinedSignal = (...signals) => {
666
633
  const cleanedSignals = signals.filter((signal) => signal != null);
@@ -711,11 +678,31 @@ const createDedupeStrategy = async (context) => {
711
678
  if (dedupeCacheScope === "global" && !$GlobalRequestInfoCache$1.has(dedupeCacheScopeKey)) $GlobalRequestInfoCache$1.set(dedupeCacheScopeKey, /* @__PURE__ */ new Map());
712
679
  const $RequestInfoCache = dedupeCacheScope === "global" ? $GlobalRequestInfoCache$1.get(dedupeCacheScopeKey) : $LocalRequestInfoCache;
713
680
  const $RequestInfoCacheOrNull = dedupeKey !== null ? $RequestInfoCache : null;
714
- /******
715
- * == Add a small delay to the execution to ensure proper request deduplication when multiple requests with the same key start simultaneously.
716
- * == This gives time for the cache to be updated with the previous request info before the next request checks it.
717
- ******/
718
- if (dedupeKey !== null) await waitFor(.1);
681
+ /**
682
+ * Force sequential execution of parallel requests to enable proper cache-based deduplication.
683
+ *
684
+ * Problem: When Promise.all([callApi(url), callApi(url)]) executes, both requests
685
+ * start synchronously and reach this point before either can populate the cache.
686
+ *
687
+ * Why `await Promise.resolve()` fails:
688
+ * - All microtasks in a batch resolve together at the next microtask checkpoint
689
+ * - Both requests resume execution simultaneously after the await
690
+ * - Both check `prevRequestInfo` at the same time → both see empty cache
691
+ * - Both proceed to populate cache → deduplication fails
692
+ *
693
+ * Why `wait new Promise(()=> setTimeout(resolve, number))` works:
694
+ * - Each setTimeout creates a separate task in the task queue
695
+ * - Tasks execute sequentially, not simultaneously
696
+ * - Request 1's task runs first: checks cache (empty) → continues → populates cache
697
+ * - Request 2's task runs after: checks cache (populated) → uses cached promise
698
+ * - Deduplication succeeds
699
+ *
700
+ * IMPORTANT: The delay must be non-zero. setTimeout(fn, 0) fails because JavaScript engines
701
+ * may optimize zero-delay timers by batching them together, causing all requests to resume
702
+ * simultaneously (same problem as microtasks). Any non-zero value (even 0.0000000001) forces
703
+ * proper sequential task queue scheduling, ensuring each request gets its own task slot.
704
+ */
705
+ if (dedupeKey !== null) await waitFor(.001);
719
706
  const prevRequestInfo = $RequestInfoCacheOrNull?.get(dedupeKey);
720
707
  const getAbortErrorMessage = () => {
721
708
  if (globalOptions.dedupeKey) return `Duplicate request detected - Aborted previous request with key '${dedupeKey}'`;
@@ -938,7 +925,7 @@ const getExponentialDelay = (currentAttemptCount, options) => {
938
925
  const exponentialDelay = resolvedRetryDelay * 2 ** currentAttemptCount;
939
926
  return Math.min(exponentialDelay, maxDelay);
940
927
  };
941
- const createRetryStrategy = (ctx) => {
928
+ const createRetryManager = (ctx) => {
942
929
  const { options, request } = ctx;
943
930
  const currentAttemptCount = options["~retryAttemptCount"] ?? 1;
944
931
  const retryStrategy = options.retryStrategy ?? options.retry?.strategy ?? extraOptionDefaults.retryStrategy;
@@ -961,9 +948,23 @@ const createRetryStrategy = (ctx) => {
961
948
  const includesStatusCodes = ctx.response != null && retryStatusCodes.size > 0 ? retryStatusCodes.has(ctx.response.status) : true;
962
949
  return includesMethod && includesStatusCodes;
963
950
  };
951
+ const handleRetry = async (context) => {
952
+ const { callApi: callApi$1, callApiArgs, errorContext, hookInfo } = context;
953
+ const retryContext = {
954
+ ...errorContext,
955
+ retryAttemptCount: currentAttemptCount
956
+ };
957
+ const hookError = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);
958
+ if (hookError) return hookError;
959
+ await waitFor(getDelay());
960
+ const updatedOptions = {
961
+ ...callApiArgs.config,
962
+ "~retryAttemptCount": currentAttemptCount + 1
963
+ };
964
+ return callApi$1(callApiArgs.initURL, updatedOptions);
965
+ };
964
966
  return {
965
- currentAttemptCount,
966
- getDelay,
967
+ handleRetry,
967
968
  shouldAttemptRetry
968
969
  };
969
970
  };
@@ -1137,21 +1138,17 @@ const createFetchClient = (initBaseConfig = {}) => {
1137
1138
  errorInfo,
1138
1139
  shouldThrowOnError
1139
1140
  };
1141
+ const { handleRetry, shouldAttemptRetry } = createRetryManager(errorContext);
1140
1142
  const handleRetryOrGetErrorResult = async () => {
1141
- const { currentAttemptCount, getDelay, shouldAttemptRetry } = createRetryStrategy(errorContext);
1142
- if (await shouldAttemptRetry()) {
1143
- const retryContext = {
1144
- ...errorContext,
1145
- retryAttemptCount: currentAttemptCount
1146
- };
1147
- const hookError = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);
1148
- if (hookError) return hookError;
1149
- await waitFor(getDelay());
1150
- return callApi$1(initURL, {
1151
- ...config,
1152
- "~retryAttemptCount": currentAttemptCount + 1
1153
- });
1154
- }
1143
+ if (await shouldAttemptRetry()) return handleRetry({
1144
+ callApi: callApi$1,
1145
+ callApiArgs: {
1146
+ config,
1147
+ initURL
1148
+ },
1149
+ errorContext,
1150
+ hookInfo
1151
+ });
1155
1152
  if (shouldThrowOnError) throw error;
1156
1153
  return errorResult;
1157
1154
  };
@@ -1183,5 +1180,5 @@ const createFetchClient = (initBaseConfig = {}) => {
1183
1180
  const callApi = createFetchClient();
1184
1181
 
1185
1182
  //#endregion
1186
- export { HTTPError, ValidationError, callApi, createFetchClient, fallBackRouteSchemaKey };
1183
+ export { callApi, createFetchClient };
1187
1184
  //# sourceMappingURL=index.js.map