@igniter-js/caller 0.1.2 → 0.1.3
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 +109 -19
- package/dist/index.d.ts +109 -19
- package/dist/index.js +0 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +0 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -209,6 +209,36 @@ type SchemaMapPaths<TSchemas extends IgniterCallerSchemaMap> = keyof TSchemas &
|
|
|
209
209
|
* Get available methods for a specific path.
|
|
210
210
|
*/
|
|
211
211
|
type SchemaMapMethods<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas> = keyof TSchemas[TPath] & IgniterCallerSchemaMethod;
|
|
212
|
+
/**
|
|
213
|
+
* Get all paths that have a specific method defined.
|
|
214
|
+
*/
|
|
215
|
+
type PathsForMethod<TSchemas extends IgniterCallerSchemaMap, TMethod extends IgniterCallerSchemaMethod> = {
|
|
216
|
+
[K in keyof TSchemas]: TMethod extends keyof TSchemas[K] ? K : never;
|
|
217
|
+
}[keyof TSchemas] & string;
|
|
218
|
+
/**
|
|
219
|
+
* Get paths available for GET method.
|
|
220
|
+
*/
|
|
221
|
+
type GetPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'GET'>;
|
|
222
|
+
/**
|
|
223
|
+
* Get paths available for POST method.
|
|
224
|
+
*/
|
|
225
|
+
type PostPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'POST'>;
|
|
226
|
+
/**
|
|
227
|
+
* Get paths available for PUT method.
|
|
228
|
+
*/
|
|
229
|
+
type PutPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'PUT'>;
|
|
230
|
+
/**
|
|
231
|
+
* Get paths available for PATCH method.
|
|
232
|
+
*/
|
|
233
|
+
type PatchPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'PATCH'>;
|
|
234
|
+
/**
|
|
235
|
+
* Get paths available for DELETE method.
|
|
236
|
+
*/
|
|
237
|
+
type DeletePaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'DELETE'>;
|
|
238
|
+
/**
|
|
239
|
+
* Get paths available for HEAD method.
|
|
240
|
+
*/
|
|
241
|
+
type HeadPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'HEAD'>;
|
|
212
242
|
/**
|
|
213
243
|
* Get endpoint schema for a specific path and method.
|
|
214
244
|
*/
|
|
@@ -221,6 +251,23 @@ type SchemaMapResponseType<TSchemas extends IgniterCallerSchemaMap, TPath extend
|
|
|
221
251
|
* Infer request type from schema map for a specific path and method.
|
|
222
252
|
*/
|
|
223
253
|
type SchemaMapRequestType<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath]> = TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<infer Request, any> ? Request extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Request> : never : never;
|
|
254
|
+
/**
|
|
255
|
+
* Infer endpoint info for a specific path and method.
|
|
256
|
+
* Returns an object with response, request, and params types.
|
|
257
|
+
*/
|
|
258
|
+
type EndpointInfo<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = TPath extends keyof TSchemas ? TMethod extends keyof TSchemas[TPath] ? {
|
|
259
|
+
response: TSchemas[TPath][TMethod] 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;
|
|
260
|
+
request: TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<infer Req, any> ? Req extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Req> : never : never;
|
|
261
|
+
params: ExtractPathParams<TPath & string>;
|
|
262
|
+
} : {
|
|
263
|
+
response: unknown;
|
|
264
|
+
request: never;
|
|
265
|
+
params: Record<never, never>;
|
|
266
|
+
} : {
|
|
267
|
+
response: unknown;
|
|
268
|
+
request: never;
|
|
269
|
+
params: Record<never, never>;
|
|
270
|
+
};
|
|
224
271
|
/**
|
|
225
272
|
* Options for schema validation behavior.
|
|
226
273
|
*/
|
|
@@ -553,6 +600,19 @@ type GetEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends string,
|
|
|
553
600
|
* Returns `unknown` if the path/method is not in the schema.
|
|
554
601
|
*/
|
|
555
602
|
type InferResponse<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = InferSuccessResponse<GetEndpoint<TSchemas, TPath, TMethod>>;
|
|
603
|
+
/**
|
|
604
|
+
* Typed request builder with inferred body and params types.
|
|
605
|
+
*/
|
|
606
|
+
type TypedRequestBuilder<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = Omit<IgniterCallerMethodRequestBuilder<EndpointInfo<TSchemas, TPath, TMethod>['response']>, 'body' | 'params'> & {
|
|
607
|
+
/**
|
|
608
|
+
* Sets the request body with type inference from schema.
|
|
609
|
+
*/
|
|
610
|
+
body: EndpointInfo<TSchemas, TPath, TMethod>['request'] extends never ? <TBody>(body: TBody) => TypedRequestBuilder<TSchemas, TPath, TMethod> : (body: EndpointInfo<TSchemas, TPath, TMethod>['request']) => TypedRequestBuilder<TSchemas, TPath, TMethod>;
|
|
611
|
+
/**
|
|
612
|
+
* Sets URL path parameters with type inference from URL pattern.
|
|
613
|
+
*/
|
|
614
|
+
params: keyof EndpointInfo<TSchemas, TPath, TMethod>['params'] extends never ? (params: Record<string, string | number | boolean>) => TypedRequestBuilder<TSchemas, TPath, TMethod> : (params: EndpointInfo<TSchemas, TPath, TMethod>['params'] & Record<string, string | number | boolean>) => TypedRequestBuilder<TSchemas, TPath, TMethod>;
|
|
615
|
+
};
|
|
556
616
|
/**
|
|
557
617
|
* HTTP client runtime for Igniter.js.
|
|
558
618
|
*
|
|
@@ -605,80 +665,110 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
|
|
|
605
665
|
/**
|
|
606
666
|
* Creates a GET request.
|
|
607
667
|
*
|
|
608
|
-
* When a URL is provided and matches a schema, the response
|
|
668
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
669
|
+
* are automatically inferred from the schema definition.
|
|
609
670
|
*
|
|
610
|
-
* @param url Optional URL for the request.
|
|
671
|
+
* @param url Optional URL for the request. When provided and matching a schema path,
|
|
672
|
+
* enables full type inference for response, body, and path params.
|
|
611
673
|
*
|
|
612
674
|
* @example
|
|
613
675
|
* ```ts
|
|
614
|
-
* // With typed schema -
|
|
615
|
-
* const result = await api.get('/users')
|
|
676
|
+
* // With typed schema - full type inference
|
|
677
|
+
* const result = await api.get('/users/:id')
|
|
678
|
+
* .params({ id: '123' }) // params are typed based on URL pattern
|
|
679
|
+
* .execute()
|
|
616
680
|
* // result.data is typed based on schema
|
|
617
681
|
*
|
|
618
|
-
* // Without
|
|
682
|
+
* // Without URL (set later with .url())
|
|
619
683
|
* const result = await api.get().url('/users').execute()
|
|
620
684
|
* ```
|
|
621
685
|
*/
|
|
686
|
+
get<TPath extends GetPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'GET'>;
|
|
622
687
|
get<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'GET'>>;
|
|
623
688
|
/**
|
|
624
689
|
* Creates a POST request.
|
|
625
690
|
*
|
|
626
691
|
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
692
|
+
/**
|
|
693
|
+
* Creates a POST request.
|
|
694
|
+
*
|
|
695
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
696
|
+
* are automatically inferred from the schema definition.
|
|
627
697
|
*
|
|
628
|
-
* @param url Optional URL for the request.
|
|
698
|
+
* @param url Optional URL for the request.
|
|
629
699
|
*
|
|
630
700
|
* @example
|
|
631
701
|
* ```ts
|
|
632
|
-
*
|
|
702
|
+
* // With typed schema - body type is inferred from schema
|
|
703
|
+
* const result = await api.post('/users')
|
|
704
|
+
* .body({ name: 'John', email: 'john@example.com' }) // body is typed
|
|
705
|
+
* .execute()
|
|
633
706
|
* ```
|
|
634
707
|
*/
|
|
708
|
+
post<TPath extends PostPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'POST'>;
|
|
635
709
|
post<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'POST'>>;
|
|
636
710
|
/**
|
|
637
711
|
* Creates a PUT request.
|
|
638
712
|
*
|
|
639
|
-
* When a URL is provided and matches a schema, the response
|
|
713
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
714
|
+
* are automatically inferred from the schema definition.
|
|
640
715
|
*
|
|
641
|
-
* @param url Optional URL for the request.
|
|
716
|
+
* @param url Optional URL for the request.
|
|
642
717
|
*
|
|
643
718
|
* @example
|
|
644
719
|
* ```ts
|
|
645
|
-
* const result = await api.put('/users
|
|
720
|
+
* const result = await api.put('/users/:id')
|
|
721
|
+
* .params({ id: '1' })
|
|
722
|
+
* .body({ name: 'Jane' })
|
|
723
|
+
* .execute()
|
|
646
724
|
* ```
|
|
647
725
|
*/
|
|
726
|
+
put<TPath extends PutPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'PUT'>;
|
|
648
727
|
put<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PUT'>>;
|
|
649
728
|
/**
|
|
650
729
|
* Creates a PATCH request.
|
|
651
730
|
*
|
|
652
|
-
* When a URL is provided and matches a schema, the response
|
|
731
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
732
|
+
* are automatically inferred from the schema definition.
|
|
653
733
|
*
|
|
654
|
-
* @param url Optional URL for the request.
|
|
734
|
+
* @param url Optional URL for the request.
|
|
655
735
|
*
|
|
656
736
|
* @example
|
|
657
737
|
* ```ts
|
|
658
|
-
* const result = await api.patch('/users
|
|
738
|
+
* const result = await api.patch('/users/:id')
|
|
739
|
+
* .params({ id: '1' })
|
|
740
|
+
* .body({ name: 'Jane' })
|
|
741
|
+
* .execute()
|
|
659
742
|
* ```
|
|
660
743
|
*/
|
|
744
|
+
patch<TPath extends PatchPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'PATCH'>;
|
|
661
745
|
patch<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PATCH'>>;
|
|
662
746
|
/**
|
|
663
747
|
* Creates a DELETE request.
|
|
664
748
|
*
|
|
665
|
-
* When a URL is provided and matches a schema, the response
|
|
749
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
750
|
+
* are automatically inferred from the schema definition.
|
|
666
751
|
*
|
|
667
|
-
* @param url Optional URL for the request.
|
|
752
|
+
* @param url Optional URL for the request.
|
|
668
753
|
*
|
|
669
754
|
* @example
|
|
670
755
|
* ```ts
|
|
671
|
-
* const result = await api.delete('/users
|
|
756
|
+
* const result = await api.delete('/users/:id')
|
|
757
|
+
* .params({ id: '1' })
|
|
758
|
+
* .execute()
|
|
672
759
|
* ```
|
|
673
760
|
*/
|
|
761
|
+
delete<TPath extends DeletePaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'DELETE'>;
|
|
674
762
|
delete<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'DELETE'>>;
|
|
675
763
|
/**
|
|
676
764
|
* Creates a HEAD request.
|
|
677
765
|
*
|
|
678
|
-
* When a URL is provided and matches a schema, the response
|
|
766
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
767
|
+
* are automatically inferred from the schema definition.
|
|
679
768
|
*
|
|
680
|
-
* @param url Optional URL for the request.
|
|
769
|
+
* @param url Optional URL for the request.
|
|
681
770
|
*/
|
|
771
|
+
head<TPath extends HeadPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'HEAD'>;
|
|
682
772
|
head<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'HEAD'>>;
|
|
683
773
|
/**
|
|
684
774
|
* Executes a request directly with all options in one object (axios-style).
|
|
@@ -1021,4 +1111,4 @@ declare class IgniterCallerUrlUtils {
|
|
|
1021
1111
|
}): string;
|
|
1022
1112
|
}
|
|
1023
1113
|
|
|
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 };
|
|
1114
|
+
export { type DeletePaths, type EndpointInfo, type ExtractPathParams, type GetPaths, type HeadPaths, 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 PatchPaths, type PathsForMethod, type PostPaths, type PutPaths, type ReplaceCallerSchema, type SchemaMapEndpoint, type SchemaMapMethods, type SchemaMapPaths, type SchemaMapRequestType, type SchemaMapResponseType, type TypedRequestBuilder };
|
package/dist/index.d.ts
CHANGED
|
@@ -209,6 +209,36 @@ type SchemaMapPaths<TSchemas extends IgniterCallerSchemaMap> = keyof TSchemas &
|
|
|
209
209
|
* Get available methods for a specific path.
|
|
210
210
|
*/
|
|
211
211
|
type SchemaMapMethods<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas> = keyof TSchemas[TPath] & IgniterCallerSchemaMethod;
|
|
212
|
+
/**
|
|
213
|
+
* Get all paths that have a specific method defined.
|
|
214
|
+
*/
|
|
215
|
+
type PathsForMethod<TSchemas extends IgniterCallerSchemaMap, TMethod extends IgniterCallerSchemaMethod> = {
|
|
216
|
+
[K in keyof TSchemas]: TMethod extends keyof TSchemas[K] ? K : never;
|
|
217
|
+
}[keyof TSchemas] & string;
|
|
218
|
+
/**
|
|
219
|
+
* Get paths available for GET method.
|
|
220
|
+
*/
|
|
221
|
+
type GetPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'GET'>;
|
|
222
|
+
/**
|
|
223
|
+
* Get paths available for POST method.
|
|
224
|
+
*/
|
|
225
|
+
type PostPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'POST'>;
|
|
226
|
+
/**
|
|
227
|
+
* Get paths available for PUT method.
|
|
228
|
+
*/
|
|
229
|
+
type PutPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'PUT'>;
|
|
230
|
+
/**
|
|
231
|
+
* Get paths available for PATCH method.
|
|
232
|
+
*/
|
|
233
|
+
type PatchPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'PATCH'>;
|
|
234
|
+
/**
|
|
235
|
+
* Get paths available for DELETE method.
|
|
236
|
+
*/
|
|
237
|
+
type DeletePaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'DELETE'>;
|
|
238
|
+
/**
|
|
239
|
+
* Get paths available for HEAD method.
|
|
240
|
+
*/
|
|
241
|
+
type HeadPaths<TSchemas extends IgniterCallerSchemaMap> = PathsForMethod<TSchemas, 'HEAD'>;
|
|
212
242
|
/**
|
|
213
243
|
* Get endpoint schema for a specific path and method.
|
|
214
244
|
*/
|
|
@@ -221,6 +251,23 @@ type SchemaMapResponseType<TSchemas extends IgniterCallerSchemaMap, TPath extend
|
|
|
221
251
|
* Infer request type from schema map for a specific path and method.
|
|
222
252
|
*/
|
|
223
253
|
type SchemaMapRequestType<TSchemas extends IgniterCallerSchemaMap, TPath extends keyof TSchemas, TMethod extends keyof TSchemas[TPath]> = TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<infer Request, any> ? Request extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Request> : never : never;
|
|
254
|
+
/**
|
|
255
|
+
* Infer endpoint info for a specific path and method.
|
|
256
|
+
* Returns an object with response, request, and params types.
|
|
257
|
+
*/
|
|
258
|
+
type EndpointInfo<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = TPath extends keyof TSchemas ? TMethod extends keyof TSchemas[TPath] ? {
|
|
259
|
+
response: TSchemas[TPath][TMethod] 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;
|
|
260
|
+
request: TSchemas[TPath][TMethod] extends IgniterCallerEndpointSchema<infer Req, any> ? Req extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Req> : never : never;
|
|
261
|
+
params: ExtractPathParams<TPath & string>;
|
|
262
|
+
} : {
|
|
263
|
+
response: unknown;
|
|
264
|
+
request: never;
|
|
265
|
+
params: Record<never, never>;
|
|
266
|
+
} : {
|
|
267
|
+
response: unknown;
|
|
268
|
+
request: never;
|
|
269
|
+
params: Record<never, never>;
|
|
270
|
+
};
|
|
224
271
|
/**
|
|
225
272
|
* Options for schema validation behavior.
|
|
226
273
|
*/
|
|
@@ -553,6 +600,19 @@ type GetEndpoint<TSchemas extends IgniterCallerSchemaMap, TPath extends string,
|
|
|
553
600
|
* Returns `unknown` if the path/method is not in the schema.
|
|
554
601
|
*/
|
|
555
602
|
type InferResponse<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = InferSuccessResponse<GetEndpoint<TSchemas, TPath, TMethod>>;
|
|
603
|
+
/**
|
|
604
|
+
* Typed request builder with inferred body and params types.
|
|
605
|
+
*/
|
|
606
|
+
type TypedRequestBuilder<TSchemas extends IgniterCallerSchemaMap, TPath extends string, TMethod extends IgniterCallerSchemaMethod> = Omit<IgniterCallerMethodRequestBuilder<EndpointInfo<TSchemas, TPath, TMethod>['response']>, 'body' | 'params'> & {
|
|
607
|
+
/**
|
|
608
|
+
* Sets the request body with type inference from schema.
|
|
609
|
+
*/
|
|
610
|
+
body: EndpointInfo<TSchemas, TPath, TMethod>['request'] extends never ? <TBody>(body: TBody) => TypedRequestBuilder<TSchemas, TPath, TMethod> : (body: EndpointInfo<TSchemas, TPath, TMethod>['request']) => TypedRequestBuilder<TSchemas, TPath, TMethod>;
|
|
611
|
+
/**
|
|
612
|
+
* Sets URL path parameters with type inference from URL pattern.
|
|
613
|
+
*/
|
|
614
|
+
params: keyof EndpointInfo<TSchemas, TPath, TMethod>['params'] extends never ? (params: Record<string, string | number | boolean>) => TypedRequestBuilder<TSchemas, TPath, TMethod> : (params: EndpointInfo<TSchemas, TPath, TMethod>['params'] & Record<string, string | number | boolean>) => TypedRequestBuilder<TSchemas, TPath, TMethod>;
|
|
615
|
+
};
|
|
556
616
|
/**
|
|
557
617
|
* HTTP client runtime for Igniter.js.
|
|
558
618
|
*
|
|
@@ -605,80 +665,110 @@ declare class IgniterCaller<TSchemas extends IgniterCallerSchemaMap = IgniterCal
|
|
|
605
665
|
/**
|
|
606
666
|
* Creates a GET request.
|
|
607
667
|
*
|
|
608
|
-
* When a URL is provided and matches a schema, the response
|
|
668
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
669
|
+
* are automatically inferred from the schema definition.
|
|
609
670
|
*
|
|
610
|
-
* @param url Optional URL for the request.
|
|
671
|
+
* @param url Optional URL for the request. When provided and matching a schema path,
|
|
672
|
+
* enables full type inference for response, body, and path params.
|
|
611
673
|
*
|
|
612
674
|
* @example
|
|
613
675
|
* ```ts
|
|
614
|
-
* // With typed schema -
|
|
615
|
-
* const result = await api.get('/users')
|
|
676
|
+
* // With typed schema - full type inference
|
|
677
|
+
* const result = await api.get('/users/:id')
|
|
678
|
+
* .params({ id: '123' }) // params are typed based on URL pattern
|
|
679
|
+
* .execute()
|
|
616
680
|
* // result.data is typed based on schema
|
|
617
681
|
*
|
|
618
|
-
* // Without
|
|
682
|
+
* // Without URL (set later with .url())
|
|
619
683
|
* const result = await api.get().url('/users').execute()
|
|
620
684
|
* ```
|
|
621
685
|
*/
|
|
686
|
+
get<TPath extends GetPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'GET'>;
|
|
622
687
|
get<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'GET'>>;
|
|
623
688
|
/**
|
|
624
689
|
* Creates a POST request.
|
|
625
690
|
*
|
|
626
691
|
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
692
|
+
/**
|
|
693
|
+
* Creates a POST request.
|
|
694
|
+
*
|
|
695
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
696
|
+
* are automatically inferred from the schema definition.
|
|
627
697
|
*
|
|
628
|
-
* @param url Optional URL for the request.
|
|
698
|
+
* @param url Optional URL for the request.
|
|
629
699
|
*
|
|
630
700
|
* @example
|
|
631
701
|
* ```ts
|
|
632
|
-
*
|
|
702
|
+
* // With typed schema - body type is inferred from schema
|
|
703
|
+
* const result = await api.post('/users')
|
|
704
|
+
* .body({ name: 'John', email: 'john@example.com' }) // body is typed
|
|
705
|
+
* .execute()
|
|
633
706
|
* ```
|
|
634
707
|
*/
|
|
708
|
+
post<TPath extends PostPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'POST'>;
|
|
635
709
|
post<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'POST'>>;
|
|
636
710
|
/**
|
|
637
711
|
* Creates a PUT request.
|
|
638
712
|
*
|
|
639
|
-
* When a URL is provided and matches a schema, the response
|
|
713
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
714
|
+
* are automatically inferred from the schema definition.
|
|
640
715
|
*
|
|
641
|
-
* @param url Optional URL for the request.
|
|
716
|
+
* @param url Optional URL for the request.
|
|
642
717
|
*
|
|
643
718
|
* @example
|
|
644
719
|
* ```ts
|
|
645
|
-
* const result = await api.put('/users
|
|
720
|
+
* const result = await api.put('/users/:id')
|
|
721
|
+
* .params({ id: '1' })
|
|
722
|
+
* .body({ name: 'Jane' })
|
|
723
|
+
* .execute()
|
|
646
724
|
* ```
|
|
647
725
|
*/
|
|
726
|
+
put<TPath extends PutPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'PUT'>;
|
|
648
727
|
put<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PUT'>>;
|
|
649
728
|
/**
|
|
650
729
|
* Creates a PATCH request.
|
|
651
730
|
*
|
|
652
|
-
* When a URL is provided and matches a schema, the response
|
|
731
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
732
|
+
* are automatically inferred from the schema definition.
|
|
653
733
|
*
|
|
654
|
-
* @param url Optional URL for the request.
|
|
734
|
+
* @param url Optional URL for the request.
|
|
655
735
|
*
|
|
656
736
|
* @example
|
|
657
737
|
* ```ts
|
|
658
|
-
* const result = await api.patch('/users
|
|
738
|
+
* const result = await api.patch('/users/:id')
|
|
739
|
+
* .params({ id: '1' })
|
|
740
|
+
* .body({ name: 'Jane' })
|
|
741
|
+
* .execute()
|
|
659
742
|
* ```
|
|
660
743
|
*/
|
|
744
|
+
patch<TPath extends PatchPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'PATCH'>;
|
|
661
745
|
patch<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'PATCH'>>;
|
|
662
746
|
/**
|
|
663
747
|
* Creates a DELETE request.
|
|
664
748
|
*
|
|
665
|
-
* When a URL is provided and matches a schema, the response
|
|
749
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
750
|
+
* are automatically inferred from the schema definition.
|
|
666
751
|
*
|
|
667
|
-
* @param url Optional URL for the request.
|
|
752
|
+
* @param url Optional URL for the request.
|
|
668
753
|
*
|
|
669
754
|
* @example
|
|
670
755
|
* ```ts
|
|
671
|
-
* const result = await api.delete('/users
|
|
756
|
+
* const result = await api.delete('/users/:id')
|
|
757
|
+
* .params({ id: '1' })
|
|
758
|
+
* .execute()
|
|
672
759
|
* ```
|
|
673
760
|
*/
|
|
761
|
+
delete<TPath extends DeletePaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'DELETE'>;
|
|
674
762
|
delete<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'DELETE'>>;
|
|
675
763
|
/**
|
|
676
764
|
* Creates a HEAD request.
|
|
677
765
|
*
|
|
678
|
-
* When a URL is provided and matches a schema, the response
|
|
766
|
+
* When a URL is provided and matches a schema, the response, body, and params types
|
|
767
|
+
* are automatically inferred from the schema definition.
|
|
679
768
|
*
|
|
680
|
-
* @param url Optional URL for the request.
|
|
769
|
+
* @param url Optional URL for the request.
|
|
681
770
|
*/
|
|
771
|
+
head<TPath extends HeadPaths<TSchemas>>(url: TPath): TypedRequestBuilder<TSchemas, TPath, 'HEAD'>;
|
|
682
772
|
head<TPath extends string>(url?: TPath): IgniterCallerTypedRequestBuilder<InferResponse<TSchemas, TPath, 'HEAD'>>;
|
|
683
773
|
/**
|
|
684
774
|
* Executes a request directly with all options in one object (axios-style).
|
|
@@ -1021,4 +1111,4 @@ declare class IgniterCallerUrlUtils {
|
|
|
1021
1111
|
}): string;
|
|
1022
1112
|
}
|
|
1023
1113
|
|
|
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 };
|
|
1114
|
+
export { type DeletePaths, type EndpointInfo, type ExtractPathParams, type GetPaths, type HeadPaths, 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 PatchPaths, type PathsForMethod, type PostPaths, type PutPaths, type ReplaceCallerSchema, type SchemaMapEndpoint, type SchemaMapMethods, type SchemaMapPaths, type SchemaMapRequestType, type SchemaMapResponseType, type TypedRequestBuilder };
|
package/dist/index.js
CHANGED
|
@@ -1316,108 +1316,36 @@ var _IgniterCaller = class _IgniterCaller {
|
|
|
1316
1316
|
}
|
|
1317
1317
|
return url;
|
|
1318
1318
|
}
|
|
1319
|
-
/**
|
|
1320
|
-
* Creates a GET request.
|
|
1321
|
-
*
|
|
1322
|
-
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1323
|
-
*
|
|
1324
|
-
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1325
|
-
*
|
|
1326
|
-
* @example
|
|
1327
|
-
* ```ts
|
|
1328
|
-
* // With typed schema - response type is inferred
|
|
1329
|
-
* const result = await api.get('/users').execute()
|
|
1330
|
-
* // result.data is typed based on schema
|
|
1331
|
-
*
|
|
1332
|
-
* // Without schema or URL set later
|
|
1333
|
-
* const result = await api.get().url('/users').execute()
|
|
1334
|
-
* ```
|
|
1335
|
-
*/
|
|
1336
1319
|
get(url) {
|
|
1337
1320
|
const builder = new IgniterCallerRequestBuilder(this.createBuilderParams());
|
|
1338
1321
|
builder._setMethod("GET");
|
|
1339
1322
|
if (url) builder._setUrl(url);
|
|
1340
1323
|
return builder;
|
|
1341
1324
|
}
|
|
1342
|
-
/**
|
|
1343
|
-
* Creates a POST request.
|
|
1344
|
-
*
|
|
1345
|
-
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1346
|
-
*
|
|
1347
|
-
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1348
|
-
*
|
|
1349
|
-
* @example
|
|
1350
|
-
* ```ts
|
|
1351
|
-
* const result = await api.post('/users').body({ name: 'John' }).execute()
|
|
1352
|
-
* ```
|
|
1353
|
-
*/
|
|
1354
1325
|
post(url) {
|
|
1355
1326
|
const builder = new IgniterCallerRequestBuilder(this.createBuilderParams());
|
|
1356
1327
|
builder._setMethod("POST");
|
|
1357
1328
|
if (url) builder._setUrl(url);
|
|
1358
1329
|
return builder;
|
|
1359
1330
|
}
|
|
1360
|
-
/**
|
|
1361
|
-
* Creates a PUT request.
|
|
1362
|
-
*
|
|
1363
|
-
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1364
|
-
*
|
|
1365
|
-
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1366
|
-
*
|
|
1367
|
-
* @example
|
|
1368
|
-
* ```ts
|
|
1369
|
-
* const result = await api.put('/users/1').body({ name: 'Jane' }).execute()
|
|
1370
|
-
* ```
|
|
1371
|
-
*/
|
|
1372
1331
|
put(url) {
|
|
1373
1332
|
const builder = new IgniterCallerRequestBuilder(this.createBuilderParams());
|
|
1374
1333
|
builder._setMethod("PUT");
|
|
1375
1334
|
if (url) builder._setUrl(url);
|
|
1376
1335
|
return builder;
|
|
1377
1336
|
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Creates a PATCH request.
|
|
1380
|
-
*
|
|
1381
|
-
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1382
|
-
*
|
|
1383
|
-
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1384
|
-
*
|
|
1385
|
-
* @example
|
|
1386
|
-
* ```ts
|
|
1387
|
-
* const result = await api.patch('/users/1').body({ name: 'Jane' }).execute()
|
|
1388
|
-
* ```
|
|
1389
|
-
*/
|
|
1390
1337
|
patch(url) {
|
|
1391
1338
|
const builder = new IgniterCallerRequestBuilder(this.createBuilderParams());
|
|
1392
1339
|
builder._setMethod("PATCH");
|
|
1393
1340
|
if (url) builder._setUrl(url);
|
|
1394
1341
|
return builder;
|
|
1395
1342
|
}
|
|
1396
|
-
/**
|
|
1397
|
-
* Creates a DELETE request.
|
|
1398
|
-
*
|
|
1399
|
-
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1400
|
-
*
|
|
1401
|
-
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1402
|
-
*
|
|
1403
|
-
* @example
|
|
1404
|
-
* ```ts
|
|
1405
|
-
* const result = await api.delete('/users/1').execute()
|
|
1406
|
-
* ```
|
|
1407
|
-
*/
|
|
1408
1343
|
delete(url) {
|
|
1409
1344
|
const builder = new IgniterCallerRequestBuilder(this.createBuilderParams());
|
|
1410
1345
|
builder._setMethod("DELETE");
|
|
1411
1346
|
if (url) builder._setUrl(url);
|
|
1412
1347
|
return builder;
|
|
1413
1348
|
}
|
|
1414
|
-
/**
|
|
1415
|
-
* Creates a HEAD request.
|
|
1416
|
-
*
|
|
1417
|
-
* When a URL is provided and matches a schema, the response type is automatically inferred.
|
|
1418
|
-
*
|
|
1419
|
-
* @param url Optional URL for the request. Can also be set via `.url()`.
|
|
1420
|
-
*/
|
|
1421
1349
|
head(url) {
|
|
1422
1350
|
const builder = new IgniterCallerRequestBuilder(this.createBuilderParams());
|
|
1423
1351
|
builder._setMethod("HEAD");
|