@zayne-labs/callapi 1.11.21 → 1.11.23
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-C7HSoU-H.d.ts → common-BKNanXjv.d.ts} +22 -15
- package/dist/{esm/constants → constants}/index.js +2 -2
- package/dist/{esm/defaults-BD3B1uIH.js → defaults-C6WKIXsf.js} +2 -2
- package/dist/defaults-C6WKIXsf.js.map +1 -0
- package/dist/{esm/guards-ClpaRdJN.js → guards-5Ij_loC1.js} +4 -3
- package/dist/guards-5Ij_loC1.js.map +1 -0
- package/dist/{esm/index.d.ts → index.d.ts} +2 -2
- package/dist/{esm/index.js → index.js} +11 -7
- package/dist/index.js.map +1 -0
- package/dist/utils/external/index.d.ts +3 -0
- package/dist/{esm/utils → utils}/external/index.js +4 -4
- package/dist/utils/external/index.js.map +1 -0
- package/dist/{esm/validation-jR4wVvCQ.js → validation-8gwacxHw.js} +2 -2
- package/dist/validation-8gwacxHw.js.map +1 -0
- package/package.json +11 -11
- package/dist/esm/defaults-BD3B1uIH.js.map +0 -1
- package/dist/esm/guards-ClpaRdJN.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/utils/external/index.d.ts +0 -3
- package/dist/esm/utils/external/index.js.map +0 -1
- package/dist/esm/validation-jR4wVvCQ.js.map +0 -1
- /package/dist/{esm/constants → constants}/index.d.ts +0 -0
- /package/dist/{esm/validation-Dq--Q5zC.d.ts → validation-Dq--Q5zC.d.ts} +0 -0
|
@@ -20,7 +20,7 @@ type UnmaskType<TValue$1> = {
|
|
|
20
20
|
}["_"];
|
|
21
21
|
type RemovePrefix<TPrefix extends "dedupe" | "retry", TKey extends string> = TKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;
|
|
22
22
|
type Awaitable<TValue$1> = Promise<TValue$1> | TValue$1;
|
|
23
|
-
type
|
|
23
|
+
type Satisfies<TActualObject extends TExpectedObject, TExpectedObject> = { [Key in keyof TActualObject & keyof TExpectedObject]: TActualObject[Key] };
|
|
24
24
|
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;
|
|
25
25
|
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
|
26
26
|
type CommonContentTypes = "application/epub+zip" | "application/gzip" | "application/json" | "application/ld+json" | "application/octet-stream" | "application/ogg" | "application/pdf" | "application/rtf" | "application/vnd.ms-fontobject" | "application/wasm" | "application/xhtml+xml" | "application/xml" | "application/zip" | "audio/aac" | "audio/mpeg" | "audio/ogg" | "audio/opus" | "audio/webm" | "audio/x-midi" | "font/otf" | "font/ttf" | "font/woff" | "font/woff2" | "image/avif" | "image/bmp" | "image/gif" | "image/jpeg" | "image/png" | "image/svg+xml" | "image/tiff" | "image/webp" | "image/x-icon" | "model/gltf-binary" | "model/gltf+json" | "text/calendar" | "text/css" | "text/csv" | "text/html" | "text/javascript" | "text/plain" | "video/3gpp" | "video/3gpp2" | "video/av1" | "video/mp2t" | "video/mp4" | "video/mpeg" | "video/ogg" | "video/webm" | "video/x-msvideo" | AnyString;
|
|
@@ -393,7 +393,7 @@ interface CallApiSchema {
|
|
|
393
393
|
/**
|
|
394
394
|
* The schema to use for validating the request body.
|
|
395
395
|
*/
|
|
396
|
-
body?: StandardSchemaV1<Body> | ((body: Body) => Awaitable<Body>);
|
|
396
|
+
body?: StandardSchemaV1<Body | undefined> | ((body: Body) => Awaitable<Body | undefined>);
|
|
397
397
|
/**
|
|
398
398
|
* The schema to use for validating the response data.
|
|
399
399
|
*/
|
|
@@ -426,7 +426,8 @@ 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
|
|
429
|
+
type BaseSchemaRouteKeyPrefixes = FallBackRouteSchemaKey | RouteKeyMethodsURLUnion;
|
|
430
|
+
type BaseCallApiSchemaRoutes = Partial<Record<AnyString | BaseSchemaRouteKeyPrefixes, CallApiSchema>>;
|
|
430
431
|
type BaseCallApiSchemaAndConfig = {
|
|
431
432
|
config?: CallApiSchemaConfig;
|
|
432
433
|
routes: BaseCallApiSchemaRoutes;
|
|
@@ -652,15 +653,21 @@ interface CallApiPlugin {
|
|
|
652
653
|
}
|
|
653
654
|
//#endregion
|
|
654
655
|
//#region src/utils/external/define.d.ts
|
|
655
|
-
declare const defineSchema: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, const TSchemaConfig extends CallApiSchemaConfig>(routes: TBaseSchemaRoutes, config?:
|
|
656
|
-
config:
|
|
657
|
-
routes: Writeable<
|
|
656
|
+
declare const defineSchema: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, const TSchemaConfig extends CallApiSchemaConfig>(routes: TBaseSchemaRoutes, config?: Satisfies<TSchemaConfig, CallApiSchemaConfig>) => {
|
|
657
|
+
config: Writeable<Satisfies<TSchemaConfig, CallApiSchemaConfig>, "deep">;
|
|
658
|
+
routes: Writeable<TBaseSchemaRoutes, "deep">;
|
|
658
659
|
};
|
|
659
|
-
declare const defineSchemaRoutes: <const TSchemaRoutes extends BaseCallApiSchemaRoutes>(routes:
|
|
660
|
-
declare const defineMainSchema: <const TSchema extends CallApiSchema>(mainSchema:
|
|
661
|
-
declare const defineSchemaConfig: <const TSchemaConfig extends CallApiSchemaConfig>(config:
|
|
660
|
+
declare const defineSchemaRoutes: <const TSchemaRoutes extends BaseCallApiSchemaRoutes>(routes: TSchemaRoutes) => Writeable<typeof routes, "deep">;
|
|
661
|
+
declare const defineMainSchema: <const TSchema extends CallApiSchema>(mainSchema: Satisfies<TSchema, CallApiSchema>) => Writeable<typeof mainSchema, "deep">;
|
|
662
|
+
declare const defineSchemaConfig: <const TSchemaConfig extends CallApiSchemaConfig>(config: Satisfies<TSchemaConfig, CallApiSchemaConfig>) => Writeable<typeof config, "deep">;
|
|
662
663
|
declare const definePlugin: <const TPlugin extends CallApiPlugin>(plugin: TPlugin) => Writeable<typeof plugin, "deep">;
|
|
663
|
-
|
|
664
|
+
type BaseConfigObject = Exclude<BaseCallApiConfig, AnyFunction>;
|
|
665
|
+
type BaseConfigFn = Extract<BaseCallApiConfig, AnyFunction>;
|
|
666
|
+
type DefineBaseConfig = {
|
|
667
|
+
<const TBaseConfig extends BaseConfigObject>(baseConfig: Satisfies<TBaseConfig, BaseConfigObject>): Writeable<typeof baseConfig, "deep">;
|
|
668
|
+
<TBaseConfig extends BaseConfigFn>(baseConfig: TBaseConfig): TBaseConfig;
|
|
669
|
+
};
|
|
670
|
+
declare const defineBaseConfig: DefineBaseConfig;
|
|
664
671
|
//#endregion
|
|
665
672
|
//#region src/utils/external/guards.d.ts
|
|
666
673
|
declare const isHTTPError: <TErrorData>(error: CallApiResultErrorVariant<TErrorData>["error"] | null) => error is PossibleHTTPError<TErrorData>;
|
|
@@ -1254,7 +1261,7 @@ type GetCurrentRouteSchema<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes,
|
|
|
1254
1261
|
type JsonPrimitive = boolean | number | string | null | undefined;
|
|
1255
1262
|
type SerializableObject = Record<PropertyKey, unknown>;
|
|
1256
1263
|
type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
|
|
1257
|
-
type Body = UnmaskType<RequestInit["body"] | SerializableArray | SerializableObject>;
|
|
1264
|
+
type Body = UnmaskType<Exclude<RequestInit["body"], undefined> | SerializableArray | SerializableObject>;
|
|
1258
1265
|
type InferBodyOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["body"], {
|
|
1259
1266
|
/**
|
|
1260
1267
|
* Body of the request, can be a object or any other supported body type.
|
|
@@ -1888,16 +1895,16 @@ type CallApiExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataTy
|
|
|
1888
1895
|
schemaConfig?: TSchemaConfig$1 | ((context: TComputedSchemaConfigContext) => TSchemaConfig$1);
|
|
1889
1896
|
};
|
|
1890
1897
|
type CallApiExtraOptionsForHooks = Hooks & Omit<CallApiExtraOptions, keyof Hooks>;
|
|
1891
|
-
type
|
|
1898
|
+
type InstanceContext = {
|
|
1892
1899
|
initURL: string;
|
|
1893
1900
|
options: CallApiExtraOptions;
|
|
1894
1901
|
request: CallApiRequestOptions;
|
|
1895
1902
|
};
|
|
1896
|
-
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:
|
|
1903
|
+
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: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
|
|
1897
1904
|
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>>;
|
|
1898
1905
|
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>];
|
|
1899
1906
|
type CallApiResult<TData$1, TErrorData$1, TResultMode extends ResultModeType, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeType> = GetCallApiResult<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType>;
|
|
1900
1907
|
type CallApiResultLoose<TData$1, TErrorData$1, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = ThrowOnErrorUnion, TResponseType extends ResponseTypeType = ResponseTypeType> = GetCallApiResult<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType>;
|
|
1901
1908
|
//#endregion
|
|
1902
|
-
export { CallApiResultSuccessVariantWithoutResponse as $, RequestContext as A, isValidationErrorInstance as B, ThrowOnErrorUnion as C,
|
|
1903
|
-
//# sourceMappingURL=common-
|
|
1909
|
+
export { CallApiResultSuccessVariantWithoutResponse as $, RequestContext as A, isValidationErrorInstance as B, ThrowOnErrorUnion as C, DefaultPluginArray as Ct, Hooks as D, AnyString as Dt, ErrorContext as E, toQueryString as Et, SuccessContext as F, defineSchemaConfig as G, defineMainSchema as H, isHTTPError as I, PluginHooks as J, defineSchemaRoutes as K, isHTTPErrorInstance as L, ResponseContext as M, ResponseErrorContext as N, HooksOrHooksArray as O, ResponseStreamContext as P, CallApiResultSuccessVariant as Q, isJavascriptError as R, Register as S, DefaultDataType as St, DedupeOptions as T, toFormData as Tt, definePlugin as U, defineBaseConfig as V, defineSchema as W, PluginSetupContext as X, PluginHooksWithMoreOptions as Y, CallApiResultErrorVariant as Z, ApplyURLBasedConfig as _, CallApiSchemaConfig as _t, CallApiExtraOptionsForHooks as a, PossibleJavaScriptOrValidationError as at, InferInitURL as b, InferSchemaResult as bt, CallApiRequestOptionsForHooks as c, ResponseTypeType as ct, GetBaseSchemaConfig as d, HTTPError as dt, CallApiSuccessOrErrorVariant as et, GetBaseSchemaRoutes as f, ValidationError as ft, ApplyStrictConfig as g, CallApiSchema as gt, InstanceContext as h, BaseSchemaRouteKeyPrefixes as ht, CallApiExtraOptions as i, PossibleJavaScriptError as it, RequestStreamContext as j, PluginExtraOptions as k, CallApiResult as l, ResultModeMap as lt, InferExtendSchemaContext as m, BaseCallApiSchemaRoutes as mt, BaseCallApiExtraOptions as n, GetResponseType as nt, CallApiParameters as o, PossibleValidationError as ot, InferExtendSchemaConfigContext as p, BaseCallApiSchemaAndConfig as pt, CallApiPlugin as q, CallApiConfig as r, PossibleHTTPError as rt, CallApiRequestOptions as s, ResponseTypeMap as st, BaseCallApiConfig as t, GetCallApiResult as tt, CallApiResultLoose as u, ResultModeType as ut, GetCurrentRouteSchema as v, InferSchemaInput as vt, RetryOptions as w, DefaultThrowOnError as wt, InferParamsFromRoute as x, URLOptions as xt, GetCurrentRouteSchemaKey as y, InferSchemaOutput as yt, isValidationError as z };
|
|
1910
|
+
//# sourceMappingURL=common-BKNanXjv.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as requestOptionDefaults, t as extraOptionDefaults } from "../defaults-
|
|
2
|
-
import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "../validation-
|
|
1
|
+
import { n as requestOptionDefaults, t as extraOptionDefaults } from "../defaults-C6WKIXsf.js";
|
|
2
|
+
import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "../validation-8gwacxHw.js";
|
|
3
3
|
|
|
4
4
|
export { extraOptionDefaults, fallBackRouteSchemaKey, fetchSpecificKeys, requestOptionDefaults };
|
|
@@ -5,7 +5,7 @@ const defineEnum = (value) => Object.freeze(value);
|
|
|
5
5
|
//#region src/constants/defaults.ts
|
|
6
6
|
const extraOptionDefaults = Object.freeze(defineEnum({
|
|
7
7
|
bodySerializer: JSON.stringify,
|
|
8
|
-
defaultHTTPErrorMessage: "
|
|
8
|
+
defaultHTTPErrorMessage: "Request failed unexpectedly",
|
|
9
9
|
dedupeCacheScope: "local",
|
|
10
10
|
dedupeCacheScopeKey: "default",
|
|
11
11
|
dedupeStrategy: "cancel",
|
|
@@ -25,4 +25,4 @@ const requestOptionDefaults = defineEnum({ method: "GET" });
|
|
|
25
25
|
|
|
26
26
|
//#endregion
|
|
27
27
|
export { requestOptionDefaults as n, defineEnum as r, extraOptionDefaults as t };
|
|
28
|
-
//# sourceMappingURL=defaults-
|
|
28
|
+
//# sourceMappingURL=defaults-C6WKIXsf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults-C6WKIXsf.js","names":[],"sources":["../src/types/type-helpers.ts","../src/constants/defaults.ts"],"sourcesContent":["// == These two types allows for adding arbitrary literal types, while still provided autocomplete for defaults.\n\n// == Usually intersection with \"{}\" or \"NonNullable<unknown>\" would make it work fine, but the placeholder with never type is added to make the AnyWhatever type appear last in a given union.\nexport type AnyString = string & NonNullable<unknown>;\nexport type AnyNumber = number & NonNullable<unknown>;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is fine here\nexport type AnyObject = Record<keyof any, any>;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is required here so that one can pass custom function type without type errors\nexport type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;\n\nexport type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };\n\ntype WriteableLevel = \"deep\" | \"shallow\";\n\n/**\n * Makes all properties in an object type writeable (removes readonly modifiers).\n * Supports both shallow and deep modes, and handles special cases like arrays, tuples, and unions.\n * @template TObject - The object type to make writeable\n * @template TVariant - The level of writeable transformation (\"shallow\" | \"deep\")\n */\n\ntype ArrayOrObject = Record<number | string | symbol, unknown> | unknown[] | readonly unknown[];\n\nexport type Writeable<TObject, TLevel extends WriteableLevel = \"shallow\"> =\n\tTObject extends ArrayOrObject ?\n\t\t{\n\t\t\t-readonly [Key in keyof TObject]: TLevel extends \"deep\" ?\n\t\t\t\tNonNullable<TObject[Key]> extends ArrayOrObject ?\n\t\t\t\t\tWriteable<TObject[Key], \"deep\">\n\t\t\t\t:\tTObject[Key]\n\t\t\t:\tTObject[Key];\n\t\t}\n\t:\tTObject;\n\nexport const defineEnum = <const TValue extends object>(value: TValue) =>\n\tObject.freeze(value) as Readonly<Writeable<TValue>>;\n\nexport type UnionToIntersection<TUnion> =\n\t(TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ?\n\t\tTParam\n\t:\tnever;\n\n// == Using this Immediately Indexed Mapped type helper to help show computed type of anything passed to it instead of just the type name\nexport type UnmaskType<TValue> = { _: TValue }[\"_\"];\n\nexport type RemovePrefix<TPrefix extends \"dedupe\" | \"retry\", TKey extends string> =\n\tTKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;\n\nexport type Awaitable<TValue> = Promise<TValue> | TValue;\n\n// export type MatchExactObjectType<TActualObject extends TExpectedObject, TExpectedObject> = {\n// \t[Key in keyof TActualObject]: Key extends keyof TExpectedObject ? TActualObject[Key] : never;\n// };\n\n// export type MatchExactObjectType<TActualObject extends TExpectedObject, TExpectedObject> = {\n// \t[Key in keyof TActualObject]: Key extends keyof TExpectedObject ?\n// \t\tTActualObject[Key]\n// \t:\tnever;\n// };\nexport type Satisfies<TActualObject extends TExpectedObject, TExpectedObject> = {\n\t[Key in keyof TActualObject & keyof TExpectedObject]: TActualObject[Key];\n};\n\nexport type CommonRequestHeaders =\n\t| \"Access-Control-Allow-Credentials\"\n\t| \"Access-Control-Allow-Headers\"\n\t| \"Access-Control-Allow-Methods\"\n\t| \"Access-Control-Allow-Origin\"\n\t| \"Access-Control-Expose-Headers\"\n\t| \"Access-Control-Max-Age\"\n\t| \"Age\"\n\t| \"Allow\"\n\t| \"Cache-Control\"\n\t| \"Clear-Site-Data\"\n\t| \"Content-Disposition\"\n\t| \"Content-Encoding\"\n\t| \"Content-Language\"\n\t| \"Content-Length\"\n\t| \"Content-Location\"\n\t| \"Content-Range\"\n\t| \"Content-Security-Policy-Report-Only\"\n\t| \"Content-Security-Policy\"\n\t| \"Cookie\"\n\t| \"Cross-Origin-Embedder-Policy\"\n\t| \"Cross-Origin-Opener-Policy\"\n\t| \"Cross-Origin-Resource-Policy\"\n\t| \"Date\"\n\t| \"ETag\"\n\t| \"Expires\"\n\t| \"Last-Modified\"\n\t| \"Location\"\n\t| \"Permissions-Policy\"\n\t| \"Pragma\"\n\t| \"Retry-After\"\n\t| \"Save-Data\"\n\t| \"Sec-CH-Prefers-Color-Scheme\"\n\t| \"Sec-CH-Prefers-Reduced-Motion\"\n\t| \"Sec-CH-UA-Arch\"\n\t| \"Sec-CH-UA-Bitness\"\n\t| \"Sec-CH-UA-Form-Factor\"\n\t| \"Sec-CH-UA-Full-Version-List\"\n\t| \"Sec-CH-UA-Full-Version\"\n\t| \"Sec-CH-UA-Mobile\"\n\t| \"Sec-CH-UA-Model\"\n\t| \"Sec-CH-UA-Platform-Version\"\n\t| \"Sec-CH-UA-Platform\"\n\t| \"Sec-CH-UA-WoW64\"\n\t| \"Sec-CH-UA\"\n\t| \"Sec-Fetch-Dest\"\n\t| \"Sec-Fetch-Mode\"\n\t| \"Sec-Fetch-Site\"\n\t| \"Sec-Fetch-User\"\n\t| \"Sec-GPC\"\n\t| \"Server-Timing\"\n\t| \"Server\"\n\t| \"Service-Worker-Navigation-Preload\"\n\t| \"Set-Cookie\"\n\t| \"Strict-Transport-Security\"\n\t| \"Timing-Allow-Origin\"\n\t| \"Trailer\"\n\t| \"Transfer-Encoding\"\n\t| \"Upgrade\"\n\t| \"Vary\"\n\t| \"Warning\"\n\t| \"WWW-Authenticate\"\n\t| \"X-Content-Type-Options\"\n\t| \"X-DNS-Prefetch-Control\"\n\t| \"X-Frame-Options\"\n\t| \"X-Permitted-Cross-Domain-Policies\"\n\t| \"X-Powered-By\"\n\t| \"X-Robots-Tag\"\n\t| \"X-XSS-Protection\"\n\t| AnyString;\n\nexport type CommonAuthorizationHeaders = `${\"Basic\" | \"Bearer\" | \"Token\"} ${string}`;\n\nexport type CommonContentTypes =\n\t| \"application/epub+zip\"\n\t| \"application/gzip\"\n\t| \"application/json\"\n\t| \"application/ld+json\"\n\t| \"application/octet-stream\"\n\t| \"application/ogg\"\n\t| \"application/pdf\"\n\t| \"application/rtf\"\n\t| \"application/vnd.ms-fontobject\"\n\t| \"application/wasm\"\n\t| \"application/xhtml+xml\"\n\t| \"application/xml\"\n\t| \"application/zip\"\n\t| \"audio/aac\"\n\t| \"audio/mpeg\"\n\t| \"audio/ogg\"\n\t| \"audio/opus\"\n\t| \"audio/webm\"\n\t| \"audio/x-midi\"\n\t| \"font/otf\"\n\t| \"font/ttf\"\n\t| \"font/woff\"\n\t| \"font/woff2\"\n\t| \"image/avif\"\n\t| \"image/bmp\"\n\t| \"image/gif\"\n\t| \"image/jpeg\"\n\t| \"image/png\"\n\t| \"image/svg+xml\"\n\t| \"image/tiff\"\n\t| \"image/webp\"\n\t| \"image/x-icon\"\n\t| \"model/gltf-binary\"\n\t| \"model/gltf+json\"\n\t| \"text/calendar\"\n\t| \"text/css\"\n\t| \"text/csv\"\n\t| \"text/html\"\n\t| \"text/javascript\"\n\t| \"text/plain\"\n\t| \"video/3gpp\"\n\t| \"video/3gpp2\"\n\t| \"video/av1\"\n\t| \"video/mp2t\"\n\t| \"video/mp4\"\n\t| \"video/mpeg\"\n\t| \"video/ogg\"\n\t| \"video/webm\"\n\t| \"video/x-msvideo\"\n\t| AnyString;\n","import type { CallApiConfig, CallApiExtraOptions } from \"../types/common\";\nimport { defineEnum } from \"../types/type-helpers\";\n\nexport const extraOptionDefaults = Object.freeze(\n\tdefineEnum({\n\t\t// Common defaults\n\t\tbodySerializer: JSON.stringify,\n\t\tdefaultHTTPErrorMessage: \"Request failed unexpectedly\",\n\n\t\t// Dedupe defaults\n\t\t/* eslint-disable perfectionist/sort-objects -- Allow */\n\t\tdedupeCacheScope: \"local\",\n\t\tdedupeCacheScopeKey: \"default\",\n\t\tdedupeStrategy: \"cancel\",\n\t\t/* eslint-enable perfectionist/sort-objects -- Allow */\n\n\t\t// Hook defaults\n\t\thooksExecutionMode: \"parallel\",\n\n\t\t// Response defaults\n\t\tresponseParser: JSON.parse,\n\t\tresponseType: \"json\",\n\t\tresultMode: \"all\",\n\n\t\t// Retry Defaults\n\t\tretryAttempts: 0,\n\t\tretryCondition: () => true,\n\t\tretryDelay: 1000,\n\t\tretryMaxDelay: 10000,\n\t\tretryMethods: [\"GET\", \"POST\"],\n\t\tretryStatusCodes: [],\n\t\tretryStrategy: \"linear\",\n\t} satisfies CallApiExtraOptions)\n);\n\nexport const requestOptionDefaults = defineEnum({\n\tmethod: \"GET\",\n} satisfies CallApiConfig);\n"],"mappings":";AAoCA,MAAa,cAA2C,UACvD,OAAO,OAAO,MAAM;;;;AClCrB,MAAa,sBAAsB,OAAO,OACzC,WAAW;CAEV,gBAAgB,KAAK;CACrB,yBAAyB;CAIzB,kBAAkB;CAClB,qBAAqB;CACrB,gBAAgB;CAIhB,oBAAoB;CAGpB,gBAAgB,KAAK;CACrB,cAAc;CACd,YAAY;CAGZ,eAAe;CACf,sBAAsB;CACtB,YAAY;CACZ,eAAe;CACf,cAAc,CAAC,OAAO,OAAO;CAC7B,kBAAkB,EAAE;CACpB,eAAe;CACf,CAA+B,CAChC;AAED,MAAa,wBAAwB,WAAW,EAC/C,QAAQ,OACR,CAAyB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as extraOptionDefaults } from "./defaults-
|
|
1
|
+
import { t as extraOptionDefaults } from "./defaults-C6WKIXsf.js";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/guards.ts
|
|
4
4
|
const isArray = (value) => Array.isArray(value);
|
|
@@ -162,7 +162,8 @@ var ValidationError = class ValidationError extends Error {
|
|
|
162
162
|
validationErrorSymbol = validationErrorSymbol;
|
|
163
163
|
constructor(details, errorOptions) {
|
|
164
164
|
const { issueCause, issues, response } = details;
|
|
165
|
-
const
|
|
165
|
+
const prettyMessage = prettifyValidationIssues(issues);
|
|
166
|
+
const message = `(${issueCause.toUpperCase()}) - ${prettyMessage}`;
|
|
166
167
|
super(message, errorOptions);
|
|
167
168
|
this.errorData = issues;
|
|
168
169
|
this.response = response;
|
|
@@ -201,4 +202,4 @@ const isJavascriptError = (error) => {
|
|
|
201
202
|
|
|
202
203
|
//#endregion
|
|
203
204
|
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-
|
|
205
|
+
//# sourceMappingURL=guards-5Ij_loC1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards-5Ij_loC1.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 prettyMessage = prettifyValidationIssues(issues);\n\n\t\tconst message = `(${issueCause.toUpperCase()}) - ${prettyMessage}`;\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\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estContext, C as ThrowOnErrorUnion, Ct as
|
|
2
|
+
import { $ as CallApiResultSuccessVariantWithoutResponse, A as RequestContext, C as ThrowOnErrorUnion, Ct as DefaultPluginArray, D as Hooks, Dt as AnyString, E as ErrorContext, F as SuccessContext, J as PluginHooks, M as ResponseContext, N as ResponseErrorContext, O as HooksOrHooksArray, P as ResponseStreamContext, Q as CallApiResultSuccessVariant, S as Register, St as DefaultDataType, T as DedupeOptions, X as PluginSetupContext, Y as PluginHooksWithMoreOptions, Z as CallApiResultErrorVariant, _ as ApplyURLBasedConfig, _t as CallApiSchemaConfig, a as CallApiExtraOptionsForHooks, at as PossibleJavaScriptOrValidationError, b as InferInitURL, bt as InferSchemaResult, c as CallApiRequestOptionsForHooks, ct as ResponseTypeType, d as GetBaseSchemaConfig, et as CallApiSuccessOrErrorVariant, f as GetBaseSchemaRoutes, g as ApplyStrictConfig, gt as CallApiSchema, h as InstanceContext, ht as BaseSchemaRouteKeyPrefixes, i as CallApiExtraOptions, it as PossibleJavaScriptError, j as RequestStreamContext, k as PluginExtraOptions, l as CallApiResult, lt as ResultModeMap, m as InferExtendSchemaContext, mt as BaseCallApiSchemaRoutes, n as BaseCallApiExtraOptions, nt as GetResponseType, o as CallApiParameters, ot as PossibleValidationError, p as InferExtendSchemaConfigContext, pt as BaseCallApiSchemaAndConfig, q as CallApiPlugin, r as CallApiConfig, rt as PossibleHTTPError, s as CallApiRequestOptions, st as ResponseTypeMap, t as BaseCallApiConfig, tt as GetCallApiResult, u as CallApiResultLoose, ut as ResultModeType, v as GetCurrentRouteSchema, vt as InferSchemaInput, w as RetryOptions, wt as DefaultThrowOnError, x as InferParamsFromRoute, xt as URLOptions, y as GetCurrentRouteSchemaKey, yt as InferSchemaOutput } from "./common-BKNanXjv.js";
|
|
3
3
|
|
|
4
4
|
//#region src/createFetchClient.d.ts
|
|
5
5
|
|
|
@@ -51,5 +51,5 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
|
51
51
|
"@put/"?: CallApiSchema | undefined;
|
|
52
52
|
}, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray>) => Promise<TComputedResult>;
|
|
53
53
|
//#endregion
|
|
54
|
-
export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type
|
|
54
|
+
export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type BaseSchemaRouteKeyPrefixes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResultLoose as 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 InstanceContext, 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 };
|
|
55
55
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as requestOptionDefaults, r as defineEnum, t as extraOptionDefaults } from "./defaults-
|
|
2
|
-
import { _ as isReadableStream, a as isValidationErrorInstance, b as isValidJsonString, d as isBoolean, f as isFunction, g as isQueryString, h as isPromise, l as toQueryString, m as isPlainObject, n as isHTTPErrorInstance, o as HTTPError, p as isObject, s as ValidationError, u as isArray, v as isSerializable, y as isString } from "./guards-
|
|
3
|
-
import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "./validation-
|
|
1
|
+
import { n as requestOptionDefaults, r as defineEnum, t as extraOptionDefaults } from "./defaults-C6WKIXsf.js";
|
|
2
|
+
import { _ as isReadableStream, a as isValidationErrorInstance, b as isValidJsonString, d as isBoolean, f as isFunction, g as isQueryString, h as isPromise, l as toQueryString, m as isPlainObject, n as isHTTPErrorInstance, o as HTTPError, p as isObject, s as ValidationError, u as isArray, v as isSerializable, y as isString } from "./guards-5Ij_loC1.js";
|
|
3
|
+
import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "./validation-8gwacxHw.js";
|
|
4
4
|
|
|
5
5
|
//#region src/auth.ts
|
|
6
6
|
const resolveAuthValue = (value) => isFunction(value) ? value() : value;
|
|
@@ -46,10 +46,11 @@ const handleValidatorFunction = async (validator, inputData) => {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
const standardSchemaParser = async (fullSchema, schemaName,
|
|
49
|
+
const standardSchemaParser = async (fullSchema, schemaName, options) => {
|
|
50
|
+
const { inputValue, response } = options;
|
|
50
51
|
const schema = fullSchema?.[schemaName];
|
|
51
|
-
if (!schema) return
|
|
52
|
-
const result = isFunction(schema) ? await handleValidatorFunction(schema,
|
|
52
|
+
if (!schema) return inputValue;
|
|
53
|
+
const result = isFunction(schema) ? await handleValidatorFunction(schema, inputValue) : await schema["~standard"].validate(inputValue);
|
|
53
54
|
if (result.issues) throw new ValidationError({
|
|
54
55
|
issueCause: schemaName,
|
|
55
56
|
issues: result.issues,
|
|
@@ -67,7 +68,10 @@ const routeKeyMethods = defineEnum([
|
|
|
67
68
|
const handleSchemaValidation = async (fullSchema, schemaName, validationOptions) => {
|
|
68
69
|
const { inputValue, response, schemaConfig } = validationOptions;
|
|
69
70
|
if (schemaConfig?.disableRuntimeValidation) return inputValue;
|
|
70
|
-
return await standardSchemaParser(fullSchema, schemaName,
|
|
71
|
+
return await standardSchemaParser(fullSchema, schemaName, {
|
|
72
|
+
inputValue,
|
|
73
|
+
response
|
|
74
|
+
});
|
|
71
75
|
};
|
|
72
76
|
const extraOptionsToBeValidated = [
|
|
73
77
|
"meta",
|