@zayne-labs/callapi 1.7.18 → 1.8.1

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.
@@ -0,0 +1,909 @@
1
+ //#region src/types/type-helpers.d.ts
2
+ type AnyString = string & NonNullable<unknown>;
3
+ type AnyFunction<TResult = unknown> = (...args: any[]) => TResult;
4
+ type Prettify<TObject> = NonNullable<unknown> & { [Key in keyof TObject]: TObject[Key] };
5
+ type WriteableLevel = "deep" | "shallow";
6
+ /**
7
+ * Makes all properties in an object type writeable (removes readonly modifiers).
8
+ * Supports both shallow and deep modes, and handles special cases like arrays, tuples, and unions.
9
+ * @template TObject - The object type to make writeable
10
+ * @template TVariant - The level of writeable transformation ("shallow" | "deep")
11
+ */
12
+ type ArrayOrObject = Record<number | string | symbol, unknown> | unknown[];
13
+ type Writeable<TObject, TLevel extends WriteableLevel = "shallow"> = TObject extends readonly [...infer TTupleItems] ? [...{ [Index in keyof TTupleItems]: TLevel extends "deep" ? Writeable<TTupleItems[Index], "deep"> : TTupleItems[Index] }] : TObject extends ArrayOrObject ? { -readonly [Key in keyof TObject]: TLevel extends "deep" ? Writeable<TObject[Key], "deep"> : TObject[Key] } : TObject;
14
+ type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends ((param: infer TParam) => void) ? TParam : never;
15
+ type UnmaskType<TValue> = {
16
+ _: TValue;
17
+ }["_"];
18
+ type Awaitable<TValue> = Promise<TValue> | TValue;
19
+ 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;
20
+ type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
21
+ 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;
22
+ //#endregion
23
+ //#region src/auth.d.ts
24
+ type ValueOrFunctionResult<TValue> = TValue | (() => TValue);
25
+ type ValidAuthValue = ValueOrFunctionResult<Awaitable<string | null | undefined>>;
26
+ /**
27
+ * Bearer Or Token authentication
28
+ *
29
+ * The value of `bearer` will be added to a header as
30
+ * `auth: Bearer some-auth-token`,
31
+ *
32
+ * The value of `token` will be added to a header as
33
+ * `auth: Token some-auth-token`,
34
+ */
35
+ type BearerOrTokenAuth = {
36
+ type?: "Bearer";
37
+ bearer?: ValidAuthValue;
38
+ token?: never;
39
+ } | {
40
+ type?: "Token";
41
+ bearer?: never;
42
+ token?: ValidAuthValue;
43
+ };
44
+ /**
45
+ * Basic auth
46
+ */
47
+ type BasicAuth = {
48
+ type: "Basic";
49
+ username: ValidAuthValue;
50
+ password: ValidAuthValue;
51
+ };
52
+ /**
53
+ * Custom auth
54
+ *
55
+ * @param prefix - prefix of the header
56
+ * @param authValue - value of the header
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * {
61
+ * type: "Custom",
62
+ * prefix: "Token",
63
+ * authValue: "token"
64
+ * }
65
+ * ```
66
+ */
67
+ type CustomAuth = {
68
+ type: "Custom";
69
+ prefix: ValidAuthValue;
70
+ value: ValidAuthValue;
71
+ };
72
+ type Auth = BearerOrTokenAuth | BasicAuth | CustomAuth;
73
+ //#endregion
74
+ //#region src/constants/common.d.ts
75
+ declare const fetchSpecificKeys: (keyof RequestInit | "duplex")[];
76
+ //#endregion
77
+ //#region src/error.d.ts
78
+ type ErrorDetails<TErrorData> = {
79
+ defaultErrorMessage: CallApiExtraOptions["defaultErrorMessage"];
80
+ errorData: TErrorData;
81
+ response: Response;
82
+ };
83
+ declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
84
+ errorData: ErrorDetails<TErrorData>["errorData"];
85
+ httpErrorSymbol: symbol;
86
+ isHTTPError: boolean;
87
+ name: "HTTPError";
88
+ response: ErrorDetails<TErrorData>["response"];
89
+ constructor(errorDetails: ErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
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<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
96
+ }
97
+ //#endregion
98
+ //#region src/types/standard-schema.d.ts
99
+ /**
100
+ * The Standard Schema interface.
101
+ * @see https://github.com/standard-schema/standard-schema
102
+ */
103
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
104
+ /**
105
+ * The Standard Schema properties.
106
+ */
107
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
108
+ }
109
+ declare namespace StandardSchemaV1 {
110
+ /**
111
+ * The Standard Schema properties interface.
112
+ */
113
+ interface Props<Input = unknown, Output = Input> {
114
+ /**
115
+ * Inferred types associated with the schema.
116
+ */
117
+ readonly types?: Types<Input, Output> | undefined;
118
+ /**
119
+ * Validates unknown input values.
120
+ */
121
+ readonly validate: (value: unknown) => Promise<Result<Output>> | Result<Output>;
122
+ /**
123
+ * The vendor name of the schema library.
124
+ */
125
+ readonly vendor: string;
126
+ /**
127
+ * The version number of the standard.
128
+ */
129
+ readonly version: 1;
130
+ }
131
+ /**
132
+ * The result interface of the validate function.
133
+ */
134
+ type Result<Output> = FailureResult | SuccessResult<Output>;
135
+ /**
136
+ * The result interface if validation succeeds.
137
+ */
138
+ interface SuccessResult<Output> {
139
+ /**
140
+ * The non-existent issues.
141
+ */
142
+ readonly issues?: undefined;
143
+ /**
144
+ * The typed output value.
145
+ */
146
+ readonly value: Output;
147
+ }
148
+ /**
149
+ * The result interface if validation fails.
150
+ */
151
+ interface FailureResult {
152
+ /**
153
+ * The issues of failed validation.
154
+ */
155
+ readonly issues: readonly Issue[];
156
+ }
157
+ /**
158
+ * The issue interface of the failure output.
159
+ */
160
+ interface Issue {
161
+ /**
162
+ * The error message of the issue.
163
+ */
164
+ readonly message: string;
165
+ /**
166
+ * The path of the issue, if any.
167
+ */
168
+ readonly path?: ReadonlyArray<PathSegment | PropertyKey> | undefined;
169
+ }
170
+ /**
171
+ * The path segment interface of the issue.
172
+ */
173
+ interface PathSegment {
174
+ /**
175
+ * The key representing a path segment.
176
+ */
177
+ readonly key: PropertyKey;
178
+ }
179
+ /**
180
+ * The Standard Schema types interface.
181
+ */
182
+ interface Types<Input = unknown, Output = Input> {
183
+ /** The input type of the schema. */
184
+ readonly input: Input;
185
+ /** The output type of the schema. */
186
+ readonly output: Output;
187
+ }
188
+ /**
189
+ * Infers the input type of a Standard Schema.
190
+ */
191
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
192
+ /**
193
+ * Infers the output type of a Standard Schema.
194
+ */
195
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
196
+ }
197
+ //#endregion
198
+ //#region src/validation.d.ts
199
+ type InferSchemaResult<TSchema, TFallbackResult = NonNullable<unknown>> = undefined extends TSchema ? TFallbackResult : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TSchema extends AnyFunction<infer TResult> ? TResult : TFallbackResult;
200
+ type ValidationErrorDetails = {
201
+ issues: readonly StandardSchemaV1.Issue[];
202
+ response: Response | null;
203
+ };
204
+ declare class ValidationError extends Error {
205
+ errorData: readonly StandardSchemaV1.Issue[];
206
+ name: string;
207
+ response: Response | null;
208
+ validationErrorSymbol: symbol;
209
+ constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
210
+ /**
211
+ * @description Checks if the given error is an instance of HTTPError
212
+ * @param error - The error to check
213
+ * @returns true if the error is an instance of HTTPError, false otherwise
214
+ */
215
+ static isError(error: unknown): error is ValidationError;
216
+ }
217
+ interface CallApiSchemaConfig {
218
+ /**
219
+ * The base url of the schema. By default it's the baseURL of the fetch instance.
220
+ */
221
+ baseURL?: string;
222
+ /**
223
+ * Disables runtime validation for the schema.
224
+ */
225
+ disableRuntimeValidation?: boolean;
226
+ /**
227
+ * If `true`, the original input value will be used instead of the transformed/validated output.
228
+ *
229
+ * This is useful when you want to validate the input but don't want any transformations
230
+ * applied by the validation schema (e.g., type coercion, default values, etc).
231
+ */
232
+ disableValidationOutputApplication?: boolean;
233
+ /**
234
+ * Controls the inference of the method option based on the route modifiers (`@get/`, `@post/`, `@put/`, `@patch/`, `@delete/`).
235
+ *
236
+ * - When `true`, the method option is made required on the type level and is not automatically added to the request options.
237
+ * - When `false` or `undefined` (default), the method option is not required on the type level, and is automatically added to the request options.
238
+ *
239
+ */
240
+ requireHttpMethodProvision?: boolean;
241
+ /**
242
+ * Controls the strictness of API route validation.
243
+ *
244
+ * When true:
245
+ * - Only routes explicitly defined in the schema will be considered valid to typescript
246
+ * - Attempting to call undefined routes will result in type errors
247
+ * - Useful for ensuring API calls conform exactly to your schema definition
248
+ *
249
+ * When false or undefined (default):
250
+ * - All routes will be allowed, whether they are defined in the schema or not
251
+ * - Provides more flexibility but less type safety
252
+ *
253
+ * @default false
254
+ */
255
+ strict?: boolean;
256
+ }
257
+ interface CallApiSchema {
258
+ /**
259
+ * The schema to use for validating the request body.
260
+ */
261
+ body?: StandardSchemaV1<Body> | ((body: Body) => Awaitable<Body>);
262
+ /**
263
+ * The schema to use for validating the response data.
264
+ */
265
+ data?: StandardSchemaV1 | ((data: unknown) => unknown);
266
+ /**
267
+ * The schema to use for validating the response error data.
268
+ */
269
+ errorData?: StandardSchemaV1 | ((errorData: unknown) => unknown);
270
+ /**
271
+ * The schema to use for validating the request headers.
272
+ */
273
+ headers?: StandardSchemaV1<HeadersOption | undefined> | ((headers: HeadersOption) => Awaitable<HeadersOption>);
274
+ /**
275
+ * The schema to use for validating the meta option.
276
+ */
277
+ meta?: StandardSchemaV1<GlobalMeta | undefined> | ((meta: GlobalMeta) => Awaitable<GlobalMeta>);
278
+ /**
279
+ * The schema to use for validating the request method.
280
+ */
281
+ method?: StandardSchemaV1<MethodUnion | undefined> | ((method: MethodUnion) => Awaitable<MethodUnion>);
282
+ /**
283
+ * The schema to use for validating the request url parameters.
284
+ */
285
+ params?: StandardSchemaV1<Params | undefined> | ((params: Params) => Awaitable<Params>);
286
+ /**
287
+ * The schema to use for validating the request url queries.
288
+ */
289
+ query?: StandardSchemaV1<Query | undefined> | ((query: Query) => Awaitable<Query>);
290
+ }
291
+ declare const routeKeyMethods: ["delete", "get", "patch", "post", "put"];
292
+ type RouteKeyMethods = (typeof routeKeyMethods)[number];
293
+ type PossibleRouteKey = `@${RouteKeyMethods}/` | AnyString;
294
+ type BaseCallApiSchema = { [Key in PossibleRouteKey]?: CallApiSchema };
295
+ declare const defineSchema: <const TBaseSchema extends BaseCallApiSchema>(baseSchema: TBaseSchema) => Writeable<typeof baseSchema, "deep">;
296
+ //#endregion
297
+ //#region src/url.d.ts
298
+ type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
299
+ type Params = UnmaskType<Record<string, AllowedQueryParamValues> | AllowedQueryParamValues[]>;
300
+ type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;
301
+ type InitURLOrURLObject = string | URL;
302
+ interface UrlOptions {
303
+ /**
304
+ * Base URL to be prepended to all request URLs
305
+ */
306
+ baseURL?: string;
307
+ /**
308
+ * Resolved request URL
309
+ */
310
+ readonly fullURL?: string;
311
+ /**
312
+ * The url string passed to the callApi instance
313
+ */
314
+ readonly initURL?: string;
315
+ /**
316
+ * The URL string passed to the callApi instance, but normalized (removed any method modifiers etc)
317
+ */
318
+ readonly initURLNormalized?: string;
319
+ /**
320
+ * Parameters to be appended to the URL (i.e: /:id)
321
+ */
322
+ params?: Params;
323
+ /**
324
+ * Query parameters to append to the URL.
325
+ */
326
+ query?: Query;
327
+ }
328
+ //#endregion
329
+ //#region src/plugins.d.ts
330
+ type PluginInitContext<TPluginExtraOptions = unknown> = RequestContext & PluginExtraOptions<TPluginExtraOptions> & {
331
+ initURL: string;
332
+ };
333
+ type PluginInitResult = Partial<Omit<PluginInitContext, "initURL" | "request"> & {
334
+ initURL: InitURLOrURLObject;
335
+ request: CallApiRequestOptions;
336
+ }>;
337
+ type PluginHooksWithMoreOptions<TMoreOptions = unknown> = HooksOrHooksArray<never, never, TMoreOptions>;
338
+ type PluginHooks<TData = never, TErrorData = never, TMoreOptions = unknown> = HooksOrHooksArray<TData, TErrorData, TMoreOptions>;
339
+ interface CallApiPlugin {
340
+ /**
341
+ * Defines additional options that can be passed to callApi
342
+ */
343
+ defineExtraOptions?: (...params: never[]) => unknown;
344
+ /**
345
+ * A description for the plugin
346
+ */
347
+ description?: string;
348
+ /**
349
+ * Hooks / Interceptors for the plugin
350
+ */
351
+ hooks?: PluginHooks;
352
+ /**
353
+ * A unique id for the plugin
354
+ */
355
+ id: string;
356
+ /**
357
+ * A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
358
+ */
359
+ init?: (context: PluginInitContext) => Awaitable<PluginInitResult> | Awaitable<void>;
360
+ /**
361
+ * A name for the plugin
362
+ */
363
+ name: string;
364
+ /**
365
+ * A version for the plugin
366
+ */
367
+ version?: string;
368
+ }
369
+ declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => TPlugin;
370
+ //#endregion
371
+ //#region src/types/default-types.d.ts
372
+ type DefaultDataType = unknown;
373
+ type DefaultPluginArray = CallApiPlugin[];
374
+ type DefaultThrowOnError = boolean;
375
+ //#endregion
376
+ //#region src/result.d.ts
377
+ type Parser = (responseString: string) => Awaitable<Record<string, unknown>>;
378
+ declare const getResponseType: <TResponse>(response: Response, parser: Parser) => {
379
+ arrayBuffer: () => Promise<ArrayBuffer>;
380
+ blob: () => Promise<Blob>;
381
+ formData: () => Promise<FormData>;
382
+ json: () => Promise<TResponse>;
383
+ stream: () => ReadableStream<Uint8Array<ArrayBufferLike>> | null;
384
+ text: () => Promise<string>;
385
+ };
386
+ type InitResponseTypeMap<TResponse = unknown> = ReturnType<typeof getResponseType<TResponse>>;
387
+ type ResponseTypeUnion = keyof InitResponseTypeMap | null;
388
+ type ResponseTypeMap<TResponse> = { [Key in keyof InitResponseTypeMap<TResponse>]: Awaited<ReturnType<InitResponseTypeMap<TResponse>[Key]>> };
389
+ type GetResponseType<TResponse, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse> = ResponseTypeMap<TResponse>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
390
+ type CallApiResultSuccessVariant<TData> = {
391
+ data: TData;
392
+ error: null;
393
+ response: Response;
394
+ };
395
+ type PossibleJavaScriptError = UnmaskType<{
396
+ errorData: PossibleJavaScriptError["originalError"];
397
+ message: string;
398
+ name: "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | (`${string}Error` & {});
399
+ originalError: DOMException | Error | SyntaxError | TypeError;
400
+ }>;
401
+ type PossibleHTTPError<TErrorData> = Prettify<UnmaskType<{
402
+ errorData: TErrorData;
403
+ message: string;
404
+ name: "HTTPError";
405
+ originalError: HTTPError;
406
+ }>>;
407
+ type PossibleValidationError = Prettify<UnmaskType<{
408
+ errorData: ValidationError["errorData"];
409
+ message: string;
410
+ name: "ValidationError";
411
+ originalError: ValidationError;
412
+ }>>;
413
+ type PossibleJavaScriptOrValidationError = UnmaskType<PossibleJavaScriptError | PossibleValidationError>;
414
+ type CallApiResultErrorVariant<TErrorData> = {
415
+ data: null;
416
+ error: PossibleHTTPError<TErrorData>;
417
+ response: Response;
418
+ } | {
419
+ data: null;
420
+ error: PossibleJavaScriptOrValidationError;
421
+ response: Response | null;
422
+ };
423
+ type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedErrorData = GetResponseType<TErrorData, TResponseType>> = UnmaskType<{
424
+ all: CallApiResultSuccessVariant<TComputedData> | CallApiResultErrorVariant<TComputedErrorData>;
425
+ allWithException: CallApiResultSuccessVariant<TComputedData>;
426
+ onlySuccess: CallApiResultErrorVariant<TComputedErrorData>["data"] | CallApiResultSuccessVariant<TComputedData>["data"];
427
+ onlySuccessWithException: CallApiResultSuccessVariant<TComputedData>["data"];
428
+ }>;
429
+ type ResultModeUnion = keyof ResultModeMap | null;
430
+ type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = TErrorData extends false ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : TErrorData extends false | undefined ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : TErrorData extends false | null ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccess"] : null extends TResultMode ? TThrowOnError extends true ? ResultModeMap<TData, TErrorData, TResponseType>["allWithException"] : ResultModeMap<TData, TErrorData, TResponseType>["all"] : TResultMode extends NonNullable<ResultModeUnion> ? ResultModeMap<TData, TErrorData, TResponseType>[TResultMode] : never;
431
+ //#endregion
432
+ //#region src/stream.d.ts
433
+ type StreamProgressEvent = {
434
+ /**
435
+ * Current chunk of data being streamed
436
+ */
437
+ chunk: Uint8Array;
438
+ /**
439
+ * Progress in percentage
440
+ */
441
+ progress: number;
442
+ /**
443
+ * Total size of data in bytes
444
+ */
445
+ totalBytes: number;
446
+ /**
447
+ * Amount of data transferred so far
448
+ */
449
+ transferredBytes: number;
450
+ };
451
+ declare global {
452
+ interface ReadableStream<R> {
453
+ [Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
454
+ }
455
+ }
456
+ //#endregion
457
+ //#region src/hooks.d.ts
458
+ type PluginExtraOptions<TPluginOptions = unknown> = {
459
+ options: Partial<TPluginOptions>;
460
+ };
461
+ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOptions = unknown> {
462
+ /**
463
+ * Hook that will be called when any error occurs within the request/response lifecycle, regardless of whether the error is from the api or not.
464
+ * It is basically a combination of `onRequestError` and `onResponseError` hooks
465
+ */
466
+ onError?: (context: ErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
467
+ /**
468
+ * Hook that will be called just before the request is being made.
469
+ */
470
+ onRequest?: (context: RequestContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
471
+ /**
472
+ * Hook that will be called when an error occurs during the fetch request.
473
+ */
474
+ onRequestError?: (context: RequestErrorContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
475
+ /**
476
+ * Hook that will be called when upload stream progress is tracked
477
+ */
478
+ onRequestStream?: (context: RequestStreamContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
479
+ /**
480
+ * Hook that will be called when any response is received from the api, whether successful or not
481
+ */
482
+ onResponse?: (context: ResponseContext<TData, TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
483
+ /**
484
+ * Hook that will be called when an error response is received from the api.
485
+ */
486
+ onResponseError?: (context: ResponseErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
487
+ /**
488
+ * Hook that will be called when download stream progress is tracked
489
+ */
490
+ onResponseStream?: (context: ResponseStreamContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
491
+ /**
492
+ * Hook that will be called when a request is retried.
493
+ */
494
+ onRetry?: (response: RetryContext<TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
495
+ /**
496
+ * Hook that will be called when a successful response is received from the api.
497
+ */
498
+ onSuccess?: (context: SuccessContext<TData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
499
+ /**
500
+ * Hook that will be called when a validation error occurs.
501
+ */
502
+ onValidationError?: (context: ValidationErrorContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
503
+ }
504
+ type HooksOrHooksArray<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = unknown> = { [Key in keyof Hooks<TData, TErrorData, TMoreOptions>]: Hooks<TData, TErrorData, TMoreOptions>[Key] | Array<Hooks<TData, TErrorData, TMoreOptions>[Key]> };
505
+ type RequestContext = {
506
+ /**
507
+ * Config object passed to createFetchClient
508
+ */
509
+ baseConfig: BaseCallApiExtraOptions & CallApiRequestOptions;
510
+ /**
511
+ * Config object passed to the callApi instance
512
+ */
513
+ config: CallApiExtraOptions & CallApiRequestOptions;
514
+ /**
515
+ * Merged options consisting of extra options from createFetchClient, the callApi instance and default options.
516
+ *
517
+ */
518
+ options: CombinedCallApiExtraOptions;
519
+ /**
520
+ * Merged request consisting of request options from createFetchClient, the callApi instance and default request options.
521
+ */
522
+ request: CallApiRequestOptionsForHooks;
523
+ };
524
+ type ResponseContext<TData, TErrorData> = RequestContext & ({
525
+ data: null;
526
+ error: PossibleHTTPError<TErrorData>;
527
+ response: Response;
528
+ } | {
529
+ data: null;
530
+ error: PossibleJavaScriptOrValidationError;
531
+ response: Response | null;
532
+ } | {
533
+ data: TData;
534
+ error: null;
535
+ response: Response;
536
+ });
537
+ type ValidationErrorContext = RequestContext & {
538
+ error: ValidationError;
539
+ response: Response | null;
540
+ };
541
+ type SuccessContext<TData> = RequestContext & {
542
+ data: TData;
543
+ response: Response;
544
+ };
545
+ type RequestErrorContext = UnmaskType<RequestContext & {
546
+ error: PossibleJavaScriptOrValidationError;
547
+ response: null;
548
+ }>;
549
+ type ResponseErrorContext<TErrorData> = UnmaskType<RequestContext & {
550
+ error: PossibleHTTPError<TErrorData>;
551
+ response: Response;
552
+ }>;
553
+ type RetryContext<TErrorData> = UnmaskType<ErrorContext<TErrorData> & {
554
+ retryAttemptCount: number;
555
+ }>;
556
+ type ErrorContext<TErrorData> = UnmaskType<RequestContext & ({
557
+ error: PossibleHTTPError<TErrorData>;
558
+ response: Response;
559
+ } | {
560
+ error: PossibleJavaScriptOrValidationError;
561
+ response: Response | null;
562
+ })>;
563
+ type RequestStreamContext = UnmaskType<RequestContext & {
564
+ event: StreamProgressEvent;
565
+ requestInstance: Request;
566
+ }>;
567
+ type ResponseStreamContext = UnmaskType<RequestContext & {
568
+ event: StreamProgressEvent;
569
+ response: Response;
570
+ }>;
571
+ //#endregion
572
+ //#region src/dedupe.d.ts
573
+ type DedupeOptions = {
574
+ /**
575
+ * Custom request key to be used to identify a request in the fetch deduplication strategy.
576
+ * @default the full request url + string formed from the request options
577
+ */
578
+ dedupeKey?: string;
579
+ /**
580
+ * Defines the deduplication strategy for the request, can be set to "none" | "defer" | "cancel".
581
+ * - If set to "cancel", the previous pending request with the same request key will be cancelled and lets the new request through.
582
+ * - If set to "defer", all new request with the same request key will be share the same response, until the previous one is completed.
583
+ * - If set to "none", deduplication is disabled.
584
+ * @default "cancel"
585
+ */
586
+ dedupeStrategy?: "cancel" | "defer" | "none";
587
+ };
588
+ //#endregion
589
+ //#region src/retry.d.ts
590
+ type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
591
+ type InnerRetryKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, "~retryAttemptCount" | "retry">;
592
+ type InnerRetryOptions<TErrorData> = { [Key in InnerRetryKeys<TErrorData> as Key extends `retry${infer TRest}` ? Uncapitalize<TRest> extends "attempts" ? never : Uncapitalize<TRest> : Key]?: RetryOptions<TErrorData>[Key] } & {
593
+ attempts: NonNullable<RetryOptions<TErrorData>["retryAttempts"]>;
594
+ };
595
+ interface RetryOptions<TErrorData> {
596
+ /**
597
+ * Keeps track of the number of times the request has already been retried
598
+ *
599
+ * @deprecated **NOTE**: This property is used internally to track retries. Please abstain from modifying it.
600
+ */
601
+ readonly ["~retryAttemptCount"]?: number;
602
+ /**
603
+ * All retry options in a single object instead of separate properties
604
+ */
605
+ retry?: InnerRetryOptions<TErrorData>;
606
+ /**
607
+ * Number of allowed retry attempts on HTTP errors
608
+ * @default 0
609
+ */
610
+ retryAttempts?: number;
611
+ /**
612
+ * Callback whose return value determines if a request should be retried or not
613
+ */
614
+ retryCondition?: RetryCondition<TErrorData>;
615
+ /**
616
+ * Delay between retries in milliseconds
617
+ * @default 1000
618
+ */
619
+ retryDelay?: number | ((currentAttemptCount: number) => number);
620
+ /**
621
+ * Maximum delay in milliseconds. Only applies to exponential strategy
622
+ * @default 10000
623
+ */
624
+ retryMaxDelay?: number;
625
+ /**
626
+ * HTTP methods that are allowed to retry
627
+ * @default ["GET", "POST"]
628
+ */
629
+ retryMethods?: MethodUnion[];
630
+ /**
631
+ * HTTP status codes that trigger a retry
632
+ */
633
+ retryStatusCodes?: number[];
634
+ /**
635
+ * Strategy to use when retrying
636
+ * @default "linear"
637
+ */
638
+ retryStrategy?: "exponential" | "linear";
639
+ }
640
+ //#endregion
641
+ //#region src/types/conditional-types.d.ts
642
+ /**
643
+ * @description Makes a type required if the output type of TSchema contains undefined, otherwise keeps it as is
644
+ */
645
+ type MakeSchemaOptionRequired<TSchema extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaResult<TSchema, undefined> ? TObject : Required<TObject>;
646
+ type ApplyURLBasedConfig<TSchemaConfig extends CallApiSchemaConfig, TCurrentRouteKeys extends string> = TSchemaConfig["baseURL"] extends string ? `${TSchemaConfig["baseURL"]}${TCurrentRouteKeys}` : TCurrentRouteKeys;
647
+ type ApplyStrictConfig<TSchemaConfig extends CallApiSchemaConfig, TCurrentRouteKeys extends string> = TSchemaConfig["strict"] extends true ? TCurrentRouteKeys : TCurrentRouteKeys | AnyString;
648
+ type ApplySchemaConfiguration<TSchemaConfig extends CallApiSchemaConfig, TCurrentRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig, ApplyURLBasedConfig<TSchemaConfig, TCurrentRouteKeys>>;
649
+ type InferAllRouteKeys<TBaseSchema extends BaseCallApiSchema, TSchemaConfig extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig, keyof TBaseSchema extends string ? keyof TBaseSchema : never>;
650
+ type InferInitURL<TBaseSchema extends BaseCallApiSchema, TSchemaConfig extends CallApiSchemaConfig> = InferAllRouteKeys<TBaseSchema, TSchemaConfig> | URL;
651
+ type GetCurrentRouteKey<TSchemaConfig extends CallApiSchemaConfig, TPath> = TSchemaConfig["baseURL"] extends string ? TPath extends `${TSchemaConfig["baseURL"]}${infer TCurrentRoute}` ? TCurrentRoute extends string ? TCurrentRoute : string : string : TPath extends URL ? string : TPath;
652
+ type JsonPrimitive = boolean | number | string | null | undefined;
653
+ type SerializableObject = Record<keyof object, unknown>;
654
+ type SerializableArray = Array<JsonPrimitive | SerializableArray | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableArray | SerializableObject>;
655
+ type Body = UnmaskType<RequestInit["body"] | SerializableArray | SerializableObject>;
656
+ type InferBodyOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequired<TSchema["body"], {
657
+ /**
658
+ * Body of the request, can be a object or any other supported body type.
659
+ */
660
+ body?: InferSchemaResult<TSchema["body"], Body>;
661
+ }>;
662
+ type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
663
+ type InferMethodFromURL<TInitURL> = TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
664
+ type MakeMethodOptionRequired<TInitURL, TRequireMethodOption extends CallApiSchemaConfig["requireHttpMethodProvision"], TObject> = TInitURL extends `@${string}/${string}` ? TRequireMethodOption extends true ? Required<TObject> : TObject : TObject;
665
+ type InferMethodOption<TSchema extends CallApiSchema, TSchemaConfig extends CallApiSchemaConfig, TInitURL> = MakeSchemaOptionRequired<TSchema["method"], MakeMethodOptionRequired<TInitURL, TSchemaConfig["requireHttpMethodProvision"], {
666
+ /**
667
+ * HTTP method for the request.
668
+ * @default "GET"
669
+ */
670
+ method?: InferSchemaResult<TSchema["method"], InferMethodFromURL<TInitURL>>;
671
+ }>>;
672
+ type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders> | Record<"Content-Type", CommonContentTypes> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | RequestInit["headers"]>;
673
+ type InferHeadersOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequired<TSchema["headers"], {
674
+ /**
675
+ * Headers to be used in the request.
676
+ */
677
+ headers?: InferSchemaResult<TSchema["headers"], HeadersOption> | ((context: {
678
+ baseHeaders: NonNullable<HeadersOption>;
679
+ }) => InferSchemaResult<TSchema["headers"], HeadersOption>);
680
+ }>;
681
+ type InferRequestOptions<TSchema extends CallApiSchema, TSchemaConfig extends CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, CallApiSchemaConfig>> = InferBodyOption<TSchema> & InferHeadersOption<TSchema> & InferMethodOption<TSchema, TSchemaConfig, TInitURL>;
682
+ interface Register {}
683
+ type GlobalMeta = Register extends {
684
+ meta?: infer TMeta extends Record<string, unknown>;
685
+ } ? TMeta : never;
686
+ type InferMetaOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequired<TSchema["meta"], {
687
+ meta?: InferSchemaResult<TSchema["meta"], GlobalMeta>;
688
+ }>;
689
+ type InferQueryOption<TSchema extends CallApiSchema> = MakeSchemaOptionRequired<TSchema["query"], {
690
+ /**
691
+ * Parameters to be appended to the URL (i.e: /:id)
692
+ */
693
+ query?: InferSchemaResult<TSchema["query"], Query>;
694
+ }>;
695
+ type EmptyString = "";
696
+ type InferParamFromPath<TPath> = TPath extends `${infer IgnoredPrefix}:${infer TCurrentParam}/${infer TRemainingPath}` ? TCurrentParam extends EmptyString ? InferParamFromPath<TRemainingPath> : Prettify<Record<TCurrentParam | (Params extends InferParamFromPath<TRemainingPath> ? never : keyof Extract<InferParamFromPath<TRemainingPath>, Record<string, unknown>>), AllowedQueryParamValues>> | [AllowedQueryParamValues, ...(Params extends InferParamFromPath<TRemainingPath> ? [] : Extract<InferParamFromPath<TRemainingPath>, unknown[]>)] : TPath extends `${infer IgnoredPrefix}:${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? Params : Prettify<Record<TCurrentParam, AllowedQueryParamValues>> | [AllowedQueryParamValues] : Params;
697
+ type InferParamsOption<TPath, TSchema extends CallApiSchema> = MakeSchemaOptionRequired<TSchema["params"], {
698
+ /**
699
+ * Parameters to be appended to the URL (i.e: /:id)
700
+ */
701
+ params?: InferSchemaResult<TSchema["params"], InferParamFromPath<TPath>>;
702
+ }>;
703
+ type InferExtraOptions<TSchema extends CallApiSchema, TPath> = InferMetaOption<TSchema> & InferParamsOption<TPath, TSchema> & InferQueryOption<TSchema>;
704
+ type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction<infer TResult> ? InferSchemaResult<TResult> : never : never : never>;
705
+ type ExtractKeys<TUnion, TSelectedUnion extends TUnion> = Extract<TUnion, TSelectedUnion>;
706
+ type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
707
+ resultMode: "onlySuccessWithException";
708
+ } : TErrorData extends false | undefined ? {
709
+ resultMode?: "onlySuccessWithException";
710
+ } : TErrorData extends false | null ? {
711
+ resultMode?: ExtractKeys<ResultModeUnion, "onlySuccess" | "onlySuccessWithException">;
712
+ } : null extends TResultMode ? {
713
+ resultMode?: TResultMode;
714
+ } : {
715
+ resultMode: TResultMode;
716
+ };
717
+ type ThrowOnErrorOption<TErrorData> = TErrorData extends false ? {
718
+ throwOnError: true;
719
+ } : TErrorData extends false | undefined ? {
720
+ throwOnError?: true;
721
+ } : NonNullable<unknown>;
722
+ //#endregion
723
+ //#region src/types/common.d.ts
724
+ type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
725
+ type ModifiedRequestInit = RequestInit & {
726
+ duplex?: "half";
727
+ };
728
+ type CallApiRequestOptions = Prettify<{
729
+ /**
730
+ * Body of the request, can be a object or any other supported body type.
731
+ */
732
+ body?: Body;
733
+ /**
734
+ * Headers to be used in the request.
735
+ */
736
+ headers?: HeadersOption;
737
+ /**
738
+ * HTTP method for the request.
739
+ * @default "GET"
740
+ */
741
+ method?: MethodUnion;
742
+ } & Pick<ModifiedRequestInit, FetchSpecificKeysUnion>>;
743
+ type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
744
+ headers?: Record<string, string | undefined>;
745
+ };
746
+ type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
747
+ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = {
748
+ /**
749
+ * Authorization header value.
750
+ */
751
+ auth?: string | Auth | null;
752
+ /**
753
+ * Custom function to serialize the body object into a string.
754
+ */
755
+ bodySerializer?: (bodyData: Record<string, unknown>) => string;
756
+ /**
757
+ * Whether or not to clone the response, so response.json() and the like can be read again else where.
758
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Response/clone
759
+ * @default false
760
+ */
761
+ cloneResponse?: boolean;
762
+ /**
763
+ * Custom fetch implementation
764
+ */
765
+ customFetchImpl?: FetchImpl;
766
+ /**
767
+ * Default error message to use if none is provided from a response.
768
+ * @default "Failed to fetch data from server!"
769
+ */
770
+ defaultErrorMessage?: string;
771
+ /**
772
+ * If true, forces the calculation of the total byte size from the request or response body, in case the content-length header is not present or is incorrect.
773
+ * @default false
774
+ */
775
+ forceCalculateStreamSize?: boolean | {
776
+ request?: boolean;
777
+ response?: boolean;
778
+ };
779
+ /**
780
+ * Defines the mode in which the composed hooks are executed".
781
+ * - If set to "parallel", main and plugin hooks will be executed in parallel.
782
+ * - If set to "sequential", the plugin hooks will be executed first, followed by the main hook.
783
+ * @default "parallel"
784
+ */
785
+ mergedHooksExecutionMode?: "parallel" | "sequential";
786
+ /**
787
+ * - Controls what order in which the composed hooks execute
788
+ * @default "mainHooksAfterPlugins"
789
+ */
790
+ mergedHooksExecutionOrder?: "mainHooksAfterPlugins" | "mainHooksBeforePlugins";
791
+ /**
792
+ * - An optional field you can fill with additional information,
793
+ * to associate with the request, typically used for logging or tracing.
794
+ *
795
+ * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
796
+ *
797
+ * @example
798
+ * ```ts
799
+ * const callMainApi = callApi.create({
800
+ * baseURL: "https://main-api.com",
801
+ * onResponseError: ({ response, options }) => {
802
+ * if (options.meta?.userId) {
803
+ * console.error(`User ${options.meta.userId} made an error`);
804
+ * }
805
+ * },
806
+ * });
807
+ *
808
+ * const response = await callMainApi({
809
+ * url: "https://example.com/api/data",
810
+ * meta: { userId: "123" },
811
+ * });
812
+ * ```
813
+ */
814
+ meta?: GlobalMeta;
815
+ /**
816
+ * Custom function to parse the response string
817
+ */
818
+ responseParser?: (responseString: string) => Awaitable<Record<string, unknown>>;
819
+ /**
820
+ * Expected response type, affects how response is parsed
821
+ * @default "json"
822
+ */
823
+ responseType?: TResponseType;
824
+ /**
825
+ * Mode of the result, can influence how results are handled or returned.
826
+ * Can be set to "all" | "onlySuccess" | "onlyError" | "onlyResponse".
827
+ * @default "all"
828
+ */
829
+ resultMode?: TResultMode;
830
+ /**
831
+ * If true or the function returns true, throws errors instead of returning them
832
+ * The function is passed the error object and can be used to conditionally throw the error
833
+ * @default false
834
+ */
835
+ throwOnError?: TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);
836
+ /**
837
+ * Request timeout in milliseconds
838
+ */
839
+ timeout?: number;
840
+ } & DedupeOptions & HooksOrHooksArray<TData, TErrorData, Partial<InferPluginOptions<TPluginArray>>> & Partial<InferPluginOptions<TPluginArray>> & RetryOptions<TErrorData> & ResultModeOption<TErrorData, TResultMode> & ThrowOnErrorOption<TErrorData> & UrlOptions;
841
+ type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig> = SharedExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
842
+ baseURL?: string;
843
+ /**
844
+ * An array of base callApi plugins. It allows you to extend the behavior of the library.
845
+ */
846
+ plugins?: TBasePluginArray;
847
+ /**
848
+ * Base schemas for the client.
849
+ */
850
+ schema?: Writeable<TBaseSchema, "deep">;
851
+ /**
852
+ * Schema Configuration
853
+ */
854
+ schemaConfig?: Writeable<TBaseSchemaConfig, "deep">;
855
+ /**
856
+ * Specifies which configuration parts should skip automatic merging between base and main configs.
857
+ * Use this when you need manual control over how configs are combined.
858
+ *
859
+ * @enum
860
+ * - `"all"` - Disables automatic merging for both request and options
861
+ * - `"options"` - Disables automatic merging of options only
862
+ * - `"request"` - Disables automatic merging of request only
863
+ *
864
+ * **Example**
865
+ *
866
+ * ```ts
867
+ * const client = createFetchClient((ctx) => ({
868
+ * skipAutoMergeFor: "options",
869
+ *
870
+ * // Now you can manually merge options in your config function
871
+ * ...ctx.options,
872
+ * }));
873
+ * ```
874
+ */
875
+ skipAutoMergeFor?: "all" | "options" | "request";
876
+ };
877
+ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchema extends CallApiSchema = CallApiSchema, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteKey extends string = string> = SharedExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
878
+ /**
879
+ * An array of instance CallApi plugins. It allows you to extend the behavior of the library.
880
+ */
881
+ plugins?: TPluginArray | ((context: {
882
+ basePlugins: TBasePluginArray;
883
+ }) => TPluginArray);
884
+ /**
885
+ * Schemas for the callapi instance
886
+ */
887
+ schema?: Writeable<TSchema, "deep"> | ((context: {
888
+ baseSchema: Writeable<TBaseSchema, "deep">;
889
+ currentRouteSchema: NonNullable<Writeable<TBaseSchema[TCurrentRouteKey], "deep">>;
890
+ }) => Writeable<TSchema, "deep">);
891
+ /**
892
+ * Schema config for the callapi instance
893
+ */
894
+ schemaConfig?: Writeable<TSchemaConfig, "deep"> | ((context: {
895
+ baseSchemaConfig: NonNullable<Writeable<TBaseSchemaConfig, "deep">>;
896
+ }) => Writeable<TSchemaConfig, "deep">);
897
+ };
898
+ interface CombinedCallApiExtraOptions extends Omit<CallApiExtraOptions, keyof Hooks>, Hooks {}
899
+ type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig> = (CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchema, TBaseSchemaConfig>) | ((context: {
900
+ initURL: string;
901
+ options: CallApiExtraOptions;
902
+ request: CallApiRequestOptions;
903
+ }) => CallApiRequestOptions & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchema, TBaseSchemaConfig>);
904
+ type CallApiConfig<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchema extends CallApiSchema = CallApiSchema, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends string = string> = InferExtraOptions<TSchema, TCurrentRouteKey> & InferRequestOptions<TSchema, TSchemaConfig, TInitURL> & Omit<CallApiExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchema, TBaseSchemaConfig, TSchema, TSchemaConfig, TCurrentRouteKey>, keyof InferExtraOptions<CallApiSchema, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, CallApiSchemaConfig, string>>;
905
+ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchema extends BaseCallApiSchema = BaseCallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchema extends CallApiSchema = CallApiSchema, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InferInitURL<BaseCallApiSchema, TSchemaConfig> = InferInitURL<BaseCallApiSchema, TSchemaConfig>, TCurrentRouteKey extends string = string> = [initURL: TInitURL, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchema, TBaseSchemaConfig, TSchema, TSchemaConfig, TInitURL, TCurrentRouteKey>];
906
+ type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
907
+ //#endregion
908
+ export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchema, CallApiConfig, CallApiExtraOptions, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, CombinedCallApiExtraOptions, DefaultDataType, DefaultPluginArray, DefaultThrowOnError, ErrorContext, GetCurrentRouteKey, HTTPError, Hooks, HooksOrHooksArray, InferInitURL, InferParamFromPath, InferSchemaResult, PluginHooks, PluginHooksWithMoreOptions, PluginInitContext, PossibleHTTPError, PossibleJavaScriptError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeUnion, ResultModeUnion, RetryOptions, SuccessContext, ValidationError, definePlugin, defineSchema };
909
+ //# sourceMappingURL=common-B_Me8xq2.d.ts.map