@zayne-labs/callapi 1.11.14 → 1.11.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/{common-Clx7i8bR.d.ts → common-CYwKssG-.d.ts} +25 -21
- package/dist/esm/constants/index.d.ts +2 -2
- package/dist/esm/constants/index.js +1 -1
- package/dist/esm/{body-B9WKokQt.js → guards-ClpaRdJN.js} +73 -73
- package/dist/esm/guards-ClpaRdJN.js.map +1 -0
- package/dist/esm/index.d.ts +12 -6
- package/dist/esm/index.js +367 -366
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/external/index.d.ts +2 -2
- package/dist/esm/utils/external/index.js +1 -1
- package/dist/esm/validation-Dq--Q5zC.d.ts +9 -0
- package/dist/esm/{validation-MjkoG9bG.js → validation-jR4wVvCQ.js} +2 -2
- package/dist/esm/{validation-MjkoG9bG.js.map → validation-jR4wVvCQ.js.map} +1 -1
- package/package.json +1 -1
- package/dist/esm/body-B9WKokQt.js.map +0 -1
- package/dist/esm/validation-uPnlxhfx.d.ts +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as fetchSpecificKeys, t as FallBackRouteSchemaKey } from "./validation-Dq--Q5zC.js";
|
|
2
2
|
|
|
3
3
|
//#region src/types/type-helpers.d.ts
|
|
4
4
|
type AnyString = string & NonNullable<unknown>;
|
|
@@ -426,12 +426,11 @@ interface CallApiSchema {
|
|
|
426
426
|
declare const routeKeyMethods: readonly ["delete", "get", "patch", "post", "put"];
|
|
427
427
|
type RouteKeyMethods = (typeof routeKeyMethods)[number];
|
|
428
428
|
type RouteKeyMethodsURLUnion = `@${RouteKeyMethods}/`;
|
|
429
|
-
type BaseCallApiSchemaRoutes = Partial<Record<AnyString | RouteKeyMethodsURLUnion, CallApiSchema>>;
|
|
429
|
+
type BaseCallApiSchemaRoutes = Partial<Record<AnyString | FallBackRouteSchemaKey | RouteKeyMethodsURLUnion, CallApiSchema>>;
|
|
430
430
|
type BaseCallApiSchemaAndConfig = {
|
|
431
431
|
config?: CallApiSchemaConfig;
|
|
432
432
|
routes: BaseCallApiSchemaRoutes;
|
|
433
433
|
};
|
|
434
|
-
type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;
|
|
435
434
|
//#endregion
|
|
436
435
|
//#region src/utils/external/error.d.ts
|
|
437
436
|
type HTTPErrorDetails<TErrorData$1> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
|
|
@@ -494,9 +493,11 @@ declare const getResponseType: <TResponse>(response: Response, parser: Parser<TR
|
|
|
494
493
|
text: () => Promise<string>;
|
|
495
494
|
};
|
|
496
495
|
type InitResponseTypeMap<TResponse$1 = unknown> = ReturnType<typeof getResponseType<TResponse$1>>;
|
|
497
|
-
type ResponseTypeUnion = keyof InitResponseTypeMap
|
|
496
|
+
type ResponseTypeUnion = keyof InitResponseTypeMap;
|
|
497
|
+
type ResponseTypePlaceholder = null;
|
|
498
|
+
type ResponseTypeType = ResponseTypePlaceholder | ResponseTypeUnion;
|
|
498
499
|
type ResponseTypeMap<TResponse$1> = { [Key in keyof InitResponseTypeMap<TResponse$1>]: Awaited<ReturnType<InitResponseTypeMap<TResponse$1>[Key]>> };
|
|
499
|
-
type GetResponseType<TResponse$1, TResponseType extends
|
|
500
|
+
type GetResponseType<TResponse$1, TResponseType extends ResponseTypeType, TComputedResponseTypeMap extends ResponseTypeMap<TResponse$1> = ResponseTypeMap<TResponse$1>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeType> ? TComputedResponseTypeMap[TResponseType] : never;
|
|
500
501
|
type CallApiResultSuccessVariant<TData$1> = {
|
|
501
502
|
data: NoInfer<TData$1>;
|
|
502
503
|
error: null;
|
|
@@ -532,20 +533,23 @@ type CallApiResultErrorVariant<TErrorData$1> = {
|
|
|
532
533
|
response: Response | null;
|
|
533
534
|
};
|
|
534
535
|
type CallApiSuccessOrErrorVariant<TData$1, TError> = CallApiResultErrorVariant<TError> | CallApiResultSuccessVariant<TData$1>;
|
|
535
|
-
type ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType extends
|
|
536
|
+
type ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType extends ResponseTypeType, TComputedData = GetResponseType<TData$1, TResponseType>, TComputedErrorData = GetResponseType<TErrorData$1, TResponseType>, TComputedResult extends CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData> = CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData>> = UnmaskType<{
|
|
536
537
|
all: TComputedResult;
|
|
537
538
|
onlyData: TComputedResult["data"];
|
|
538
539
|
onlyResponse: TComputedResult["response"];
|
|
540
|
+
withoutResponse: TComputedResult["data"] | TComputedResult["error"];
|
|
539
541
|
}>;
|
|
540
|
-
type ResultModeMapWithException<TData$1, TResponseType extends
|
|
542
|
+
type ResultModeMapWithException<TData$1, TResponseType extends ResponseTypeType, TComputedData = GetResponseType<TData$1, TResponseType>, TComputedResult extends CallApiResultSuccessVariant<TComputedData> = CallApiResultSuccessVariant<TComputedData>> = {
|
|
541
543
|
all: TComputedResult;
|
|
542
544
|
onlyData: TComputedResult["data"];
|
|
543
545
|
onlyResponse: TComputedResult["response"];
|
|
546
|
+
withoutResponse: TComputedResult["data"] | TComputedResult["error"];
|
|
544
547
|
};
|
|
545
|
-
type ResultModeMap<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResponseType extends
|
|
548
|
+
type ResultModeMap<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResponseType extends ResponseTypeType = ResponseTypeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError> = TThrowOnError extends true ? ResultModeMapWithException<TData$1, TResponseType> : ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType>;
|
|
546
549
|
type ResultModePlaceholder = null;
|
|
547
|
-
type ResultModeUnion = keyof ResultModeMap
|
|
548
|
-
type
|
|
550
|
+
type ResultModeUnion = keyof ResultModeMap;
|
|
551
|
+
type ResultModeType = ResultModePlaceholder | ResultModeUnion;
|
|
552
|
+
type GetCallApiResult<TData$1, TErrorData$1, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeType, TComputedResultModeMapWithException extends ResultModeMapWithException<TData$1, TResponseType> = ResultModeMapWithException<TData$1, TResponseType>, TComputedResultModeMap extends ResultModeMap<TData$1, TErrorData$1, TResponseType, TThrowOnError> = ResultModeMap<TData$1, TErrorData$1, TResponseType, TThrowOnError>> = TErrorData$1 extends false ? TComputedResultModeMapWithException["onlyData"] : TErrorData$1 extends false | undefined ? TComputedResultModeMapWithException["onlyData"] : ResultModePlaceholder extends TResultMode ? TComputedResultModeMap["all"] : TResultMode extends ResultModeUnion ? TComputedResultModeMap[TResultMode] : never;
|
|
549
553
|
//#endregion
|
|
550
554
|
//#region src/middlewares.d.ts
|
|
551
555
|
type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
|
|
@@ -1235,7 +1239,7 @@ type InferInitURL<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TSchemaCo
|
|
|
1235
1239
|
type GetCurrentRouteSchemaKey<TSchemaConfig$1 extends CallApiSchemaConfig, TPath> = TPath extends URL ? string : TSchemaConfig$1["baseURL"] extends string ? TPath extends `${TSchemaConfig$1["baseURL"]}${infer TCurrentRoute}` ? TCurrentRoute extends string ? TCurrentRoute : string : TPath extends `${TSchemaConfig$1["prefix"]}${infer TCurrentRoute}` ? TCurrentRoute extends string ? TCurrentRoute : string : string : TPath;
|
|
1236
1240
|
type GetCurrentRouteSchema<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes$1[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes$1[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
|
|
1237
1241
|
type JsonPrimitive = boolean | number | string | null | undefined;
|
|
1238
|
-
type SerializableObject = Record<
|
|
1242
|
+
type SerializableObject = Record<PropertyKey, unknown>;
|
|
1239
1243
|
type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
|
|
1240
1244
|
type Body = UnmaskType<RequestInit["body"] | SerializableArray | SerializableObject>;
|
|
1241
1245
|
type InferBodyOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["body"], {
|
|
@@ -1316,7 +1320,7 @@ type InferParamsOption<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 exte
|
|
|
1316
1320
|
}>;
|
|
1317
1321
|
type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema$1> & InferParamsOption<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferQueryOption<TSchema$1>;
|
|
1318
1322
|
type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction<infer TReturnedSchema> ? InferSchemaInput<TReturnedSchema> : never : never : never>;
|
|
1319
|
-
type ResultModeOption<TErrorData$1, TResultMode extends
|
|
1323
|
+
type ResultModeOption<TErrorData$1, TResultMode extends ResultModeType> = TErrorData$1 extends false ? {
|
|
1320
1324
|
resultMode: "onlyData";
|
|
1321
1325
|
} : TErrorData$1 extends false | undefined ? {
|
|
1322
1326
|
resultMode?: "onlyData";
|
|
@@ -1356,7 +1360,7 @@ type CallApiRequestOptions = Prettify<{
|
|
|
1356
1360
|
type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
|
|
1357
1361
|
headers: Record<string, string | undefined>;
|
|
1358
1362
|
};
|
|
1359
|
-
type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends
|
|
1363
|
+
type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TData$1, TErrorData$1, Partial<InferPluginOptions<TPluginArray>>> & Middlewares & Partial<InferPluginOptions<TPluginArray>> & ResultModeOption<TErrorData$1, TResultMode> & RetryOptions<TErrorData$1> & ThrowOnErrorOption<TErrorData$1, TThrowOnError> & URLOptions & {
|
|
1360
1364
|
/**
|
|
1361
1365
|
* Automatically add an Authorization header value.
|
|
1362
1366
|
*
|
|
@@ -1730,7 +1734,7 @@ type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataTyp
|
|
|
1730
1734
|
*/
|
|
1731
1735
|
timeout?: number;
|
|
1732
1736
|
};
|
|
1733
|
-
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends
|
|
1737
|
+
type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
|
|
1734
1738
|
/**
|
|
1735
1739
|
* Array of base CallApi plugins to extend library functionality.
|
|
1736
1740
|
*
|
|
@@ -1842,7 +1846,7 @@ type InferExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfi
|
|
|
1842
1846
|
type InferExtendPluginContext<TBasePluginArray extends CallApiPlugin[]> = {
|
|
1843
1847
|
basePlugins: TBasePluginArray;
|
|
1844
1848
|
};
|
|
1845
|
-
type CallApiExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends
|
|
1849
|
+
type CallApiExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string, TComputedPluginContext = InferExtendPluginContext<TBasePluginArray>, TComputedSchemaContext = InferExtendSchemaContext<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey>, TComputedSchemaConfigContext = InferExtendSchemaConfigContext<TBaseSchemaConfig>> = SharedExtraOptions<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1846
1850
|
/**
|
|
1847
1851
|
* Array of instance-specific CallApi plugins or a function to configure plugins.
|
|
1848
1852
|
*
|
|
@@ -1876,10 +1880,10 @@ type BaseInstanceContext = {
|
|
|
1876
1880
|
options: CallApiExtraOptions;
|
|
1877
1881
|
request: CallApiRequestOptions;
|
|
1878
1882
|
};
|
|
1879
|
-
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends
|
|
1880
|
-
type CallApiConfig<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends
|
|
1881
|
-
type CallApiParameters<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends
|
|
1882
|
-
type CallApiResult<TData$1, TErrorData$1, TResultMode extends
|
|
1883
|
+
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: BaseInstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
|
|
1884
|
+
type CallApiConfig<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema$1, TInitURL> & Omit<CallApiExtraOptions<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1885
|
+
type CallApiParameters<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = [initURL: TInitURL, config?: CallApiConfig<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
|
1886
|
+
type CallApiResult<TData$1, TErrorData$1, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeType> = GetCallApiResult<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType>;
|
|
1883
1887
|
//#endregion
|
|
1884
|
-
export { GetResponseType as $, RequestStreamContext as A, defineBaseConfig as B, RetryOptions as C, AnyFunction as Ct, HooksOrHooksArray as D, Hooks as E, isHTTPError as F, CallApiPlugin as G, defineSchema as H, isHTTPErrorInstance as I, PluginSetupContext as J, PluginHooks as K, isJavascriptError as L, ResponseErrorContext as M, ResponseStreamContext as N, PluginExtraOptions as O, SuccessContext as P, GetCallApiResult as Q, isValidationError as R, ThrowOnErrorUnion as S, toQueryString as St, ErrorContext as T, defineSchemaConfig as U, definePlugin as V, defineSchemaRoutes as W, CallApiResultSuccessVariant as X, CallApiResultErrorVariant as Y, CallApiSuccessOrErrorVariant as Z, GetCurrentRouteSchema as _, StandardSchemaV1 as _t, CallApiExtraOptions as a,
|
|
1885
|
-
//# sourceMappingURL=common-
|
|
1888
|
+
export { GetResponseType as $, RequestStreamContext as A, defineBaseConfig as B, RetryOptions as C, AnyFunction as Ct, HooksOrHooksArray as D, Hooks as E, isHTTPError as F, CallApiPlugin as G, defineSchema as H, isHTTPErrorInstance as I, PluginSetupContext as J, PluginHooks as K, isJavascriptError as L, ResponseErrorContext as M, ResponseStreamContext as N, PluginExtraOptions as O, SuccessContext as P, GetCallApiResult as Q, isValidationError as R, ThrowOnErrorUnion as S, toQueryString as St, ErrorContext as T, defineSchemaConfig as U, definePlugin as V, defineSchemaRoutes as W, CallApiResultSuccessVariant as X, CallApiResultErrorVariant as Y, CallApiSuccessOrErrorVariant as Z, GetCurrentRouteSchema as _, StandardSchemaV1 as _t, CallApiExtraOptions as a, ResponseTypeType as at, InferParamsFromRoute as b, DefaultThrowOnError as bt, CallApiRequestOptions as c, HTTPError as ct, GetBaseSchemaConfig as d, BaseCallApiSchemaRoutes as dt, PossibleHTTPError as et, GetBaseSchemaRoutes as f, CallApiSchema as ft, ApplyURLBasedConfig as g, URLOptions as gt, ApplyStrictConfig as h, InferSchemaOutput as ht, CallApiConfig as i, ResponseTypeMap as it, ResponseContext as j, RequestContext as k, CallApiRequestOptionsForHooks as l, ValidationError as lt, InferExtendSchemaContext as m, InferSchemaInput as mt, BaseCallApiExtraOptions as n, PossibleJavaScriptOrValidationError as nt, CallApiExtraOptionsForHooks as o, ResultModeMap as ot, InferExtendSchemaConfigContext as p, CallApiSchemaConfig as pt, PluginHooksWithMoreOptions as q, BaseInstanceContext as r, PossibleValidationError as rt, CallApiParameters as s, ResultModeType as st, BaseCallApiConfig as t, PossibleJavaScriptError as tt, CallApiResult as u, BaseCallApiSchemaAndConfig as ut, GetCurrentRouteSchemaKey as v, DefaultDataType as vt, DedupeOptions as w, AnyString as wt, Register as x, toFormData as xt, InferInitURL as y, DefaultPluginArray as yt, isValidationErrorInstance as z };
|
|
1889
|
+
//# sourceMappingURL=common-CYwKssG-.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as fetchSpecificKeys, t as
|
|
1
|
+
import { n as fallBackRouteSchemaKey, r as fetchSpecificKeys, t as FallBackRouteSchemaKey } from "../validation-Dq--Q5zC.js";
|
|
2
2
|
|
|
3
3
|
//#region src/constants/defaults.d.ts
|
|
4
4
|
declare const extraOptionDefaults: Readonly<Readonly<{
|
|
@@ -26,5 +26,5 @@ declare const requestOptionDefaults: Readonly<{
|
|
|
26
26
|
method: "GET";
|
|
27
27
|
}>;
|
|
28
28
|
//#endregion
|
|
29
|
-
export { extraOptionDefaults, fallBackRouteSchemaKey, fetchSpecificKeys, requestOptionDefaults };
|
|
29
|
+
export { FallBackRouteSchemaKey, extraOptionDefaults, fallBackRouteSchemaKey, fetchSpecificKeys, requestOptionDefaults };
|
|
30
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { n as requestOptionDefaults, t as extraOptionDefaults } from "../defaults-BD3B1uIH.js";
|
|
2
|
-
import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "../validation-
|
|
2
|
+
import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "../validation-jR4wVvCQ.js";
|
|
3
3
|
|
|
4
4
|
export { extraOptionDefaults, fallBackRouteSchemaKey, fetchSpecificKeys, requestOptionDefaults };
|
|
@@ -44,6 +44,77 @@ const isReadableStream = (value) => {
|
|
|
44
44
|
return value instanceof ReadableStream;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/utils/external/body.ts
|
|
49
|
+
const toQueryString = (query) => {
|
|
50
|
+
if (!query) {
|
|
51
|
+
console.error("toQueryString:", "No query params provided!");
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return new URLSearchParams(query).toString();
|
|
55
|
+
};
|
|
56
|
+
const toBlobOrString = (value) => {
|
|
57
|
+
return isBlob(value) ? value : String(value);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* @description Converts a plain object to FormData.
|
|
61
|
+
*
|
|
62
|
+
* Handles various data types:
|
|
63
|
+
* - **Primitives** (string, number, boolean): Converted to strings
|
|
64
|
+
* - **Blobs/Files**: Added directly to FormData
|
|
65
|
+
* - **Arrays**: Each item is appended (allows multiple values for same key)
|
|
66
|
+
* - **Objects**: JSON stringified before adding to FormData
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* // Basic usage
|
|
71
|
+
* const formData = toFormData({
|
|
72
|
+
* name: "John",
|
|
73
|
+
* age: 30,
|
|
74
|
+
* active: true
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // With arrays
|
|
78
|
+
* const formData = toFormData({
|
|
79
|
+
* tags: ["javascript", "typescript"],
|
|
80
|
+
* name: "John"
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // With files
|
|
84
|
+
* const formData = toFormData({
|
|
85
|
+
* avatar: fileBlob,
|
|
86
|
+
* name: "John"
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* // With nested objects (one level only)
|
|
90
|
+
* const formData = toFormData({
|
|
91
|
+
* user: { name: "John", age: 30 },
|
|
92
|
+
* settings: { theme: "dark" }
|
|
93
|
+
* });
|
|
94
|
+
*
|
|
95
|
+
* // Type-preserving usage with Zod
|
|
96
|
+
* const schema = z.object({ name: z.string(), file: z.instanceof(Blob) });
|
|
97
|
+
* const data = schema.parse({ name: "John", file: blob });
|
|
98
|
+
* const typedFormData = toFormData(data, { returnType: "inputType" });
|
|
99
|
+
* // Type is { name: string; file: Blob }, runtime is FormData
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
const toFormData = (data) => {
|
|
103
|
+
const formData = new FormData();
|
|
104
|
+
for (const [key, value] of Object.entries(data)) {
|
|
105
|
+
if (isArray(value)) {
|
|
106
|
+
value.forEach((innerValue) => formData.append(key, toBlobOrString(innerValue)));
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (isObject(value) && !isBlob(value)) {
|
|
110
|
+
formData.set(key, JSON.stringify(value));
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
formData.set(key, toBlobOrString(value));
|
|
114
|
+
}
|
|
115
|
+
return formData;
|
|
116
|
+
};
|
|
117
|
+
|
|
47
118
|
//#endregion
|
|
48
119
|
//#region src/utils/external/error.ts
|
|
49
120
|
const httpErrorSymbol = Symbol("HTTPError");
|
|
@@ -129,76 +200,5 @@ const isJavascriptError = (error) => {
|
|
|
129
200
|
};
|
|
130
201
|
|
|
131
202
|
//#endregion
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!query) {
|
|
135
|
-
console.error("toQueryString:", "No query params provided!");
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
return new URLSearchParams(query).toString();
|
|
139
|
-
};
|
|
140
|
-
const toBlobOrString = (value) => {
|
|
141
|
-
return isBlob(value) ? value : String(value);
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* @description Converts a plain object to FormData.
|
|
145
|
-
*
|
|
146
|
-
* Handles various data types:
|
|
147
|
-
* - **Primitives** (string, number, boolean): Converted to strings
|
|
148
|
-
* - **Blobs/Files**: Added directly to FormData
|
|
149
|
-
* - **Arrays**: Each item is appended (allows multiple values for same key)
|
|
150
|
-
* - **Objects**: JSON stringified before adding to FormData
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```ts
|
|
154
|
-
* // Basic usage
|
|
155
|
-
* const formData = toFormData({
|
|
156
|
-
* name: "John",
|
|
157
|
-
* age: 30,
|
|
158
|
-
* active: true
|
|
159
|
-
* });
|
|
160
|
-
*
|
|
161
|
-
* // With arrays
|
|
162
|
-
* const formData = toFormData({
|
|
163
|
-
* tags: ["javascript", "typescript"],
|
|
164
|
-
* name: "John"
|
|
165
|
-
* });
|
|
166
|
-
*
|
|
167
|
-
* // With files
|
|
168
|
-
* const formData = toFormData({
|
|
169
|
-
* avatar: fileBlob,
|
|
170
|
-
* name: "John"
|
|
171
|
-
* });
|
|
172
|
-
*
|
|
173
|
-
* // With nested objects (one level only)
|
|
174
|
-
* const formData = toFormData({
|
|
175
|
-
* user: { name: "John", age: 30 },
|
|
176
|
-
* settings: { theme: "dark" }
|
|
177
|
-
* });
|
|
178
|
-
*
|
|
179
|
-
* // Type-preserving usage with Zod
|
|
180
|
-
* const schema = z.object({ name: z.string(), file: z.instanceof(Blob) });
|
|
181
|
-
* const data = schema.parse({ name: "John", file: blob });
|
|
182
|
-
* const typedFormData = toFormData(data, { returnType: "inputType" });
|
|
183
|
-
* // Type is { name: string; file: Blob }, runtime is FormData
|
|
184
|
-
* ```
|
|
185
|
-
*/
|
|
186
|
-
const toFormData = (data) => {
|
|
187
|
-
const formData = new FormData();
|
|
188
|
-
for (const [key, value] of Object.entries(data)) {
|
|
189
|
-
if (isArray(value)) {
|
|
190
|
-
value.forEach((innerValue) => formData.append(key, toBlobOrString(innerValue)));
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
if (isObject(value) && !isBlob(value)) {
|
|
194
|
-
formData.set(key, JSON.stringify(value));
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
formData.set(key, toBlobOrString(value));
|
|
198
|
-
}
|
|
199
|
-
return formData;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
//#endregion
|
|
203
|
-
export { isReadableStream as _, isJavascriptError as a, isValidJsonString as b, HTTPError as c, isBoolean as d, isFunction as f, isQueryString as g, isPromise as h, isHTTPErrorInstance as i, ValidationError as l, isPlainObject as m, toQueryString as n, isValidationError as o, isObject as p, isHTTPError as r, isValidationErrorInstance as s, toFormData as t, isArray as u, isSerializable as v, isString as y };
|
|
204
|
-
//# sourceMappingURL=body-B9WKokQt.js.map
|
|
203
|
+
export { isReadableStream as _, isValidationErrorInstance as a, isValidJsonString as b, toFormData as c, isBoolean as d, isFunction as f, isQueryString as g, isPromise as h, isValidationError as i, toQueryString as l, isPlainObject as m, isHTTPErrorInstance as n, HTTPError as o, isObject as p, isJavascriptError as r, ValidationError as s, isHTTPError as t, isArray as u, isSerializable as v, isString as y };
|
|
204
|
+
//# sourceMappingURL=guards-ClpaRdJN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards-ClpaRdJN.js","names":["toQueryString: ToQueryStringFn","toFormData: ToFormDataFn"],"sources":["../../src/utils/guards.ts","../../src/utils/external/body.ts","../../src/utils/external/error.ts","../../src/utils/external/guards.ts"],"sourcesContent":["import type { AnyFunction } from \"../types/type-helpers\";\n\nexport const isArray = <TArrayItem>(value: unknown): value is TArrayItem[] => Array.isArray(value);\n\nexport const isBoolean = (value: unknown): value is boolean => typeof value === \"boolean\";\n\nexport const isBlob = (value: unknown): value is Blob => value instanceof Blob;\n\nexport const isObject = <TObject extends object>(value: unknown): value is TObject => {\n\treturn typeof value === \"object\" && value !== null;\n};\n\nconst hasObjectPrototype = (value: unknown) => {\n\treturn Object.prototype.toString.call(value) === \"[object Object]\";\n};\n\n/**\n * @description Copied from TanStack Query's isPlainObject\n * @see https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L321\n */\nexport const isPlainObject = <TPlainObject extends Record<string, unknown>>(\n\tvalue: unknown\n): value is TPlainObject => {\n\tif (!hasObjectPrototype(value)) {\n\t\treturn false;\n\t}\n\n\t// If has no constructor\n\tconst constructor = (value as object | undefined)?.constructor;\n\tif (constructor === undefined) {\n\t\treturn true;\n\t}\n\n\t// If has modified prototype\n\tconst prototype = constructor.prototype as object;\n\tif (!hasObjectPrototype(prototype)) {\n\t\treturn false;\n\t}\n\n\t// If constructor does not have an Object-specific method\n\tif (!Object.hasOwn(prototype, \"isPrototypeOf\")) {\n\t\treturn false;\n\t}\n\n\t// Handles Objects created by Object.create(<arbitrary prototype>)\n\tif (Object.getPrototypeOf(value) !== Object.prototype) {\n\t\treturn false;\n\t}\n\n\t// It's probably a plain object at this point\n\treturn true;\n};\n\nexport const isValidJsonString = (value: unknown): value is string => {\n\tif (!isString(value)) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\tJSON.parse(value);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n};\n\nexport const isSerializable = (value: unknown) => {\n\treturn (\n\t\tisPlainObject(value)\n\t\t|| isArray(value)\n\t\t|| typeof (value as { toJSON: unknown } | undefined)?.toJSON === \"function\"\n\t);\n};\n\nexport const isFunction = <TFunction extends AnyFunction>(value: unknown): value is TFunction =>\n\ttypeof value === \"function\";\n\nexport const isQueryString = (value: unknown): value is string => isString(value) && value.includes(\"=\");\n\nexport const isString = (value: unknown) => typeof value === \"string\";\n\nexport const isPromise = (value: unknown) => value instanceof Promise;\n\nexport const isReadableStream = (value: unknown): value is ReadableStream<unknown> => {\n\treturn value instanceof ReadableStream;\n};\n\n// https://github.com/unjs/ofetch/blob/main/src/utils.ts\nexport const isJSONSerializable = (value: unknown) => {\n\tif (value === undefined) {\n\t\treturn false;\n\t}\n\tconst t = typeof value;\n\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- No time to make this more type-safe\n\tif (t === \"string\" || t === \"number\" || t === \"boolean\" || t === null) {\n\t\treturn true;\n\t}\n\tif (t !== \"object\") {\n\t\treturn false;\n\t}\n\tif (isArray(value)) {\n\t\treturn true;\n\t}\n\tif ((value as Buffer | null)?.buffer) {\n\t\treturn false;\n\t}\n\n\treturn (\n\t\tvalue?.constructor.name === \"Object\"\n\t\t|| typeof (value as { toJSON: () => unknown } | null)?.toJSON === \"function\"\n\t);\n};\n","import type { CallApiExtraOptions } from \"../../types/common\";\nimport { isArray, isBlob, isObject } from \"../guards\";\n\ntype ToQueryStringFn = {\n\t(query: CallApiExtraOptions[\"query\"]): string | null;\n\t(query: Required<CallApiExtraOptions>[\"query\"]): string;\n};\n\nexport const toQueryString: ToQueryStringFn = (query) => {\n\tif (!query) {\n\t\tconsole.error(\"toQueryString:\", \"No query params provided!\");\n\n\t\treturn null as never;\n\t}\n\n\treturn new URLSearchParams(query as Record<string, string>).toString();\n};\n\ntype AllowedPrimitives = boolean | number | string | Blob;\n\ntype AllowedValues = AllowedPrimitives | AllowedPrimitives[] | Record<string, AllowedPrimitives>;\n\nconst toBlobOrString = (value: AllowedPrimitives): string | Blob => {\n\treturn isBlob(value) ? value : String(value);\n};\n\ntype ToFormDataFn = {\n\t(data: Record<string, AllowedValues>): FormData;\n\n\t<TData extends Record<string, AllowedValues>>(data: TData, options: { returnType: \"inputType\" }): TData;\n};\n\n/**\n * @description Converts a plain object to FormData.\n *\n * Handles various data types:\n * - **Primitives** (string, number, boolean): Converted to strings\n * - **Blobs/Files**: Added directly to FormData\n * - **Arrays**: Each item is appended (allows multiple values for same key)\n * - **Objects**: JSON stringified before adding to FormData\n *\n * @example\n * ```ts\n * // Basic usage\n * const formData = toFormData({\n * name: \"John\",\n * age: 30,\n * active: true\n * });\n *\n * // With arrays\n * const formData = toFormData({\n * tags: [\"javascript\", \"typescript\"],\n * name: \"John\"\n * });\n *\n * // With files\n * const formData = toFormData({\n * avatar: fileBlob,\n * name: \"John\"\n * });\n *\n * // With nested objects (one level only)\n * const formData = toFormData({\n * user: { name: \"John\", age: 30 },\n * settings: { theme: \"dark\" }\n * });\n *\n * // Type-preserving usage with Zod\n * const schema = z.object({ name: z.string(), file: z.instanceof(Blob) });\n * const data = schema.parse({ name: \"John\", file: blob });\n * const typedFormData = toFormData(data, { returnType: \"inputType\" });\n * // Type is { name: string; file: Blob }, runtime is FormData\n * ```\n */\nexport const toFormData: ToFormDataFn = (data: Record<string, AllowedValues>) => {\n\tconst formData = new FormData();\n\n\tfor (const [key, value] of Object.entries(data)) {\n\t\tif (isArray(value)) {\n\t\t\tvalue.forEach((innerValue) => formData.append(key, toBlobOrString(innerValue)));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (isObject(value) && !isBlob(value)) {\n\t\t\tformData.set(key, JSON.stringify(value));\n\t\t\tcontinue;\n\t\t}\n\n\t\tformData.set(key, toBlobOrString(value));\n\t}\n\n\treturn formData;\n};\n","import { extraOptionDefaults } from \"../../constants/defaults\";\nimport type { CallApiExtraOptions } from \"../../types\";\nimport type { StandardSchemaV1 } from \"../../types/standard-schema\";\nimport type { CallApiSchema, CallApiSchemaConfig } from \"../../validation\";\nimport { isObject, isString } from \"../guards\";\n\ntype HTTPErrorDetails<TErrorData> = Pick<CallApiExtraOptions, \"defaultHTTPErrorMessage\"> & {\n\terrorData: TErrorData;\n\tresponse: Response;\n};\n\nconst httpErrorSymbol = Symbol(\"HTTPError\");\n\nexport class HTTPError<TErrorData = Record<string, unknown>> extends Error {\n\terrorData: HTTPErrorDetails<TErrorData>[\"errorData\"];\n\n\treadonly httpErrorSymbol = httpErrorSymbol;\n\n\toverride name = \"HTTPError\" as const;\n\n\tresponse: HTTPErrorDetails<TErrorData>[\"response\"];\n\n\tconstructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions) {\n\t\tconst { defaultHTTPErrorMessage, errorData, response } = errorDetails;\n\n\t\tconst resolvedDefaultHTTPErrorMessage =\n\t\t\tisString(defaultHTTPErrorMessage) ? defaultHTTPErrorMessage : (\n\t\t\t\tdefaultHTTPErrorMessage?.({ errorData, response })\n\t\t\t);\n\n\t\tconst selectedDefaultErrorMessage =\n\t\t\tresolvedDefaultHTTPErrorMessage\n\t\t\t?? (response.statusText || extraOptionDefaults.defaultHTTPErrorMessage);\n\n\t\tconst message =\n\t\t\t(errorData as { message?: string } | undefined)?.message ?? selectedDefaultErrorMessage;\n\n\t\tsuper(message, errorOptions);\n\n\t\tthis.errorData = errorData;\n\t\tthis.response = response;\n\t}\n\n\t/**\n\t * @description Checks if the given error is an instance of HTTPError\n\t * @param error - The error to check\n\t * @returns true if the error is an instance of HTTPError, false otherwise\n\t */\n\tstatic override isError<TErrorData>(error: unknown): error is HTTPError<TErrorData> {\n\t\tif (!isObject<HTTPError>(error)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (error instanceof HTTPError) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst actualError = error as HTTPError;\n\n\t\treturn (\n\t\t\tactualError.httpErrorSymbol === httpErrorSymbol\n\t\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Allow\n\t\t\t&& actualError.name === \"HTTPError\"\n\t\t);\n\t}\n}\n\nconst prettifyPath = (path: ValidationError[\"errorData\"][number][\"path\"]) => {\n\tif (!path || path.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst pathString = path.map((segment) => (isObject(segment) ? segment.key : segment)).join(\".\");\n\n\treturn ` → at ${pathString}`;\n};\n\nconst prettifyValidationIssues = (issues: ValidationError[\"errorData\"]) => {\n\tconst issuesString = issues\n\t\t.map((issue) => `✖ ${issue.message}${prettifyPath(issue.path)}`)\n\t\t.join(\" | \");\n\n\treturn issuesString;\n};\n\ntype SafeExtract<TUnion, TKey extends TUnion> = Extract<TUnion, TKey>;\n\ntype ValidationErrorDetails = {\n\t/**\n\t * The cause of the validation error.\n\t *\n\t * It's either the name the schema for which validation failed, or the name of the schema config option that led to the validation error.\n\t */\n\tissueCause:\n\t\t| \"unknown\"\n\t\t| `schemaConfig-(${SafeExtract<keyof CallApiSchemaConfig, \"strict\">})`\n\t\t| keyof CallApiSchema;\n\n\t/**\n\t * The issues that caused the validation error.\n\t */\n\tissues: readonly StandardSchemaV1.Issue[];\n\n\t/**\n\t * The response from server, if any.\n\t */\n\tresponse: Response | null;\n};\n\nconst validationErrorSymbol = Symbol(\"ValidationErrorSymbol\");\n\nexport class ValidationError extends Error {\n\terrorData: ValidationErrorDetails[\"issues\"];\n\n\tissueCause: ValidationErrorDetails[\"issueCause\"];\n\n\toverride name = \"ValidationError\" as const;\n\n\tresponse: ValidationErrorDetails[\"response\"];\n\n\treadonly validationErrorSymbol = validationErrorSymbol;\n\n\tconstructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions) {\n\t\tconst { issueCause, issues, response } = details;\n\n\t\tconst message = prettifyValidationIssues(issues);\n\n\t\tsuper(message, errorOptions);\n\n\t\tthis.errorData = issues;\n\t\tthis.response = response;\n\t\tthis.issueCause = issueCause;\n\t}\n\n\t/**\n\t * @description Checks if the given error is an instance of ValidationError\n\t * @param error - The error to check\n\t * @returns true if the error is an instance of ValidationError, false otherwise\n\t */\n\tstatic override isError(error: unknown): error is ValidationError {\n\t\tif (!isObject<ValidationError>(error)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (error instanceof ValidationError) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst actualError = error as ValidationError;\n\n\t\treturn (\n\t\t\tactualError.validationErrorSymbol === validationErrorSymbol\n\t\t\t// eslint-disable-next-line ts-eslint/no-unnecessary-condition -- Allow\n\t\t\t&& actualError.name === \"ValidationError\"\n\t\t);\n\t}\n}\n","import type {\n\tCallApiResultErrorVariant,\n\tPossibleHTTPError,\n\tPossibleJavaScriptError,\n\tPossibleValidationError,\n} from \"../../result\";\nimport { isObject } from \"../guards\";\nimport { HTTPError, ValidationError } from \"./error\";\n\nexport const isHTTPError = <TErrorData>(\n\terror: CallApiResultErrorVariant<TErrorData>[\"error\"] | null\n): error is PossibleHTTPError<TErrorData> => {\n\treturn isObject(error) && error.name === \"HTTPError\";\n};\n\nexport const isHTTPErrorInstance = <TErrorData>(error: unknown) => {\n\treturn HTTPError.isError<TErrorData>(error);\n};\n\nexport const isValidationError = (\n\terror: CallApiResultErrorVariant<unknown>[\"error\"] | null\n): error is PossibleValidationError => {\n\treturn isObject(error) && error.name === \"ValidationError\";\n};\n\nexport const isValidationErrorInstance = (error: unknown): error is ValidationError => {\n\treturn ValidationError.isError(error);\n};\n\nexport const isJavascriptError = (\n\terror: CallApiResultErrorVariant<unknown>[\"error\"] | null\n): error is PossibleJavaScriptError => {\n\treturn isObject(error) && !isHTTPError(error) && !isValidationError(error);\n};\n"],"mappings":"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"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import "./validation-
|
|
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
|
|
1
|
+
import "./validation-Dq--Q5zC.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 ResponseTypeType, 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 ResultModeType, 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-CYwKssG-.js";
|
|
3
3
|
|
|
4
4
|
//#region src/createFetchClient.d.ts
|
|
5
5
|
|
|
6
|
-
declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends
|
|
7
|
-
declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends
|
|
6
|
+
declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeType = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeType = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, 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>;
|
|
7
|
+
declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeType = ResponseTypeType, const TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<{
|
|
8
8
|
[x: AnyString]: CallApiSchema | undefined;
|
|
9
|
+
"@default"?: CallApiSchema | undefined;
|
|
9
10
|
"@delete/"?: CallApiSchema | undefined;
|
|
10
11
|
"@get/"?: CallApiSchema | undefined;
|
|
11
12
|
"@patch/"?: CallApiSchema | undefined;
|
|
@@ -13,6 +14,7 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
|
13
14
|
"@put/"?: CallApiSchema | undefined;
|
|
14
15
|
}, TCurrentRouteSchemaKey, CallApiSchema | undefined, {
|
|
15
16
|
[x: AnyString]: CallApiSchema | undefined;
|
|
17
|
+
"@default"?: CallApiSchema | undefined;
|
|
16
18
|
"@delete/"?: CallApiSchema | undefined;
|
|
17
19
|
"@get/"?: CallApiSchema | undefined;
|
|
18
20
|
"@patch/"?: CallApiSchema | undefined;
|
|
@@ -20,6 +22,7 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
|
20
22
|
"@put/"?: CallApiSchema | undefined;
|
|
21
23
|
}[TCurrentRouteSchemaKey], NonNullable<Omit<CallApiSchema | undefined, keyof {
|
|
22
24
|
[x: AnyString]: CallApiSchema | undefined;
|
|
25
|
+
"@default"?: CallApiSchema | undefined;
|
|
23
26
|
"@delete/"?: CallApiSchema | undefined;
|
|
24
27
|
"@get/"?: CallApiSchema | undefined;
|
|
25
28
|
"@patch/"?: CallApiSchema | undefined;
|
|
@@ -27,6 +30,7 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
|
27
30
|
"@put/"?: CallApiSchema | undefined;
|
|
28
31
|
}[TCurrentRouteSchemaKey]> & {
|
|
29
32
|
[x: AnyString]: CallApiSchema | undefined;
|
|
33
|
+
"@default"?: CallApiSchema | undefined;
|
|
30
34
|
"@delete/"?: CallApiSchema | undefined;
|
|
31
35
|
"@get/"?: CallApiSchema | undefined;
|
|
32
36
|
"@patch/"?: CallApiSchema | undefined;
|
|
@@ -36,8 +40,10 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
|
36
40
|
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
41
|
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>>>;
|
|
38
42
|
onlyResponse: Response;
|
|
39
|
-
|
|
43
|
+
withoutResponse: NoInfer<GetResponseType<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, TResponseType, ResponseTypeMap<undefined extends TSchema["data"] ? TData : TSchema["data"] extends infer T_7 ? T_7 extends TSchema["data"] ? T_7 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_7> : T_7 extends AnyFunction<infer TResult> ? Awaited<TResult> : TData : never : never>>> | null;
|
|
44
|
+
}, ResultModeMap<undefined extends TSchema["data"] ? 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> : TData : never : never, undefined extends TSchema["errorData"] ? 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> : TErrorData : never : never, TResponseType, TThrowOnError>>>(initURL: TInitURL, initConfig?: CallApiConfig<undefined extends TSchema["data"] ? GetResponseType<TData, TResponseType, ResponseTypeMap<TData>> : TSchema["data"] extends infer T_10 ? T_10 extends TSchema["data"] ? T_10 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_10> : T_10 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_11 ? T_11 extends TSchema["errorData"] ? T_11 extends StandardSchemaV1<unknown, unknown> ? StandardSchemaV1.InferOutput<T_11> : T_11 extends AnyFunction<infer TResult> ? Awaited<TResult> : GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>> : never : never, TResultMode, TThrowOnError, TResponseType, {
|
|
40
45
|
[x: AnyString]: CallApiSchema | undefined;
|
|
46
|
+
"@default"?: CallApiSchema | undefined;
|
|
41
47
|
"@delete/"?: CallApiSchema | undefined;
|
|
42
48
|
"@get/"?: CallApiSchema | undefined;
|
|
43
49
|
"@patch/"?: CallApiSchema | undefined;
|
|
@@ -45,5 +51,5 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
|
45
51
|
"@put/"?: CallApiSchema | undefined;
|
|
46
52
|
}, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray>) => Promise<TComputedResult>;
|
|
47
53
|
//#endregion
|
|
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
|
|
54
|
+
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 ResponseTypeType, type ResultModeType, type RetryOptions, type SuccessContext, type URLOptions, callApi, createFetchClient };
|
|
49
55
|
//# sourceMappingURL=index.d.ts.map
|