@zayne-labs/callapi 1.14.0 → 1.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ declare const fetchSpecificKeys: readonly (keyof RequestInit | "duplex" | "extra
5
5
  type AnyString = string & NonNullable<unknown>;
6
6
  type AnyNumber = number & NonNullable<unknown>;
7
7
  type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;
8
- type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };
8
+ type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key]; };
9
9
  type WriteableLevel = "deep" | "shallow";
10
10
  /**
11
11
  * Makes all properties in an object type writeable (removes readonly modifiers).
@@ -14,7 +14,7 @@ type WriteableLevel = "deep" | "shallow";
14
14
  * @template TVariant - The level of writeable transformation ("shallow" | "deep")
15
15
  */
16
16
  type ArrayOrObject = Record<number | string | symbol, unknown> | unknown[] | readonly unknown[];
17
- type Writeable<TObject, TLevel extends WriteableLevel = "shallow"> = TObject extends ArrayOrObject ? { -readonly [Key in keyof TObject]: TLevel extends "deep" ? NonNullable<TObject[Key]> extends ArrayOrObject ? Writeable<TObject[Key], "deep"> : TObject[Key] : TObject[Key] } : TObject;
17
+ type Writeable<TObject, TLevel extends WriteableLevel = "shallow"> = TObject extends ArrayOrObject ? { -readonly [Key in keyof TObject]: TLevel extends "deep" ? NonNullable<TObject[Key]> extends ArrayOrObject ? Writeable<TObject[Key], "deep"> : TObject[Key] : TObject[Key]; } : TObject;
18
18
  type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends ((param: infer TParam) => void) ? TParam : never;
19
19
  type UnmaskType<TValue> = {
20
20
  value: TValue;
@@ -31,7 +31,7 @@ type RemoveSlashImpl<TUrl extends string, TDirection extends "leading" | "traili
31
31
  type RemoveTrailingSlash<TUrl extends string> = RemoveSlashImpl<TUrl, "trailing">;
32
32
  type RemoveLeadingSlash<TUrl extends string> = RemoveSlashImpl<TUrl, "leading">;
33
33
  type Awaitable<TValue> = Promise<TValue> | TValue;
34
- type Satisfies<TActualType extends TExpectedTypeShape, TExpectedTypeShape> = { [Key in keyof TActualType]: Key extends keyof TExpectedTypeShape ? TActualType[Key] : never };
34
+ type Satisfies<TActualType extends TExpectedTypeShape, TExpectedTypeShape> = { [Key in keyof TActualType]: Key extends keyof TExpectedTypeShape ? TActualType[Key] : never; };
35
35
  type DistributiveOmit<TObject, TKeysToOmit extends keyof TObject> = TObject extends unknown ? Omit<TObject, TKeysToOmit> : never;
36
36
  type CommonRequestHeaders = "Access-Control-Allow-Credentials" | "Access-Control-Allow-Headers" | "Access-Control-Allow-Methods" | "Access-Control-Allow-Origin" | "Access-Control-Expose-Headers" | "Access-Control-Max-Age" | "Age" | "Allow" | "Cache-Control" | "Clear-Site-Data" | "Content-Disposition" | "Content-Encoding" | "Content-Language" | "Content-Length" | "Content-Location" | "Content-Range" | "Content-Security-Policy-Report-Only" | "Content-Security-Policy" | "Cookie" | "Cross-Origin-Embedder-Policy" | "Cross-Origin-Opener-Policy" | "Cross-Origin-Resource-Policy" | "Date" | "ETag" | "Expires" | "Last-Modified" | "Location" | "Permissions-Policy" | "Pragma" | "Retry-After" | "Save-Data" | "Sec-CH-Prefers-Color-Scheme" | "Sec-CH-Prefers-Reduced-Motion" | "Sec-CH-UA-Arch" | "Sec-CH-UA-Bitness" | "Sec-CH-UA-Form-Factor" | "Sec-CH-UA-Full-Version-List" | "Sec-CH-UA-Full-Version" | "Sec-CH-UA-Mobile" | "Sec-CH-UA-Model" | "Sec-CH-UA-Platform-Version" | "Sec-CH-UA-Platform" | "Sec-CH-UA-WoW64" | "Sec-CH-UA" | "Sec-Fetch-Dest" | "Sec-Fetch-Mode" | "Sec-Fetch-Site" | "Sec-Fetch-User" | "Sec-GPC" | "Server-Timing" | "Server" | "Service-Worker-Navigation-Preload" | "Set-Cookie" | "Strict-Transport-Security" | "Timing-Allow-Origin" | "Trailer" | "Transfer-Encoding" | "Upgrade" | "Vary" | "Warning" | "WWW-Authenticate" | "X-Content-Type-Options" | "X-DNS-Prefetch-Control" | "X-Frame-Options" | "X-Permitted-Cross-Domain-Policies" | "X-Powered-By" | "X-Robots-Tag" | "X-XSS-Protection" | AnyString;
37
37
  type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
@@ -125,7 +125,8 @@ type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
125
125
  type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
126
126
  type TupleStyleParams = UnmaskType<AllowedQueryParamValues[]>;
127
127
  type Params = UnmaskType<RecordStyleParams | TupleStyleParams>;
128
- type Query = UnmaskType<Record<string, AllowedQueryParamValues> | URLSearchParams>;
128
+ type StructuredQueryValues = Record<string, unknown> | unknown[] | null | undefined;
129
+ type Query = UnmaskType<Record<string, AllowedQueryParamValues | StructuredQueryValues> | URLSearchParams>;
129
130
  type InitURLOrURLObject = AnyString | RouteKeyMethodsURLUnion | URL;
130
131
  interface URLOptions {
131
132
  /**
@@ -245,7 +246,7 @@ type ResultVariant = "infer-input" | "infer-output";
245
246
  type InferSchemaResult<TSchema, TFallbackResult, TResultVariant extends ResultVariant> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? TResultVariant extends "infer-input" ? StandardSchemaV1.InferInput<TSchema> : StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
246
247
  type InferSchemaOutput<TSchema, TFallbackResult = unknown> = InferSchemaResult<TSchema, TFallbackResult, "infer-output">;
247
248
  type InferSchemaInput<TSchema, TFallbackResult = unknown> = InferSchemaResult<TSchema, TFallbackResult, "infer-input">;
248
- type BooleanObject = { [Key in keyof CallApiSchema]: boolean };
249
+ type BooleanObject = { [Key in keyof CallApiSchema]: boolean; };
249
250
  interface CallApiSchemaConfig {
250
251
  /**
251
252
  * The base url of the schema. By default it's the baseURL of the callApi instance.
@@ -405,7 +406,7 @@ type InitResponseTypeMap<TData = unknown> = ReturnType<typeof getResponseType<TD
405
406
  type ResponseTypeUnion = keyof InitResponseTypeMap;
406
407
  type ResponseTypePlaceholder = null;
407
408
  type ResponseTypeType = ResponseTypePlaceholder | ResponseTypeUnion;
408
- type ResponseTypeMap<TData> = { [Key in keyof InitResponseTypeMap<TData>]: Awaited<ReturnType<InitResponseTypeMap<TData>[Key]>> };
409
+ type ResponseTypeMap<TData> = { [Key in keyof InitResponseTypeMap<TData>]: Awaited<ReturnType<InitResponseTypeMap<TData>[Key]>>; };
409
410
  type GetResponseType<TData, TResponseType extends ResponseTypeType, TComputedResponseTypeMap extends ResponseTypeMap<TData> = ResponseTypeMap<TData>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeType> ? TComputedResponseTypeMap[TResponseType] : never;
410
411
  type CallApiResultSuccessVariant<TData> = {
411
412
  data: NoInferUnMasked<TData>;
@@ -883,7 +884,7 @@ interface Hooks<TCallApiContext extends CallApiContext = DefaultCallApiContext>
883
884
  */
884
885
  onValidationError?: (context: ValidationErrorContext<TCallApiContext>) => Awaitable<unknown>;
885
886
  }
886
- type HooksOrHooksArray<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> = { [Key in keyof Hooks<TCallApiContext>]: Hooks<TCallApiContext>[Key] | Array<Hooks<TCallApiContext>[Key]> };
887
+ type HooksOrHooksArray<TCallApiContext extends NoInfer<CallApiContext> = DefaultCallApiContext> = { [Key in keyof Hooks<TCallApiContext>]: Hooks<TCallApiContext>[Key] | Array<Hooks<TCallApiContext>[Key]>; };
887
888
  interface HookConfigOptions {
888
889
  /**
889
890
  * Controls the execution mode of all composed hooks (main + plugin hooks).
@@ -1473,24 +1474,24 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = DefaultCallApiC
1473
1474
  */
1474
1475
  responseType?: TResponseType;
1475
1476
  /**
1476
- * Dictates how CallApi processes and returns the final result
1477
- *
1478
- - **"all"** (default): Returns `{ data, error, response }`. Standard lifecycle.
1479
- - **"onlyData"**: Returns only the data from the response.
1480
- - **"onlyResponse"**: Returns only the `Response` object.
1481
- - **"fetchApi"**: Also returns only the `Response` object, but also skips parsing of the response body internally and data/errorData schema validation.
1482
- - **"withoutResponse"**: Returns `{ data, error }`. Standard lifecycle, but omits the `response` property.
1483
- *
1484
- *
1485
- * **Note:**
1486
- * By default, simplified modes (`"onlyData"`, `"onlyResponse"`, `"fetchApi"`) do not throw errors.
1487
- * Success/failure should be handled via hooks or by checking the return value (e.g., `if (data)` or `if (response?.ok)`).
1488
- * To force an exception instead, set `throwOnError: true`.
1489
- *
1490
- *
1491
- * @default "all"
1492
- *
1493
- */
1477
+ * Dictates how CallApi processes and returns the final result
1478
+ *
1479
+ - **"all"** (default): Returns `{ data, error, response }`. Standard lifecycle.
1480
+ - **"onlyData"**: Returns only the data from the response.
1481
+ - **"onlyResponse"**: Returns only the `Response` object.
1482
+ - **"fetchApi"**: Also returns only the `Response` object, but also skips parsing of the response body internally and data/errorData schema validation.
1483
+ - **"withoutResponse"**: Returns `{ data, error }`. Standard lifecycle, but omits the `response` property.
1484
+ *
1485
+ *
1486
+ * **Note:**
1487
+ * By default, simplified modes (`"onlyData"`, `"onlyResponse"`, `"fetchApi"`) do not throw errors.
1488
+ * Success/failure should be handled via hooks or by checking the return value (e.g., `if (data)` or `if (response?.ok)`).
1489
+ * To force an exception instead, set `throwOnError: true`.
1490
+ *
1491
+ *
1492
+ * @default "all"
1493
+ *
1494
+ */
1494
1495
  resultMode?: TResultMode;
1495
1496
  /**
1496
1497
  * Controls whether errors are thrown as exceptions or returned in the result.
@@ -1710,7 +1711,7 @@ type InstanceContext = {
1710
1711
  };
1711
1712
  type BaseCallApiConfig<TBaseCallApiContext extends CallApiContext = DefaultCallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
1712
1713
  type CallApiConfig<TCallApiContext extends CallApiContext = DefaultCallApiContext, TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBody extends InferSchemaOutput<TSchema["body"], Body> = InferSchemaOutput<TSchema["body"], Body>, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey, TCallApiContext> & InferRequestOptions<TSchema, TInitURL, TBody> & Omit<CallApiExtraOptions<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey, TBody>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string, CallApiContext>> & Omit<CallApiRequestOptions<TBody>, keyof InferRequestOptions<CallApiSchema, string, TBody>>;
1713
- type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TCallApiContext extends CallApiContext = DefaultCallApiContext, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBody extends InferSchemaOutput<TSchema["body"], Body> = InferSchemaOutput<TSchema["body"], Body>> = [initURL: TInitURL, config?: CallApiConfig<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBody, TBasePluginArray, TPluginArray>];
1714
+ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TCallApiContext extends CallApiContext = DefaultCallApiContext, TThrowOnError extends ThrowOnErrorBoolean = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBody extends InferSchemaOutput<TSchema["body"], Body> = InferSchemaOutput<TSchema["body"], Body>, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedConfig = CallApiConfig<TCallApiContext, TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBody, TBasePluginArray, TPluginArray>, TComputedRequiredOptions = InferExtraOptions<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey, TCallApiContext> & InferRequestOptions<TSchema, TInitURL, TBody>> = NonNullable<unknown> extends TComputedRequiredOptions ? [initURL: TInitURL, config?: TComputedConfig] : [initURL: TInitURL, config: TComputedConfig];
1714
1715
  type CallApiResult<TData, TErrorData, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorBoolean> = InferCallApiResult<TData, TErrorData, TResultMode, TThrowOnError>;
1715
1716
  type CallApiResultLoose<TData, TErrorData, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorBoolean = ThrowOnErrorBoolean> = InferCallApiResult<TData, TErrorData, TResultMode, TThrowOnError>;
1716
1717
  //#endregion
@@ -1759,8 +1760,8 @@ type AuthOption = PossibleAuthValueOrGetter | BearerAuth | TokenAuth | BasicAuth
1759
1760
  type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaOutput<TSchemaOption, undefined> ? TObject : Required<TObject>;
1760
1761
  type MergeBaseWithRouteKey<TBaseURLOrPrefix extends string | undefined, TRouteKey extends string> = TBaseURLOrPrefix extends string ? TRouteKey extends `${AtSymbol}${infer TMethod extends RouteKeyMethods}/${infer TRestOfRoutKey}` ? `${AtSymbol}${TMethod}/${RemoveLeadingSlash<RemoveTrailingSlash<TBaseURLOrPrefix>>}/${RemoveLeadingSlash<TRestOfRoutKey>}` : `${TBaseURLOrPrefix}${TRouteKey}` : TRouteKey;
1761
1762
  type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["prefix"] extends string ? MergeBaseWithRouteKey<TSchemaConfig["prefix"], TSchemaRouteKeys> : TSchemaConfig["baseURL"] extends string ? MergeBaseWithRouteKey<TSchemaConfig["baseURL"], TSchemaRouteKeys> : TSchemaRouteKeys;
1762
- type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["strict"] extends true ? TSchemaRouteKeys : // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
1763
- TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
1763
+ type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig["strict"] extends true ? TSchemaRouteKeys // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
1764
+ : TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
1764
1765
  type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, TSchemaRouteKeys>>;
1765
1766
  type InferAllMainRoutes<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes> = Omit<TBaseSchemaRoutes, FallBackRouteSchemaKey>;
1766
1767
  type InferAllMainRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Extract<keyof InferAllMainRoutes<TBaseSchemaRoutes>, string>>;
@@ -1824,50 +1825,50 @@ type InferMetaOption<TSchema extends CallApiSchema, TCallApiContext extends Call
1824
1825
  }>;
1825
1826
  type InferAuthOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["auth"], {
1826
1827
  /**
1827
- * Automatically add an Authorization header value.
1828
- *
1829
- * Supports multiple authentication patterns:
1830
- * - String: Direct authorization header value
1831
- * - Auth object: Structured authentication configuration
1832
- *
1833
- * @example
1834
- * ```ts
1835
- * // Bearer auth
1836
- * const response = await callMainApi({
1837
- * url: "https://example.com/api/data",
1838
- * auth: "123456",
1839
- * });
1840
- *
1841
- * // Bearer auth
1842
- * const response = await callMainApi({
1843
- * url: "https://example.com/api/data",
1844
- * auth: {
1845
- * type: "Bearer",
1846
- * value: "123456",
1847
- * },
1848
- })
1849
- *
1850
- * // Token auth
1851
- * const response = await callMainApi({
1852
- * url: "https://example.com/api/data",
1853
- * auth: {
1854
- * type: "Token",
1855
- * value: "123456",
1856
- * },
1857
- * });
1858
- *
1859
- * // Basic auth
1860
- * const response = await callMainApi({
1861
- * url: "https://example.com/api/data",
1862
- * auth: {
1863
- * type: "Basic",
1864
- * username: "username",
1865
- * password: "password",
1866
- * },
1867
- * });
1868
- *
1869
- * ```
1870
- */
1828
+ * Automatically add an Authorization header value.
1829
+ *
1830
+ * Supports multiple authentication patterns:
1831
+ * - String: Direct authorization header value
1832
+ * - Auth object: Structured authentication configuration
1833
+ *
1834
+ * @example
1835
+ * ```ts
1836
+ * // Bearer auth
1837
+ * const response = await callMainApi({
1838
+ * url: "https://example.com/api/data",
1839
+ * auth: "123456",
1840
+ * });
1841
+ *
1842
+ * // Bearer auth
1843
+ * const response = await callMainApi({
1844
+ * url: "https://example.com/api/data",
1845
+ * auth: {
1846
+ * type: "Bearer",
1847
+ * value: "123456",
1848
+ * },
1849
+ })
1850
+ *
1851
+ * // Token auth
1852
+ * const response = await callMainApi({
1853
+ * url: "https://example.com/api/data",
1854
+ * auth: {
1855
+ * type: "Token",
1856
+ * value: "123456",
1857
+ * },
1858
+ * });
1859
+ *
1860
+ * // Basic auth
1861
+ * const response = await callMainApi({
1862
+ * url: "https://example.com/api/data",
1863
+ * auth: {
1864
+ * type: "Basic",
1865
+ * username: "username",
1866
+ * password: "password",
1867
+ * },
1868
+ * });
1869
+ *
1870
+ * ```
1871
+ */
1871
1872
  auth?: InferSchemaOutput<TSchema["auth"], AuthOption>;
1872
1873
  }>;
1873
1874
  type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["query"], {
@@ -1911,5 +1912,5 @@ type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorBoolean> =
1911
1912
  throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
1912
1913
  };
1913
1914
  //#endregion
1914
- export { defineSchema as $, CallApiExtraOptionsForHooks as A, BaseSchemaRouteKeyPrefixes as At, SuccessContext as B, DistributiveOmit as Bt, GetBaseSchemaRoutes as C, ResponseTypeMap as Ct, InstanceContext as D, ValidationError as Dt, GlobalMeta as E, HTTPError as Et, RequestContext as F, InferSchemaResult as Ft, isHTTPErrorInstance as G, RetryOptions as H, Writeable as Ht, RequestStreamContext as I, URLOptions as It, isValidationErrorInstance as J, isJavascriptError as K, ResponseContext as L, FallBackRouteSchemaKey as Lt, ErrorContext as M, CallApiSchemaConfig as Mt, Hooks as N, InferSchemaInput as Nt, Register as O, BaseCallApiSchemaAndConfig as Ot, HooksOrHooksArray as P, InferSchemaOutput as Pt, definePlugin as Q, ResponseErrorContext as R, fallBackRouteSchemaKey as Rt, GetBaseSchemaConfig as S, PossibleValidationError as St, GetCallApiContextRequired as T, ResultModeType as Tt, objectifyHeaders as U, fetchSpecificKeys as Ut, RefetchOptions as V, NoInferUnMasked as Vt, isHTTPError as W, defineInstanceConfig as X, defineBaseConfig as Y, defineMainSchema as Z, CallApiExtraOptions as _, CallApiResultSuccessVariant as _t, GetCurrentRouteSchemaKey as a, DefaultCallApiContext as at, CallApiResult as b, PossibleHTTPError as bt, InferInitURL as c, CallApiPlugin as ct, SerializableObject as d, PluginSetupContext as dt, defineSchemaConfig as et, ThrowOnErrorBoolean as f, FetchImpl as ft, CallApiContext as g, CallApiResultSuccessOrErrorVariant as gt, CallApiConfig as h, CallApiResultErrorVariant as ht, GetCurrentRouteSchema as i, toSearchParams as it, CallApiRequestOptionsForHooks as j, CallApiSchema as jt, DedupeOptions as k, BaseCallApiSchemaRoutes as kt, InferParamsFromRoute as l, PluginHooks as lt, BaseCallApiExtraOptions as m, Middlewares as mt, ApplyURLBasedConfig as n, toFormData as nt, InferAllMainRouteKeys as o, DefaultDataType as ot, BaseCallApiConfig as p, FetchMiddlewareContext as pt, isValidationError as q, Body as r, toQueryString as rt, InferAllMainRoutes as s, DefaultPluginArray as st, ApplyStrictConfig as t, defineSchemaRoutes as tt, SerializableArray as u, PluginMiddlewares as ut, CallApiParameters as v, GetResponseType as vt, GetCallApiContext as w, ResponseTypeType as wt, CallApiResultLoose as x, PossibleJavaScriptError as xt, CallApiRequestOptions as y, InferCallApiResult as yt, ResponseStreamContext as z, AnyString as zt };
1915
- //# sourceMappingURL=conditional-types-BXgYQJ5q.d.ts.map
1915
+ export { defineMainSchema as $, Register as A, BaseCallApiSchemaAndConfig as At, ResponseErrorContext as B, fallBackRouteSchemaKey as Bt, CallApiResultLoose as C, PossibleJavaScriptError as Ct, GetCallApiContextRequired as D, ResultModeType as Dt, GetCallApiContext as E, ResponseTypeType as Et, Hooks as F, InferSchemaInput as Ft, objectifyHeaders as G, NoInferUnMasked as Gt, SuccessContext as H, CommonContentTypes as Ht, HooksOrHooksArray as I, InferSchemaOutput as It, isJavascriptError as J, isHTTPError as K, Writeable as Kt, RequestContext as L, InferSchemaResult as Lt, CallApiExtraOptionsForHooks as M, BaseSchemaRouteKeyPrefixes as Mt, CallApiRequestOptionsForHooks as N, CallApiSchema as Nt, GlobalMeta as O, HTTPError as Ot, ErrorContext as P, CallApiSchemaConfig as Pt, defineInstanceConfig as Q, RequestStreamContext as R, URLOptions as Rt, CallApiResult as S, PossibleHTTPError as St, GetBaseSchemaRoutes as T, ResponseTypeMap as Tt, RefetchOptions as U, CommonRequestHeaders as Ut, ResponseStreamContext as V, AnyString as Vt, RetryOptions as W, DistributiveOmit as Wt, isValidationErrorInstance as X, isValidationError as Y, defineBaseConfig as Z, CallApiConfig as _, CallApiResultErrorVariant as _t, GetCurrentRouteSchemaKey as a, toQueryString as at, CallApiParameters as b, GetResponseType as bt, InferAllMainRoutes as c, DefaultDataType as ct, SerializableArray as d, PluginHooks as dt, definePlugin as et, SerializableObject as f, PluginMiddlewares as ft, BaseCallApiExtraOptions as g, Middlewares as gt, BaseCallApiConfig as h, FetchMiddlewareContext as ht, GetCurrentRouteSchema as i, toFormData as it, DedupeOptions as j, BaseCallApiSchemaRoutes as jt, InstanceContext as k, ValidationError as kt, InferInitURL as l, DefaultPluginArray as lt, AuthOption as m, FetchImpl as mt, ApplyURLBasedConfig as n, defineSchemaConfig as nt, HeadersOption as o, toSearchParams as ot, ThrowOnErrorBoolean as p, PluginSetupContext as pt, isHTTPErrorInstance as q, fetchSpecificKeys as qt, Body as r, defineSchemaRoutes as rt, InferAllMainRouteKeys as s, DefaultCallApiContext as st, ApplyStrictConfig as t, defineSchema as tt, InferParamsFromRoute as u, CallApiPlugin as ut, CallApiContext as v, CallApiResultSuccessOrErrorVariant as vt, GetBaseSchemaConfig as w, PossibleValidationError as wt, CallApiRequestOptions as x, InferCallApiResult as xt, CallApiExtraOptions as y, CallApiResultSuccessVariant as yt, ResponseContext as z, FallBackRouteSchemaKey as zt };
1916
+ //# sourceMappingURL=conditional-types-C9cMfJMZ.d.ts.map
@@ -1,5 +1,4 @@
1
- import { F as RequestContext, Lt as FallBackRouteSchemaKey, Rt as fallBackRouteSchemaKey, Ut as fetchSpecificKeys } from "../conditional-types-BXgYQJ5q.js";
2
-
1
+ import { Bt as fallBackRouteSchemaKey, L as RequestContext, qt as fetchSpecificKeys, zt as FallBackRouteSchemaKey } from "../conditional-types-C9cMfJMZ.js";
3
2
  //#region src/constants/defaults.d.ts
4
3
  declare const extraOptionDefaults: Readonly<Readonly<{
5
4
  bodySerializer: {
@@ -1,2 +1,2 @@
1
- import { F as fallBackRouteSchemaKey, n as requestOptionDefaults, t as extraOptionDefaults, z as fetchSpecificKeys } from "../constants-CQmUuQDT.js";
1
+ import { F as fallBackRouteSchemaKey, n as requestOptionDefaults, t as extraOptionDefaults, z as fetchSpecificKeys } from "../constants-C8dGbmdY.js";
2
2
  export { extraOptionDefaults, fallBackRouteSchemaKey, fetchSpecificKeys, requestOptionDefaults };
@@ -323,19 +323,24 @@ const getCurrentRouteSchemaKeyAndMainInitURL = (context) => {
323
323
  const { methodFromURL, pathWithoutMethod } = extractURLParts(initURL);
324
324
  const prefixWithoutLeadingSlash = schemaConfig?.prefix && removeLeadingSlash(schemaConfig.prefix);
325
325
  if (prefixWithoutLeadingSlash && pathWithoutMethod.startsWith(prefixWithoutLeadingSlash)) {
326
+ const restOfPathWithoutPrefix = pathWithoutMethod.slice(prefixWithoutLeadingSlash.length);
326
327
  currentRouteSchemaKey = mergeURLParts({
327
328
  method: methodFromURL,
328
- path: pathWithoutMethod.slice(prefixWithoutLeadingSlash.length)
329
+ path: restOfPathWithoutPrefix
329
330
  });
331
+ const pathWithReplacedPrefix = pathWithoutMethod.replace(prefixWithoutLeadingSlash, schemaConfig.baseURL ?? "");
330
332
  mainInitURL = mergeURLParts({
331
333
  method: methodFromURL,
332
- path: pathWithoutMethod.replace(prefixWithoutLeadingSlash, schemaConfig.baseURL ?? "")
334
+ path: pathWithReplacedPrefix
335
+ });
336
+ }
337
+ if (schemaConfig?.baseURL && pathWithoutMethod.startsWith(schemaConfig.baseURL)) {
338
+ const restOfPathWithoutBaseURL = pathWithoutMethod.slice(schemaConfig.baseURL.length);
339
+ currentRouteSchemaKey = mergeURLParts({
340
+ method: methodFromURL,
341
+ path: restOfPathWithoutBaseURL
333
342
  });
334
343
  }
335
- if (schemaConfig?.baseURL && pathWithoutMethod.startsWith(schemaConfig.baseURL)) currentRouteSchemaKey = mergeURLParts({
336
- method: methodFromURL,
337
- path: pathWithoutMethod.slice(schemaConfig.baseURL.length)
338
- });
339
344
  return {
340
345
  currentRouteSchemaKey,
341
346
  initURL,
@@ -343,90 +348,6 @@ const getCurrentRouteSchemaKeyAndMainInitURL = (context) => {
343
348
  };
344
349
  };
345
350
  //#endregion
346
- //#region src/url.ts
347
- const handleArrayParams = (url, params) => {
348
- let newUrl = url;
349
- const urlParts = newUrl.split("/");
350
- const matchedParamsArray = [];
351
- for (const part of urlParts) {
352
- if (!(part.startsWith(":") || part.startsWith("{") && part.endsWith("}"))) continue;
353
- matchedParamsArray.push(part);
354
- }
355
- for (const [paramIndex, matchedParam] of matchedParamsArray.entries()) {
356
- const stringParamValue = String(params[paramIndex]);
357
- newUrl = newUrl.replace(matchedParam, stringParamValue);
358
- }
359
- return newUrl;
360
- };
361
- const handleObjectParams = (url, params) => {
362
- let newUrl = url;
363
- for (const [paramKey, paramValue] of Object.entries(params)) {
364
- const colonPattern = `:${paramKey}`;
365
- const bracePattern = `{${paramKey}}`;
366
- const stringValue = String(paramValue);
367
- newUrl = newUrl.replace(colonPattern, stringValue);
368
- newUrl = newUrl.replace(bracePattern, stringValue);
369
- }
370
- return newUrl;
371
- };
372
- const mergeUrlWithParams = (url, params) => {
373
- if (!params) return url;
374
- return isArray(params) ? handleArrayParams(url, params) : handleObjectParams(url, params);
375
- };
376
- const mergeUrlWithQuery = (url, query) => {
377
- if (!query) return url;
378
- const queryString = new URLSearchParams(query).toString();
379
- if (queryString.length === 0) return url;
380
- if (url.endsWith("?")) return `${url}${queryString}`;
381
- if (url.includes("?")) return `${url}&${queryString}`;
382
- return `${url}?${queryString}`;
383
- };
384
- /**
385
- * @description Extracts the HTTP method from method-prefixed route patterns.
386
- *
387
- * Analyzes URLs that start with method modifiers (e.g., "@get/", "@post/") and extracts
388
- * the HTTP method for use in API requests. This enables method specification directly
389
- * in route definitions.
390
- *
391
- * @param initURL - The URL string to analyze for method modifiers
392
- * @returns The extracted HTTP method (lowercase) if found, otherwise undefined
393
- *
394
- * @example
395
- * ```typescript
396
- * extractMethodFromURL("@get/users"); // Returns: "get"
397
- * extractMethodFromURL("@post/users"); // Returns: "post"
398
- * ```
399
- */
400
- const extractMethodFromURL = (initURL) => {
401
- if (!initURL?.startsWith("@")) return;
402
- const methodFromURL = routeKeyMethods.find((method) => initURL.startsWith(`@${method}/`));
403
- if (!methodFromURL) return;
404
- return methodFromURL;
405
- };
406
- const normalizeURL = (initURL, options = {}) => {
407
- const { retainLeadingSlashForRelativeURLs = true } = options;
408
- const methodFromURL = extractMethodFromURL(initURL);
409
- if (!methodFromURL) return initURL;
410
- return retainLeadingSlashForRelativeURLs && !initURL.includes("http") ? initURL.replace(`@${methodFromURL}`, "") : initURL.replace(`@${methodFromURL}/`, "");
411
- };
412
- const getFullURL = (initURL, baseURL) => {
413
- if (!baseURL || initURL.startsWith("http")) return initURL;
414
- return initURL.length > 0 && !initURL.startsWith("/") && !baseURL.endsWith("/") ? `${baseURL}/${initURL}` : `${baseURL}${initURL}`;
415
- };
416
- const getFullAndNormalizedURL = (options) => {
417
- const { baseURL, debugMode, initURL, params, query } = options;
418
- const normalizedInitURL = normalizeURL(initURL);
419
- const fullURL = getFullURL(mergeUrlWithQuery(mergeUrlWithParams(normalizedInitURL, params), query), baseURL);
420
- if ((debugMode ?? extraOptionDefaults.debugMode) && !URL.canParse(fullURL)) {
421
- const errorMessage = !baseURL ? `Invalid URL '${initURL}'. Are you passing a relative url to CallApi without setting the 'baseURL' option?` : `Invalid URL '${fullURL}'. Please validate that you are passing the correct url.`;
422
- console.error(errorMessage);
423
- }
424
- return {
425
- fullURL,
426
- normalizedInitURL
427
- };
428
- };
429
- //#endregion
430
351
  //#region src/utils/external/body.ts
431
352
  const toStringOrStringify = (value) => {
432
353
  return isString(value) ? value : JSON.stringify(value);
@@ -438,6 +359,7 @@ const toSearchParams = (data, schema) => {
438
359
  issues: result.issues,
439
360
  response: null
440
361
  });
362
+ if (result.value instanceof URLSearchParams) return new URLSearchParams(result.value);
441
363
  const searchParams = new URLSearchParams();
442
364
  for (const [key, value] of Object.entries(result.value)) {
443
365
  if (value == null) continue;
@@ -563,6 +485,115 @@ const objectifyHeaders = (headers) => {
563
485
  return Object.fromEntries(headers);
564
486
  };
565
487
  //#endregion
488
+ //#region src/url.ts
489
+ const isReservedPathSegment = (value) => value === "." || value === "..";
490
+ const encodeParamValue = (value) => {
491
+ const stringValue = String(value);
492
+ if (isReservedPathSegment(stringValue)) throw new TypeError("Path parameters cannot be reserved path segments");
493
+ return encodeURIComponent(stringValue);
494
+ };
495
+ const isColonPathParam = (segment) => Boolean(segment?.startsWith(":"));
496
+ const isBracePathParam = (segment) => {
497
+ return Boolean(segment?.startsWith("{") && segment.endsWith("}"));
498
+ };
499
+ const handleArrayParams = (url, params) => {
500
+ const placeholders = [];
501
+ const urlSegments = url.split("/");
502
+ for (const segment of urlSegments) {
503
+ if (!isColonPathParam(segment) && !isBracePathParam(segment)) continue;
504
+ placeholders.push(segment);
505
+ }
506
+ let resolvedURL = url;
507
+ for (const index of placeholders.keys()) {
508
+ const placeholder = placeholders[index];
509
+ if (placeholder === void 0) continue;
510
+ const paramValue = params[index];
511
+ resolvedURL = resolvedURL.replace(placeholder, encodeParamValue(paramValue));
512
+ }
513
+ return resolvedURL;
514
+ };
515
+ const getPathParamKey = (segment) => {
516
+ if (isColonPathParam(segment)) return segment.slice(1);
517
+ if (isBracePathParam(segment)) return segment.slice(1, -1);
518
+ return null;
519
+ };
520
+ const handleObjectParams = (url, params) => {
521
+ const urlSegments = url.split("/");
522
+ for (const segmentIndex of urlSegments.keys()) {
523
+ const segment = urlSegments[segmentIndex];
524
+ if (segment === void 0) continue;
525
+ const paramKey = getPathParamKey(segment);
526
+ if (paramKey === null || !Object.hasOwn(params, paramKey)) continue;
527
+ const paramValue = params[paramKey];
528
+ urlSegments[segmentIndex] = encodeParamValue(paramValue);
529
+ }
530
+ return urlSegments.join("/");
531
+ };
532
+ const mergeUrlWithParams = (url, params) => {
533
+ if (!params) return url;
534
+ return isArray(params) ? handleArrayParams(url, params) : handleObjectParams(url, params);
535
+ };
536
+ const mergeUrlWithQuery = (url, query) => {
537
+ if (!query) return url;
538
+ const incomingSearchParams = toSearchParams(query);
539
+ if (incomingSearchParams.size === 0) return url;
540
+ if (!url.includes("?")) return `${url}?${incomingSearchParams}`;
541
+ if (url.endsWith("?")) return `${url}${incomingSearchParams}`;
542
+ const [mainUrl, existingQueryString] = url.split("?");
543
+ const searchParams = new URLSearchParams(existingQueryString);
544
+ for (const key of incomingSearchParams.keys()) searchParams.delete(key);
545
+ for (const entry of incomingSearchParams) searchParams.append(...entry);
546
+ return `${mainUrl}?${searchParams}`;
547
+ };
548
+ /**
549
+ * @description Extracts the HTTP method from method-prefixed route patterns.
550
+ *
551
+ * Analyzes URLs that start with method modifiers (e.g., "@get/", "@post/") and extracts
552
+ * the HTTP method for use in API requests. This enables method specification directly
553
+ * in route definitions.
554
+ *
555
+ * @param initURL - The URL string to analyze for method modifiers
556
+ * @returns The extracted HTTP method (lowercase) if found, otherwise undefined
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * extractMethodFromURL("@get/users"); // Returns: "get"
561
+ * extractMethodFromURL("@post/users"); // Returns: "post"
562
+ * ```
563
+ */
564
+ const extractMethodFromURL = (initURL) => {
565
+ if (!initURL?.startsWith("@")) return;
566
+ const methodFromURL = routeKeyMethods.find((method) => initURL.startsWith(`@${method}/`));
567
+ if (!methodFromURL) return;
568
+ return methodFromURL;
569
+ };
570
+ const isAbsoluteHTTPURL = (value) => {
571
+ return value.startsWith("http://") || value.startsWith("https://");
572
+ };
573
+ const normalizeURL = (initURL, options = {}) => {
574
+ const { retainLeadingSlashForRelativeURLs = true } = options;
575
+ const methodFromURL = extractMethodFromURL(initURL);
576
+ if (!methodFromURL) return initURL;
577
+ const initURLWithoutMethod = initURL.replace(`@${methodFromURL}/`, "");
578
+ return retainLeadingSlashForRelativeURLs && !isAbsoluteHTTPURL(initURLWithoutMethod) ? `/${initURLWithoutMethod}` : initURLWithoutMethod;
579
+ };
580
+ const getFullURL = (initURL, baseURL) => {
581
+ if (!baseURL || isAbsoluteHTTPURL(initURL)) return initURL;
582
+ const normalizedBaseURL = baseURL.replace(/\/+$/, "");
583
+ const normalizedInitURL = initURL.replace(/^\/+/, "");
584
+ return normalizedInitURL ? `${normalizedBaseURL}/${normalizedInitURL}` : normalizedBaseURL;
585
+ };
586
+ const getFullAndNormalizedURL = (options) => {
587
+ const { baseURL, debugMode, initURL, params, query } = options;
588
+ const normalizedInitURL = normalizeURL(initURL);
589
+ const fullURL = getFullURL(mergeUrlWithQuery(mergeUrlWithParams(normalizedInitURL, params), query), baseURL);
590
+ if ((debugMode ?? extraOptionDefaults.debugMode) && !isAbsoluteHTTPURL(fullURL) && !URL.canParse(fullURL)) console.error(`Relative URL '${fullURL}' may fail during SSR. Set an absolute 'baseURL' for server-side requests.`);
591
+ return {
592
+ fullURL,
593
+ normalizedInitURL
594
+ };
595
+ };
596
+ //#endregion
566
597
  //#region src/utils/common.ts
567
598
  const omitKeys = (initialObject, keysToOmit) => {
568
599
  const updatedObject = {};
@@ -589,16 +620,16 @@ const detectContentTypeHeader = (body) => {
589
620
  };
590
621
  const getHeaders = async (options) => {
591
622
  const { auth, body, resolvedHeaders } = options;
592
- const authHeaderObject = await getAuthHeader(auth);
593
623
  const resolvedHeadersObject = objectifyHeaders(resolvedHeaders);
594
- if (!(Object.hasOwn(resolvedHeadersObject, "Content-Type") || Object.hasOwn(resolvedHeadersObject, "content-type"))) {
595
- const contentTypeHeader = detectContentTypeHeader(body);
596
- contentTypeHeader && Object.assign(resolvedHeadersObject, contentTypeHeader);
597
- }
598
- return {
599
- ...authHeaderObject,
624
+ const headersObject = {
625
+ ...await getAuthHeader(auth),
600
626
  ...resolvedHeadersObject
601
627
  };
628
+ if (!new Headers(headersObject).has("Content-Type")) {
629
+ const contentTypeHeader = detectContentTypeHeader(body);
630
+ contentTypeHeader && Object.assign(headersObject, contentTypeHeader);
631
+ }
632
+ return headersObject;
602
633
  };
603
634
  const getMethod = (ctx) => {
604
635
  const { initURL, method } = ctx;
@@ -679,6 +710,6 @@ const extraOptionDefaults = Object.freeze(defineEnum({
679
710
  }));
680
711
  const requestOptionDefaults = Object.freeze(defineEnum({ method: "GET" }));
681
712
  //#endregion
682
- export { getCurrentRouteSchemaKeyAndMainInitURL as A, defineSchema as C, toQueryString as D, toFormData as E, fallBackRouteSchemaKey as F, isArray as I, isFunction as L, handleSchemaValidation as M, HTTPError as N, toSearchParams as O, ValidationError as P, isString as R, definePlugin as S, defineSchemaRoutes as T, isValidationError as _, getBody as a, defineInstanceConfig as b, getMethod as c, splitConfig as d, waitFor as f, isJavascriptError as g, isHTTPErrorInstance as h, createTimeoutSignal as i, handleConfigValidation as j, getFullAndNormalizedURL as k, getResolvedHeaders as l, isHTTPError as m, requestOptionDefaults as n, getFetchImpl as o, objectifyHeaders as p, createCombinedSignal as r, getHeaders as s, extraOptionDefaults as t, omitKeys as u, isValidationErrorInstance as v, defineSchemaConfig as w, defineMainSchema as x, defineBaseConfig as y, fetchSpecificKeys as z };
713
+ export { getCurrentRouteSchemaKeyAndMainInitURL as A, definePlugin as C, toFormData as D, defineSchemaRoutes as E, fallBackRouteSchemaKey as F, isArray as I, isFunction as L, handleSchemaValidation as M, HTTPError as N, toQueryString as O, ValidationError as P, isString as R, defineMainSchema as S, defineSchemaConfig as T, isJavascriptError as _, getBody as a, defineBaseConfig as b, getMethod as c, splitConfig as d, waitFor as f, isHTTPErrorInstance as g, isHTTPError as h, createTimeoutSignal as i, handleConfigValidation as j, toSearchParams as k, getResolvedHeaders as l, objectifyHeaders as m, requestOptionDefaults as n, getFetchImpl as o, getFullAndNormalizedURL as p, createCombinedSignal as r, getHeaders as s, extraOptionDefaults as t, omitKeys as u, isValidationError as v, defineSchema as w, defineInstanceConfig as x, isValidationErrorInstance as y, fetchSpecificKeys as z };
683
714
 
684
- //# sourceMappingURL=constants-CQmUuQDT.js.map
715
+ //# sourceMappingURL=constants-C8dGbmdY.js.map