From 0cbfa4d47a2d14b83f3c8f0083aa64820a65fcd4 Mon Sep 17 00:00:00 2001 From: Qiaosen Huang Date: Mon, 7 Aug 2017 16:32:51 +0800 Subject: [PATCH] seperate extract methoddescription method --- package.json | 2 +- src/RestfulService.ts | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index ee571e9..6e50fa2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@t2ee/restful", - "version": "1.0.1", + "version": "1.0.2", "description": "restful", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/RestfulService.ts b/src/RestfulService.ts index a45aab6..aa07316 100644 --- a/src/RestfulService.ts +++ b/src/RestfulService.ts @@ -80,6 +80,19 @@ export default class RestfulService { } public create(service: new (...args) => T): T { + const description = this.extract(service); + return new Proxy({} as any, new RestfulClient( + description, + this._baseUrl, + this._headers, + this._params, + this._query, + this._json, + this._fields, + )); + } + + public extract(service: new (...args) => T): {[key: string]: MethodDescription} { const description: {[key: string]: MethodDescription} = {}; const methods = Metadata.get('t2ee:restful:method', service.prototype); for (const key in methods) { @@ -93,15 +106,6 @@ export default class RestfulService { type: Metadata.get(`t2ee:restful:method:${key}:type`, service.prototype) || 'json', }; } - return new Proxy({} as any, new RestfulClient( - description, - this._baseUrl, - this._headers, - this._params, - this._query, - this._json, - this._fields, - )); + return description; } - }