@zayne-labs/callapi 1.8.19 → 1.8.21

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