@zayne-labs/callapi 1.11.6 → 1.11.7
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/README.md +2 -1
- package/dist/esm/{utils-DOVvfarH.js → body-BVMFJoeo.js} +49 -46
- package/dist/esm/body-BVMFJoeo.js.map +1 -0
- package/dist/esm/{common-ClytspsT.d.ts → common-BsDcf2vu.d.ts} +24 -18
- package/dist/esm/index.d.ts +8 -26
- package/dist/esm/index.js +6 -31
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/{index.d.ts → external/index.d.ts} +14 -4
- package/dist/esm/utils/external/index.js +25 -0
- package/dist/esm/utils/external/index.js.map +1 -0
- package/package.json +3 -3
- package/dist/esm/utils/index.js +0 -3
- package/dist/esm/utils-DOVvfarH.js.map +0 -1
package/README.md
CHANGED
|
@@ -78,7 +78,8 @@ await callApi("/api/data", {
|
|
|
78
78
|
|
|
79
79
|
```js
|
|
80
80
|
import { z } from "zod";
|
|
81
|
-
import {
|
|
81
|
+
import { createFetchClient } from "@zayne-labs/callapi";
|
|
82
|
+
import { defineSchema } from "@zayne-labs/callapi/utils";
|
|
82
83
|
|
|
83
84
|
const callMainApi = createFetchClient({
|
|
84
85
|
schema: defineSchema({
|
|
@@ -23,6 +23,51 @@ const extraOptionDefaults = Object.freeze(defineEnum({
|
|
|
23
23
|
}));
|
|
24
24
|
const requestOptionDefaults = defineEnum({ method: "GET" });
|
|
25
25
|
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/utils/guards.ts
|
|
28
|
+
const isArray = (value) => Array.isArray(value);
|
|
29
|
+
const isBoolean = (value) => typeof value === "boolean";
|
|
30
|
+
const isBlob = (value) => value instanceof Blob;
|
|
31
|
+
const isObject = (value) => {
|
|
32
|
+
return typeof value === "object" && value !== null;
|
|
33
|
+
};
|
|
34
|
+
const hasObjectPrototype = (value) => {
|
|
35
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* @description Copied from TanStack Query's isPlainObject
|
|
39
|
+
* @see https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L321
|
|
40
|
+
*/
|
|
41
|
+
const isPlainObject = (value) => {
|
|
42
|
+
if (!hasObjectPrototype(value)) return false;
|
|
43
|
+
const constructor = value?.constructor;
|
|
44
|
+
if (constructor === void 0) return true;
|
|
45
|
+
const prototype = constructor.prototype;
|
|
46
|
+
if (!hasObjectPrototype(prototype)) return false;
|
|
47
|
+
if (!Object.hasOwn(prototype, "isPrototypeOf")) return false;
|
|
48
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) return false;
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
const isValidJsonString = (value) => {
|
|
52
|
+
if (!isString(value)) return false;
|
|
53
|
+
try {
|
|
54
|
+
JSON.parse(value);
|
|
55
|
+
return true;
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const isSerializable = (value) => {
|
|
61
|
+
return isPlainObject(value) || isArray(value) || typeof value?.toJSON === "function";
|
|
62
|
+
};
|
|
63
|
+
const isFunction = (value) => typeof value === "function";
|
|
64
|
+
const isQueryString = (value) => isString(value) && value.includes("=");
|
|
65
|
+
const isString = (value) => typeof value === "string";
|
|
66
|
+
const isPromise = (value) => value instanceof Promise;
|
|
67
|
+
const isReadableStream = (value) => {
|
|
68
|
+
return value instanceof ReadableStream;
|
|
69
|
+
};
|
|
70
|
+
|
|
26
71
|
//#endregion
|
|
27
72
|
//#region src/error.ts
|
|
28
73
|
const httpErrorSymbol = Symbol("HTTPError");
|
|
@@ -90,7 +135,7 @@ var ValidationError = class ValidationError extends Error {
|
|
|
90
135
|
};
|
|
91
136
|
|
|
92
137
|
//#endregion
|
|
93
|
-
//#region src/utils/guards.ts
|
|
138
|
+
//#region src/utils/external/guards.ts
|
|
94
139
|
const isHTTPError = (error) => {
|
|
95
140
|
return isObject(error) && error.name === "HTTPError";
|
|
96
141
|
};
|
|
@@ -106,51 +151,9 @@ const isValidationErrorInstance = (error) => {
|
|
|
106
151
|
const isJavascriptError = (error) => {
|
|
107
152
|
return isObject(error) && !isHTTPError(error) && !isValidationError(error);
|
|
108
153
|
};
|
|
109
|
-
const isArray = (value) => Array.isArray(value);
|
|
110
|
-
const isBoolean = (value) => typeof value === "boolean";
|
|
111
|
-
const isBlob = (value) => value instanceof Blob;
|
|
112
|
-
const isObject = (value) => {
|
|
113
|
-
return typeof value === "object" && value !== null;
|
|
114
|
-
};
|
|
115
|
-
const hasObjectPrototype = (value) => {
|
|
116
|
-
return Object.prototype.toString.call(value) === "[object Object]";
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* @description Copied from TanStack Query's isPlainObject
|
|
120
|
-
* @see https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L321
|
|
121
|
-
*/
|
|
122
|
-
const isPlainObject = (value) => {
|
|
123
|
-
if (!hasObjectPrototype(value)) return false;
|
|
124
|
-
const constructor = value?.constructor;
|
|
125
|
-
if (constructor === void 0) return true;
|
|
126
|
-
const prototype = constructor.prototype;
|
|
127
|
-
if (!hasObjectPrototype(prototype)) return false;
|
|
128
|
-
if (!Object.hasOwn(prototype, "isPrototypeOf")) return false;
|
|
129
|
-
if (Object.getPrototypeOf(value) !== Object.prototype) return false;
|
|
130
|
-
return true;
|
|
131
|
-
};
|
|
132
|
-
const isValidJsonString = (value) => {
|
|
133
|
-
if (!isString(value)) return false;
|
|
134
|
-
try {
|
|
135
|
-
JSON.parse(value);
|
|
136
|
-
return true;
|
|
137
|
-
} catch {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const isSerializable = (value) => {
|
|
142
|
-
return isPlainObject(value) || isArray(value) || typeof value?.toJSON === "function";
|
|
143
|
-
};
|
|
144
|
-
const isFunction = (value) => typeof value === "function";
|
|
145
|
-
const isQueryString = (value) => isString(value) && value.includes("=");
|
|
146
|
-
const isString = (value) => typeof value === "string";
|
|
147
|
-
const isPromise = (value) => value instanceof Promise;
|
|
148
|
-
const isReadableStream = (value) => {
|
|
149
|
-
return value instanceof ReadableStream;
|
|
150
|
-
};
|
|
151
154
|
|
|
152
155
|
//#endregion
|
|
153
|
-
//#region src/utils/
|
|
156
|
+
//#region src/utils/external/body.ts
|
|
154
157
|
const toQueryString = (query) => {
|
|
155
158
|
if (!query) {
|
|
156
159
|
console.error("toQueryString:", "No query params provided!");
|
|
@@ -221,5 +224,5 @@ const toFormData = (data) => {
|
|
|
221
224
|
};
|
|
222
225
|
|
|
223
226
|
//#endregion
|
|
224
|
-
export { defineEnum as C, requestOptionDefaults as S,
|
|
225
|
-
//# sourceMappingURL=
|
|
227
|
+
export { defineEnum as C, requestOptionDefaults as S, 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, extraOptionDefaults as x, isString as y };
|
|
228
|
+
//# sourceMappingURL=body-BVMFJoeo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-BVMFJoeo.js","names":["toQueryString: ToQueryStringFn","toFormData: ToFormDataFn"],"sources":["../../src/types/type-helpers.ts","../../src/constants/defaults.ts","../../src/utils/guards.ts","../../src/error.ts","../../src/utils/external/guards.ts","../../src/utils/external/body.ts"],"sourcesContent":["// == These two types allows for adding arbitrary literal types, while still provided autocomplete for defaults.\n\n// == Usually intersection with \"{}\" or \"NonNullable<unknown>\" would make it work fine, but the placeholder with never type is added to make the AnyWhatever type appear last in a given union.\nexport type AnyString = string & NonNullable<unknown>;\nexport type AnyNumber = number & NonNullable<unknown>;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is fine here\nexport type AnyObject = Record<keyof any, any>;\n\n// eslint-disable-next-line ts-eslint/no-explicit-any -- Any is required here so that one can pass custom function type without type errors\nexport type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;\n\nexport type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };\n\ntype WriteableLevel = \"deep\" | \"shallow\";\n\n/**\n * Makes all properties in an object type writeable (removes readonly modifiers).\n * Supports both shallow and deep modes, and handles special cases like arrays, tuples, and unions.\n * @template TObject - The object type to make writeable\n * @template TVariant - The level of writeable transformation (\"shallow\" | \"deep\")\n */\n\ntype ArrayOrObject = Record<number | string | symbol, unknown> | unknown[] | readonly unknown[];\n\nexport type Writeable<TObject, TLevel extends WriteableLevel = \"shallow\"> =\n\tTObject extends ArrayOrObject ?\n\t\t{\n\t\t\t-readonly [Key in keyof TObject]: TLevel extends \"deep\" ?\n\t\t\t\tNonNullable<TObject[Key]> extends ArrayOrObject ?\n\t\t\t\t\tWriteable<TObject[Key], \"deep\">\n\t\t\t\t:\tTObject[Key]\n\t\t\t:\tTObject[Key];\n\t\t}\n\t:\tTObject;\n\nexport const defineEnum = <const TValue extends object>(value: TValue) =>\n\tObject.freeze(value) as Readonly<Writeable<TValue>>;\n\nexport type UnionToIntersection<TUnion> =\n\t(TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ?\n\t\tTParam\n\t:\tnever;\n\n// == Using this Immediately Indexed Mapped type helper to help show computed type of anything passed to it instead of just the type name\nexport type UnmaskType<TValue> = { _: TValue }[\"_\"];\n\nexport type RemovePrefix<TPrefix extends \"dedupe\" | \"retry\", TKey extends string> =\n\tTKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;\n\nexport type Awaitable<TValue> = Promise<TValue> | TValue;\n\nexport type MatchExactObjectType<TActualObject extends TExpectedObject, TExpectedObject> = {\n\t[Key in keyof TActualObject]: Key extends keyof TExpectedObject ? TActualObject[Key] : never;\n};\n\nexport type CommonRequestHeaders =\n\t| \"Access-Control-Allow-Credentials\"\n\t| \"Access-Control-Allow-Headers\"\n\t| \"Access-Control-Allow-Methods\"\n\t| \"Access-Control-Allow-Origin\"\n\t| \"Access-Control-Expose-Headers\"\n\t| \"Access-Control-Max-Age\"\n\t| \"Age\"\n\t| \"Allow\"\n\t| \"Cache-Control\"\n\t| \"Clear-Site-Data\"\n\t| \"Content-Disposition\"\n\t| \"Content-Encoding\"\n\t| \"Content-Language\"\n\t| \"Content-Length\"\n\t| \"Content-Location\"\n\t| \"Content-Range\"\n\t| \"Content-Security-Policy-Report-Only\"\n\t| \"Content-Security-Policy\"\n\t| \"Cookie\"\n\t| \"Cross-Origin-Embedder-Policy\"\n\t| \"Cross-Origin-Opener-Policy\"\n\t| \"Cross-Origin-Resource-Policy\"\n\t| \"Date\"\n\t| \"ETag\"\n\t| \"Expires\"\n\t| \"Last-Modified\"\n\t| \"Location\"\n\t| \"Permissions-Policy\"\n\t| \"Pragma\"\n\t| \"Retry-After\"\n\t| \"Save-Data\"\n\t| \"Sec-CH-Prefers-Color-Scheme\"\n\t| \"Sec-CH-Prefers-Reduced-Motion\"\n\t| \"Sec-CH-UA-Arch\"\n\t| \"Sec-CH-UA-Bitness\"\n\t| \"Sec-CH-UA-Form-Factor\"\n\t| \"Sec-CH-UA-Full-Version-List\"\n\t| \"Sec-CH-UA-Full-Version\"\n\t| \"Sec-CH-UA-Mobile\"\n\t| \"Sec-CH-UA-Model\"\n\t| \"Sec-CH-UA-Platform-Version\"\n\t| \"Sec-CH-UA-Platform\"\n\t| \"Sec-CH-UA-WoW64\"\n\t| \"Sec-CH-UA\"\n\t| \"Sec-Fetch-Dest\"\n\t| \"Sec-Fetch-Mode\"\n\t| \"Sec-Fetch-Site\"\n\t| \"Sec-Fetch-User\"\n\t| \"Sec-GPC\"\n\t| \"Server-Timing\"\n\t| \"Server\"\n\t| \"Service-Worker-Navigation-Preload\"\n\t| \"Set-Cookie\"\n\t| \"Strict-Transport-Security\"\n\t| \"Timing-Allow-Origin\"\n\t| \"Trailer\"\n\t| \"Transfer-Encoding\"\n\t| \"Upgrade\"\n\t| \"Vary\"\n\t| \"Warning\"\n\t| \"WWW-Authenticate\"\n\t| \"X-Content-Type-Options\"\n\t| \"X-DNS-Prefetch-Control\"\n\t| \"X-Frame-Options\"\n\t| \"X-Permitted-Cross-Domain-Policies\"\n\t| \"X-Powered-By\"\n\t| \"X-Robots-Tag\"\n\t| \"X-XSS-Protection\"\n\t| AnyString;\n\nexport type CommonAuthorizationHeaders = `${\"Basic\" | \"Bearer\" | \"Token\"} ${string}`;\n\nexport type CommonContentTypes =\n\t| \"application/epub+zip\"\n\t| \"application/gzip\"\n\t| \"application/json\"\n\t| \"application/ld+json\"\n\t| \"application/octet-stream\"\n\t| \"application/ogg\"\n\t| \"application/pdf\"\n\t| \"application/rtf\"\n\t| \"application/vnd.ms-fontobject\"\n\t| \"application/wasm\"\n\t| \"application/xhtml+xml\"\n\t| \"application/xml\"\n\t| \"application/zip\"\n\t| \"audio/aac\"\n\t| \"audio/mpeg\"\n\t| \"audio/ogg\"\n\t| \"audio/opus\"\n\t| \"audio/webm\"\n\t| \"audio/x-midi\"\n\t| \"font/otf\"\n\t| \"font/ttf\"\n\t| \"font/woff\"\n\t| \"font/woff2\"\n\t| \"image/avif\"\n\t| \"image/bmp\"\n\t| \"image/gif\"\n\t| \"image/jpeg\"\n\t| \"image/png\"\n\t| \"image/svg+xml\"\n\t| \"image/tiff\"\n\t| \"image/webp\"\n\t| \"image/x-icon\"\n\t| \"model/gltf-binary\"\n\t| \"model/gltf+json\"\n\t| \"text/calendar\"\n\t| \"text/css\"\n\t| \"text/csv\"\n\t| \"text/html\"\n\t| \"text/javascript\"\n\t| \"text/plain\"\n\t| \"video/3gpp\"\n\t| \"video/3gpp2\"\n\t| \"video/av1\"\n\t| \"video/mp2t\"\n\t| \"video/mp4\"\n\t| \"video/mpeg\"\n\t| \"video/ogg\"\n\t| \"video/webm\"\n\t| \"video/x-msvideo\"\n\t| AnyString;\n","import type { CallApiConfig, CallApiExtraOptions } from \"../types/common\";\nimport { defineEnum } from \"../types/type-helpers\";\n\nexport const extraOptionDefaults = Object.freeze(\n\tdefineEnum({\n\t\t// Common defaults\n\t\tbodySerializer: JSON.stringify,\n\t\tdefaultHTTPErrorMessage: \"HTTP request failed unexpectedly\",\n\n\t\t// Dedupe defaults\n\t\t/* eslint-disable perfectionist/sort-objects -- Allow */\n\t\tdedupeCacheScope: \"local\",\n\t\tdedupeCacheScopeKey: \"default\",\n\t\tdedupeStrategy: \"cancel\",\n\t\t/* eslint-enable perfectionist/sort-objects -- Allow */\n\n\t\t// Hook defaults\n\t\thooksExecutionMode: \"parallel\",\n\n\t\t// Response defaults\n\t\tresponseParser: JSON.parse,\n\t\tresponseType: \"json\",\n\t\tresultMode: \"all\",\n\n\t\t// Retry Defaults\n\t\tretryAttempts: 0,\n\t\tretryCondition: () => true,\n\t\tretryDelay: 1000,\n\t\tretryMaxDelay: 10000,\n\t\tretryMethods: [\"GET\", \"POST\"],\n\t\tretryStatusCodes: [],\n\t\tretryStrategy: \"linear\",\n\t} satisfies CallApiExtraOptions)\n);\n\nexport const requestOptionDefaults = defineEnum({\n\tmethod: \"GET\",\n} satisfies CallApiConfig);\n","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 { extraOptionDefaults } from \"./constants/defaults\";\nimport type { CallApiExtraOptions } from \"./types\";\nimport type { StandardSchemaV1 } from \"./types/standard-schema\";\nimport { isObject, isString } from \"./utils/guards\";\nimport type { CallApiSchema, CallApiSchemaConfig } from \"./validation\";\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 { HTTPError, ValidationError } from \"../../error\";\nimport type {\n\tCallApiResultErrorVariant,\n\tPossibleHTTPError,\n\tPossibleJavaScriptError,\n\tPossibleValidationError,\n} from \"../../result\";\nimport { isObject } from \"../guards\";\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","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"],"mappings":"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"}
|
|
@@ -10,14 +10,15 @@ type WriteableLevel = "deep" | "shallow";
|
|
|
10
10
|
* @template TObject - The object type to make writeable
|
|
11
11
|
* @template TVariant - The level of writeable transformation ("shallow" | "deep")
|
|
12
12
|
*/
|
|
13
|
-
type ArrayOrObject = Record<number | string | symbol, unknown> | unknown[];
|
|
14
|
-
type Writeable<TObject, TLevel extends WriteableLevel = "shallow"> = TObject extends
|
|
13
|
+
type ArrayOrObject = Record<number | string | symbol, unknown> | unknown[] | readonly unknown[];
|
|
14
|
+
type Writeable<TObject, TLevel extends WriteableLevel = "shallow"> = TObject extends ArrayOrObject ? { -readonly [Key in keyof TObject]: TLevel extends "deep" ? NonNullable<TObject[Key]> extends ArrayOrObject ? Writeable<TObject[Key], "deep"> : TObject[Key] : TObject[Key] } : TObject;
|
|
15
15
|
type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends ((param: infer TParam) => void) ? TParam : never;
|
|
16
16
|
type UnmaskType<TValue$1> = {
|
|
17
17
|
_: TValue$1;
|
|
18
18
|
}["_"];
|
|
19
19
|
type RemovePrefix<TPrefix extends "dedupe" | "retry", TKey extends string> = TKey extends `${TPrefix}${infer TRest}` ? Uncapitalize<TRest> : TKey;
|
|
20
20
|
type Awaitable<TValue$1> = Promise<TValue$1> | TValue$1;
|
|
21
|
+
type MatchExactObjectType<TActualObject extends TExpectedObject, TExpectedObject> = { [Key in keyof TActualObject]: Key extends keyof TExpectedObject ? TActualObject[Key] : never };
|
|
21
22
|
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;
|
|
22
23
|
type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
|
|
23
24
|
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;
|
|
@@ -386,14 +387,14 @@ declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
|
|
|
386
387
|
*/
|
|
387
388
|
static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
|
|
388
389
|
}
|
|
389
|
-
type
|
|
390
|
+
type SafeExtract<TUnion, TKey extends TUnion> = Extract<TUnion, TKey>;
|
|
390
391
|
type ValidationErrorDetails = {
|
|
391
392
|
/**
|
|
392
393
|
* The cause of the validation error.
|
|
393
394
|
*
|
|
394
395
|
* 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.
|
|
395
396
|
*/
|
|
396
|
-
issueCause: "unknown" | `schemaConfig-(${
|
|
397
|
+
issueCause: "unknown" | `schemaConfig-(${SafeExtract<keyof CallApiSchemaConfig, "strict">})` | keyof CallApiSchema;
|
|
397
398
|
/**
|
|
398
399
|
* The issues that caused the validation error.
|
|
399
400
|
*/
|
|
@@ -1156,7 +1157,7 @@ type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TSchema
|
|
|
1156
1157
|
type InferAllRouteKeys<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, Exclude<Extract<keyof TBaseSchemaRoutes, string>, FallBackRouteSchemaKey>>;
|
|
1157
1158
|
type InferInitURL<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TSchemaConfig extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes, TSchemaConfig>;
|
|
1158
1159
|
type GetCurrentRouteSchemaKey<TSchemaConfig extends CallApiSchemaConfig, TPath> = TPath extends URL ? string : TSchemaConfig["baseURL"] extends string ? TPath extends `${TSchemaConfig["baseURL"]}${infer TCurrentRoute}` ? TCurrentRoute extends string ? TCurrentRoute : string : TPath extends `${TSchemaConfig["prefix"]}${infer TCurrentRoute}` ? TCurrentRoute extends string ? TCurrentRoute : string : string : TPath;
|
|
1159
|
-
type GetCurrentRouteSchema<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string,
|
|
1160
|
+
type GetCurrentRouteSchema<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
|
|
1160
1161
|
type JsonPrimitive = boolean | number | string | null | undefined;
|
|
1161
1162
|
type SerializableObject = Record<keyof object, unknown>;
|
|
1162
1163
|
type SerializableArray = Array<JsonPrimitive | SerializableArray | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableArray | SerializableObject>;
|
|
@@ -1753,7 +1754,19 @@ type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = Defau
|
|
|
1753
1754
|
*/
|
|
1754
1755
|
skipAutoMergeFor?: "all" | "options" | "request";
|
|
1755
1756
|
};
|
|
1756
|
-
type
|
|
1757
|
+
type GetBaseSchemaRoutes<TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig> = Writeable<TBaseSchemaAndConfig["routes"], "deep">;
|
|
1758
|
+
type GetBaseSchemaConfig<TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig> = Writeable<NonNullable<TBaseSchemaAndConfig["config"]>, "deep">;
|
|
1759
|
+
type InferExtendSchemaContext<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = {
|
|
1760
|
+
baseSchemaRoutes: TBaseSchemaRoutes;
|
|
1761
|
+
currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes, TCurrentRouteSchemaKey>;
|
|
1762
|
+
};
|
|
1763
|
+
type InferExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfig> = {
|
|
1764
|
+
baseSchemaConfig: TBaseSchemaConfig;
|
|
1765
|
+
};
|
|
1766
|
+
type InferExtendPluginContext<TBasePluginArray extends CallApiPlugin[]> = {
|
|
1767
|
+
basePlugins: TBasePluginArray;
|
|
1768
|
+
};
|
|
1769
|
+
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string, TComputedPluginContext = InferExtendPluginContext<TBasePluginArray>, TComputedSchemaContext = InferExtendSchemaContext<TBaseSchemaRoutes, TCurrentRouteSchemaKey>, TComputedSchemaConfigContext = InferExtendSchemaConfigContext<TBaseSchemaConfig>> = SharedExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1757
1770
|
/**
|
|
1758
1771
|
* Array of instance-specific CallApi plugins or a function to configure plugins.
|
|
1759
1772
|
*
|
|
@@ -1762,9 +1775,7 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
|
|
|
1762
1775
|
* that receives base plugins and returns the instance plugins.
|
|
1763
1776
|
*
|
|
1764
1777
|
*/
|
|
1765
|
-
plugins?: TPluginArray | ((context:
|
|
1766
|
-
basePlugins: Writeable<TBasePluginArray, "deep">;
|
|
1767
|
-
}) => TPluginArray);
|
|
1778
|
+
plugins?: TPluginArray | ((context: TComputedPluginContext) => TPluginArray);
|
|
1768
1779
|
/**
|
|
1769
1780
|
* For instance-specific validation schemas
|
|
1770
1781
|
*
|
|
@@ -1773,10 +1784,7 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
|
|
|
1773
1784
|
* Can be a static schema object or a function that receives base schema context and returns instance schemas.
|
|
1774
1785
|
*
|
|
1775
1786
|
*/
|
|
1776
|
-
schema?: TSchema$1 | ((context:
|
|
1777
|
-
baseSchemaRoutes: Writeable<TBaseSchemaRoutes, "deep">;
|
|
1778
|
-
currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes, TCurrentRouteSchemaKey>;
|
|
1779
|
-
}) => TSchema$1);
|
|
1787
|
+
schema?: TSchema$1 | ((context: TComputedSchemaContext) => TSchema$1);
|
|
1780
1788
|
/**
|
|
1781
1789
|
* Instance-specific schema configuration or a function to configure schema behavior.
|
|
1782
1790
|
*
|
|
@@ -1784,9 +1792,7 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
|
|
|
1784
1792
|
* Can override base schema configuration or extend it with instance-specific validation rules.
|
|
1785
1793
|
*
|
|
1786
1794
|
*/
|
|
1787
|
-
schemaConfig?: TSchemaConfig | ((context:
|
|
1788
|
-
baseSchemaConfig: Writeable<TBaseSchemaConfig, "deep">;
|
|
1789
|
-
}) => TSchemaConfig);
|
|
1795
|
+
schemaConfig?: TSchemaConfig | ((context: TComputedSchemaConfigContext) => TSchemaConfig);
|
|
1790
1796
|
};
|
|
1791
1797
|
type CallApiExtraOptionsForHooks = Hooks & Omit<CallApiExtraOptions, keyof Hooks>;
|
|
1792
1798
|
type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>) | ((instanceConfig: {
|
|
@@ -1798,5 +1804,5 @@ type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResul
|
|
|
1798
1804
|
type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = [initURL: TInitURL, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema$1, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
|
1799
1805
|
type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion, TResponseType extends ResponseTypeUnion> = GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>;
|
|
1800
1806
|
//#endregion
|
|
1801
|
-
export {
|
|
1802
|
-
//# sourceMappingURL=common-
|
|
1807
|
+
export { ValidationError as $, ResponseStreamContext as A, PossibleValidationError as B, Hooks as C, RequestStreamContext as D, RequestContext as E, GetCallApiResult as F, DefaultDataType as G, ResponseTypeUnion as H, GetResponseType as I, CallApiPlugin as J, DefaultPluginArray as K, PossibleHTTPError as L, CallApiResultErrorVariant as M, CallApiResultSuccessVariant as N, ResponseContext as O, CallApiSuccessOrErrorVariant as P, HTTPError as Q, PossibleJavaScriptError as R, ErrorContext as S, PluginExtraOptions as T, ResultModeMap as U, ResponseTypeMap as V, ResultModeUnion as W, PluginHooksWithMoreOptions as X, PluginHooks as Y, PluginSetupContext as Z, InferParamsFromRoute as _, CallApiExtraOptionsForHooks as a, fallBackRouteSchemaKey as at, RetryOptions as b, CallApiRequestOptionsForHooks as c, MatchExactObjectType as ct, GetBaseSchemaRoutes as d, BaseCallApiSchemaAndConfig as et, ApplyStrictConfig as f, InferInitURL as g, GetCurrentRouteSchemaKey as h, CallApiExtraOptions as i, InferSchemaOutputResult as it, SuccessContext as j, ResponseErrorContext as k, CallApiResult as l, Writeable as lt, GetCurrentRouteSchema as m, BaseCallApiExtraOptions as n, CallApiSchema as nt, CallApiParameters as o, URLOptions as ot, ApplyURLBasedConfig as p, DefaultThrowOnError as q, CallApiConfig as r, CallApiSchemaConfig as rt, CallApiRequestOptions as s, AnyString as st, BaseCallApiConfig as t, BaseCallApiSchemaRoutes as tt, GetBaseSchemaConfig as u, Register as v, HooksOrHooksArray as w, DedupeOptions as x, ThrowOnErrorUnion as y, PossibleJavaScriptOrValidationError as z };
|
|
1808
|
+
//# sourceMappingURL=common-BsDcf2vu.d.ts.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as ValidationError, A as ResponseStreamContext, B as PossibleValidationError, C as Hooks, D as RequestStreamContext, E as RequestContext, F as GetCallApiResult, G as DefaultDataType, H as ResponseTypeUnion, I as GetResponseType, J as CallApiPlugin, K as DefaultPluginArray, L as PossibleHTTPError, M as CallApiResultErrorVariant, N as CallApiResultSuccessVariant, O as ResponseContext, P as CallApiSuccessOrErrorVariant, Q as HTTPError, R as PossibleJavaScriptError, S as ErrorContext, T as PluginExtraOptions, U as ResultModeMap, V as ResponseTypeMap, W as ResultModeUnion, X as PluginHooksWithMoreOptions, Y as PluginHooks, Z as PluginSetupContext, _ as InferParamsFromRoute, a as CallApiExtraOptionsForHooks, at as fallBackRouteSchemaKey, b as RetryOptions, c as CallApiRequestOptionsForHooks, d as GetBaseSchemaRoutes, et as BaseCallApiSchemaAndConfig, f as ApplyStrictConfig, g as InferInitURL, h as GetCurrentRouteSchemaKey, i as CallApiExtraOptions, it as InferSchemaOutputResult, j as SuccessContext, k as ResponseErrorContext, l as CallApiResult, m as GetCurrentRouteSchema, n as BaseCallApiExtraOptions, nt as CallApiSchema, o as CallApiParameters, ot as URLOptions, p as ApplyURLBasedConfig, q as DefaultThrowOnError, r as CallApiConfig, rt as CallApiSchemaConfig, s as CallApiRequestOptions, st as AnyString, t as BaseCallApiConfig, tt as BaseCallApiSchemaRoutes, u as GetBaseSchemaConfig, v as Register, w as HooksOrHooksArray, x as DedupeOptions, y as ThrowOnErrorUnion, z as PossibleJavaScriptOrValidationError } from "./common-BsDcf2vu.js";
|
|
2
2
|
|
|
3
3
|
//#region src/createFetchClient.d.ts
|
|
4
4
|
|
|
5
|
-
declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig =
|
|
5
|
+
declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, const TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseSchemaConfig extends CallApiSchemaConfig = GetBaseSchemaConfig<TBaseSchemaAndConfig>, TComputedBaseSchemaRoutes extends BaseCallApiSchemaRoutes = GetBaseSchemaRoutes<TBaseSchemaAndConfig>>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBaseSchemaAndConfig, TBasePluginArray>) => <TData = TBaseData, TErrorData = TBaseErrorData, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends ThrowOnErrorUnion = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, const TSchemaConfig extends CallApiSchemaConfig = TComputedBaseSchemaConfig, TInitURL extends InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig> = InferInitURL<TComputedBaseSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<TComputedBaseSchemaRoutes, TCurrentRouteSchemaKey>, const TPluginArray extends CallApiPlugin[] = TBasePluginArray, TComputedResult = CallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType>>, TResultMode, TThrowOnError, TResponseType, TComputedBaseSchemaRoutes, TSchema, TComputedBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => Promise<TComputedResult>;
|
|
6
6
|
declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, const TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, AnyString | "@delete/" | "@get/" | "@patch/" | "@post/" | "@put/">>, TCurrentRouteSchemaKey extends GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL> = GetCurrentRouteSchemaKey<TSchemaConfig, TInitURL>, const TSchema extends CallApiSchema = GetCurrentRouteSchema<{
|
|
7
7
|
[x: AnyString]: CallApiSchema | undefined;
|
|
8
8
|
"@delete/"?: CallApiSchema | undefined;
|
|
@@ -10,21 +10,14 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
|
10
10
|
"@patch/"?: CallApiSchema | undefined;
|
|
11
11
|
"@post/"?: CallApiSchema | undefined;
|
|
12
12
|
"@put/"?: CallApiSchema | undefined;
|
|
13
|
-
}, TCurrentRouteSchemaKey,
|
|
13
|
+
}, TCurrentRouteSchemaKey, CallApiSchema | undefined, {
|
|
14
14
|
[x: AnyString]: CallApiSchema | undefined;
|
|
15
15
|
"@delete/"?: CallApiSchema | undefined;
|
|
16
16
|
"@get/"?: CallApiSchema | undefined;
|
|
17
17
|
"@patch/"?: CallApiSchema | undefined;
|
|
18
18
|
"@post/"?: CallApiSchema | undefined;
|
|
19
19
|
"@put/"?: CallApiSchema | undefined;
|
|
20
|
-
}[TCurrentRouteSchemaKey]
|
|
21
|
-
[x: AnyString]: CallApiSchema | undefined;
|
|
22
|
-
"@delete/"?: CallApiSchema | undefined;
|
|
23
|
-
"@get/"?: CallApiSchema | undefined;
|
|
24
|
-
"@patch/"?: CallApiSchema | undefined;
|
|
25
|
-
"@post/"?: CallApiSchema | undefined;
|
|
26
|
-
"@put/"?: CallApiSchema | undefined;
|
|
27
|
-
}[TCurrentRouteSchemaKey], NonNullable<Writeable<Omit<CallApiSchema | undefined, keyof {
|
|
20
|
+
}[TCurrentRouteSchemaKey], NonNullable<Omit<CallApiSchema | undefined, keyof {
|
|
28
21
|
[x: AnyString]: CallApiSchema | undefined;
|
|
29
22
|
"@delete/"?: CallApiSchema | undefined;
|
|
30
23
|
"@get/"?: CallApiSchema | undefined;
|
|
@@ -38,29 +31,18 @@ declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode exten
|
|
|
38
31
|
"@patch/"?: CallApiSchema | undefined;
|
|
39
32
|
"@post/"?: CallApiSchema | undefined;
|
|
40
33
|
"@put/"?: CallApiSchema | undefined;
|
|
41
|
-
}[TCurrentRouteSchemaKey]
|
|
34
|
+
}[TCurrentRouteSchemaKey]>>, const TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedResult = GetCallApiResult<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType, {
|
|
42
35
|
all: CallApiResultSuccessVariant<GetResponseType<InferSchemaOutputResult<TSchema["data"], TData>, TResponseType, ResponseTypeMap<InferSchemaOutputResult<TSchema["data"], TData>>>>;
|
|
43
36
|
onlyData: NoInfer<GetResponseType<InferSchemaOutputResult<TSchema["data"], TData>, TResponseType, ResponseTypeMap<InferSchemaOutputResult<TSchema["data"], TData>>>>;
|
|
44
37
|
onlyResponse: Response;
|
|
45
|
-
}, ResultModeMap<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResponseType, TThrowOnError>>>(initURL: TInitURL,
|
|
38
|
+
}, ResultModeMap<InferSchemaOutputResult<TSchema["data"], TData>, InferSchemaOutputResult<TSchema["errorData"], TErrorData>, TResponseType, TThrowOnError>>>(initURL: TInitURL, initConfig?: CallApiConfig<InferSchemaOutputResult<TSchema["data"], GetResponseType<TData, TResponseType, ResponseTypeMap<TData>>>, InferSchemaOutputResult<TSchema["errorData"], GetResponseType<TErrorData, TResponseType, ResponseTypeMap<TErrorData>>>, TResultMode, TThrowOnError, TResponseType, {
|
|
46
39
|
[x: AnyString]: CallApiSchema | undefined;
|
|
47
40
|
"@delete/"?: CallApiSchema | undefined;
|
|
48
41
|
"@get/"?: CallApiSchema | undefined;
|
|
49
42
|
"@patch/"?: CallApiSchema | undefined;
|
|
50
43
|
"@post/"?: CallApiSchema | undefined;
|
|
51
44
|
"@put/"?: CallApiSchema | undefined;
|
|
52
|
-
}, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray>
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/defineHelpers.d.ts
|
|
55
|
-
declare const defineSchema: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, const TSchemaConfig extends CallApiSchemaConfig>(routes: TBaseSchemaRoutes, config?: TSchemaConfig) => {
|
|
56
|
-
config: Writeable<TSchemaConfig, "deep"> & {};
|
|
57
|
-
routes: Writeable<TBaseSchemaRoutes, "deep">;
|
|
58
|
-
};
|
|
59
|
-
declare const defineSchemaConfig: <const TConfig extends CallApiExtraOptions["schemaConfig"]>(config: TConfig) => NonNullable<Writeable<typeof config, "deep">>;
|
|
60
|
-
declare const defineSchemaRoutes: <const TBaseSchemaRoutes extends BaseCallApiSchemaRoutes>(routes: TBaseSchemaRoutes) => Writeable<typeof routes, "deep">;
|
|
61
|
-
declare const definePlugin: <const TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => Writeable<TPlugin, "deep">;
|
|
62
|
-
declare const defineBaseConfig: <const TBaseConfig extends BaseCallApiConfig>(baseConfig: TBaseConfig) => Writeable<typeof baseConfig, "deep">;
|
|
63
|
-
declare const defineParameters: <TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig> = InferInitURL<BaseCallApiSchemaRoutes, TSchemaConfig>, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray>(...parameters: CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>) => CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>;
|
|
45
|
+
}, TSchema, CallApiSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, DefaultPluginArray, TPluginArray>) => Promise<TComputedResult>;
|
|
64
46
|
//#endregion
|
|
65
|
-
export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type CallApiSuccessOrErrorVariant, type DedupeOptions, type ErrorContext, HTTPError, type Hooks, type HooksOrHooksArray, type InferParamsFromRoute, type InferSchemaOutputResult, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeUnion, type ResultModeUnion, type RetryOptions, type SuccessContext, type URLOptions, ValidationError, callApi, createFetchClient,
|
|
47
|
+
export { type BaseCallApiConfig, type BaseCallApiExtraOptions, type BaseCallApiSchemaRoutes, type CallApiConfig, type CallApiExtraOptions, type CallApiExtraOptionsForHooks, type CallApiParameters, type CallApiPlugin, type CallApiRequestOptions, type CallApiRequestOptionsForHooks, type CallApiResult, type CallApiResultErrorVariant, type CallApiResultSuccessVariant, type CallApiSchema, type CallApiSchemaConfig, type CallApiSuccessOrErrorVariant, type DedupeOptions, type ErrorContext, HTTPError, type Hooks, type HooksOrHooksArray, type InferParamsFromRoute, type InferSchemaOutputResult, type PluginExtraOptions, type PluginHooks, type PluginHooksWithMoreOptions, type PluginSetupContext, type PossibleHTTPError, type PossibleJavaScriptError, type PossibleJavaScriptOrValidationError, type PossibleValidationError, type Register, type RequestContext, type RequestStreamContext, type ResponseContext, type ResponseErrorContext, type ResponseStreamContext, type ResponseTypeUnion, type ResultModeUnion, type RetryOptions, type SuccessContext, type URLOptions, ValidationError, callApi, createFetchClient, fallBackRouteSchemaKey };
|
|
66
48
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as defineEnum, S as requestOptionDefaults,
|
|
1
|
+
import { C as defineEnum, S as requestOptionDefaults, _ as isReadableStream, b as isValidJsonString, c as HTTPError, d as isBoolean, f as isFunction, g as isQueryString, h as isPromise, i as isHTTPErrorInstance, l as ValidationError, m as isPlainObject, n as toQueryString, p as isObject, s as isValidationErrorInstance, u as isArray, v as isSerializable, x as extraOptionDefaults, y as isString } from "./body-BVMFJoeo.js";
|
|
2
2
|
|
|
3
3
|
//#region src/result.ts
|
|
4
4
|
const getResponseType = (response, parser) => ({
|
|
@@ -973,11 +973,10 @@ const createRetryStrategy = (ctx) => {
|
|
|
973
973
|
const $GlobalRequestInfoCache = /* @__PURE__ */ new Map();
|
|
974
974
|
const createFetchClient = (initBaseConfig = {}) => {
|
|
975
975
|
const $LocalRequestInfoCache = /* @__PURE__ */ new Map();
|
|
976
|
-
const callApi$1 = async (
|
|
977
|
-
const [initURLOrURLObject, initConfig = {}] = parameters;
|
|
976
|
+
const callApi$1 = async (initURL, initConfig = {}) => {
|
|
978
977
|
const [fetchOptions, extraOptions] = splitConfig(initConfig);
|
|
979
978
|
const baseConfig = isFunction(initBaseConfig) ? initBaseConfig({
|
|
980
|
-
initURL:
|
|
979
|
+
initURL: initURL.toString(),
|
|
981
980
|
options: extraOptions,
|
|
982
981
|
request: fetchOptions
|
|
983
982
|
}) : initBaseConfig;
|
|
@@ -997,7 +996,7 @@ const createFetchClient = (initBaseConfig = {}) => {
|
|
|
997
996
|
const { resolvedCurrentRouteSchemaKey, resolvedHooks, resolvedInitURL, resolvedMiddlewares, resolvedOptions, resolvedRequestOptions } = await initializePlugins({
|
|
998
997
|
baseConfig,
|
|
999
998
|
config,
|
|
1000
|
-
initURL:
|
|
999
|
+
initURL: initURL.toString(),
|
|
1001
1000
|
options: mergedExtraOptions,
|
|
1002
1001
|
request: mergedRequestOptions
|
|
1003
1002
|
});
|
|
@@ -1148,7 +1147,7 @@ const createFetchClient = (initBaseConfig = {}) => {
|
|
|
1148
1147
|
const hookError = await executeHooksInCatchBlock([options.onRetry?.(retryContext)], hookInfo);
|
|
1149
1148
|
if (hookError) return hookError;
|
|
1150
1149
|
await waitFor(getDelay());
|
|
1151
|
-
return callApi$1(
|
|
1150
|
+
return callApi$1(initURL, {
|
|
1152
1151
|
...config,
|
|
1153
1152
|
"~retryAttemptCount": currentAttemptCount + 1
|
|
1154
1153
|
});
|
|
@@ -1184,29 +1183,5 @@ const createFetchClient = (initBaseConfig = {}) => {
|
|
|
1184
1183
|
const callApi = createFetchClient();
|
|
1185
1184
|
|
|
1186
1185
|
//#endregion
|
|
1187
|
-
|
|
1188
|
-
const defineSchema = (routes, config) => {
|
|
1189
|
-
return {
|
|
1190
|
-
config: defineSchemaConfig(config),
|
|
1191
|
-
routes: defineSchemaRoutes(routes)
|
|
1192
|
-
};
|
|
1193
|
-
};
|
|
1194
|
-
const defineSchemaConfig = (config) => {
|
|
1195
|
-
return config;
|
|
1196
|
-
};
|
|
1197
|
-
const defineSchemaRoutes = (routes) => {
|
|
1198
|
-
return routes;
|
|
1199
|
-
};
|
|
1200
|
-
const definePlugin = (plugin) => {
|
|
1201
|
-
return plugin;
|
|
1202
|
-
};
|
|
1203
|
-
const defineBaseConfig = (baseConfig) => {
|
|
1204
|
-
return baseConfig;
|
|
1205
|
-
};
|
|
1206
|
-
const defineParameters = (...parameters) => {
|
|
1207
|
-
return parameters;
|
|
1208
|
-
};
|
|
1209
|
-
|
|
1210
|
-
//#endregion
|
|
1211
|
-
export { HTTPError, ValidationError, callApi, createFetchClient, defineBaseConfig, defineParameters, definePlugin, defineSchema, defineSchemaConfig, defineSchemaRoutes, fallBackRouteSchemaKey };
|
|
1186
|
+
export { HTTPError, ValidationError, callApi, createFetchClient, fallBackRouteSchemaKey };
|
|
1212
1187
|
//# sourceMappingURL=index.js.map
|