@zayne-labs/callapi-plugins 4.0.10 → 4.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +214 -121
- package/package.json +3 -3
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import * as _zayne_labs_callapi_utils0 from "@zayne-labs/callapi/utils";
|
|
1
2
|
import { AnyFunction } from "@zayne-labs/toolkit-type-helpers";
|
|
2
3
|
|
|
3
|
-
//#region ../callapi/dist/esm/common-
|
|
4
|
+
//#region ../callapi/dist/esm/common-DTliA7CY.d.ts
|
|
4
5
|
//#region src/types/type-helpers.d.ts
|
|
5
6
|
type AnyString = string & NonNullable<unknown>;
|
|
6
7
|
type AnyNumber = number & NonNullable<unknown>;
|
|
@@ -289,6 +290,7 @@ interface URLOptions {
|
|
|
289
290
|
//#endregion
|
|
290
291
|
//#region src/validation.d.ts
|
|
291
292
|
type InferSchemaOutputResult<TSchema$1, TFallbackResult = unknown> = undefined extends TSchema$1 ? TFallbackResult : TSchema$1 extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema$1> : TSchema$1 extends AnyFunction$1<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
293
|
+
type InferSchemaInputResult<TSchema$1, TFallbackResult = unknown> = undefined extends TSchema$1 ? TFallbackResult : TSchema$1 extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema$1> : TSchema$1 extends AnyFunction$1<infer TResult> ? Awaited<TResult> : TFallbackResult;
|
|
292
294
|
interface CallApiSchemaConfig {
|
|
293
295
|
/**
|
|
294
296
|
* The base url of the schema. By default it's the baseURL of the callApi instance.
|
|
@@ -370,23 +372,31 @@ type BaseCallApiSchemaAndConfig = {
|
|
|
370
372
|
declare const fallBackRouteSchemaKey = ".";
|
|
371
373
|
type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;
|
|
372
374
|
//#endregion
|
|
373
|
-
//#region src/
|
|
374
|
-
|
|
375
|
-
|
|
375
|
+
//#region src/utils/external/body.d.ts
|
|
376
|
+
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/types/default-types.d.ts
|
|
379
|
+
type DefaultDataType = unknown;
|
|
380
|
+
type DefaultPluginArray = CallApiPlugin[];
|
|
381
|
+
type DefaultThrowOnError = boolean;
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region src/utils/external/error.d.ts
|
|
384
|
+
type HTTPErrorDetails<TErrorData$1> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
|
|
385
|
+
errorData: TErrorData$1;
|
|
376
386
|
response: Response;
|
|
377
387
|
};
|
|
378
|
-
declare class HTTPError<TErrorData = Record<string, unknown>> extends Error {
|
|
379
|
-
errorData: HTTPErrorDetails<TErrorData>["errorData"];
|
|
388
|
+
declare class HTTPError<TErrorData$1 = Record<string, unknown>> extends Error {
|
|
389
|
+
errorData: HTTPErrorDetails<TErrorData$1>["errorData"];
|
|
380
390
|
readonly httpErrorSymbol: symbol;
|
|
381
391
|
name: "HTTPError";
|
|
382
|
-
response: HTTPErrorDetails<TErrorData>["response"];
|
|
383
|
-
constructor(errorDetails: HTTPErrorDetails<TErrorData>, errorOptions?: ErrorOptions);
|
|
392
|
+
response: HTTPErrorDetails<TErrorData$1>["response"];
|
|
393
|
+
constructor(errorDetails: HTTPErrorDetails<TErrorData$1>, errorOptions?: ErrorOptions);
|
|
384
394
|
/**
|
|
385
395
|
* @description Checks if the given error is an instance of HTTPError
|
|
386
396
|
* @param error - The error to check
|
|
387
397
|
* @returns true if the error is an instance of HTTPError, false otherwise
|
|
388
398
|
*/
|
|
389
|
-
static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData>;
|
|
399
|
+
static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData$1>;
|
|
390
400
|
}
|
|
391
401
|
type SafeExtract<TUnion, TKey extends TUnion> = Extract<TUnion, TKey>;
|
|
392
402
|
type ValidationErrorDetails = {
|
|
@@ -420,6 +430,69 @@ declare class ValidationError extends Error {
|
|
|
420
430
|
static isError(error: unknown): error is ValidationError;
|
|
421
431
|
}
|
|
422
432
|
//#endregion
|
|
433
|
+
//#region src/result.d.ts
|
|
434
|
+
type Parser<TData$1> = (responseString: string) => Awaitable<TData$1>;
|
|
435
|
+
declare const getResponseType: <TResponse>(response: Response, parser: Parser<TResponse>) => {
|
|
436
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
437
|
+
blob: () => Promise<Blob>;
|
|
438
|
+
formData: () => Promise<FormData>;
|
|
439
|
+
json: () => Promise<TResponse>;
|
|
440
|
+
stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
|
|
441
|
+
text: () => Promise<string>;
|
|
442
|
+
};
|
|
443
|
+
type InitResponseTypeMap<TResponse$1 = unknown> = ReturnType<typeof getResponseType<TResponse$1>>;
|
|
444
|
+
type ResponseTypeUnion = keyof InitResponseTypeMap | null;
|
|
445
|
+
type ResponseTypeMap<TResponse$1> = { [Key in keyof InitResponseTypeMap<TResponse$1>]: Awaited<ReturnType<InitResponseTypeMap<TResponse$1>[Key]>> };
|
|
446
|
+
type GetResponseType<TResponse$1, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse$1> = ResponseTypeMap<TResponse$1>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
|
|
447
|
+
type CallApiResultSuccessVariant<TData$1> = {
|
|
448
|
+
data: NoInfer<TData$1>;
|
|
449
|
+
error: null;
|
|
450
|
+
response: Response;
|
|
451
|
+
};
|
|
452
|
+
type PossibleJavaScriptError = UnmaskType<{
|
|
453
|
+
errorData: false;
|
|
454
|
+
message: string;
|
|
455
|
+
name: "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | AnyString;
|
|
456
|
+
originalError: DOMException | Error | SyntaxError | TypeError;
|
|
457
|
+
}>;
|
|
458
|
+
type PossibleHTTPError<TErrorData$1> = UnmaskType<{
|
|
459
|
+
errorData: NoInfer<TErrorData$1>;
|
|
460
|
+
message: string;
|
|
461
|
+
name: "HTTPError";
|
|
462
|
+
originalError: HTTPError;
|
|
463
|
+
}>;
|
|
464
|
+
type PossibleValidationError = UnmaskType<{
|
|
465
|
+
errorData: ValidationError["errorData"];
|
|
466
|
+
issueCause: ValidationError["issueCause"];
|
|
467
|
+
message: string;
|
|
468
|
+
name: "ValidationError";
|
|
469
|
+
originalError: ValidationError;
|
|
470
|
+
}>;
|
|
471
|
+
type PossibleJavaScriptOrValidationError = UnmaskType<PossibleJavaScriptError | PossibleValidationError>;
|
|
472
|
+
type CallApiResultErrorVariant<TErrorData$1> = {
|
|
473
|
+
data: null;
|
|
474
|
+
error: PossibleHTTPError<TErrorData$1>;
|
|
475
|
+
response: Response;
|
|
476
|
+
} | {
|
|
477
|
+
data: null;
|
|
478
|
+
error: PossibleJavaScriptOrValidationError;
|
|
479
|
+
response: Response | null;
|
|
480
|
+
};
|
|
481
|
+
type CallApiSuccessOrErrorVariant<TData$1, TError> = CallApiResultErrorVariant<TError> | CallApiResultSuccessVariant<TData$1>;
|
|
482
|
+
type ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType extends ResponseTypeUnion, TComputedData = GetResponseType<TData$1, TResponseType>, TComputedErrorData = GetResponseType<TErrorData$1, TResponseType>, TComputedResult extends CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData> = CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData>> = UnmaskType<{
|
|
483
|
+
all: TComputedResult;
|
|
484
|
+
onlyData: TComputedResult["data"];
|
|
485
|
+
onlyResponse: TComputedResult["response"];
|
|
486
|
+
}>;
|
|
487
|
+
type ResultModeMapWithException<TData$1, TResponseType extends ResponseTypeUnion, TComputedData = GetResponseType<TData$1, TResponseType>, TComputedResult extends CallApiResultSuccessVariant<TComputedData> = CallApiResultSuccessVariant<TComputedData>> = {
|
|
488
|
+
all: TComputedResult;
|
|
489
|
+
onlyData: TComputedResult["data"];
|
|
490
|
+
onlyResponse: TComputedResult["response"];
|
|
491
|
+
};
|
|
492
|
+
type ResultModeMap<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError> = TThrowOnError extends true ? ResultModeMapWithException<TData$1, TResponseType> : ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType>;
|
|
493
|
+
type ResultModePlaceholder = null;
|
|
494
|
+
type ResultModeUnion = keyof ResultModeMap | ResultModePlaceholder;
|
|
495
|
+
//#endregion
|
|
423
496
|
//#region src/middlewares.d.ts
|
|
424
497
|
type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
|
|
425
498
|
interface Middlewares {
|
|
@@ -467,7 +540,7 @@ type PluginInitResult = Partial<Omit<PluginSetupContext, "initURL" | "request">
|
|
|
467
540
|
initURL: InitURLOrURLObject;
|
|
468
541
|
request: CallApiRequestOptions;
|
|
469
542
|
}>;
|
|
470
|
-
type PluginHooks<TData = never, TErrorData = never, TMoreOptions = unknown> = HooksOrHooksArray<TData, TErrorData, TMoreOptions>;
|
|
543
|
+
type PluginHooks<TData$1 = never, TErrorData$1 = never, TMoreOptions = unknown> = HooksOrHooksArray<TData$1, TErrorData$1, TMoreOptions>;
|
|
471
544
|
interface CallApiPlugin {
|
|
472
545
|
/**
|
|
473
546
|
* Defines additional options that can be passed to callApi
|
|
@@ -507,73 +580,8 @@ interface CallApiPlugin {
|
|
|
507
580
|
version?: string;
|
|
508
581
|
}
|
|
509
582
|
//#endregion
|
|
510
|
-
//#region src/
|
|
511
|
-
|
|
512
|
-
type DefaultPluginArray = CallApiPlugin[];
|
|
513
|
-
type DefaultThrowOnError = boolean;
|
|
514
|
-
//#endregion
|
|
515
|
-
//#region src/result.d.ts
|
|
516
|
-
type Parser<TData> = (responseString: string) => Awaitable<TData>;
|
|
517
|
-
declare const getResponseType: <TResponse>(response: Response, parser: Parser<TResponse>) => {
|
|
518
|
-
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
519
|
-
blob: () => Promise<Blob>;
|
|
520
|
-
formData: () => Promise<FormData>;
|
|
521
|
-
json: () => Promise<TResponse>;
|
|
522
|
-
stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
|
|
523
|
-
text: () => Promise<string>;
|
|
524
|
-
};
|
|
525
|
-
type InitResponseTypeMap<TResponse$1 = unknown> = ReturnType<typeof getResponseType<TResponse$1>>;
|
|
526
|
-
type ResponseTypeUnion = keyof InitResponseTypeMap | null;
|
|
527
|
-
type ResponseTypeMap<TResponse$1> = { [Key in keyof InitResponseTypeMap<TResponse$1>]: Awaited<ReturnType<InitResponseTypeMap<TResponse$1>[Key]>> };
|
|
528
|
-
type GetResponseType<TResponse$1, TResponseType extends ResponseTypeUnion, TComputedResponseTypeMap extends ResponseTypeMap<TResponse$1> = ResponseTypeMap<TResponse$1>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeUnion> ? TComputedResponseTypeMap[TResponseType] : never;
|
|
529
|
-
type CallApiResultSuccessVariant<TData> = {
|
|
530
|
-
data: NoInfer<TData>;
|
|
531
|
-
error: null;
|
|
532
|
-
response: Response;
|
|
533
|
-
};
|
|
534
|
-
type PossibleJavaScriptError = UnmaskType<{
|
|
535
|
-
errorData: false;
|
|
536
|
-
message: string;
|
|
537
|
-
name: "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | AnyString;
|
|
538
|
-
originalError: DOMException | Error | SyntaxError | TypeError;
|
|
539
|
-
}>;
|
|
540
|
-
type PossibleHTTPError<TErrorData> = UnmaskType<{
|
|
541
|
-
errorData: NoInfer<TErrorData>;
|
|
542
|
-
message: string;
|
|
543
|
-
name: "HTTPError";
|
|
544
|
-
originalError: HTTPError;
|
|
545
|
-
}>;
|
|
546
|
-
type PossibleValidationError = UnmaskType<{
|
|
547
|
-
errorData: ValidationError["errorData"];
|
|
548
|
-
issueCause: ValidationError["issueCause"];
|
|
549
|
-
message: string;
|
|
550
|
-
name: "ValidationError";
|
|
551
|
-
originalError: ValidationError;
|
|
552
|
-
}>;
|
|
553
|
-
type PossibleJavaScriptOrValidationError = UnmaskType<PossibleJavaScriptError | PossibleValidationError>;
|
|
554
|
-
type CallApiResultErrorVariant<TErrorData> = {
|
|
555
|
-
data: null;
|
|
556
|
-
error: PossibleHTTPError<TErrorData>;
|
|
557
|
-
response: Response;
|
|
558
|
-
} | {
|
|
559
|
-
data: null;
|
|
560
|
-
error: PossibleJavaScriptOrValidationError;
|
|
561
|
-
response: Response | null;
|
|
562
|
-
};
|
|
563
|
-
type CallApiSuccessOrErrorVariant<TData, TError> = CallApiResultErrorVariant<TError> | CallApiResultSuccessVariant<TData>;
|
|
564
|
-
type ResultModeMapWithoutException<TData, TErrorData, TResponseType extends ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedErrorData = GetResponseType<TErrorData, TResponseType>, TComputedResult extends CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData> = CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData>> = UnmaskType<{
|
|
565
|
-
all: TComputedResult;
|
|
566
|
-
onlyData: TComputedResult["data"];
|
|
567
|
-
onlyResponse: TComputedResult["response"];
|
|
568
|
-
}>;
|
|
569
|
-
type ResultModeMapWithException<TData, TResponseType extends ResponseTypeUnion, TComputedData = GetResponseType<TData, TResponseType>, TComputedResult extends CallApiResultSuccessVariant<TComputedData> = CallApiResultSuccessVariant<TComputedData>> = {
|
|
570
|
-
all: TComputedResult;
|
|
571
|
-
onlyData: TComputedResult["data"];
|
|
572
|
-
onlyResponse: TComputedResult["response"];
|
|
573
|
-
};
|
|
574
|
-
type ResultModeMap<TData = DefaultDataType, TErrorData = DefaultDataType, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError> = TThrowOnError extends true ? ResultModeMapWithException<TData, TResponseType> : ResultModeMapWithoutException<TData, TErrorData, TResponseType>;
|
|
575
|
-
type ResultModePlaceholder = null;
|
|
576
|
-
type ResultModeUnion = keyof ResultModeMap | ResultModePlaceholder;
|
|
583
|
+
//#region src/utils/external/define.d.ts
|
|
584
|
+
|
|
577
585
|
//#endregion
|
|
578
586
|
//#region src/stream.d.ts
|
|
579
587
|
type StreamProgressEvent = {
|
|
@@ -605,7 +613,7 @@ type PluginExtraOptions<TPluginOptions = unknown> = {
|
|
|
605
613
|
/** Plugin-specific options passed to the plugin configuration */
|
|
606
614
|
options: Partial<TPluginOptions>;
|
|
607
615
|
};
|
|
608
|
-
interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOptions = unknown> {
|
|
616
|
+
interface Hooks<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TPluginOptions = unknown> {
|
|
609
617
|
/**
|
|
610
618
|
* Hook called when any error occurs within the request/response lifecycle.
|
|
611
619
|
*
|
|
@@ -616,7 +624,7 @@ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOp
|
|
|
616
624
|
* @param context - Error context containing error details, request info, and response (if available)
|
|
617
625
|
* @returns Promise or void - Hook can be async or sync
|
|
618
626
|
*/
|
|
619
|
-
onError?: (context: ErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
627
|
+
onError?: (context: ErrorContext<TErrorData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
620
628
|
/**
|
|
621
629
|
* Hook called before the HTTP request is sent and before any internal processing of the request object begins.
|
|
622
630
|
*
|
|
@@ -668,7 +676,7 @@ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOp
|
|
|
668
676
|
* @returns Promise or void - Hook can be async or sync
|
|
669
677
|
*
|
|
670
678
|
*/
|
|
671
|
-
onResponse?: (context: ResponseContext<TData, TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
679
|
+
onResponse?: (context: ResponseContext<TData$1, TErrorData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
672
680
|
/**
|
|
673
681
|
* Hook called when an HTTP error response (4xx, 5xx) is received from the API.
|
|
674
682
|
*
|
|
@@ -679,7 +687,7 @@ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOp
|
|
|
679
687
|
* @param context - Response error context with HTTP error details and response
|
|
680
688
|
* @returns Promise or void - Hook can be async or sync
|
|
681
689
|
*/
|
|
682
|
-
onResponseError?: (context: ResponseErrorContext<TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
690
|
+
onResponseError?: (context: ResponseErrorContext<TErrorData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
683
691
|
/**
|
|
684
692
|
* Hook called during download stream progress tracking.
|
|
685
693
|
*
|
|
@@ -703,7 +711,7 @@ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOp
|
|
|
703
711
|
* @returns Promise or void - Hook can be async or sync
|
|
704
712
|
*
|
|
705
713
|
*/
|
|
706
|
-
onRetry?: (response: RetryContext<TErrorData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
714
|
+
onRetry?: (response: RetryContext<TErrorData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
707
715
|
/**
|
|
708
716
|
* Hook called when a successful response (2xx status) is received from the API.
|
|
709
717
|
*
|
|
@@ -715,7 +723,7 @@ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOp
|
|
|
715
723
|
* @returns Promise or void - Hook can be async or sync
|
|
716
724
|
*
|
|
717
725
|
*/
|
|
718
|
-
onSuccess?: (context: SuccessContext<TData> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
726
|
+
onSuccess?: (context: SuccessContext<TData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
719
727
|
/**
|
|
720
728
|
* Hook called when a validation error occurs.
|
|
721
729
|
*
|
|
@@ -729,7 +737,7 @@ interface Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TPluginOp
|
|
|
729
737
|
*/
|
|
730
738
|
onValidationError?: (context: ValidationErrorContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
|
|
731
739
|
}
|
|
732
|
-
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]> };
|
|
740
|
+
type HooksOrHooksArray<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TMoreOptions = unknown> = { [Key in keyof Hooks<TData$1, TErrorData$1, TMoreOptions>]: Hooks<TData$1, TErrorData$1, TMoreOptions>[Key] | Array<Hooks<TData$1, TErrorData$1, TMoreOptions>[Key]> };
|
|
733
741
|
interface HookConfigOptions {
|
|
734
742
|
/**
|
|
735
743
|
* Controls the execution mode of all composed hooks (main + plugin hooks).
|
|
@@ -790,14 +798,14 @@ type RequestContext = {
|
|
|
790
798
|
* made by this client instance, such as baseURL, default headers, and
|
|
791
799
|
* global options.
|
|
792
800
|
*/
|
|
793
|
-
baseConfig:
|
|
801
|
+
baseConfig: Exclude<BaseCallApiConfig, AnyFunction$1>;
|
|
794
802
|
/**
|
|
795
803
|
* Instance-specific configuration object passed to the callApi instance.
|
|
796
804
|
*
|
|
797
805
|
* Contains configuration specific to this particular API call, which
|
|
798
806
|
* can override or extend the base configuration.
|
|
799
807
|
*/
|
|
800
|
-
config:
|
|
808
|
+
config: CallApiConfig;
|
|
801
809
|
/**
|
|
802
810
|
* Merged options combining base config, instance config, and default options.
|
|
803
811
|
*
|
|
@@ -820,14 +828,14 @@ type ValidationErrorContext = UnmaskType<RequestContext & {
|
|
|
820
828
|
/** HTTP response object if validation failed on response, null if on request */
|
|
821
829
|
response: Response | null;
|
|
822
830
|
}>;
|
|
823
|
-
type SuccessContext<TData> = UnmaskType<RequestContext & {
|
|
831
|
+
type SuccessContext<TData$1> = UnmaskType<RequestContext & {
|
|
824
832
|
/** Parsed response data with the expected success type */
|
|
825
|
-
data: TData;
|
|
833
|
+
data: TData$1;
|
|
826
834
|
/** HTTP response object for the successful request */
|
|
827
835
|
response: Response;
|
|
828
836
|
}>;
|
|
829
|
-
type ResponseContext<TData, TErrorData> = UnmaskType<RequestContext & (Prettify<CallApiResultSuccessVariant<TData>> | Prettify<Extract<CallApiResultErrorVariant<TErrorData>, {
|
|
830
|
-
error: PossibleHTTPError<TErrorData>;
|
|
837
|
+
type ResponseContext<TData$1, TErrorData$1> = UnmaskType<RequestContext & (Prettify<CallApiResultSuccessVariant<TData$1>> | Prettify<Extract<CallApiResultErrorVariant<TErrorData$1>, {
|
|
838
|
+
error: PossibleHTTPError<TErrorData$1>;
|
|
831
839
|
}>>)>;
|
|
832
840
|
type RequestErrorContext = RequestContext & {
|
|
833
841
|
/** Error that occurred during the request (network, timeout, etc.) */
|
|
@@ -835,9 +843,9 @@ type RequestErrorContext = RequestContext & {
|
|
|
835
843
|
/** Always null for request errors since no response was received */
|
|
836
844
|
response: null;
|
|
837
845
|
};
|
|
838
|
-
type ErrorContext<TErrorData> = UnmaskType<RequestContext & ({
|
|
846
|
+
type ErrorContext<TErrorData$1> = UnmaskType<RequestContext & ({
|
|
839
847
|
/** HTTP error with response data */
|
|
840
|
-
error: PossibleHTTPError<TErrorData>;
|
|
848
|
+
error: PossibleHTTPError<TErrorData$1>;
|
|
841
849
|
/** HTTP response object containing error status */
|
|
842
850
|
response: Response;
|
|
843
851
|
} | {
|
|
@@ -846,10 +854,10 @@ type ErrorContext<TErrorData> = UnmaskType<RequestContext & ({
|
|
|
846
854
|
/** Response object if available, null for request errors */
|
|
847
855
|
response: Response | null;
|
|
848
856
|
})>;
|
|
849
|
-
type ResponseErrorContext<TErrorData> = UnmaskType<Extract<ErrorContext<TErrorData>, {
|
|
850
|
-
error: PossibleHTTPError<TErrorData>;
|
|
857
|
+
type ResponseErrorContext<TErrorData$1> = UnmaskType<Extract<ErrorContext<TErrorData$1>, {
|
|
858
|
+
error: PossibleHTTPError<TErrorData$1>;
|
|
851
859
|
}> & RequestContext>;
|
|
852
|
-
type RetryContext<TErrorData> = UnmaskType<ErrorContext<TErrorData> & {
|
|
860
|
+
type RetryContext<TErrorData$1> = UnmaskType<ErrorContext<TErrorData$1> & {
|
|
853
861
|
/** Current retry attempt number (1-based, so 1 = first retry) */
|
|
854
862
|
retryAttemptCount: number;
|
|
855
863
|
}>;
|
|
@@ -1094,10 +1102,10 @@ declare const defaultRetryStatusCodesLookup: () => Readonly<{
|
|
|
1094
1102
|
504: "Gateway Timeout";
|
|
1095
1103
|
}>;
|
|
1096
1104
|
type RetryStatusCodes = UnmaskType<AnyNumber | keyof ReturnType<typeof defaultRetryStatusCodesLookup>>;
|
|
1097
|
-
type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
|
|
1098
|
-
type RetryOptionKeys<TErrorData> = Exclude<keyof RetryOptions<TErrorData>, "~retryAttemptCount" | "retry">;
|
|
1099
|
-
type InnerRetryOptions<TErrorData> = { [Key in RetryOptionKeys<TErrorData> as RemovePrefix<"retry", Key>]?: RetryOptions<TErrorData>[Key] };
|
|
1100
|
-
interface RetryOptions<TErrorData> {
|
|
1105
|
+
type RetryCondition<TErrorData$1> = (context: ErrorContext<TErrorData$1>) => Awaitable<boolean>;
|
|
1106
|
+
type RetryOptionKeys<TErrorData$1> = Exclude<keyof RetryOptions<TErrorData$1>, "~retryAttemptCount" | "retry">;
|
|
1107
|
+
type InnerRetryOptions<TErrorData$1> = { [Key in RetryOptionKeys<TErrorData$1> as RemovePrefix<"retry", Key>]?: RetryOptions<TErrorData$1>[Key] };
|
|
1108
|
+
interface RetryOptions<TErrorData$1> {
|
|
1101
1109
|
/**
|
|
1102
1110
|
* Keeps track of the number of times the request has already been retried
|
|
1103
1111
|
* @internal
|
|
@@ -1107,7 +1115,7 @@ interface RetryOptions<TErrorData> {
|
|
|
1107
1115
|
/**
|
|
1108
1116
|
* All retry options in a single object instead of separate properties
|
|
1109
1117
|
*/
|
|
1110
|
-
retry?: InnerRetryOptions<TErrorData>;
|
|
1118
|
+
retry?: InnerRetryOptions<TErrorData$1>;
|
|
1111
1119
|
/**
|
|
1112
1120
|
* Number of allowed retry attempts on HTTP errors
|
|
1113
1121
|
* @default 0
|
|
@@ -1116,7 +1124,7 @@ interface RetryOptions<TErrorData> {
|
|
|
1116
1124
|
/**
|
|
1117
1125
|
* Callback whose return value determines if a request should be retried or not
|
|
1118
1126
|
*/
|
|
1119
|
-
retryCondition?: RetryCondition<TErrorData>;
|
|
1127
|
+
retryCondition?: RetryCondition<TErrorData$1>;
|
|
1120
1128
|
/**
|
|
1121
1129
|
* Delay between retries in milliseconds
|
|
1122
1130
|
* @default 1000
|
|
@@ -1147,34 +1155,112 @@ interface RetryOptions<TErrorData> {
|
|
|
1147
1155
|
/**
|
|
1148
1156
|
* @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
|
|
1149
1157
|
*/
|
|
1150
|
-
|
|
1151
|
-
type
|
|
1158
|
+
type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaInputResult<TSchemaOption, undefined> ? TObject : Required<TObject>;
|
|
1159
|
+
type ApplyURLBasedConfig<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig$1["prefix"] extends string ? `${TSchemaConfig$1["prefix"]}${TSchemaRouteKeys}` : TSchemaConfig$1["baseURL"] extends string ? `${TSchemaConfig$1["baseURL"]}${TSchemaRouteKeys}` : TSchemaRouteKeys;
|
|
1160
|
+
type ApplyStrictConfig<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig$1["strict"] extends true ? TSchemaRouteKeys :
|
|
1161
|
+
// eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
|
|
1162
|
+
TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
|
|
1163
|
+
type ApplySchemaConfiguration<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig$1, ApplyURLBasedConfig<TSchemaConfig$1, TSchemaRouteKeys>>;
|
|
1164
|
+
type InferAllRouteKeys<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TSchemaConfig$1 extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig$1, Exclude<Extract<keyof TBaseSchemaRoutes$1, string>, FallBackRouteSchemaKey>>;
|
|
1165
|
+
type InferInitURL<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TSchemaConfig$1 extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes$1 extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes$1, TSchemaConfig$1>;
|
|
1166
|
+
type GetCurrentRouteSchema<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes$1[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes$1[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
|
|
1152
1167
|
type JsonPrimitive = boolean | number | string | null | undefined;
|
|
1153
1168
|
type SerializableObject = Record<keyof object, unknown>;
|
|
1154
|
-
type SerializableArray = Array<JsonPrimitive |
|
|
1169
|
+
type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
|
|
1155
1170
|
type Body = UnmaskType<RequestInit["body"] | SerializableArray | SerializableObject>;
|
|
1171
|
+
type InferBodyOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["body"], {
|
|
1172
|
+
/**
|
|
1173
|
+
* Body of the request, can be a object or any other supported body type.
|
|
1174
|
+
*/
|
|
1175
|
+
body?: InferSchemaInputResult<TSchema$1["body"], Body>;
|
|
1176
|
+
}>;
|
|
1156
1177
|
type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
|
|
1178
|
+
type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
|
|
1179
|
+
type InferMethodOption<TSchema$1 extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema$1["method"], {
|
|
1180
|
+
/**
|
|
1181
|
+
* HTTP method for the request.
|
|
1182
|
+
* @default "GET"
|
|
1183
|
+
*/
|
|
1184
|
+
method?: InferSchemaInputResult<TSchema$1["method"], InferMethodFromURL<TInitURL>>;
|
|
1185
|
+
}>;
|
|
1157
1186
|
type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
|
|
1187
|
+
type InferHeadersOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["headers"], {
|
|
1188
|
+
/**
|
|
1189
|
+
* Headers to be used in the request.
|
|
1190
|
+
*/
|
|
1191
|
+
headers?: InferSchemaInputResult<TSchema$1["headers"], HeadersOption> | ((context: {
|
|
1192
|
+
baseHeaders: NonNullable<HeadersOption>;
|
|
1193
|
+
}) => InferSchemaInputResult<TSchema$1["headers"], HeadersOption>);
|
|
1194
|
+
}>;
|
|
1195
|
+
type InferRequestOptions<TSchema$1 extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema$1> & InferHeadersOption<TSchema$1> & InferMethodOption<TSchema$1, TInitURL>;
|
|
1158
1196
|
interface Register {}
|
|
1159
1197
|
type GlobalMeta = Register extends {
|
|
1160
1198
|
meta?: infer TMeta extends Record<string, unknown>;
|
|
1161
1199
|
} ? TMeta : never;
|
|
1200
|
+
type InferMetaOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
|
|
1201
|
+
/**
|
|
1202
|
+
* - An optional field you can fill with additional information,
|
|
1203
|
+
* to associate with the request, typically used for logging or tracing.
|
|
1204
|
+
*
|
|
1205
|
+
* - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
|
|
1206
|
+
*
|
|
1207
|
+
* @example
|
|
1208
|
+
* ```ts
|
|
1209
|
+
* const callMainApi = callApi.create({
|
|
1210
|
+
* baseURL: "https://main-api.com",
|
|
1211
|
+
* onResponseError: ({ response, options }) => {
|
|
1212
|
+
* if (options.meta?.userId) {
|
|
1213
|
+
* console.error(`User ${options.meta.userId} made an error`);
|
|
1214
|
+
* }
|
|
1215
|
+
* },
|
|
1216
|
+
* });
|
|
1217
|
+
*
|
|
1218
|
+
* const response = await callMainApi({
|
|
1219
|
+
* url: "https://example.com/api/data",
|
|
1220
|
+
* meta: { userId: "123" },
|
|
1221
|
+
* });
|
|
1222
|
+
* ```
|
|
1223
|
+
*/
|
|
1224
|
+
meta?: InferSchemaInputResult<TSchema$1["meta"], GlobalMeta>;
|
|
1225
|
+
}>;
|
|
1226
|
+
type InferQueryOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["query"], {
|
|
1227
|
+
/**
|
|
1228
|
+
* Parameters to be appended to the URL (i.e: /:id)
|
|
1229
|
+
*/
|
|
1230
|
+
query?: InferSchemaInputResult<TSchema$1["query"], Query>;
|
|
1231
|
+
}>;
|
|
1232
|
+
type EmptyString = "";
|
|
1233
|
+
type EmptyTuple = readonly [];
|
|
1234
|
+
type StringTuple = readonly string[];
|
|
1235
|
+
type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
|
|
1236
|
+
type ExtractRouteParamNames<TCurrentRoute$1, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute$1 extends PossibleParamNamePatterns ? TCurrentRoute$1 extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute$1 extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
|
|
1237
|
+
type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
|
|
1238
|
+
type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
|
|
1239
|
+
type InferParamsFromRoute<TCurrentRoute$1> = ExtractRouteParamNames<TCurrentRoute$1> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute$1> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute$1>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute$1>> : Params;
|
|
1240
|
+
type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> ? undefined extends InferSchemaInputResult<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
|
|
1241
|
+
type InferParamsOption<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema$1["params"], TBaseSchemaRoutes$1, TCurrentRouteSchemaKey, {
|
|
1242
|
+
/**
|
|
1243
|
+
* Parameters to be appended to the URL (i.e: /:id)
|
|
1244
|
+
*/
|
|
1245
|
+
params?: InferSchemaInputResult<TSchema$1["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
|
|
1246
|
+
}>;
|
|
1247
|
+
type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = InferMetaOption<TSchema$1> & InferParamsOption<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferQueryOption<TSchema$1>;
|
|
1162
1248
|
type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction$1<infer TReturnedSchema> ? InferSchemaOutputResult<TReturnedSchema> : never : never : never>;
|
|
1163
|
-
type ResultModeOption<TErrorData, TResultMode extends ResultModeUnion> = TErrorData extends false ? {
|
|
1249
|
+
type ResultModeOption<TErrorData$1, TResultMode extends ResultModeUnion> = TErrorData$1 extends false ? {
|
|
1164
1250
|
resultMode: "onlyData";
|
|
1165
|
-
} : TErrorData extends false | undefined ? {
|
|
1251
|
+
} : TErrorData$1 extends false | undefined ? {
|
|
1166
1252
|
resultMode?: "onlyData";
|
|
1167
1253
|
} : {
|
|
1168
1254
|
resultMode?: TResultMode;
|
|
1169
1255
|
};
|
|
1170
1256
|
type ThrowOnErrorUnion = boolean;
|
|
1171
|
-
type ThrowOnErrorType<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<TErrorData>) => TThrowOnError);
|
|
1172
|
-
type ThrowOnErrorOption<TErrorData, TThrowOnError extends ThrowOnErrorUnion> = TErrorData extends false ? {
|
|
1257
|
+
type ThrowOnErrorType<TErrorData$1, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<TErrorData$1>) => TThrowOnError);
|
|
1258
|
+
type ThrowOnErrorOption<TErrorData$1, TThrowOnError extends ThrowOnErrorUnion> = TErrorData$1 extends false ? {
|
|
1173
1259
|
throwOnError: true;
|
|
1174
|
-
} : TErrorData extends false | undefined ? {
|
|
1260
|
+
} : TErrorData$1 extends false | undefined ? {
|
|
1175
1261
|
throwOnError?: true;
|
|
1176
1262
|
} : {
|
|
1177
|
-
throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
|
|
1263
|
+
throwOnError?: ThrowOnErrorType<TErrorData$1, TThrowOnError>;
|
|
1178
1264
|
};
|
|
1179
1265
|
//#endregion
|
|
1180
1266
|
//#region src/types/common.d.ts
|
|
@@ -1200,7 +1286,7 @@ type CallApiRequestOptions = Prettify<{
|
|
|
1200
1286
|
type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
|
|
1201
1287
|
headers: Record<string, string | undefined>;
|
|
1202
1288
|
};
|
|
1203
|
-
type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TData, TErrorData, Partial<InferPluginOptions<TPluginArray>>> & Middlewares & Partial<InferPluginOptions<TPluginArray>> & ResultModeOption<TErrorData, TResultMode> & RetryOptions<TErrorData> & ThrowOnErrorOption<TErrorData, TThrowOnError> & URLOptions & {
|
|
1289
|
+
type SharedExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TData$1, TErrorData$1, Partial<InferPluginOptions<TPluginArray>>> & Middlewares & Partial<InferPluginOptions<TPluginArray>> & ResultModeOption<TErrorData$1, TResultMode> & RetryOptions<TErrorData$1> & ThrowOnErrorOption<TErrorData$1, TThrowOnError> & URLOptions & {
|
|
1204
1290
|
/**
|
|
1205
1291
|
* Automatically add an Authorization header value.
|
|
1206
1292
|
*
|
|
@@ -1322,7 +1408,7 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
|
1322
1408
|
* }
|
|
1323
1409
|
* ```
|
|
1324
1410
|
*/
|
|
1325
|
-
defaultHTTPErrorMessage?: string | ((context: Pick<HTTPError<TErrorData>, "errorData" | "response">) => string);
|
|
1411
|
+
defaultHTTPErrorMessage?: string | ((context: Pick<HTTPError<TErrorData$1>, "errorData" | "response">) => string);
|
|
1326
1412
|
/**
|
|
1327
1413
|
* Forces calculation of total byte size from request/response body streams.
|
|
1328
1414
|
*
|
|
@@ -1413,7 +1499,7 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
|
1413
1499
|
*
|
|
1414
1500
|
* ```
|
|
1415
1501
|
*/
|
|
1416
|
-
responseParser?: (responseString: string) => Awaitable<TData>;
|
|
1502
|
+
responseParser?: (responseString: string) => Awaitable<TData$1>;
|
|
1417
1503
|
/**
|
|
1418
1504
|
* Expected response type, determines how the response body is parsed.
|
|
1419
1505
|
*
|
|
@@ -1548,7 +1634,7 @@ type SharedExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, T
|
|
|
1548
1634
|
* }
|
|
1549
1635
|
* ```
|
|
1550
1636
|
*/
|
|
1551
|
-
throwOnError?: ThrowOnErrorType<TErrorData, TThrowOnError>;
|
|
1637
|
+
throwOnError?: ThrowOnErrorType<TErrorData$1, TThrowOnError>;
|
|
1552
1638
|
/**
|
|
1553
1639
|
* Request timeout in milliseconds. Request will be aborted if it takes longer.
|
|
1554
1640
|
*
|
|
@@ -1674,9 +1760,9 @@ type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = Defau
|
|
|
1674
1760
|
*/
|
|
1675
1761
|
skipAutoMergeFor?: "all" | "options" | "request";
|
|
1676
1762
|
};
|
|
1677
|
-
type InferExtendSchemaContext<TBaseSchemaRoutes extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = {
|
|
1678
|
-
baseSchemaRoutes: TBaseSchemaRoutes;
|
|
1679
|
-
currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes, TCurrentRouteSchemaKey>;
|
|
1763
|
+
type InferExtendSchemaContext<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = {
|
|
1764
|
+
baseSchemaRoutes: TBaseSchemaRoutes$1;
|
|
1765
|
+
currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey>;
|
|
1680
1766
|
};
|
|
1681
1767
|
type InferExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfig> = {
|
|
1682
1768
|
baseSchemaConfig: TBaseSchemaConfig;
|
|
@@ -1684,7 +1770,7 @@ type InferExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfi
|
|
|
1684
1770
|
type InferExtendPluginContext<TBasePluginArray extends CallApiPlugin[]> = {
|
|
1685
1771
|
basePlugins: TBasePluginArray;
|
|
1686
1772
|
};
|
|
1687
|
-
type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string, TComputedPluginContext = InferExtendPluginContext<TBasePluginArray>, TComputedSchemaContext = InferExtendSchemaContext<TBaseSchemaRoutes, TCurrentRouteSchemaKey>, TComputedSchemaConfigContext = InferExtendSchemaConfigContext<TBaseSchemaConfig>> = SharedExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1773
|
+
type CallApiExtraOptions<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string, TComputedPluginContext = InferExtendPluginContext<TBasePluginArray>, TComputedSchemaContext = InferExtendSchemaContext<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey>, TComputedSchemaConfigContext = InferExtendSchemaConfigContext<TBaseSchemaConfig>> = SharedExtraOptions<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
|
|
1688
1774
|
/**
|
|
1689
1775
|
* Array of instance-specific CallApi plugins or a function to configure plugins.
|
|
1690
1776
|
*
|
|
@@ -1710,9 +1796,16 @@ type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType,
|
|
|
1710
1796
|
* Can override base schema configuration or extend it with instance-specific validation rules.
|
|
1711
1797
|
*
|
|
1712
1798
|
*/
|
|
1713
|
-
schemaConfig?: TSchemaConfig | ((context: TComputedSchemaConfigContext) => TSchemaConfig);
|
|
1799
|
+
schemaConfig?: TSchemaConfig$1 | ((context: TComputedSchemaConfigContext) => TSchemaConfig$1);
|
|
1714
1800
|
};
|
|
1715
1801
|
type CallApiExtraOptionsForHooks = Hooks & Omit<CallApiExtraOptions, keyof Hooks>;
|
|
1802
|
+
type BaseInstanceContext = {
|
|
1803
|
+
initURL: string;
|
|
1804
|
+
options: CallApiExtraOptions;
|
|
1805
|
+
request: CallApiRequestOptions;
|
|
1806
|
+
};
|
|
1807
|
+
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, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: BaseInstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
|
|
1808
|
+
type CallApiConfig<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferRequestOptions<TSchema$1, TInitURL> & Omit<CallApiExtraOptions<TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
|
|
1716
1809
|
//#endregion
|
|
1717
1810
|
//#region src/logger/logger.d.ts
|
|
1718
1811
|
type ConsoleLikeObject = {
|
|
@@ -1762,7 +1855,7 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
|
|
|
1762
1855
|
errorData: never;
|
|
1763
1856
|
message: string;
|
|
1764
1857
|
name: "HTTPError";
|
|
1765
|
-
originalError: HTTPError;
|
|
1858
|
+
originalError: _zayne_labs_callapi_utils0.HTTPError;
|
|
1766
1859
|
};
|
|
1767
1860
|
response: Response;
|
|
1768
1861
|
} & PluginExtraOptions<unknown>) => void;
|
|
@@ -1774,7 +1867,7 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
|
|
|
1774
1867
|
errorData: never;
|
|
1775
1868
|
message: string;
|
|
1776
1869
|
name: "HTTPError";
|
|
1777
|
-
originalError: HTTPError;
|
|
1870
|
+
originalError: _zayne_labs_callapi_utils0.HTTPError;
|
|
1778
1871
|
};
|
|
1779
1872
|
response: Response;
|
|
1780
1873
|
})) & {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zayne-labs/callapi-plugins",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.11",
|
|
5
5
|
"description": "A collection of plugins for callapi",
|
|
6
6
|
"author": "Ryan Zayne",
|
|
7
7
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@zayne-labs/toolkit-type-helpers": ">=0.11.17",
|
|
23
23
|
"consola": "3.x.x",
|
|
24
|
-
"@zayne-labs/callapi": "1.11.
|
|
24
|
+
"@zayne-labs/callapi": "1.11.11"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@arethetypeswrong/cli": "0.18.2",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"tsdown": "^0.15.9",
|
|
39
39
|
"typescript": "5.9.3",
|
|
40
40
|
"vitest": "^4.0.1",
|
|
41
|
-
"@zayne-labs/callapi": "1.11.
|
|
41
|
+
"@zayne-labs/callapi": "1.11.11"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public",
|