@r2don/nest-http-interface
Advanced tools
@@ -1,2 +0,2 @@ | ||
| import { type HttpMethod } from '../types'; | ||
| import { type HttpClientOptions, type HttpMethod } from '../types'; | ||
| export declare class HttpRequestBuilder { | ||
@@ -8,2 +8,3 @@ readonly target: object; | ||
| readonly gqlQuery?: string | undefined; | ||
| readonly options?: HttpClientOptions | undefined; | ||
| private baseUrl; | ||
@@ -14,3 +15,5 @@ private readonly pathVariableBuilder?; | ||
| private readonly payloadBuilder; | ||
| constructor(target: object, propertyKey: string, method: HttpMethod, url: string, gqlQuery?: string | undefined); | ||
| private constructor(); | ||
| static forRest(target: object, propertyKey: string, method: HttpMethod, url: string, options?: HttpClientOptions): HttpRequestBuilder; | ||
| static forGraphQL(target: object, propertyKey: string, query: string, options?: HttpClientOptions, url?: string): HttpRequestBuilder; | ||
| setBaseUrl(baseUrl: string): void; | ||
@@ -17,0 +20,0 @@ build(args: any[]): Request; |
@@ -8,3 +8,3 @@ "use strict"; | ||
| class HttpRequestBuilder { | ||
| constructor(target, propertyKey, method, url, gqlQuery) { | ||
| constructor(target, propertyKey, method, url, gqlQuery, options) { | ||
| this.target = target; | ||
@@ -15,2 +15,3 @@ this.propertyKey = propertyKey; | ||
| this.gqlQuery = gqlQuery; | ||
| this.options = options; | ||
| this.baseUrl = ''; | ||
@@ -22,2 +23,8 @@ this.pathVariableBuilder = this.getMetadata(decorators_1.PATH_VARIABLE_METADATA); | ||
| } | ||
| static forRest(target, propertyKey, method, url, options) { | ||
| return new HttpRequestBuilder(target, propertyKey, method, url, undefined, options); | ||
| } | ||
| static forGraphQL(target, propertyKey, query, options, url = '/graphql') { | ||
| return new HttpRequestBuilder(target, propertyKey, 'POST', url, query, options); | ||
| } | ||
| setBaseUrl(baseUrl) { | ||
@@ -24,0 +31,0 @@ this.baseUrl = baseUrl; |
@@ -1,2 +0,2 @@ | ||
| import { type AsyncFunction } from '../types'; | ||
| export declare function GraphQLExchange(query: string, url?: string): <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| import { type AsyncFunction, type HttpClientOptions } from '../types'; | ||
| export declare function GraphQLExchange(query: string, url?: string, options?: HttpClientOptions): <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; |
@@ -6,7 +6,7 @@ "use strict"; | ||
| const http_request_builder_1 = require("../builders/http-request.builder"); | ||
| function GraphQLExchange(query, url = '/graphql') { | ||
| function GraphQLExchange(query, url = '/graphql', options) { | ||
| return (target, propertyKey) => { | ||
| Reflect.defineMetadata(constants_1.HTTP_EXCHANGE_METADATA, new http_request_builder_1.HttpRequestBuilder(target, propertyKey, 'POST', url, query), target, propertyKey); | ||
| Reflect.defineMetadata(constants_1.HTTP_EXCHANGE_METADATA, http_request_builder_1.HttpRequestBuilder.forGraphQL(target, propertyKey, query, options, url), target, propertyKey); | ||
| }; | ||
| } | ||
| exports.GraphQLExchange = GraphQLExchange; |
@@ -1,9 +0,9 @@ | ||
| import { type AsyncFunction, type HttpMethod } from '../types'; | ||
| export declare const HttpExchange: (method: HttpMethod, url: string) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const GetExchange: (url?: string) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const PostExchange: (url?: string) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const PutExchange: (url?: string) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const DeleteExchange: (url?: string) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const PatchExchange: (url?: string) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const HeadExchange: (url?: string) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const OptionsExchange: (url?: string) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| import { type AsyncFunction, type HttpClientOptions, type HttpMethod } from '../types'; | ||
| export declare const HttpExchange: (method: HttpMethod, url: string, options?: HttpClientOptions) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const GetExchange: (url?: string, options?: HttpClientOptions) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const PostExchange: (url?: string, options?: HttpClientOptions) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const PutExchange: (url?: string, options?: HttpClientOptions) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const DeleteExchange: (url?: string, options?: HttpClientOptions) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const PatchExchange: (url?: string, options?: HttpClientOptions) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const HeadExchange: (url?: string, options?: HttpClientOptions) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; | ||
| export declare const OptionsExchange: (url?: string, options?: HttpClientOptions) => <P extends string>(target: Record<P, AsyncFunction>, propertyKey: P) => void; |
@@ -6,20 +6,20 @@ "use strict"; | ||
| const http_request_builder_1 = require("../builders/http-request.builder"); | ||
| const HttpExchange = (method, url) => (target, propertyKey) => { | ||
| Reflect.defineMetadata(constants_1.HTTP_EXCHANGE_METADATA, new http_request_builder_1.HttpRequestBuilder(target, propertyKey, method, url), target, propertyKey); | ||
| const HttpExchange = (method, url, options) => (target, propertyKey) => { | ||
| Reflect.defineMetadata(constants_1.HTTP_EXCHANGE_METADATA, http_request_builder_1.HttpRequestBuilder.forRest(target, propertyKey, method, url, options), target, propertyKey); | ||
| }; | ||
| exports.HttpExchange = HttpExchange; | ||
| /* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
| const GetExchange = (url = '') => (0, exports.HttpExchange)('GET', url); | ||
| const GetExchange = (url = '', options) => (0, exports.HttpExchange)('GET', url, options); | ||
| exports.GetExchange = GetExchange; | ||
| const PostExchange = (url = '') => (0, exports.HttpExchange)('POST', url); | ||
| const PostExchange = (url = '', options) => (0, exports.HttpExchange)('POST', url, options); | ||
| exports.PostExchange = PostExchange; | ||
| const PutExchange = (url = '') => (0, exports.HttpExchange)('PUT', url); | ||
| const PutExchange = (url = '', options) => (0, exports.HttpExchange)('PUT', url, options); | ||
| exports.PutExchange = PutExchange; | ||
| const DeleteExchange = (url = '') => (0, exports.HttpExchange)('DELETE', url); | ||
| const DeleteExchange = (url = '', options) => (0, exports.HttpExchange)('DELETE', url, options); | ||
| exports.DeleteExchange = DeleteExchange; | ||
| const PatchExchange = (url = '') => (0, exports.HttpExchange)('PATCH', url); | ||
| const PatchExchange = (url = '', options) => (0, exports.HttpExchange)('PATCH', url, options); | ||
| exports.PatchExchange = PatchExchange; | ||
| const HeadExchange = (url = '') => (0, exports.HttpExchange)('HEAD', url); | ||
| const HeadExchange = (url = '', options) => (0, exports.HttpExchange)('HEAD', url, options); | ||
| exports.HeadExchange = HeadExchange; | ||
| const OptionsExchange = (url = '') => (0, exports.HttpExchange)('OPTIONS', url); | ||
| const OptionsExchange = (url = '', options) => (0, exports.HttpExchange)('OPTIONS', url, options); | ||
| exports.OptionsExchange = OptionsExchange; |
@@ -1,6 +0,6 @@ | ||
| import { type HttpClient } from '../types'; | ||
| import { type HttpClient, type HttpClientOptions } from '../types'; | ||
| export declare class FetchHttpClient implements HttpClient { | ||
| #private; | ||
| constructor(timeout: number); | ||
| request(request: Request): Promise<Response>; | ||
| request(request: Request, options?: HttpClientOptions): Promise<Response>; | ||
| } |
@@ -30,5 +30,7 @@ "use strict"; | ||
| } | ||
| request(request) { | ||
| request(request, options) { | ||
| var _a; | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const controller = new AbortController(); | ||
| const timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : __classPrivateFieldGet(this, _FetchHttpClient_timeout, "f"); | ||
| return yield Promise.race([ | ||
@@ -38,4 +40,4 @@ fetch(request, { signal: controller.signal }), | ||
| controller.abort(); | ||
| reject(new Error(`Request Timeout: ${__classPrivateFieldGet(this, _FetchHttpClient_timeout, "f")}ms`)); | ||
| }, __classPrivateFieldGet(this, _FetchHttpClient_timeout, "f"))), | ||
| reject(new Error(`Request Timeout: ${timeout}ms`)); | ||
| }, timeout)), | ||
| ]); | ||
@@ -42,0 +44,0 @@ }); |
@@ -49,3 +49,3 @@ "use strict"; | ||
| return yield this.httpClient | ||
| .request(httpRequestBuilder.build(args)) | ||
| .request(httpRequestBuilder.build(args), httpRequestBuilder.options) | ||
| .then((response) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -52,0 +52,0 @@ if (responseBodyBuilder != null) { |
@@ -0,3 +1,5 @@ | ||
| import { type HttpInterfaceConfig } from '../http-interface.module'; | ||
| export type HttpClientOptions = Omit<HttpInterfaceConfig, 'httpClient'>; | ||
| export interface HttpClient { | ||
| request: (request: Request) => Promise<Response>; | ||
| request: (request: Request, options?: HttpClientOptions) => Promise<Response>; | ||
| } |
+1
-1
| { | ||
| "name": "@r2don/nest-http-interface", | ||
| "version": "1.1.2", | ||
| "version": "1.1.3", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "maintainers": [ |
+2
-2
@@ -82,6 +82,6 @@ <p align="center"> | ||
| - `@{HTTP Method}Exchange(path: string)`: Marks the method as an HTTP request method, with `path` being the request's | ||
| - `@{HTTP Method}Exchange(path: string, options?: HttpClientOptions)`: Marks the method as an HTTP request method, with `path` being the request's | ||
| path or full URL. | ||
| - `@GraphQLExchange(query: string, url = '/graphql')`: Marks the method as a GraphQL request method, with `query` being | ||
| - `@GraphQLExchange(query: string, url = '/graphql', options?: HttpClientOptions)`: Marks the method as a GraphQL request method, with `query` being | ||
| the GraphQL query and `url` being the GraphQL endpoint. | ||
@@ -88,0 +88,0 @@ |
50388
3.16%911
1.56%