ts-retrofit
Advanced tools
Comparing version 1.5.1 to 1.6.0
@@ -90,5 +90,14 @@ "use strict"; | ||
}; | ||
// response type | ||
if (this.__meta__[methodName].responseType) { | ||
config.responseType = this.__meta__[methodName].responseType; | ||
} | ||
// request transformer | ||
if (this.__meta__[methodName].requestTransformer) { | ||
config.transformRequest = this.__meta__[methodName].requestTransformer; | ||
} | ||
// response transformer | ||
if (this.__meta__[methodName].responseTransformer) { | ||
config.transformResponse = this.__meta__[methodName].responseTransformer; | ||
} | ||
return this._httpClient.sendRequest(config); | ||
@@ -95,0 +104,0 @@ } |
@@ -5,4 +5,4 @@ "use strict"; | ||
* Ensure the `__meta__` attribute is in the target object and `methodName` has been initialized. | ||
* @param {BaseService} target | ||
* @param {string} methodName | ||
* @param target | ||
* @param methodName | ||
*/ | ||
@@ -19,5 +19,4 @@ const ensureMeta = (target, methodName) => { | ||
* Register HTTP method and path in API method. | ||
* @param {HttpMethod} method | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param method | ||
* @param url | ||
*/ | ||
@@ -33,4 +32,3 @@ const registerMethod = (method, url) => { | ||
* GET decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -43,4 +41,3 @@ */ | ||
* POST decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -53,4 +50,3 @@ */ | ||
* PUT decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -63,4 +59,3 @@ */ | ||
* PATCH decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -73,4 +68,3 @@ */ | ||
* DELETE decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -83,4 +77,3 @@ */ | ||
* HEAD decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -92,5 +85,4 @@ */ | ||
/** | ||
* OPTIONS decorator | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* OPTIONS decorator. | ||
* @param url | ||
* @constructor | ||
@@ -103,4 +95,3 @@ */ | ||
* Set base path for API service. | ||
* @param {string} path | ||
* @return {(target: BaseService) => void} | ||
* @param path | ||
* @constructor | ||
@@ -116,4 +107,3 @@ */ | ||
* Set path parameter for API endpoint. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* @param paramName | ||
* @constructor | ||
@@ -133,4 +123,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {number} paramIndex | ||
* @param methodName | ||
* @param paramIndex | ||
* @constructor | ||
@@ -144,4 +134,3 @@ */ | ||
* Set static HTTP headers for API endpoint. | ||
* @param {Headers} headers | ||
* @return {(target: any, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param headers | ||
* @constructor | ||
@@ -160,4 +149,3 @@ */ | ||
* Set HTTP header as variable in API method. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* @param paramName | ||
* @constructor | ||
@@ -177,4 +165,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {number} paramIndex | ||
* @param methodName | ||
* @param paramIndex | ||
* @constructor | ||
@@ -188,4 +176,3 @@ */ | ||
* Set static query for API endpoint. | ||
* @param {Query} query | ||
* @return {(target: any, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param query | ||
* @constructor | ||
@@ -204,4 +191,3 @@ */ | ||
* Set query as variable in API method. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* @param paramName | ||
* @constructor | ||
@@ -221,4 +207,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {number} paramIndex | ||
* @param methodName | ||
* @param paramIndex | ||
* @constructor | ||
@@ -231,6 +217,6 @@ */ | ||
/** | ||
* 'content-type': 'application/x-www-form-urlencoded;charset=utf-8' will be added | ||
* 'content-type': 'application/x-www-form-urlencoded;charset=utf-8' will be added. | ||
* @param target | ||
* @param {string} methodName | ||
* @param {PropertyDescriptor} descriptor | ||
* @param methodName | ||
* @param descriptor | ||
* @constructor | ||
@@ -242,6 +228,4 @@ */ | ||
/** | ||
* Set field of form for API endpoint. Only effective when method has been | ||
* decorated by @FormUrlEncoded. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* Set field of form for API endpoint. Only effective when method has been decorated by @FormUrlEncoded. | ||
* @param paramName | ||
* @constructor | ||
@@ -261,4 +245,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {number} paramIndex | ||
* @param methodName | ||
* @param paramIndex | ||
* @constructor | ||
@@ -273,4 +257,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {PropertyDescriptor} descriptor | ||
* @param methodName | ||
* @param descriptor | ||
* @constructor | ||
@@ -282,6 +266,4 @@ */ | ||
/** | ||
* Set part of form data for API endpoint. Only effective when method has been | ||
* decorated by @Multipart. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* Set part of form data for API endpoint. Only effective when method has been decorated by @Multipart. | ||
* @param paramName | ||
* @constructor | ||
@@ -299,5 +281,4 @@ */ | ||
/** | ||
* Specify the response type in axios. | ||
* Set the response type for method. | ||
* @param responseType | ||
* @returns {(target:any, methodName:string, paramIndex:number)=>undefined} | ||
* @constructor | ||
@@ -311,1 +292,23 @@ */ | ||
}; | ||
/** | ||
* Set request transformer for method. | ||
* @param transformer | ||
* @constructor | ||
*/ | ||
exports.RequestTransformer = (transformer) => { | ||
return (target, methodName) => { | ||
ensureMeta(target, methodName); | ||
target.__meta__[methodName].requestTransformer = transformer; | ||
}; | ||
}; | ||
/** | ||
* Set response transformer for method. | ||
* @param transformer | ||
* @constructor | ||
*/ | ||
exports.ResponseTransformer = (transformer) => { | ||
return (target, methodName) => { | ||
ensureMeta(target, methodName); | ||
target.__meta__[methodName].responseTransformer = transformer; | ||
}; | ||
}; |
@@ -0,1 +1,2 @@ | ||
import { ResponseType as AxiosResponseType, AxiosTransformer } from "axios"; | ||
import { BaseService } from "./baseService"; | ||
@@ -8,6 +9,9 @@ interface Headers { | ||
} | ||
export interface PartDescriptor<T> { | ||
value: T; | ||
filename?: string; | ||
} | ||
/** | ||
* GET decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -18,4 +22,3 @@ */ | ||
* POST decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -26,4 +29,3 @@ */ | ||
* PUT decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -34,4 +36,3 @@ */ | ||
* PATCH decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -42,4 +43,3 @@ */ | ||
* DELETE decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -50,4 +50,3 @@ */ | ||
* HEAD decorator. | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param url | ||
* @constructor | ||
@@ -57,5 +56,4 @@ */ | ||
/** | ||
* OPTIONS decorator | ||
* @param {string} url | ||
* @return {(target: BaseService, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* OPTIONS decorator. | ||
* @param url | ||
* @constructor | ||
@@ -66,4 +64,3 @@ */ | ||
* Set base path for API service. | ||
* @param {string} path | ||
* @return {(target: BaseService) => void} | ||
* @param path | ||
* @constructor | ||
@@ -74,4 +71,3 @@ */ | ||
* Set path parameter for API endpoint. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* @param paramName | ||
* @constructor | ||
@@ -83,4 +79,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {number} paramIndex | ||
* @param methodName | ||
* @param paramIndex | ||
* @constructor | ||
@@ -91,4 +87,3 @@ */ | ||
* Set static HTTP headers for API endpoint. | ||
* @param {Headers} headers | ||
* @return {(target: any, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param headers | ||
* @constructor | ||
@@ -99,4 +94,3 @@ */ | ||
* Set HTTP header as variable in API method. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* @param paramName | ||
* @constructor | ||
@@ -108,4 +102,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {number} paramIndex | ||
* @param methodName | ||
* @param paramIndex | ||
* @constructor | ||
@@ -116,4 +110,3 @@ */ | ||
* Set static query for API endpoint. | ||
* @param {Query} query | ||
* @return {(target: any, methodName: string, descriptor: PropertyDescriptor) => void} | ||
* @param query | ||
* @constructor | ||
@@ -124,4 +117,3 @@ */ | ||
* Set query as variable in API method. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* @param paramName | ||
* @constructor | ||
@@ -133,4 +125,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {number} paramIndex | ||
* @param methodName | ||
* @param paramIndex | ||
* @constructor | ||
@@ -140,6 +132,6 @@ */ | ||
/** | ||
* 'content-type': 'application/x-www-form-urlencoded;charset=utf-8' will be added | ||
* 'content-type': 'application/x-www-form-urlencoded;charset=utf-8' will be added. | ||
* @param target | ||
* @param {string} methodName | ||
* @param {PropertyDescriptor} descriptor | ||
* @param methodName | ||
* @param descriptor | ||
* @constructor | ||
@@ -149,6 +141,4 @@ */ | ||
/** | ||
* Set field of form for API endpoint. Only effective when method has been | ||
* decorated by @FormUrlEncoded. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* Set field of form for API endpoint. Only effective when method has been decorated by @FormUrlEncoded. | ||
* @param paramName | ||
* @constructor | ||
@@ -160,4 +150,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {number} paramIndex | ||
* @param methodName | ||
* @param paramIndex | ||
* @constructor | ||
@@ -169,4 +159,4 @@ */ | ||
* @param target | ||
* @param {string} methodName | ||
* @param {PropertyDescriptor} descriptor | ||
* @param methodName | ||
* @param descriptor | ||
* @constructor | ||
@@ -176,6 +166,4 @@ */ | ||
/** | ||
* Set part of form data for API endpoint. Only effective when method has been | ||
* decorated by @Multipart. | ||
* @param {string} paramName | ||
* @return {(target: any, methodName: string, paramIndex: number) => void} | ||
* Set part of form data for API endpoint. Only effective when method has been decorated by @Multipart. | ||
* @param paramName | ||
* @constructor | ||
@@ -185,12 +173,19 @@ */ | ||
/** | ||
* Specify the response type in axios. | ||
* Set the response type for method. | ||
* @param responseType | ||
* @returns {(target:any, methodName:string, paramIndex:number)=>undefined} | ||
* @constructor | ||
*/ | ||
export declare const ResponseType: (responseType: string) => (target: any, methodName: string) => void; | ||
export interface PartDescriptor<T> { | ||
value: T; | ||
filename?: string; | ||
} | ||
export declare const ResponseType: (responseType: AxiosResponseType) => (target: any, methodName: string) => void; | ||
/** | ||
* Set request transformer for method. | ||
* @param transformer | ||
* @constructor | ||
*/ | ||
export declare const RequestTransformer: (transformer: AxiosTransformer) => (target: any, methodName: string) => void; | ||
/** | ||
* Set response transformer for method. | ||
* @param transformer | ||
* @constructor | ||
*/ | ||
export declare const ResponseTransformer: (transformer: AxiosTransformer) => (target: any, methodName: string) => void; | ||
export {}; |
{ | ||
"name": "ts-retrofit", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"description": "A declarative and axios based retrofit implementation for JavaScript and TypeScript.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/nullcc/ts-retrofit", |
@@ -173,2 +173,4 @@ # ts-retrofit | ||
| Response | @ResponseType | Specifying the response type in axios config| Method | @ResponseType("stream") | | ||
| RequestTransformer | @RequestTransformer | Specifying the request transformer in axios config| Method | @RequestTransformer((data: any, headers?: any) => { data.foo = 'foo'; return JSON.stringify(data); }) | | ||
| ResponseTransformer | @ResponseTransformer | Specifying the response transformer in axios config| Method | @ResponseTransformer((data: any, headers?: any) => { const json = JSON.parse(data); json.foo = 'foo'; return json; }) | | ||
@@ -175,0 +177,0 @@ ## Test |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1007
181
55384