@zayne-labs/callapi 1.11.5 → 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 +7 -6
- package/dist/esm/body-BVMFJoeo.js +228 -0
- package/dist/esm/body-BVMFJoeo.js.map +1 -0
- package/dist/esm/{common-NVdD93VW.d.ts → common-BsDcf2vu.d.ts} +55 -49
- package/dist/esm/index.d.ts +8 -26
- package/dist/esm/index.js +432 -37
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/external/index.d.ts +80 -0
- package/dist/esm/utils/external/index.js +25 -0
- package/dist/esm/utils/external/index.js.map +1 -0
- package/package.json +13 -13
- package/dist/esm/common-CfCB_X1k.js +0 -580
- package/dist/esm/common-CfCB_X1k.js.map +0 -1
- package/dist/esm/utils/index.d.ts +0 -19
- package/dist/esm/utils/index.js +0 -3
package/README.md
CHANGED
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
<a href="https://github.com/zayne-labs/callapi/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="license"></a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@zayne-labs/callapi"><img src="https://img.shields.io/npm/dm/@zayne-labs/callapi?style=flat&color=EFBA5F" alt="downloads per month"></a>
|
|
12
12
|
<a href="https://github.com/zayne-labs/callapi/graphs/commit-activity"><img src="https://img.shields.io/github/commit-activity/m/zayne-labs/callapi?style=flat&color=EFBA5F" alt="commit activity"></a>
|
|
13
|
-
<a href="https://deepwiki.com/zayne-labs/callapi"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
|
|
14
13
|
<a href="https://code2tutorial.com/tutorial/f77cfbd0-3c37-4c37-9608-b3c977e46f00/index.md"><img src="https://img.shields.io/badge/Code2Tutorial-blue?color=blue&logo=victoriametrics" alt="Code2Tutorial"></a>
|
|
14
|
+
<a href="https://deepwiki.com/zayne-labs/callapi"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
|
|
15
15
|
</p>
|
|
16
16
|
|
|
17
17
|
<p align="center">
|
|
18
|
-
<
|
|
18
|
+
<b>An advanced fetch library that actually solves real problems.</b>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
21
|
<p align="center">
|
|
22
|
-
<a href="https://zayne-labs-callapi.netlify.app"><
|
|
23
|
-
<a href="https://zayne-labs-callapi.netlify.app/docs/getting-started"><
|
|
24
|
-
<a href="https://github.com/zayne-labs/callapi/tree/main/packages/callapi-plugins"><
|
|
22
|
+
<a href="https://zayne-labs-callapi.netlify.app"><b>Documentation</b></a> ·
|
|
23
|
+
<a href="https://zayne-labs-callapi.netlify.app/docs/getting-started"><b>Getting Started</b></a> ·
|
|
24
|
+
<a href="https://github.com/zayne-labs/callapi/tree/main/packages/callapi-plugins"><b>Plugins</b></a>
|
|
25
25
|
</p>
|
|
26
26
|
|
|
27
27
|
---
|
|
@@ -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({
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
//#region src/types/type-helpers.ts
|
|
2
|
+
const defineEnum = (value) => Object.freeze(value);
|
|
3
|
+
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/constants/defaults.ts
|
|
6
|
+
const extraOptionDefaults = Object.freeze(defineEnum({
|
|
7
|
+
bodySerializer: JSON.stringify,
|
|
8
|
+
defaultHTTPErrorMessage: "HTTP request failed unexpectedly",
|
|
9
|
+
dedupeCacheScope: "local",
|
|
10
|
+
dedupeCacheScopeKey: "default",
|
|
11
|
+
dedupeStrategy: "cancel",
|
|
12
|
+
hooksExecutionMode: "parallel",
|
|
13
|
+
responseParser: JSON.parse,
|
|
14
|
+
responseType: "json",
|
|
15
|
+
resultMode: "all",
|
|
16
|
+
retryAttempts: 0,
|
|
17
|
+
retryCondition: () => true,
|
|
18
|
+
retryDelay: 1e3,
|
|
19
|
+
retryMaxDelay: 1e4,
|
|
20
|
+
retryMethods: ["GET", "POST"],
|
|
21
|
+
retryStatusCodes: [],
|
|
22
|
+
retryStrategy: "linear"
|
|
23
|
+
}));
|
|
24
|
+
const requestOptionDefaults = defineEnum({ method: "GET" });
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#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
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/error.ts
|
|
73
|
+
const httpErrorSymbol = Symbol("HTTPError");
|
|
74
|
+
var HTTPError = class HTTPError extends Error {
|
|
75
|
+
errorData;
|
|
76
|
+
httpErrorSymbol = httpErrorSymbol;
|
|
77
|
+
name = "HTTPError";
|
|
78
|
+
response;
|
|
79
|
+
constructor(errorDetails, errorOptions) {
|
|
80
|
+
const { defaultHTTPErrorMessage, errorData, response } = errorDetails;
|
|
81
|
+
const selectedDefaultErrorMessage = (isString(defaultHTTPErrorMessage) ? defaultHTTPErrorMessage : defaultHTTPErrorMessage?.({
|
|
82
|
+
errorData,
|
|
83
|
+
response
|
|
84
|
+
})) ?? (response.statusText || extraOptionDefaults.defaultHTTPErrorMessage);
|
|
85
|
+
const message = errorData?.message ?? selectedDefaultErrorMessage;
|
|
86
|
+
super(message, errorOptions);
|
|
87
|
+
this.errorData = errorData;
|
|
88
|
+
this.response = response;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @description Checks if the given error is an instance of HTTPError
|
|
92
|
+
* @param error - The error to check
|
|
93
|
+
* @returns true if the error is an instance of HTTPError, false otherwise
|
|
94
|
+
*/
|
|
95
|
+
static isError(error) {
|
|
96
|
+
if (!isObject(error)) return false;
|
|
97
|
+
if (error instanceof HTTPError) return true;
|
|
98
|
+
const actualError = error;
|
|
99
|
+
return actualError.httpErrorSymbol === httpErrorSymbol && actualError.name === "HTTPError";
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const prettifyPath = (path) => {
|
|
103
|
+
if (!path || path.length === 0) return "";
|
|
104
|
+
return ` → at ${path.map((segment) => isObject(segment) ? segment.key : segment).join(".")}`;
|
|
105
|
+
};
|
|
106
|
+
const prettifyValidationIssues = (issues) => {
|
|
107
|
+
return issues.map((issue) => `✖ ${issue.message}${prettifyPath(issue.path)}`).join(" | ");
|
|
108
|
+
};
|
|
109
|
+
const validationErrorSymbol = Symbol("ValidationErrorSymbol");
|
|
110
|
+
var ValidationError = class ValidationError extends Error {
|
|
111
|
+
errorData;
|
|
112
|
+
issueCause;
|
|
113
|
+
name = "ValidationError";
|
|
114
|
+
response;
|
|
115
|
+
validationErrorSymbol = validationErrorSymbol;
|
|
116
|
+
constructor(details, errorOptions) {
|
|
117
|
+
const { issueCause, issues, response } = details;
|
|
118
|
+
const message = prettifyValidationIssues(issues);
|
|
119
|
+
super(message, errorOptions);
|
|
120
|
+
this.errorData = issues;
|
|
121
|
+
this.response = response;
|
|
122
|
+
this.issueCause = issueCause;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @description Checks if the given error is an instance of ValidationError
|
|
126
|
+
* @param error - The error to check
|
|
127
|
+
* @returns true if the error is an instance of ValidationError, false otherwise
|
|
128
|
+
*/
|
|
129
|
+
static isError(error) {
|
|
130
|
+
if (!isObject(error)) return false;
|
|
131
|
+
if (error instanceof ValidationError) return true;
|
|
132
|
+
const actualError = error;
|
|
133
|
+
return actualError.validationErrorSymbol === validationErrorSymbol && actualError.name === "ValidationError";
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/utils/external/guards.ts
|
|
139
|
+
const isHTTPError = (error) => {
|
|
140
|
+
return isObject(error) && error.name === "HTTPError";
|
|
141
|
+
};
|
|
142
|
+
const isHTTPErrorInstance = (error) => {
|
|
143
|
+
return HTTPError.isError(error);
|
|
144
|
+
};
|
|
145
|
+
const isValidationError = (error) => {
|
|
146
|
+
return isObject(error) && error.name === "ValidationError";
|
|
147
|
+
};
|
|
148
|
+
const isValidationErrorInstance = (error) => {
|
|
149
|
+
return ValidationError.isError(error);
|
|
150
|
+
};
|
|
151
|
+
const isJavascriptError = (error) => {
|
|
152
|
+
return isObject(error) && !isHTTPError(error) && !isValidationError(error);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/utils/external/body.ts
|
|
157
|
+
const toQueryString = (query) => {
|
|
158
|
+
if (!query) {
|
|
159
|
+
console.error("toQueryString:", "No query params provided!");
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return new URLSearchParams(query).toString();
|
|
163
|
+
};
|
|
164
|
+
const toBlobOrString = (value) => {
|
|
165
|
+
return isBlob(value) ? value : String(value);
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* @description Converts a plain object to FormData.
|
|
169
|
+
*
|
|
170
|
+
* Handles various data types:
|
|
171
|
+
* - **Primitives** (string, number, boolean): Converted to strings
|
|
172
|
+
* - **Blobs/Files**: Added directly to FormData
|
|
173
|
+
* - **Arrays**: Each item is appended (allows multiple values for same key)
|
|
174
|
+
* - **Objects**: JSON stringified before adding to FormData
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* // Basic usage
|
|
179
|
+
* const formData = toFormData({
|
|
180
|
+
* name: "John",
|
|
181
|
+
* age: 30,
|
|
182
|
+
* active: true
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* // With arrays
|
|
186
|
+
* const formData = toFormData({
|
|
187
|
+
* tags: ["javascript", "typescript"],
|
|
188
|
+
* name: "John"
|
|
189
|
+
* });
|
|
190
|
+
*
|
|
191
|
+
* // With files
|
|
192
|
+
* const formData = toFormData({
|
|
193
|
+
* avatar: fileBlob,
|
|
194
|
+
* name: "John"
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* // With nested objects (one level only)
|
|
198
|
+
* const formData = toFormData({
|
|
199
|
+
* user: { name: "John", age: 30 },
|
|
200
|
+
* settings: { theme: "dark" }
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* // Type-preserving usage with Zod
|
|
204
|
+
* const schema = z.object({ name: z.string(), file: z.instanceof(Blob) });
|
|
205
|
+
* const data = schema.parse({ name: "John", file: blob });
|
|
206
|
+
* const typedFormData = toFormData(data, { returnType: "inputType" });
|
|
207
|
+
* // Type is { name: string; file: Blob }, runtime is FormData
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
const toFormData = (data) => {
|
|
211
|
+
const formData = new FormData();
|
|
212
|
+
for (const [key, value] of Object.entries(data)) {
|
|
213
|
+
if (isArray(value)) {
|
|
214
|
+
value.forEach((innerValue) => formData.append(key, toBlobOrString(innerValue)));
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (isObject(value) && !isBlob(value)) {
|
|
218
|
+
formData.set(key, JSON.stringify(value));
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
formData.set(key, toBlobOrString(value));
|
|
222
|
+
}
|
|
223
|
+
return formData;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
//#endregion
|
|
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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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/types/type-helpers.d.ts
|
|
2
2
|
type AnyString = string & NonNullable<unknown>;
|
|
3
3
|
type AnyNumber = number & NonNullable<unknown>;
|
|
4
|
-
type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;
|
|
4
|
+
type AnyFunction<TResult$1 = unknown> = (...args: any[]) => TResult$1;
|
|
5
5
|
type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };
|
|
6
6
|
type WriteableLevel = "deep" | "shallow";
|
|
7
7
|
/**
|
|
@@ -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
|
-
type UnmaskType<TValue> = {
|
|
17
|
-
_: TValue;
|
|
16
|
+
type UnmaskType<TValue$1> = {
|
|
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
|
-
type Awaitable<TValue> = Promise<TValue> | TValue;
|
|
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;
|
|
@@ -69,11 +70,11 @@ declare const fetchSpecificKeys: readonly (keyof RequestInit | "duplex")[];
|
|
|
69
70
|
* The Standard Schema interface.
|
|
70
71
|
* @see https://github.com/standard-schema/standard-schema
|
|
71
72
|
*/
|
|
72
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
73
|
+
interface StandardSchemaV1<Input$1 = unknown, Output$1 = Input$1> {
|
|
73
74
|
/**
|
|
74
75
|
* The Standard Schema properties.
|
|
75
76
|
*/
|
|
76
|
-
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
77
|
+
readonly "~standard": StandardSchemaV1.Props<Input$1, Output$1>;
|
|
77
78
|
}
|
|
78
79
|
declare namespace StandardSchemaV1 {
|
|
79
80
|
/**
|
|
@@ -285,8 +286,8 @@ interface URLOptions {
|
|
|
285
286
|
}
|
|
286
287
|
//#endregion
|
|
287
288
|
//#region src/validation.d.ts
|
|
288
|
-
type InferSchemaOutputResult<TSchema, TFallbackResult = unknown> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
289
|
-
type InferSchemaInputResult<TSchema, TFallbackResult = unknown> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TSchema extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
289
|
+
type InferSchemaOutputResult<TSchema$1, TFallbackResult = unknown> = undefined extends TSchema$1 ? TFallbackResult : TSchema$1 extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema$1> : TSchema$1 extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
290
|
+
type InferSchemaInputResult<TSchema$1, TFallbackResult = unknown> = undefined extends TSchema$1 ? TFallbackResult : TSchema$1 extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema$1> : TSchema$1 extends AnyFunction<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
290
291
|
interface CallApiSchemaConfig {
|
|
291
292
|
/**
|
|
292
293
|
* The base url of the schema. By default it's the baseURL of the callApi instance.
|
|
@@ -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
|
*/
|
|
@@ -521,10 +522,10 @@ declare const getResponseType: <TResponse>(response: Response, parser: Parser<TR
|
|
|
521
522
|
stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
|
|
522
523
|
text: () => Promise<string>;
|
|
523
524
|
};
|
|
524
|
-
type InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;
|
|
525
|
+
type InitResponseTypeMap<TResponse$1 = unknown> = ReturnType<typeof getResponseType<TResponse$1>>;
|
|
525
526
|
type ResponseTypeUnion = keyof InitResponseTypeMap | null;
|
|
526
|
-
type ResponseTypeMap<TResponse> = { [Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>> };
|
|
527
|
-
type GetResponseType<TResponse, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
|
|
527
|
+
type ResponseTypeMap<TResponse$1> = { [Key in keyof InitResponseTypeMap<TResponse$1>]: Awaited<ReturnType<InitResponseTypeMap<TResponse$1>[Key]>> };
|
|
528
|
+
type GetResponseType<TResponse$1, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse$1> = ResponseTypeMap<TResponse$1>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
|
|
528
529
|
type CallApiResultSuccessVariant<TData> = {
|
|
529
530
|
data: NoInfer<TData>;
|
|
530
531
|
error: null;
|
|
@@ -1100,7 +1101,7 @@ type InnerRetryOptions<TErrorData> = { [Key in RetryOptionKeys<TErrorData> as Re
|
|
|
1100
1101
|
interface RetryOptions<TErrorData> {
|
|
1101
1102
|
/**
|
|
1102
1103
|
* Keeps track of the number of times the request has already been retried
|
|
1103
|
-
*
|
|
1104
|
+
* @internal
|
|
1104
1105
|
* @deprecated **NOTE**: This property is used internally to track retries. Please abstain from modifying it.
|
|
1105
1106
|
*/
|
|
1106
1107
|
readonly ["~retryAttemptCount"]?: number;
|
|
@@ -1156,41 +1157,41 @@ 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>;
|
|
1163
1164
|
type Body = UnmaskType<RequestInit["body"] | SerializableArray | SerializableObject>;
|
|
1164
|
-
type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["body"], {
|
|
1165
|
+
type InferBodyOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["body"], {
|
|
1165
1166
|
/**
|
|
1166
1167
|
* Body of the request, can be a object or any other supported body type.
|
|
1167
1168
|
*/
|
|
1168
|
-
body?: InferSchemaInputResult<TSchema["body"], Body>;
|
|
1169
|
+
body?: InferSchemaInputResult<TSchema$1["body"], Body>;
|
|
1169
1170
|
}>;
|
|
1170
1171
|
type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
|
|
1171
1172
|
type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
|
|
1172
|
-
type InferMethodOption<TSchema extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema["method"], {
|
|
1173
|
+
type InferMethodOption<TSchema$1 extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema$1["method"], {
|
|
1173
1174
|
/**
|
|
1174
1175
|
* HTTP method for the request.
|
|
1175
1176
|
* @default "GET"
|
|
1176
1177
|
*/
|
|
1177
|
-
method?: InferSchemaInputResult<TSchema["method"], InferMethodFromURL<TInitURL>>;
|
|
1178
|
+
method?: InferSchemaInputResult<TSchema$1["method"], InferMethodFromURL<TInitURL>>;
|
|
1178
1179
|
}>;
|
|
1179
1180
|
type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
|
|
1180
|
-
type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["headers"], {
|
|
1181
|
+
type InferHeadersOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["headers"], {
|
|
1181
1182
|
/**
|
|
1182
1183
|
* Headers to be used in the request.
|
|
1183
1184
|
*/
|
|
1184
|
-
headers?: InferSchemaInputResult<TSchema["headers"], HeadersOption> | ((context: {
|
|
1185
|
+
headers?: InferSchemaInputResult<TSchema$1["headers"], HeadersOption> | ((context: {
|
|
1185
1186
|
baseHeaders: NonNullable<HeadersOption>;
|
|
1186
|
-
}) => InferSchemaInputResult<TSchema["headers"], HeadersOption>);
|
|
1187
|
+
}) => InferSchemaInputResult<TSchema$1["headers"], HeadersOption>);
|
|
1187
1188
|
}>;
|
|
1188
|
-
type InferRequestOptions<TSchema extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TInitURL>;
|
|
1189
|
+
type InferRequestOptions<TSchema$1 extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema$1> & InferHeadersOption<TSchema$1> & InferMethodOption<TSchema$1, TInitURL>;
|
|
1189
1190
|
interface Register {}
|
|
1190
1191
|
type GlobalMeta = Register extends {
|
|
1191
1192
|
meta?: infer TMeta extends Record<string, unknown>;
|
|
1192
1193
|
} ? TMeta : never;
|
|
1193
|
-
type InferMetaOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["meta"], {
|
|
1194
|
+
type InferMetaOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
|
|
1194
1195
|
/**
|
|
1195
1196
|
* - An optional field you can fill with additional information,
|
|
1196
1197
|
* to associate with the request, typically used for logging or tracing.
|
|
@@ -1214,30 +1215,30 @@ type InferMetaOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIf
|
|
|
1214
1215
|
* });
|
|
1215
1216
|
* ```
|
|
1216
1217
|
*/
|
|
1217
|
-
meta?: InferSchemaInputResult<TSchema["meta"], GlobalMeta>;
|
|
1218
|
+
meta?: InferSchemaInputResult<TSchema$1["meta"], GlobalMeta>;
|
|
1218
1219
|
}>;
|
|
1219
|
-
type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema["query"], {
|
|
1220
|
+
type InferQueryOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["query"], {
|
|
1220
1221
|
/**
|
|
1221
1222
|
* Parameters to be appended to the URL (i.e: /:id)
|
|
1222
1223
|
*/
|
|
1223
|
-
query?: InferSchemaInputResult<TSchema["query"], Query>;
|
|
1224
|
+
query?: InferSchemaInputResult<TSchema$1["query"], Query>;
|
|
1224
1225
|
}>;
|
|
1225
1226
|
type EmptyString = "";
|
|
1226
1227
|
type EmptyTuple = readonly [];
|
|
1227
1228
|
type StringTuple = readonly string[];
|
|
1228
1229
|
type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
|
|
1229
|
-
type ExtractRouteParamNames<TCurrentRoute, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute extends PossibleParamNamePatterns ? TCurrentRoute extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
|
|
1230
|
+
type ExtractRouteParamNames<TCurrentRoute$1, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute$1 extends PossibleParamNamePatterns ? TCurrentRoute$1 extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute$1 extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
|
|
1230
1231
|
type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
|
|
1231
1232
|
type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
|
|
1232
|
-
type InferParamsFromRoute<TCurrentRoute> = ExtractRouteParamNames<TCurrentRoute> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute>> : Params;
|
|
1233
|
+
type InferParamsFromRoute<TCurrentRoute$1> = ExtractRouteParamNames<TCurrentRoute$1> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute$1> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute$1>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute$1>> : Params;
|
|
1233
1234
|
type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes, TCurrentRouteSchemaKey> ? undefined extends InferSchemaInputResult<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
|
|
1234
|
-
type InferParamsOption<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
|
|
1235
|
+
type InferParamsOption<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema$1["params"], TBaseSchemaRoutes, TCurrentRouteSchemaKey, {
|
|
1235
1236
|
/**
|
|
1236
1237
|
* Parameters to be appended to the URL (i.e: /:id)
|
|
1237
1238
|
*/
|
|
1238
|
-
params?: InferSchemaInputResult<TSchema["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
|
|
1239
|
+
params?: InferSchemaInputResult<TSchema$1["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
|
|
1239
1240
|
}>;
|
|
1240
|
-
type InferExtraOptions<TSchema extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema> & InferParamsOption<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema>;
|
|
1241
|
+
type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema$1> & InferParamsOption<TSchema$1, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferQueryOption<TSchema$1>;
|
|
1241
1242
|
type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction<infer TReturnedSchema> ? InferSchemaOutputResult<TReturnedSchema> : never : never : never>;
|
|
1242
1243
|
type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
|
|
1243
1244
|
resultMode: "onlyData";
|
|
@@ -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 | ((context:
|
|
1777
|
-
baseSchemaRoutes: Writeable<TBaseSchemaRoutes, "deep">;
|
|
1778
|
-
currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes, TCurrentRouteSchemaKey>;
|
|
1779
|
-
}) => TSchema);
|
|
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: {
|
|
@@ -1794,9 +1800,9 @@ type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultData
|
|
|
1794
1800
|
options: CallApiExtraOptions;
|
|
1795
1801
|
request: CallApiRequestOptions;
|
|
1796
1802
|
}) => CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>);
|
|
1797
|
-
type CallApiConfig<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 InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1798
|
-
type CallApiParameters<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 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, TBaseSchemaConfig, TSchemaConfig, TInitURL, TCurrentRouteSchemaKey, TBasePluginArray, TPluginArray>];
|
|
1803
|
+
type CallApiConfig<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> = InferExtraOptions<TSchema$1, TBaseSchemaRoutes, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema$1, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes, TSchema$1, TBaseSchemaConfig, TSchemaConfig, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
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
|