@igniter-js/caller 0.1.1 → 0.1.2
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/index.d.mts +64 -15
- package/dist/index.d.ts +64 -15
- package/dist/index.js +24 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -291,7 +291,7 @@ interface IgniterCallerStoreOptions {
|
|
|
291
291
|
fallbackToFetch?: boolean;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap =
|
|
294
|
+
type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = {
|
|
295
295
|
baseURL?: string;
|
|
296
296
|
headers?: Record<string, string>;
|
|
297
297
|
cookies?: Record<string, string>;
|
|
@@ -303,7 +303,16 @@ type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap = any> =
|
|
|
303
303
|
schemas?: TSchemas;
|
|
304
304
|
schemaValidation?: IgniterCallerSchemaValidationOptions;
|
|
305
305
|
};
|
|
306
|
-
type IgniterCallerBuilderFactory<TCaller, TSchemas extends IgniterCallerSchemaMap =
|
|
306
|
+
type IgniterCallerBuilderFactory<TCaller, TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = (state: IgniterCallerBuilderState<TSchemas>) => TCaller;
|
|
307
|
+
/**
|
|
308
|
+
* Utility type to replace the schema type in a caller.
|
|
309
|
+
* Used by withSchemas to properly type the returned caller.
|
|
310
|
+
*/
|
|
311
|
+
type ReplaceCallerSchema<TCaller, TNewSchemas extends IgniterCallerSchemaMap> = TCaller extends {
|
|
312
|
+
schemas?: infer _;
|
|
313
|
+
} ? Omit<TCaller, 'schemas'> & {
|
|
314
|
+
schemas?: TNewSchemas;
|
|
315
|
+
} : TCaller;
|
|
307
316
|
/**
|
|
308
317
|
* Builder used by developers to initialize the `IgniterCaller` client.
|
|
309
318
|
*
|
|
@@ -509,6 +518,14 @@ declare class IgniterCallerRequestBuilder<TResponse = unknown> {
|
|
|
509
518
|
* Used when creating requests via specific HTTP methods (get, post, etc.)
|
|
510
519
|
*/
|
|
511
520
|
type IgniterCallerMethodRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, '_setMethod' | '_setUrl'>;
|
|
521
|
+
/**
|
|
522
|
+
* Request builder with typed response based on schema inference.
|
|
523
|
+
* Used when creating requests via HTTP methods with URL that matches a schema.
|
|
524
|
+
*
|
|
525
|
+
* This type ensures that the execute() method returns the correct response type
|
|
526
|
+
* based on the schema map configuration.
|
|
527
|
+
*/
|
|
528
|
+
type IgniterCallerTypedRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, '_setMethod' | '_setUrl'>;
|
|
512
529
|
|
|
513
530
|
/**
|
|
514
531
|
* Callback function for event listeners.
|
|
@@ -523,13 +540,28 @@ type IgniterCallerEventCallback<T = any> = (result: IgniterCallerApiResponse<T>,
|
|
|
523
540
|
*/
|
|
524
541
|
type IgniterCallerUrlPattern = string | RegExp;
|
|
525
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Infer success response type from endpoint schema (200 or 201).
|
|
545
|
+
*/
|
|
546
|
+
type InferSuccessResponse<T> = T extends IgniterCallerEndpointSchema<any, infer R> ? 200 extends keyof R ? R[200] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<R[200]> : unknown : 201 extends keyof R ? R[201] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<R[201]> : unknown : unknown : unknown;
|
|
547
|
+
/**
|
|
548
|
+
* Get the endpoint schema for a path and method from a schema map.
|
|
549
|
+
*/
|
|
550
|
+
type GetEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = TPath extends keyof TSchemas ? TMethod extends keyof TSchemas[TPath] ? TSchemas[TPath][TMethod] : undefined : undefined;
|
|
551
|
+
/**
|
|
552
|
+
* Infer the response type for a given path and method.
|
|
553
|
+
* Returns `unknown` if the path/method is not in the schema.
|
|
554
|
+
*/
|
|
555
|
+
type InferResponse<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = InferSuccessResponse<GetEndpoint<TSchemas, TPath, TMethod>>;
|
|
526
556
|
/**
|
|
527
557
|
* HTTP client runtime for Igniter.js.
|
|
528
558
|
*
|
|
529
559
|
* This module is intentionally structured to be extracted into a standalone package
|
|
530
560
|
* in the Igniter.js ecosystem as `@igniter-js/caller`.
|
|
561
|
+
*
|
|
562
|
+
* @template TSchemas - The schema map type for type-safe requests/responses.
|
|
531
563
|
*/
|
|
532
|
-
declare class IgniterCaller {
|
|
564
|
+
declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
|
|
533
565
|
/** Global event emitter for observing HTTP responses */
|
|
534
566
|
private static readonly events;
|
|
535
567
|
private baseURL?;
|
|
@@ -546,7 +578,7 @@ declare class IgniterCaller {
|
|
|
546
578
|
logger?: IgniterLogger;
|
|
547
579
|
requestInterceptors?: IgniterCallerRequestInterceptor[];
|
|
548
580
|
responseInterceptors?: IgniterCallerResponseInterceptor[];
|
|
549
|
-
schemas?:
|
|
581
|
+
schemas?: TSchemas;
|
|
550
582
|
schemaValidation?: IgniterCallerSchemaValidationOptions;
|
|
551
583
|
});
|
|
552
584
|
/**
|
|
@@ -554,11 +586,11 @@ declare class IgniterCaller {
|
|
|
554
586
|
*
|
|
555
587
|
* This is designed to remain stable when extracted to `@igniter-js/caller`.
|
|
556
588
|
*/
|
|
557
|
-
static create(): IgniterCallerBuilder<IgniterCaller>;
|
|
589
|
+
static create<TInitSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap>(): IgniterCallerBuilder<IgniterCaller<TInitSchemas>, TInitSchemas>;
|
|
558
590
|
/**
|
|
559
591
|
* Returns a new client with the same config and a new logger.
|
|
560
592
|
*/
|
|
561
|
-
withLogger(logger: IgniterLogger): IgniterCaller
|
|
593
|
+
withLogger(logger: IgniterLogger): IgniterCaller<TSchemas>;
|
|
562
594
|
setBaseURL(baseURL: string): this;
|
|
563
595
|
setHeaders(headers: Record<string, string>): this;
|
|
564
596
|
setCookies(cookies: Record<string, string>): this;
|
|
@@ -566,24 +598,33 @@ declare class IgniterCaller {
|
|
|
566
598
|
* Creates common request builder params.
|
|
567
599
|
*/
|
|
568
600
|
private createBuilderParams;
|
|
601
|
+
/**
|
|
602
|
+
* Resolves the full URL path by prepending baseURL if needed.
|
|
603
|
+
*/
|
|
604
|
+
private resolveSchemaPath;
|
|
569
605
|
/**
|
|
570
606
|
* Creates a GET request.
|
|
571
607
|
*
|
|
608
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
609
|
+
*
|
|
572
610
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
573
611
|
*
|
|
574
612
|
* @example
|
|
575
613
|
* ```ts
|
|
576
|
-
* // With
|
|
614
|
+
* // With typed schema - response type is inferred
|
|
577
615
|
* const result = await api.get('/users').execute()
|
|
616
|
+
* // result.data is typed based on schema
|
|
578
617
|
*
|
|
579
|
-
* //
|
|
618
|
+
* // Without schema or URL set later
|
|
580
619
|
* const result = await api.get().url('/users').execute()
|
|
581
620
|
* ```
|
|
582
621
|
*/
|
|
583
|
-
get(url?:
|
|
622
|
+
get<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'GET'>>;
|
|
584
623
|
/**
|
|
585
624
|
* Creates a POST request.
|
|
586
625
|
*
|
|
626
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
627
|
+
*
|
|
587
628
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
588
629
|
*
|
|
589
630
|
* @example
|
|
@@ -591,10 +632,12 @@ declare class IgniterCaller {
|
|
|
591
632
|
* const result = await api.post('/users').body({ name: 'John' }).execute()
|
|
592
633
|
* ```
|
|
593
634
|
*/
|
|
594
|
-
post(url?:
|
|
635
|
+
post<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'POST'>>;
|
|
595
636
|
/**
|
|
596
637
|
* Creates a PUT request.
|
|
597
638
|
*
|
|
639
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
640
|
+
*
|
|
598
641
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
599
642
|
*
|
|
600
643
|
* @example
|
|
@@ -602,10 +645,12 @@ declare class IgniterCaller {
|
|
|
602
645
|
* const result = await api.put('/users/1').body({ name: 'Jane' }).execute()
|
|
603
646
|
* ```
|
|
604
647
|
*/
|
|
605
|
-
put(url?:
|
|
648
|
+
put<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PUT'>>;
|
|
606
649
|
/**
|
|
607
650
|
* Creates a PATCH request.
|
|
608
651
|
*
|
|
652
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
653
|
+
*
|
|
609
654
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
610
655
|
*
|
|
611
656
|
* @example
|
|
@@ -613,10 +658,12 @@ declare class IgniterCaller {
|
|
|
613
658
|
* const result = await api.patch('/users/1').body({ name: 'Jane' }).execute()
|
|
614
659
|
* ```
|
|
615
660
|
*/
|
|
616
|
-
patch(url?:
|
|
661
|
+
patch<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PATCH'>>;
|
|
617
662
|
/**
|
|
618
663
|
* Creates a DELETE request.
|
|
619
664
|
*
|
|
665
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
666
|
+
*
|
|
620
667
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
621
668
|
*
|
|
622
669
|
* @example
|
|
@@ -624,13 +671,15 @@ declare class IgniterCaller {
|
|
|
624
671
|
* const result = await api.delete('/users/1').execute()
|
|
625
672
|
* ```
|
|
626
673
|
*/
|
|
627
|
-
delete(url?:
|
|
674
|
+
delete<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'DELETE'>>;
|
|
628
675
|
/**
|
|
629
676
|
* Creates a HEAD request.
|
|
630
677
|
*
|
|
678
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
679
|
+
*
|
|
631
680
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
632
681
|
*/
|
|
633
|
-
head(url?:
|
|
682
|
+
head<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'HEAD'>>;
|
|
634
683
|
/**
|
|
635
684
|
* Executes a request directly with all options in one object (axios-style).
|
|
636
685
|
*
|
|
@@ -972,4 +1021,4 @@ declare class IgniterCallerUrlUtils {
|
|
|
972
1021
|
}): string;
|
|
973
1022
|
}
|
|
974
1023
|
|
|
975
|
-
export { type ExtractPathParams, IgniterCaller, type IgniterCallerApiResponse, type IgniterCallerBaseRequestOptions, IgniterCallerBodyUtils, IgniterCallerBuilder, type IgniterCallerBuilderFactory, type IgniterCallerBuilderState, IgniterCallerCacheUtils, type IgniterCallerDirectRequestOptions, type IgniterCallerEndpointSchema, IgniterCallerError, type IgniterCallerErrorCode, type IgniterCallerErrorPayload, type IgniterCallerEventCallback, IgniterCallerEvents, type IgniterCallerFileResponse, type IgniterCallerHttpMethod, type IgniterCallerMethodRequestBuilder, IgniterCallerMock, type IgniterCallerOperation, IgniterCallerRequestBuilder, type IgniterCallerRequestBuilderParams, type IgniterCallerRequestInterceptor, type IgniterCallerRequestOptions, type IgniterCallerResponseContentType, type IgniterCallerResponseInterceptor, type IgniterCallerResponseMarker, type IgniterCallerRetryOptions, type IgniterCallerSchemaMap, type IgniterCallerSchemaMethod, IgniterCallerSchemaUtils, type IgniterCallerSchemaValidationOptions, type IgniterCallerStoreAdapter, type IgniterCallerStoreOptions, type IgniterCallerUrlPattern, IgniterCallerUrlUtils, type IgniterCallerValidatableContentType, type InferAllResponseTypes, type InferRequestType, type InferResponseType, type InferSuccessResponseType, type SchemaMapEndpoint, type SchemaMapMethods, type SchemaMapPaths, type SchemaMapRequestType, type SchemaMapResponseType };
|
|
1024
|
+
export { type ExtractPathParams, IgniterCaller, type IgniterCallerApiResponse, type IgniterCallerBaseRequestOptions, IgniterCallerBodyUtils, IgniterCallerBuilder, type IgniterCallerBuilderFactory, type IgniterCallerBuilderState, IgniterCallerCacheUtils, type IgniterCallerDirectRequestOptions, type IgniterCallerEndpointSchema, IgniterCallerError, type IgniterCallerErrorCode, type IgniterCallerErrorPayload, type IgniterCallerEventCallback, IgniterCallerEvents, type IgniterCallerFileResponse, type IgniterCallerHttpMethod, type IgniterCallerMethodRequestBuilder, IgniterCallerMock, type IgniterCallerOperation, IgniterCallerRequestBuilder, type IgniterCallerRequestBuilderParams, type IgniterCallerRequestInterceptor, type IgniterCallerRequestOptions, type IgniterCallerResponseContentType, type IgniterCallerResponseInterceptor, type IgniterCallerResponseMarker, type IgniterCallerRetryOptions, type IgniterCallerSchemaMap, type IgniterCallerSchemaMethod, IgniterCallerSchemaUtils, type IgniterCallerSchemaValidationOptions, type IgniterCallerStoreAdapter, type IgniterCallerStoreOptions, type IgniterCallerTypedRequestBuilder, type IgniterCallerUrlPattern, IgniterCallerUrlUtils, type IgniterCallerValidatableContentType, type InferAllResponseTypes, type InferRequestType, type InferResponseType, type InferSuccessResponseType, type ReplaceCallerSchema, type SchemaMapEndpoint, type SchemaMapMethods, type SchemaMapPaths, type SchemaMapRequestType, type SchemaMapResponseType };
|
package/dist/index.d.ts
CHANGED
|
@@ -291,7 +291,7 @@ interface IgniterCallerStoreOptions {
|
|
|
291
291
|
fallbackToFetch?: boolean;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap =
|
|
294
|
+
type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = {
|
|
295
295
|
baseURL?: string;
|
|
296
296
|
headers?: Record<string, string>;
|
|
297
297
|
cookies?: Record<string, string>;
|
|
@@ -303,7 +303,16 @@ type IgniterCallerBuilderState<TSchemas extends IgniterCallerSchemaMap = any> =
|
|
|
303
303
|
schemas?: TSchemas;
|
|
304
304
|
schemaValidation?: IgniterCallerSchemaValidationOptions;
|
|
305
305
|
};
|
|
306
|
-
type IgniterCallerBuilderFactory<TCaller, TSchemas extends IgniterCallerSchemaMap =
|
|
306
|
+
type IgniterCallerBuilderFactory<TCaller, TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> = (state: IgniterCallerBuilderState<TSchemas>) => TCaller;
|
|
307
|
+
/**
|
|
308
|
+
* Utility type to replace the schema type in a caller.
|
|
309
|
+
* Used by withSchemas to properly type the returned caller.
|
|
310
|
+
*/
|
|
311
|
+
type ReplaceCallerSchema<TCaller, TNewSchemas extends IgniterCallerSchemaMap> = TCaller extends {
|
|
312
|
+
schemas?: infer _;
|
|
313
|
+
} ? Omit<TCaller, 'schemas'> & {
|
|
314
|
+
schemas?: TNewSchemas;
|
|
315
|
+
} : TCaller;
|
|
307
316
|
/**
|
|
308
317
|
* Builder used by developers to initialize the `IgniterCaller` client.
|
|
309
318
|
*
|
|
@@ -509,6 +518,14 @@ declare class IgniterCallerRequestBuilder<TResponse = unknown> {
|
|
|
509
518
|
* Used when creating requests via specific HTTP methods (get, post, etc.)
|
|
510
519
|
*/
|
|
511
520
|
type IgniterCallerMethodRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, '_setMethod' | '_setUrl'>;
|
|
521
|
+
/**
|
|
522
|
+
* Request builder with typed response based on schema inference.
|
|
523
|
+
* Used when creating requests via HTTP methods with URL that matches a schema.
|
|
524
|
+
*
|
|
525
|
+
* This type ensures that the execute() method returns the correct response type
|
|
526
|
+
* based on the schema map configuration.
|
|
527
|
+
*/
|
|
528
|
+
type IgniterCallerTypedRequestBuilder<TResponse = unknown> = Omit<IgniterCallerRequestBuilder<TResponse>, '_setMethod' | '_setUrl'>;
|
|
512
529
|
|
|
513
530
|
/**
|
|
514
531
|
* Callback function for event listeners.
|
|
@@ -523,13 +540,28 @@ type IgniterCallerEventCallback<T = any> = (result: IgniterCallerApiResponse<T>,
|
|
|
523
540
|
*/
|
|
524
541
|
type IgniterCallerUrlPattern = string | RegExp;
|
|
525
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Infer success response type from endpoint schema (200 or 201).
|
|
545
|
+
*/
|
|
546
|
+
type InferSuccessResponse<T> = T extends IgniterCallerEndpointSchema<any, infer R> ? 200 extends keyof R ? R[200] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<R[200]> : unknown : 201 extends keyof R ? R[201] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<R[201]> : unknown : unknown : unknown;
|
|
547
|
+
/**
|
|
548
|
+
* Get the endpoint schema for a path and method from a schema map.
|
|
549
|
+
*/
|
|
550
|
+
type GetEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = TPath extends keyof TSchemas ? TMethod extends keyof TSchemas[TPath] ? TSchemas[TPath][TMethod] : undefined : undefined;
|
|
551
|
+
/**
|
|
552
|
+
* Infer the response type for a given path and method.
|
|
553
|
+
* Returns `unknown` if the path/method is not in the schema.
|
|
554
|
+
*/
|
|
555
|
+
type InferResponse<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = InferSuccessResponse<GetEndpoint<TSchemas, TPath, TMethod>>;
|
|
526
556
|
/**
|
|
527
557
|
* HTTP client runtime for Igniter.js.
|
|
528
558
|
*
|
|
529
559
|
* This module is intentionally structured to be extracted into a standalone package
|
|
530
560
|
* in the Igniter.js ecosystem as `@igniter-js/caller`.
|
|
561
|
+
*
|
|
562
|
+
* @template TSchemas - The schema map type for type-safe requests/responses.
|
|
531
563
|
*/
|
|
532
|
-
declare class IgniterCaller {
|
|
564
|
+
declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap> {
|
|
533
565
|
/** Global event emitter for observing HTTP responses */
|
|
534
566
|
private static readonly events;
|
|
535
567
|
private baseURL?;
|
|
@@ -546,7 +578,7 @@ declare class IgniterCaller {
|
|
|
546
578
|
logger?: IgniterLogger;
|
|
547
579
|
requestInterceptors?: IgniterCallerRequestInterceptor[];
|
|
548
580
|
responseInterceptors?: IgniterCallerResponseInterceptor[];
|
|
549
|
-
schemas?:
|
|
581
|
+
schemas?: TSchemas;
|
|
550
582
|
schemaValidation?: IgniterCallerSchemaValidationOptions;
|
|
551
583
|
});
|
|
552
584
|
/**
|
|
@@ -554,11 +586,11 @@ declare class IgniterCaller {
|
|
|
554
586
|
*
|
|
555
587
|
* This is designed to remain stable when extracted to `@igniter-js/caller`.
|
|
556
588
|
*/
|
|
557
|
-
static create(): IgniterCallerBuilder<IgniterCaller>;
|
|
589
|
+
static create<TInitSchemas extends IgniterCallerSchemaMap = IgniterCallerSchemaMap>(): IgniterCallerBuilder<IgniterCaller<TInitSchemas>, TInitSchemas>;
|
|
558
590
|
/**
|
|
559
591
|
* Returns a new client with the same config and a new logger.
|
|
560
592
|
*/
|
|
561
|
-
withLogger(logger: IgniterLogger): IgniterCaller
|
|
593
|
+
withLogger(logger: IgniterLogger): IgniterCaller<TSchemas>;
|
|
562
594
|
setBaseURL(baseURL: string): this;
|
|
563
595
|
setHeaders(headers: Record<string, string>): this;
|
|
564
596
|
setCookies(cookies: Record<string, string>): this;
|
|
@@ -566,24 +598,33 @@ declare class IgniterCaller {
|
|
|
566
598
|
* Creates common request builder params.
|
|
567
599
|
*/
|
|
568
600
|
private createBuilderParams;
|
|
601
|
+
/**
|
|
602
|
+
* Resolves the full URL path by prepending baseURL if needed.
|
|
603
|
+
*/
|
|
604
|
+
private resolveSchemaPath;
|
|
569
605
|
/**
|
|
570
606
|
* Creates a GET request.
|
|
571
607
|
*
|
|
608
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
609
|
+
*
|
|
572
610
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
573
611
|
*
|
|
574
612
|
* @example
|
|
575
613
|
* ```ts
|
|
576
|
-
* // With
|
|
614
|
+
* // With typed schema - response type is inferred
|
|
577
615
|
* const result = await api.get('/users').execute()
|
|
616
|
+
* // result.data is typed based on schema
|
|
578
617
|
*
|
|
579
|
-
* //
|
|
618
|
+
* // Without schema or URL set later
|
|
580
619
|
* const result = await api.get().url('/users').execute()
|
|
581
620
|
* ```
|
|
582
621
|
*/
|
|
583
|
-
get(url?:
|
|
622
|
+
get<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'GET'>>;
|
|
584
623
|
/**
|
|
585
624
|
* Creates a POST request.
|
|
586
625
|
*
|
|
626
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
627
|
+
*
|
|
587
628
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
588
629
|
*
|
|
589
630
|
* @example
|
|
@@ -591,10 +632,12 @@ declare class IgniterCaller {
|
|
|
591
632
|
* const result = await api.post('/users').body({ name: 'John' }).execute()
|
|
592
633
|
* ```
|
|
593
634
|
*/
|
|
594
|
-
post(url?:
|
|
635
|
+
post<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'POST'>>;
|
|
595
636
|
/**
|
|
596
637
|
* Creates a PUT request.
|
|
597
638
|
*
|
|
639
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
640
|
+
*
|
|
598
641
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
599
642
|
*
|
|
600
643
|
* @example
|
|
@@ -602,10 +645,12 @@ declare class IgniterCaller {
|
|
|
602
645
|
* const result = await api.put('/users/1').body({ name: 'Jane' }).execute()
|
|
603
646
|
* ```
|
|
604
647
|
*/
|
|
605
|
-
put(url?:
|
|
648
|
+
put<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PUT'>>;
|
|
606
649
|
/**
|
|
607
650
|
* Creates a PATCH request.
|
|
608
651
|
*
|
|
652
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
653
|
+
*
|
|
609
654
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
610
655
|
*
|
|
611
656
|
* @example
|
|
@@ -613,10 +658,12 @@ declare class IgniterCaller {
|
|
|
613
658
|
* const result = await api.patch('/users/1').body({ name: 'Jane' }).execute()
|
|
614
659
|
* ```
|
|
615
660
|
*/
|
|
616
|
-
patch(url?:
|
|
661
|
+
patch<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PATCH'>>;
|
|
617
662
|
/**
|
|
618
663
|
* Creates a DELETE request.
|
|
619
664
|
*
|
|
665
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
666
|
+
*
|
|
620
667
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
621
668
|
*
|
|
622
669
|
* @example
|
|
@@ -624,13 +671,15 @@ declare class IgniterCaller {
|
|
|
624
671
|
* const result = await api.delete('/users/1').execute()
|
|
625
672
|
* ```
|
|
626
673
|
*/
|
|
627
|
-
delete(url?:
|
|
674
|
+
delete<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'DELETE'>>;
|
|
628
675
|
/**
|
|
629
676
|
* Creates a HEAD request.
|
|
630
677
|
*
|
|
678
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
679
|
+
*
|
|
631
680
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
632
681
|
*/
|
|
633
|
-
head(url?:
|
|
682
|
+
head<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'HEAD'>>;
|
|
634
683
|
/**
|
|
635
684
|
* Executes a request directly with all options in one object (axios-style).
|
|
636
685
|
*
|
|
@@ -972,4 +1021,4 @@ declare class IgniterCallerUrlUtils {
|
|
|
972
1021
|
}): string;
|
|
973
1022
|
}
|
|
974
1023
|
|
|
975
|
-
export { type ExtractPathParams, IgniterCaller, type IgniterCallerApiResponse, type IgniterCallerBaseRequestOptions, IgniterCallerBodyUtils, IgniterCallerBuilder, type IgniterCallerBuilderFactory, type IgniterCallerBuilderState, IgniterCallerCacheUtils, type IgniterCallerDirectRequestOptions, type IgniterCallerEndpointSchema, IgniterCallerError, type IgniterCallerErrorCode, type IgniterCallerErrorPayload, type IgniterCallerEventCallback, IgniterCallerEvents, type IgniterCallerFileResponse, type IgniterCallerHttpMethod, type IgniterCallerMethodRequestBuilder, IgniterCallerMock, type IgniterCallerOperation, IgniterCallerRequestBuilder, type IgniterCallerRequestBuilderParams, type IgniterCallerRequestInterceptor, type IgniterCallerRequestOptions, type IgniterCallerResponseContentType, type IgniterCallerResponseInterceptor, type IgniterCallerResponseMarker, type IgniterCallerRetryOptions, type IgniterCallerSchemaMap, type IgniterCallerSchemaMethod, IgniterCallerSchemaUtils, type IgniterCallerSchemaValidationOptions, type IgniterCallerStoreAdapter, type IgniterCallerStoreOptions, type IgniterCallerUrlPattern, IgniterCallerUrlUtils, type IgniterCallerValidatableContentType, type InferAllResponseTypes, type InferRequestType, type InferResponseType, type InferSuccessResponseType, type SchemaMapEndpoint, type SchemaMapMethods, type SchemaMapPaths, type SchemaMapRequestType, type SchemaMapResponseType };
|
|
1024
|
+
export { type ExtractPathParams, IgniterCaller, type IgniterCallerApiResponse, type IgniterCallerBaseRequestOptions, IgniterCallerBodyUtils, IgniterCallerBuilder, type IgniterCallerBuilderFactory, type IgniterCallerBuilderState, IgniterCallerCacheUtils, type IgniterCallerDirectRequestOptions, type IgniterCallerEndpointSchema, IgniterCallerError, type IgniterCallerErrorCode, type IgniterCallerErrorPayload, type IgniterCallerEventCallback, IgniterCallerEvents, type IgniterCallerFileResponse, type IgniterCallerHttpMethod, type IgniterCallerMethodRequestBuilder, IgniterCallerMock, type IgniterCallerOperation, IgniterCallerRequestBuilder, type IgniterCallerRequestBuilderParams, type IgniterCallerRequestInterceptor, type IgniterCallerRequestOptions, type IgniterCallerResponseContentType, type IgniterCallerResponseInterceptor, type IgniterCallerResponseMarker, type IgniterCallerRetryOptions, type IgniterCallerSchemaMap, type IgniterCallerSchemaMethod, IgniterCallerSchemaUtils, type IgniterCallerSchemaValidationOptions, type IgniterCallerStoreAdapter, type IgniterCallerStoreOptions, type IgniterCallerTypedRequestBuilder, type IgniterCallerUrlPattern, IgniterCallerUrlUtils, type IgniterCallerValidatableContentType, type InferAllResponseTypes, type InferRequestType, type InferResponseType, type InferSuccessResponseType, type ReplaceCallerSchema, type SchemaMapEndpoint, type SchemaMapMethods, type SchemaMapPaths, type SchemaMapRequestType, type SchemaMapResponseType };
|
package/dist/index.js
CHANGED
|
@@ -1307,17 +1307,29 @@ var _IgniterCaller = class _IgniterCaller {
|
|
|
1307
1307
|
schemaValidation: this.schemaValidation
|
|
1308
1308
|
};
|
|
1309
1309
|
}
|
|
1310
|
+
/**
|
|
1311
|
+
* Resolves the full URL path by prepending baseURL if needed.
|
|
1312
|
+
*/
|
|
1313
|
+
resolveSchemaPath(url) {
|
|
1314
|
+
if (this.baseURL && !url.startsWith("http")) {
|
|
1315
|
+
return `${this.baseURL}${url}`;
|
|
1316
|
+
}
|
|
1317
|
+
return url;
|
|
1318
|
+
}
|
|
1310
1319
|
/**
|
|
1311
1320
|
* Creates a GET request.
|
|
1312
1321
|
*
|
|
1322
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1323
|
+
*
|
|
1313
1324
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1314
1325
|
*
|
|
1315
1326
|
* @example
|
|
1316
1327
|
* ```ts
|
|
1317
|
-
* // With
|
|
1328
|
+
* // With typed schema - response type is inferred
|
|
1318
1329
|
* const result = await api.get('/users').execute()
|
|
1330
|
+
* // result.data is typed based on schema
|
|
1319
1331
|
*
|
|
1320
|
-
* //
|
|
1332
|
+
* // Without schema or URL set later
|
|
1321
1333
|
* const result = await api.get().url('/users').execute()
|
|
1322
1334
|
* ```
|
|
1323
1335
|
*/
|
|
@@ -1330,6 +1342,8 @@ var _IgniterCaller = class _IgniterCaller {
|
|
|
1330
1342
|
/**
|
|
1331
1343
|
* Creates a POST request.
|
|
1332
1344
|
*
|
|
1345
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1346
|
+
*
|
|
1333
1347
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1334
1348
|
*
|
|
1335
1349
|
* @example
|
|
@@ -1346,6 +1360,8 @@ var _IgniterCaller = class _IgniterCaller {
|
|
|
1346
1360
|
/**
|
|
1347
1361
|
* Creates a PUT request.
|
|
1348
1362
|
*
|
|
1363
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1364
|
+
*
|
|
1349
1365
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1350
1366
|
*
|
|
1351
1367
|
* @example
|
|
@@ -1362,6 +1378,8 @@ var _IgniterCaller = class _IgniterCaller {
|
|
|
1362
1378
|
/**
|
|
1363
1379
|
* Creates a PATCH request.
|
|
1364
1380
|
*
|
|
1381
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1382
|
+
*
|
|
1365
1383
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1366
1384
|
*
|
|
1367
1385
|
* @example
|
|
@@ -1378,6 +1396,8 @@ var _IgniterCaller = class _IgniterCaller {
|
|
|
1378
1396
|
/**
|
|
1379
1397
|
* Creates a DELETE request.
|
|
1380
1398
|
*
|
|
1399
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1400
|
+
*
|
|
1381
1401
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1382
1402
|
*
|
|
1383
1403
|
* @example
|
|
@@ -1394,6 +1414,8 @@ var _IgniterCaller = class _IgniterCaller {
|
|
|
1394
1414
|
/**
|
|
1395
1415
|
* Creates a HEAD request.
|
|
1396
1416
|
*
|
|
1417
|
+
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1418
|
+
*
|
|
1397
1419
|
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1398
1420
|
*/
|
|
1399
1421
|
head(url) {
|